diff --git a/Controller/BackendController.php b/Controller/BackendController.php index 3e0258e..00f6a27 100644 --- a/Controller/BackendController.php +++ b/Controller/BackendController.php @@ -70,7 +70,10 @@ final class BackendController extends Controller $view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1000801001, $request, $response)); $path = \str_replace('+', ' ', (string) ($request->getData('path') ?? '/')); - $surveys = SurveyTemplateMapper::with('language', $response->getLanguage())::getByVirtualPath($path); + $surveys = SurveyTemplateMapper::getByVirtualPath($path) + ->where('tags/title/language', $response->getLanguage()) + ->where('l11n/language', $response->getLanguage()) + ->execute(); list($collection, $parent) = CollectionMapper::getCollectionsByPath($path); @@ -122,7 +125,21 @@ final class BackendController extends Controller $view->setTemplate('/Modules/Surveys/Theme/Backend/surveys-create'); $view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1000801001, $request, $response)); - $survey = SurveyTemplateMapper::get($request->getData('id')); + $survey = SurveyTemplateMapper::get() + ->with('createdBy') + ->with('elements') + ->with('elements/l11n') + ->with('elements/labels') + ->with('media') + ->with('l11n') + ->with('tags') + ->with('tags/title') + ->where('id', $request->getData('id')) + ->where('tags/title/language', $response->getLanguage()) + ->where('l11n/language', $response->getLanguage()) + ->where('elements/l11n/language', $response->getLanguage()) + ->where('elements/labels/language', $response->getLanguage()) + ->execute(); $view->addData('survey', $survey); return $view; diff --git a/Models/SurveyTemplateElementL11nMapper.php b/Models/SurveyTemplateElementL11nMapper.php index a521cce..d2dd4fb 100644 --- a/Models/SurveyTemplateElementL11nMapper.php +++ b/Models/SurveyTemplateElementL11nMapper.php @@ -14,7 +14,7 @@ declare(strict_types=1); namespace Modules\Surveys\Models; -use phpOMS\DataStorage\Database\DataMapperAbstract; +use phpOMS\DataStorage\Database\Mapper\DataMapperFactory; /** * Tag mapper class. @@ -24,7 +24,7 @@ use phpOMS\DataStorage\Database\DataMapperAbstract; * @link https://orange-management.org * @since 1.0.0 */ -final class SurveyTemplateElementL11nMapper extends DataMapperAbstract +final class SurveyTemplateElementL11nMapper extends DataMapperFactory { /** * Columns. @@ -32,7 +32,7 @@ final class SurveyTemplateElementL11nMapper extends DataMapperAbstract * @var array * @since 1.0.0 */ - protected static array $columns = [ + public const COLUMNS = [ 'survey_template_element_l11n_id' => ['name' => 'survey_template_element_l11n_id', 'type' => 'int', 'internal' => 'id'], 'survey_template_element_l11n_text' => ['name' => 'survey_template_element_l11n_text', 'type' => 'string', 'internal' => 'text', 'autocomplete' => true], 'survey_template_element_l11n_description' => ['name' => 'survey_template_element_l11n_description', 'type' => 'string', 'internal' => 'description'], @@ -47,7 +47,7 @@ final class SurveyTemplateElementL11nMapper extends DataMapperAbstract * @var string * @since 1.0.0 */ - protected static string $table = 'survey_template_element_l11n'; + public const TABLE = 'survey_template_element_l11n'; /** * Primary field name. @@ -55,5 +55,5 @@ final class SurveyTemplateElementL11nMapper extends DataMapperAbstract * @var string * @since 1.0.0 */ - protected static string $primaryField = 'survey_template_element_l11n_id'; + public const PRIMARYFIELD ='survey_template_element_l11n_id'; } diff --git a/Models/SurveyTemplateElementMapper.php b/Models/SurveyTemplateElementMapper.php index 9429998..6a55633 100644 --- a/Models/SurveyTemplateElementMapper.php +++ b/Models/SurveyTemplateElementMapper.php @@ -14,7 +14,7 @@ declare(strict_types=1); namespace Modules\Surveys\Models; -use phpOMS\DataStorage\Database\DataMapperAbstract; +use phpOMS\DataStorage\Database\Mapper\DataMapperFactory; /** * Mapper class. @@ -24,7 +24,7 @@ use phpOMS\DataStorage\Database\DataMapperAbstract; * @link https://orange-management.org * @since 1.0.0 */ -final class SurveyTemplateElementMapper extends DataMapperAbstract +final class SurveyTemplateElementMapper extends DataMapperFactory { /** * Columns. @@ -32,7 +32,7 @@ final class SurveyTemplateElementMapper extends DataMapperAbstract * @var array * @since 1.0.0 */ - protected static array $columns = [ + public const COLUMNS = [ 'survey_template_element_id' => ['name' => 'survey_template_element_id', 'type' => 'int', 'internal' => 'id'], 'survey_template_element_type' => ['name' => 'survey_template_element_type', 'type' => 'int', 'internal' => 'type'], 'survey_template_element_order' => ['name' => 'survey_template_element_order', 'type' => 'int', 'internal' => 'order'], @@ -47,19 +47,17 @@ final class SurveyTemplateElementMapper extends DataMapperAbstract * @var array * @since 1.0.0 */ - protected static array $hasMany = [ + public const HAS_MANY = [ 'l11n' => [ 'mapper' => SurveyTemplateElementL11nMapper::class, 'table' => 'survey_template_element_l11n', 'self' => 'survey_template_element_l11n_element', - 'conditional' => true, 'external' => null, ], 'labels' => [ 'mapper' => SurveyTemplateLabelL11nMapper::class, 'table' => 'survey_template_element_label_l11n', 'self' => 'survey_template_element_label_l11n_element', - 'conditional' => true, 'external' => null, ], ]; @@ -70,7 +68,7 @@ final class SurveyTemplateElementMapper extends DataMapperAbstract * @var string * @since 1.0.0 */ - protected static string $table = 'survey_template_element'; + public const TABLE = 'survey_template_element'; /** * Created at. @@ -78,7 +76,7 @@ final class SurveyTemplateElementMapper extends DataMapperAbstract * @var string * @since 1.0.0 */ - protected static string $createdAt = 'survey_template_element_created_at'; + public const CREATED_AT = 'survey_template_element_created_at'; /** * Primary field name. @@ -86,5 +84,5 @@ final class SurveyTemplateElementMapper extends DataMapperAbstract * @var string * @since 1.0.0 */ - protected static string $primaryField = 'survey_template_element_id'; + public const PRIMARYFIELD ='survey_template_element_id'; } diff --git a/Models/SurveyTemplateL11nMapper.php b/Models/SurveyTemplateL11nMapper.php index 7366712..1f06b4b 100644 --- a/Models/SurveyTemplateL11nMapper.php +++ b/Models/SurveyTemplateL11nMapper.php @@ -14,7 +14,7 @@ declare(strict_types=1); namespace Modules\Surveys\Models; -use phpOMS\DataStorage\Database\DataMapperAbstract; +use phpOMS\DataStorage\Database\Mapper\DataMapperFactory; /** * Tag mapper class. @@ -24,7 +24,7 @@ use phpOMS\DataStorage\Database\DataMapperAbstract; * @link https://orange-management.org * @since 1.0.0 */ -final class SurveyTemplateL11nMapper extends DataMapperAbstract +final class SurveyTemplateL11nMapper extends DataMapperFactory { /** * Columns. @@ -32,7 +32,7 @@ final class SurveyTemplateL11nMapper extends DataMapperAbstract * @var array * @since 1.0.0 */ - protected static array $columns = [ + public const COLUMNS = [ 'survey_template_l11n_id' => ['name' => 'survey_template_l11n_id', 'type' => 'int', 'internal' => 'id'], 'survey_template_l11n_title' => ['name' => 'survey_template_l11n_title', 'type' => 'string', 'internal' => 'title', 'autocomplete' => true], 'survey_template_l11n_description' => ['name' => 'survey_template_l11n_description', 'type' => 'string', 'internal' => 'description'], @@ -47,7 +47,7 @@ final class SurveyTemplateL11nMapper extends DataMapperAbstract * @var string * @since 1.0.0 */ - protected static string $table = 'survey_template_l11n'; + public const TABLE = 'survey_template_l11n'; /** * Primary field name. @@ -55,5 +55,5 @@ final class SurveyTemplateL11nMapper extends DataMapperAbstract * @var string * @since 1.0.0 */ - protected static string $primaryField = 'survey_template_l11n_id'; + public const PRIMARYFIELD ='survey_template_l11n_id'; } diff --git a/Models/SurveyTemplateLabelL11nMapper.php b/Models/SurveyTemplateLabelL11nMapper.php index 1aafb41..fc9ca4d 100644 --- a/Models/SurveyTemplateLabelL11nMapper.php +++ b/Models/SurveyTemplateLabelL11nMapper.php @@ -14,7 +14,7 @@ declare(strict_types=1); namespace Modules\Surveys\Models; -use phpOMS\DataStorage\Database\DataMapperAbstract; +use phpOMS\DataStorage\Database\Mapper\DataMapperFactory; /** * Tag mapper class. @@ -24,7 +24,7 @@ use phpOMS\DataStorage\Database\DataMapperAbstract; * @link https://orange-management.org * @since 1.0.0 */ -final class SurveyTemplateLabelL11nMapper extends DataMapperAbstract +final class SurveyTemplateLabelL11nMapper extends DataMapperFactory { /** * Columns. @@ -32,7 +32,7 @@ final class SurveyTemplateLabelL11nMapper extends DataMapperAbstract * @var array * @since 1.0.0 */ - protected static array $columns = [ + public const COLUMNS = [ 'survey_template_element_label_l11n_id' => ['name' => 'survey_template_element_label_l11n_id', 'type' => 'int', 'internal' => 'id'], 'survey_template_element_label_l11n_title' => ['name' => 'survey_template_element_label_l11n_title', 'type' => 'string', 'internal' => 'title', 'autocomplete' => true], 'survey_template_element_label_l11n_element' => ['name' => 'survey_template_element_label_l11n_element', 'type' => 'int', 'internal' => 'element'], @@ -46,7 +46,7 @@ final class SurveyTemplateLabelL11nMapper extends DataMapperAbstract * @var string * @since 1.0.0 */ - protected static string $table = 'survey_template_element_label_l11n'; + public const TABLE = 'survey_template_element_label_l11n'; /** * Primary field name. @@ -54,5 +54,5 @@ final class SurveyTemplateLabelL11nMapper extends DataMapperAbstract * @var string * @since 1.0.0 */ - protected static string $primaryField = 'survey_template_element_label_l11n_id'; + public const PRIMARYFIELD ='survey_template_element_label_l11n_id'; } diff --git a/Models/SurveyTemplateMapper.php b/Models/SurveyTemplateMapper.php index 8ecee8a..fc02844 100644 --- a/Models/SurveyTemplateMapper.php +++ b/Models/SurveyTemplateMapper.php @@ -17,8 +17,8 @@ namespace Modules\Surveys\Models; use Modules\Admin\Models\AccountMapper; use Modules\Media\Models\MediaMapper; use Modules\Tag\Models\TagMapper; -use phpOMS\DataStorage\Database\DataMapperAbstract; -use phpOMS\DataStorage\Database\RelationType; +use phpOMS\DataStorage\Database\Mapper\DataMapperFactory; +use phpOMS\DataStorage\Database\Mapper\ReadMapper; /** * Mapper class. @@ -28,7 +28,7 @@ use phpOMS\DataStorage\Database\RelationType; * @link https://orange-management.org * @since 1.0.0 */ -final class SurveyTemplateMapper extends DataMapperAbstract +final class SurveyTemplateMapper extends DataMapperFactory { /** * Columns. @@ -36,7 +36,7 @@ final class SurveyTemplateMapper extends DataMapperAbstract * @var array * @since 1.0.0 */ - protected static array $columns = [ + public const COLUMNS = [ 'survey_template_id' => ['name' => 'survey_template_id', 'type' => 'int', 'internal' => 'id'], 'survey_template_status' => ['name' => 'survey_template_status', 'type' => 'int', 'internal' => 'status'], 'survey_template_public_result' => ['name' => 'survey_template_public_result', 'type' => 'bool', 'internal' => 'hasPublicResult'], @@ -53,7 +53,7 @@ final class SurveyTemplateMapper extends DataMapperAbstract * @var array * @since 1.0.0 */ - protected static array $hasMany = [ + public const HAS_MANY = [ 'elements' => [ 'mapper' => SurveyTemplateElementMapper::class, 'table' => 'survey_template_element', @@ -64,7 +64,6 @@ final class SurveyTemplateMapper extends DataMapperAbstract 'mapper' => SurveyTemplateL11nMapper::class, 'table' => 'survey_template_l11n', 'self' => 'survey_template_l11n_template', - 'conditional' => true, 'external' => null, ], 'tags' => [ @@ -87,7 +86,7 @@ final class SurveyTemplateMapper extends DataMapperAbstract * @var array * @since 1.0.0 */ - protected static array $belongsTo = [ + public const BELONGS_TO = [ 'createdBy' => [ 'mapper' => AccountMapper::class, 'external' => 'survey_template_created_by', @@ -100,7 +99,7 @@ final class SurveyTemplateMapper extends DataMapperAbstract * @var string * @since 1.0.0 */ - protected static string $table = 'survey_template'; + public const TABLE = 'survey_template'; /** * Created at. @@ -108,7 +107,7 @@ final class SurveyTemplateMapper extends DataMapperAbstract * @var string * @since 1.0.0 */ - protected static string $createdAt = 'survey_template_created_at'; + public const CREATED_AT = 'survey_template_created_at'; /** * Primary field name. @@ -116,23 +115,24 @@ final class SurveyTemplateMapper extends DataMapperAbstract * @var string * @since 1.0.0 */ - protected static string $primaryField = 'survey_template_id'; + public const PRIMARYFIELD ='survey_template_id'; /** * Get editor doc based on virtual path. * * @param string $virtualPath Virtual path * - * @return array + * @return ReadMapper * * @since 1.0.0 */ - public static function getByVirtualPath(string $virtualPath = '/') : array + public static function getByVirtualPath(string $virtualPath = '/') : ReadMapper { - $depth = 2; - $query = self::getQuery(depth: $depth); - $query->where(self::$table . '_d' . $depth . '.survey_template_virtual', '=', $virtualPath); - - return self::getAllByQuery($query, RelationType::ALL, $depth); + return self::getAll() + ->with('createdBy') + ->with('l11n') + ->with('tags') + ->with('tags/title') + ->where('virtualPath', $virtualPath); } }