From 66f328bbb0c6fd2fd784c107c4989f1d48c33e6d Mon Sep 17 00:00:00 2001 From: Franck Allimant Date: Wed, 30 Dec 2020 14:32:19 +0100 Subject: [PATCH] Added "code" parameter to selections --- Action/SelectionAction.php | 21 ++-- Action/SelectionContainerAction.php | 30 +++-- Config/module.xml | 2 +- Config/routing.xml | 1 + Config/schema.xml | 4 +- Config/sqldb.map | 2 - Config/thelia.sql | 18 +-- Config/update/1.1.13.sql | 11 ++ Controller/ImageUploadController.php | 51 ++++----- .../SelectionContainerUpdateController.php | 12 +- Controller/SelectionController.php | 29 ++--- Controller/SelectionUpdateController.php | 26 +++-- Event/SelectionContainerEvent.php | 20 +++- Event/SelectionEvent.php | 19 ++++ Form/CreationCommonFieldsTrait.php | 47 ++++++-- Form/SelectionContainerCreateForm.php | 18 +++ Form/SelectionContainerUpdateForm.php | 52 +++++++-- Form/SelectionCreateForm.php | 16 +++ Form/SelectionUpdateForm.php | 69 ++++++++---- Hook/BackHook.php | 2 +- I18n/fr_FR.php | 2 + Loop/SelectionContainerLoop.php | 105 +++++++++++------- Loop/SelectionLoop.php | 24 +++- Readme.md | 9 +- Selection.php | 37 +++--- .../backOffice/default/container-edit.html | 1 + .../backOffice/default/selection-edit.html | 1 + .../default/selection-list-containers.html | 54 ++++----- .../default/selection-list-selections.html | 27 ++++- .../default/selectionContentRelated.html | 4 +- 30 files changed, 480 insertions(+), 234 deletions(-) delete mode 100644 Config/sqldb.map create mode 100644 Config/update/1.1.13.sql diff --git a/Action/SelectionAction.php b/Action/SelectionAction.php index 8887505..8dd287f 100644 --- a/Action/SelectionAction.php +++ b/Action/SelectionAction.php @@ -57,8 +57,8 @@ public function updateSeo( UpdateSeoEvent $event, /** @noinspection PhpUnusedParameterInspection */ $eventName, - EventDispatcherInterface $dispatcher) - { + EventDispatcherInterface $dispatcher + ) { return $this->genericUpdateSeo(SelectionQuery::create(), $event, $dispatcher); } @@ -84,7 +84,6 @@ public function delete(SelectionEvent $event) ->update(array( "View" => ConfigQuery::getObsoleteRewrittenUrlView() )); - } protected function getSelection(SelectionEvent $event) @@ -118,6 +117,10 @@ protected function createOrUpdate(SelectionEvent $event, Selection $model) $model->setId($id); } + if (null !== $code = $event->getCode()) { + $model->setCode($code); + } + if (null !== $title = $event->getTitle()) { $model->setTitle($title); } @@ -157,14 +160,14 @@ protected function updateContainerAssociatedToSelection(SelectionEvent $event, C $associationQuery = SelectionContainerAssociatedSelectionQuery::create(); $association = $associationQuery->findOneBySelectionId($event->getId()); $containerId = $event->getContainerId(); - if (empty($association)) { + if ($association === null) { if (empty($containerId)) { return; } $association = new SelectionContainerAssociatedSelection(); $association->setSelectionId($event->getId()); } else if ($association->getSelectionContainerId() === $containerId) { - return; + return; } else if (empty($containerId)) { $association->delete($con); return; @@ -202,8 +205,7 @@ public function updateProductPosition( $eventName, /** @noinspection PhpUnusedParameterInspection */ EventDispatcherInterface $dispatcher - ) - { + ) { $this->genericUpdateDelegatePosition( SelectionProductQuery::create() ->filterByProductId($event->getObjectId()) @@ -222,8 +224,7 @@ public function updatePosition( /** @noinspection PhpUnusedParameterInspection */ $eventName, EventDispatcherInterface $dispatcher - ) - { + ) { $modelCriteria = SelectionQuery::create()->filterById($event->getObjectId()); $this->genericUpdateDelegatePosition( $modelCriteria, @@ -271,4 +272,4 @@ public static function getSubscribedEvents() SelectionEvents::RELATED_PRODUCT_UPDATE_POSITION => array("updateProductPosition", 128), ); } -} \ No newline at end of file +} diff --git a/Action/SelectionContainerAction.php b/Action/SelectionContainerAction.php index 87d3f67..7a18306 100644 --- a/Action/SelectionContainerAction.php +++ b/Action/SelectionContainerAction.php @@ -8,7 +8,6 @@ namespace Selection\Action; - use Propel\Runtime\ActiveQuery\ModelCriteria; use Propel\Runtime\Propel; use Selection\Event\SelectionContainerEvent; @@ -58,8 +57,8 @@ public function updateSeo( UpdateSeoEvent $event, /** @noinspection PhpUnusedParameterInspection */ $eventName, - EventDispatcherInterface $dispatcher) - { + EventDispatcherInterface $dispatcher + ) { return $this->genericUpdateSeo(SelectionContainerQuery::create(), $event, $dispatcher); } @@ -102,6 +101,10 @@ protected function createOrUpdate(SelectionContainerEvent $event, SelectionConta $model->setId($id); } + if (null !== $code = $event->getCode()) { + $model->setCode($code); + } + if (null !== $title = $event->getTitle()) { $model->setTitle($title); } @@ -156,8 +159,7 @@ public function updatePosition( /** @noinspection PhpUnusedParameterInspection */ $eventName, EventDispatcherInterface $dispatcher - ) - { + ) { $modelCriteria = SelectionContainerQuery::create()->filterById($event->getObjectId()); $this->genericUpdateDelegatePosition( $modelCriteria, @@ -166,12 +168,16 @@ public function updatePosition( ); } + /** + * @param ModelCriteria $query + * @param UpdatePositionEvent $event + * @param EventDispatcherInterface|null $dispatcher + */ protected function genericUpdateDelegatePosition( ModelCriteria $query, UpdatePositionEvent $event, - EventDispatcherInterface $dispatcher = null) - { - + EventDispatcherInterface $dispatcher = null + ) { if (null !== $object = $query->findOne()) { if (!isset(class_uses($object)['Thelia\Model\Tools\PositionManagementTrait'])) { throw new \InvalidArgumentException("Your model does not implement the PositionManagementTrait trait"); @@ -183,11 +189,11 @@ protected function genericUpdateDelegatePosition( $mode = $event->getMode(); - if ($mode == UpdatePositionEvent::POSITION_ABSOLUTE) { + if ($mode === UpdatePositionEvent::POSITION_ABSOLUTE) { $object->changeAbsolutePosition($event->getPosition()); - } elseif ($mode == UpdatePositionEvent::POSITION_UP) { + } elseif ($mode === UpdatePositionEvent::POSITION_UP) { $object->movePositionUp(); - } elseif ($mode == UpdatePositionEvent::POSITION_DOWN) { + } elseif ($mode === UpdatePositionEvent::POSITION_DOWN) { $object->movePositionDown(); } } @@ -208,4 +214,4 @@ public static function getSubscribedEvents() SelectionEvents::SELECTION_CONTAINER_TOGGLE_VISIBILITY => array("toggleVisibility", 128), ); } -} \ No newline at end of file +} diff --git a/Config/module.xml b/Config/module.xml index 7d481d4..75e7031 100644 --- a/Config/module.xml +++ b/Config/module.xml @@ -13,7 +13,7 @@ en_US fr_FR - 1.1.12 + 1.1.13 Maxime BRUCHET diff --git a/Config/routing.xml b/Config/routing.xml index fd7efea..8c0261c 100644 --- a/Config/routing.xml +++ b/Config/routing.xml @@ -6,6 +6,7 @@ xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd"> + Selection\Controller\SelectionController::viewAction diff --git a/Config/schema.xml b/Config/schema.xml index b1195cd..4b94538 100644 --- a/Config/schema.xml +++ b/Config/schema.xml @@ -1,11 +1,12 @@ + xsi:noNamespaceSchemaLocation="../../../../core/vendor/thelia/propel/resources/xsd/database.xsd" > + @@ -72,6 +73,7 @@
+ diff --git a/Config/sqldb.map b/Config/sqldb.map deleted file mode 100644 index 63a93ba..0000000 --- a/Config/sqldb.map +++ /dev/null @@ -1,2 +0,0 @@ -# Sqlfile -> Database map -thelia.sql=thelia diff --git a/Config/thelia.sql b/Config/thelia.sql index 924ed2c..808c036 100644 --- a/Config/thelia.sql +++ b/Config/thelia.sql @@ -13,6 +13,7 @@ CREATE TABLE `selection` ( `id` INTEGER NOT NULL AUTO_INCREMENT, `visible` TINYINT NOT NULL, + `code` VARCHAR(255), `position` INTEGER, `created_at` DATETIME, `updated_at` DATETIME, @@ -33,7 +34,7 @@ CREATE TABLE `selection_product` `created_at` DATETIME, `updated_at` DATETIME, PRIMARY KEY (`selection_id`,`product_id`), - INDEX `FI_selection_product_product_id` (`product_id`), + INDEX `fi_selection_product_product_id` (`product_id`), CONSTRAINT `fk_selection_product_product_id` FOREIGN KEY (`product_id`) REFERENCES `product` (`id`) @@ -60,7 +61,7 @@ CREATE TABLE `selection_content` `created_at` DATETIME, `updated_at` DATETIME, PRIMARY KEY (`selection_id`,`content_id`), - INDEX `FI_selection_content_content_id` (`content_id`), + INDEX `fi_selection_content_content_id` (`content_id`), CONSTRAINT `fk_selection_content_content_id` FOREIGN KEY (`content_id`) REFERENCES `content` (`id`) @@ -89,7 +90,7 @@ CREATE TABLE `selection_image` `created_at` DATETIME, `updated_at` DATETIME, PRIMARY KEY (`id`), - INDEX `FI_selection_image_selection_id` (`selection_id`), + INDEX `fi_selection_image_selection_id` (`selection_id`), CONSTRAINT `fk_selection_image_selection_id` FOREIGN KEY (`selection_id`) REFERENCES `selection` (`id`) @@ -107,6 +108,7 @@ CREATE TABLE `selection_container` ( `id` INTEGER NOT NULL AUTO_INCREMENT, `visible` TINYINT NOT NULL, + `code` VARCHAR(255), `position` INTEGER, `created_at` DATETIME, `updated_at` DATETIME, @@ -157,7 +159,7 @@ CREATE TABLE `selection_container_image` `created_at` DATETIME, `updated_at` DATETIME, PRIMARY KEY (`id`), - INDEX `FI_selection_container_image_selection_id` (`selection_container_id`), + INDEX `fi_selection_container_image_selection_id` (`selection_container_id`), CONSTRAINT `fk_selection_container_image_selection_id` FOREIGN KEY (`selection_container_id`) REFERENCES `selection_container` (`id`) @@ -183,7 +185,7 @@ CREATE TABLE `selection_i18n` `meta_description` TEXT, `meta_keywords` TEXT, PRIMARY KEY (`id`,`locale`), - CONSTRAINT `selection_i18n_FK_1` + CONSTRAINT `selection_i18n_fk_765b89` FOREIGN KEY (`id`) REFERENCES `selection` (`id`) ON DELETE CASCADE @@ -204,7 +206,7 @@ CREATE TABLE `selection_image_i18n` `chapo` TEXT, `postscriptum` TEXT, PRIMARY KEY (`id`,`locale`), - CONSTRAINT `selection_image_i18n_FK_1` + CONSTRAINT `selection_image_i18n_fk_d501a8` FOREIGN KEY (`id`) REFERENCES `selection_image` (`id`) ON DELETE CASCADE @@ -228,7 +230,7 @@ CREATE TABLE `selection_container_i18n` `meta_description` TEXT, `meta_keywords` TEXT, PRIMARY KEY (`id`,`locale`), - CONSTRAINT `selection_container_i18n_FK_1` + CONSTRAINT `selection_container_i18n_fk_25b287` FOREIGN KEY (`id`) REFERENCES `selection_container` (`id`) ON DELETE CASCADE @@ -249,7 +251,7 @@ CREATE TABLE `selection_container_image_i18n` `chapo` TEXT, `postscriptum` TEXT, PRIMARY KEY (`id`,`locale`), - CONSTRAINT `selection_container_image_i18n_FK_1` + CONSTRAINT `selection_container_image_i18n_fk_eed190` FOREIGN KEY (`id`) REFERENCES `selection_container_image` (`id`) ON DELETE CASCADE diff --git a/Config/update/1.1.13.sql b/Config/update/1.1.13.sql new file mode 100644 index 0000000..9b8db58 --- /dev/null +++ b/Config/update/1.1.13.sql @@ -0,0 +1,11 @@ +SET FOREIGN_KEY_CHECKS = 0; + +-- Add the 'code' column to the selection tables. +ALTER TABLE `selection` ADD `code` varchar(255) NOT NULL AFTER `visible`; +ALTER TABLE `selection_container` ADD `code` varchar(255) NOT NULL AFTER `visible`; + +-- Generate a pseudo-code for each existing selection +UPDATE `selection` set `code` = CONCAT('selection_', id); +UPDATE `selection_container` set `code` = CONCAT('container_', id); + +SET FOREIGN_KEY_CHECKS = 1; diff --git a/Controller/ImageUploadController.php b/Controller/ImageUploadController.php index 02905e0..8610508 100644 --- a/Controller/ImageUploadController.php +++ b/Controller/ImageUploadController.php @@ -67,8 +67,7 @@ public function updateImageTitleAction($imageId, $parentType) $this->addModuleResource($parentType); $parentId = $this->getRequest()->get('parentId'); $this->registerFileModel($parentType); - if (null !== $response = $this->checkAccessForType(AccessManager::UPDATE, $parentType)) - { + if (null !== $response = $this->checkAccessForType(AccessManager::UPDATE, $parentType)) { return $response; } @@ -170,19 +169,15 @@ public function saveFileAjaxAction( ) { $this->addModuleResource($parentType); $this->registerFileModel($parentType); - if (null !== $response = $this->checkAccessForType(AccessManager::UPDATE, $parentType)) - { + if (null !== $response = $this->checkAccessForType(AccessManager::UPDATE, $parentType)) { return $response; } $this->checkXmlHttpRequest(); - if ($this->getRequest()->isMethod('POST')) - { + if ($this->getRequest()->isMethod('POST')) { /** @var UploadedFile $fileBeingUploaded */ $fileBeingUploaded = $this->getRequest()->files->get('file'); - try - { - if (null !== $fileBeingUploaded) - { + try { + if (null !== $fileBeingUploaded) { $this->processFile( $fileBeingUploaded, $parentId, @@ -192,8 +187,7 @@ public function saveFileAjaxAction( $extBlackList ); } - } catch (ProcessFileException $e) - { + } catch (ProcessFileException $e) { return new ResponseRest($e->getMessage(), 'text', $e->getCode()); } return $this->getImagetTypeUpdateRedirectionUrl($parentType, $parentId); @@ -212,8 +206,7 @@ public function viewImageAction($imageId, $parentType) { $this->addModuleResource($parentType); $this->registerFileModel($parentType); - if (null !== $response = $this->checkAccessForType(AccessManager::UPDATE, $parentType)) - { + if (null !== $response = $this->checkAccessForType(AccessManager::UPDATE, $parentType)) { return $response; } $fileManager = $this->getFileManager(); @@ -315,7 +308,8 @@ protected function updateFileAction($fileId, $parentType, $objectType, $eventNam $fileUpdated = $event->getModel(); - $this->adminUpadteLogAppend($parentType, + $this->adminUpadteLogAppend( + $parentType, sprintf( '%s with Ref %s (ID %d) modified', ucfirst($objectType), @@ -327,7 +321,7 @@ protected function updateFileAction($fileId, $parentType, $objectType, $eventNam } catch (FormValidationException $e) { $message = sprintf('Please check your input: %s', $e->getMessage()); } catch (\Exception $e) { - $message = sprintf('Sorry, an error occurred: %s', $e->getMessage().' '.$e->getFile()); + $message = sprintf('Sorry, an error occurred: %s', $e->getMessage() . ' ' . $e->getFile()); } if ($message !== false) { @@ -339,7 +333,7 @@ protected function updateFileAction($fileId, $parentType, $objectType, $eventNam ->addForm($fileUpdateForm) ->setGeneralError($message); } - if ($this->getRequest()->get('save_mode') == 'close') { + if ($this->getRequest()->get('save_mode') === 'close') { return $this->generateRedirect( URL::getInstance()->absoluteUrl($file->getRedirectionUrl(), ['current_tab' => 'images']) ); @@ -356,8 +350,7 @@ protected function updateFileAction($fileId, $parentType, $objectType, $eventNam public function updateImageAction($imageId, $parentType) { $this->addModuleResource($parentType); - if (null !== $response = $this->checkAccessForType(AccessManager::UPDATE, $parentType)) - { + if (null !== $response = $this->checkAccessForType(AccessManager::UPDATE, $parentType)) { return $response; } $this->registerFileModel($parentType); @@ -399,14 +392,14 @@ public function toggleVisibilityFileAction($documentId, $parentType, $objectType } catch (\Exception $e) { $message = $this->getTranslator()->trans( 'Fail to update %type% visibility: %err%', - [ '%type%' => $objectType, '%err%' => $e->getMessage() ] + ['%type%' => $objectType, '%err%' => $e->getMessage()] ); } if (null === $message) { $message = $this->getTranslator()->trans( '%type% visibility updated', - [ '%type%' => ucfirst($objectType) ] + ['%type%' => ucfirst($objectType)] ); } $this->adminUpadteLogAppend($parentType, $message, $documentId); @@ -453,14 +446,14 @@ public function updateFilePositionAction($parentType, $parentId, $objectType, $e } catch (\Exception $e) { $message = $this->getTranslator()->trans( 'Fail to update %type% position: %err%', - [ '%type%' => $objectType, '%err%' => $e->getMessage() ] + ['%type%' => $objectType, '%err%' => $e->getMessage()] ); } if (null === $message) { $message = $this->getTranslator()->trans( '%type% position updated', - [ '%type%' => ucfirst($objectType) ] + ['%type%' => ucfirst($objectType)] ); } @@ -472,7 +465,8 @@ public function updateFilePositionAction($parentType, $parentId, $objectType, $e * @param $message string * @param string|null $resourceId */ - protected function adminUpadteLogAppend($type, $message, $resourceId = null) { + protected function adminUpadteLogAppend($type, $message, $resourceId = null) + { $this->adminLogAppend( $this->getAdminResources()->getResource($type, ucfirst(Selection::DOMAIN_NAME)), AccessManager::UPDATE, @@ -485,7 +479,8 @@ protected function adminUpadteLogAppend($type, $message, $resourceId = null) { * @param string $type * @throws \Exception */ - protected function addModuleResource($type) { + protected function addModuleResource($type) + { $data = [strtoupper($type) => "admin.selection"]; $module = ucfirst(Selection::DOMAIN_NAME); /** @noinspection PhpParamsInspection */ @@ -497,7 +492,8 @@ protected function addModuleResource($type) { * @param string $type * @return mixed null if authorization is granted, or a Response object which contains the error page otherwise */ - protected function checkAccessForType($access, $type) { + protected function checkAccessForType($access, $type) + { return $this->checkAuth( $this->getAdminResources()->getResource($type, ucfirst(Selection::DOMAIN_NAME)), array(), @@ -508,7 +504,8 @@ protected function checkAccessForType($access, $type) { /** * @param string $type */ - private function registerFileModel($type) { + private function registerFileModel($type) + { $this->getFileManager()->addFileModel( 'image', $type, diff --git a/Controller/SelectionContainerUpdateController.php b/Controller/SelectionContainerUpdateController.php index c02846d..903fba1 100644 --- a/Controller/SelectionContainerUpdateController.php +++ b/Controller/SelectionContainerUpdateController.php @@ -8,17 +8,14 @@ namespace Selection\Controller; - use Propel\Runtime\ActiveQuery\Criteria; use Selection\Event\SelectionContainerEvent; use Selection\Event\SelectionEvents; use Selection\Form\SelectionCreateForm; use Selection\Model\SelectionContainer; use Selection\Model\SelectionContainerQuery; -use Selection\Selection; use Symfony\Component\HttpFoundation\RedirectResponse; use Thelia\Controller\Admin\AbstractSeoCrudController; -use Thelia\Core\Event\UpdatePositionEvent; use Thelia\Core\Security\AccessManager; use Thelia\Core\Security\Resource\AdminResources; use Thelia\Form\BaseForm; @@ -79,6 +76,7 @@ protected function hydrateObjectForm($object) 'selection_container_id'=> $object->getId(), 'id' => $object->getId(), 'locale' => $object->getLocale(), + 'selection_container_code' => $object->getCode(), 'selection_container_chapo' => $object->getChapo(), 'selection_container_title' => $object->getTitle(), 'selection_container_description' => $object->getDescription(), @@ -99,6 +97,7 @@ protected function getCreationEvent($formData) $event = new SelectionContainerEvent(); $event->setTitle($formData['title']); + $event->setCode($formData['code']); $event->setChapo($formData['chapo']); $event->setDescription($formData['description']); $event->setPostscriptum($formData['postscriptum']); @@ -118,6 +117,7 @@ protected function getUpdateEvent($formData) $event = new SelectionContainerEvent($selectionContainer); $event->setId($formData['selection_container_id']); + $event->setCode($formData['selection_container_code']); $event->setTitle($formData['selection_container_title']); $event->setChapo($formData['selection_container_chapo']); $event->setDescription($formData['selection_container_description']); @@ -213,11 +213,13 @@ protected function renderEditionTemplate() { $selectionContainerId = $this->getRequest()->get('selection_container_id'); $currentTab = $this->getRequest()->get('current_tab'); - return $this->render("container-edit", + return $this->render( + "container-edit", [ 'selection_container_id' => $selectionContainerId, 'current_tab' => $currentTab - ]); + ] + ); } /** diff --git a/Controller/SelectionController.php b/Controller/SelectionController.php index 5fc09b1..f7b02c9 100644 --- a/Controller/SelectionController.php +++ b/Controller/SelectionController.php @@ -1,4 +1,5 @@ render("selection-list", - array( + return $this->render( + "selection-list", + [ 'selection_order' => $this->getAttributeSelectionOrder(), 'selection_container_order' => $this->getAttributeContainerOrder() - )); + ] + ); } - protected function createUpdatePositionEvent($positionChangeMode, $positionValue) + private function getAttributeSelectionOrder() { - return new UpdatePositionEvent( - $this->getRequest()->get('selection_id', null), - $positionChangeMode, - $positionValue + return $this->getListOrderFromSession( + 'selection', + 'selection_order', + 'manual' ); } @@ -38,12 +41,12 @@ private function getAttributeContainerOrder() ); } - private function getAttributeSelectionOrder() + protected function createUpdatePositionEvent($positionChangeMode, $positionValue) { - return $this->getListOrderFromSession( - 'selection', - 'selection_order', - 'manual' + return new UpdatePositionEvent( + $this->getRequest()->get('selection_id', null), + $positionChangeMode, + $positionValue ); } } diff --git a/Controller/SelectionUpdateController.php b/Controller/SelectionUpdateController.php index c2df383..3851d5d 100644 --- a/Controller/SelectionUpdateController.php +++ b/Controller/SelectionUpdateController.php @@ -38,36 +38,33 @@ class SelectionUpdateController extends AbstractSeoCrudController */ public function saveSelection() { - $form = new SelectionUpdateForm($this->getRequest()); $validForm = $this->validateForm($form); $data = $validForm->getData(); $selectionID = $data['selection_id']; + $selectionCode = $data['selection_code']; $selectionTitle = $data['selection_title']; $selectionChapo = $data['selection_chapo']; $selectionDescription = $data['selection_description']; $selectionPostscriptum = $data['selection_postscriptum']; - $aSelection = SelectionI18nQuery::create() - ->filterById($selectionID) - ->filterByLocale($this->getCurrentEditionLocale()) - ->findOne(); + $aSelection = SelectionQuery::create()->findPk($selectionID); $aSelection + ->setCode($selectionCode) + ->setLocale($this->getCurrentEditionLocale()) ->setTitle($selectionTitle) ->setChapo($selectionChapo) ->setDescription($selectionDescription) - ->setPostscriptum($selectionPostscriptum); - - $aSelection->save(); + ->setPostscriptum($selectionPostscriptum) + ->save(); if ($validForm->get('save_and_close')->isClicked()) { return $this->render("electionlist"); } - return $this->generateRedirectFromRoute('selection.update', [], ['selectionId' => $selectionID], null); } @@ -77,6 +74,7 @@ public function createSelection() try { $validForm = $this->validateForm($form); $data = $validForm->getData(); + $code = $data['code']; $title = $data['title']; $chapo = $data['chapo']; $description = $data['description']; @@ -104,6 +102,7 @@ public function createSelection() ->setCreatedAt($date->format('Y-m-d H:i:s')) ->setUpdatedAt($date->format('Y-m-d H:i:s')) ->setVisible(1) + ->setCode($code) ->setPosition($position) ->setLocale($this->getCurrentEditionLocale()) ->setTitle($title) @@ -155,9 +154,9 @@ public function updateSelectionPositionAction() try { $mode = $this->getRequest()->get('mode', null); - if ($mode == 'up') { + if ($mode === 'up') { $mode = UpdatePositionEvent::POSITION_UP; - } elseif ($mode == 'down') { + } elseif ($mode === 'down') { $mode = UpdatePositionEvent::POSITION_DOWN; } else { $mode = UpdatePositionEvent::POSITION_ABSOLUTE; @@ -264,6 +263,7 @@ protected function hydrateObjectForm($selection) 'selection_container' => $container, 'id' => $selection->getId(), 'locale' => $selection->getLocale(), + 'selection_code' => $selection->getCode(), 'selection_title' => $selection->getTitle(), 'selection_chapo' => $selection->getChapo(), 'selection_description' => $selection->getDescription(), @@ -278,6 +278,7 @@ protected function getCreationEvent($formData) { $event = new SelectionEvent(); + $event->setCode($formData['code']); $event->setTitle($formData['title']); $event->setChapo($formData['chapo']); $event->setDescription($formData['description']); @@ -294,6 +295,7 @@ protected function getUpdateEvent($formData) $event->setId($formData['selection_id']); $event->setContainerId($formData['selection_container_id']); + $event->setCode($formData['selection_code']); $event->setTitle($formData['selection_title']); $event->setChapo($formData['selection_chapo']); $event->setDescription($formData['selection_description']); @@ -376,7 +378,7 @@ protected function renderEditionTemplate() protected function redirectToEditionTemplate() { - if (!$id = $this->getRequest()->get('selection_id')){ + if (!$id = $this->getRequest()->get('selection_id')) { $id = $this->getRequest()->get('admin_selection_update')['selection_id']; } diff --git a/Event/SelectionContainerEvent.php b/Event/SelectionContainerEvent.php index df6f4a7..87d3058 100644 --- a/Event/SelectionContainerEvent.php +++ b/Event/SelectionContainerEvent.php @@ -8,13 +8,13 @@ namespace Selection\Event; - use Selection\Model\SelectionContainer; use Thelia\Core\Event\ActionEvent; class SelectionContainerEvent extends ActionEvent { protected $id; + protected $code; protected $title; protected $chapo; protected $postscriptum; @@ -137,5 +137,21 @@ public function getDescription() return $this->description; } + /** + * @return mixed + */ + public function getCode() + { + return $this->code; + } -} \ No newline at end of file + /** + * @param mixed $code + * @return $this + */ + public function setCode($code) + { + $this->code = $code; + return $this; + } +} diff --git a/Event/SelectionEvent.php b/Event/SelectionEvent.php index 38fa578..0083076 100644 --- a/Event/SelectionEvent.php +++ b/Event/SelectionEvent.php @@ -11,6 +11,7 @@ class SelectionEvent extends ActionEvent /*---- GENERAL parts */ protected $id; protected $containerId; + protected $code; protected $title; protected $chapo; protected $description; @@ -191,4 +192,22 @@ public function setContainerId($containerId) { $this->containerId = $containerId; } + + /** + * @return mixed + */ + public function getCode() + { + return $this->code; + } + + /** + * @param mixed $code + * @return $this + */ + public function setCode($code) + { + $this->code = $code; + return $this; + } } diff --git a/Form/CreationCommonFieldsTrait.php b/Form/CreationCommonFieldsTrait.php index 103d4b5..8505774 100644 --- a/Form/CreationCommonFieldsTrait.php +++ b/Form/CreationCommonFieldsTrait.php @@ -20,43 +20,66 @@ protected function addCommonFields() { /** @noinspection PhpUndefinedMethodInspection */ $this->formBuilder + ->add( + 'locale', + 'hidden', + [ + 'constraints' => [ new Constraints\NotBlank() ], + 'required' => true, + ] + ) ->add( 'title', TextType::class, array( - "constraints" => array( + "constraints" => [ new Constraints\NotBlank() - ), + ], "label" => Translator::getInstance()->trans('Title', [], Selection::DOMAIN_NAME) ) ) + ->add( + 'code', + TextType::class, + array( + "constraints" => [ + new Constraints\NotBlank(), + new Constraints\Callback([ + "methods" => [ + [$this, "checkDuplicateCode"], + ] + ]), + ], + "label" => Translator::getInstance()->trans('Code', [], Selection::DOMAIN_NAME) + ) + ) ->add( 'chapo', TextareaType::class, - array( + [ 'required' => false, - "constraints" => array(), + "constraints" => [], "label" => Translator::getInstance()->trans('Summary', [], Selection::DOMAIN_NAME), - ) + ] ) ->add( 'description', TextareaType::class, - array( + [ 'required' => false, - 'attr' => array('class' => 'tinymce'), - "constraints" => array(), + 'attr' => ['class' => 'tinymce'], + "constraints" => [], "label" => Translator::getInstance()->trans('Description', [], Selection::DOMAIN_NAME), - ) + ] ) ->add( 'postscriptum', TextareaType::class, - array( + [ 'required' => false, - "constraints" => array(), + "constraints" => [], "label" => Translator::getInstance()->trans('Conclusion', [], Selection::DOMAIN_NAME), - ) + ] ); } } diff --git a/Form/SelectionContainerCreateForm.php b/Form/SelectionContainerCreateForm.php index 13067b2..4601a6e 100644 --- a/Form/SelectionContainerCreateForm.php +++ b/Form/SelectionContainerCreateForm.php @@ -9,6 +9,11 @@ namespace Selection\Form; +use Selection\Model\SelectionContainerQuery; +use Selection\Model\SelectionQuery; +use Selection\Selection; +use Symfony\Component\Validator\Context\ExecutionContextInterface; +use Thelia\Core\Translation\Translator; use Thelia\Form\BaseForm; class SelectionContainerCreateForm extends BaseForm @@ -20,6 +25,19 @@ protected function buildForm() $this->addCommonFields(); } + public function checkDuplicateCode($value, ExecutionContextInterface $context) + { + if (SelectionContainerQuery::create()->filterByCode($value)->count() > 0) { + $context->addViolation( + Translator::getInstance()->trans( + "A selection container with code %code already exists. Please enter a different code.", + ['%code' => $value], + Selection::DOMAIN_NAME + ) + ); + } + } + /** * @return string the name of the form. This name need to be unique. */ diff --git a/Form/SelectionContainerUpdateForm.php b/Form/SelectionContainerUpdateForm.php index 2c1cc9e..7b7d864 100644 --- a/Form/SelectionContainerUpdateForm.php +++ b/Form/SelectionContainerUpdateForm.php @@ -8,17 +8,18 @@ namespace Selection\Form; - -use Symfony\Component\Form\Extension\Core\Type\SubmitType; +use Propel\Runtime\ActiveQuery\Criteria; +use Selection\Model\SelectionContainerQuery; +use Selection\Selection; use Symfony\Component\Form\Extension\Core\Type\TextareaType; use Symfony\Component\Form\Extension\Core\Type\TextType; +use Symfony\Component\Validator\Constraints; +use Symfony\Component\Validator\Context\ExecutionContextInterface; use Thelia\Core\Translation\Translator; use Thelia\Form\BaseForm; -use Symfony\Component\Validator\Constraints; class SelectionContainerUpdateForm extends BaseForm { - /** * Form build for add and update a selection */ @@ -32,11 +33,26 @@ protected function buildForm() "constraints" => array( new Constraints\NotBlank() ), - "label" => Translator::getInstance()->trans('Selection reference'), + "label" => Translator::getInstance()->trans('Selection reference', [], Selection::DOMAIN_NAME), "required" => false, "read_only" => true, ) ) + ->add( + 'selection_container_code', + TextType::class, + array( + "constraints" => array( + new Constraints\NotBlank(), + new Constraints\Callback([ + "methods" => [ + [$this, "checkDuplicateCode"], + ] + ]), + ), + "label" => Translator::getInstance()->trans('Selection code', [], Selection::DOMAIN_NAME), + ) + ) ->add( 'selection_container_title', TextType::class, @@ -44,7 +60,7 @@ protected function buildForm() "constraints" => array( new Constraints\NotBlank() ), - "label" => Translator::getInstance()->trans('Title'), + "label" => Translator::getInstance()->trans('Title', [], Selection::DOMAIN_NAME), "required" => false, ) ) @@ -55,7 +71,7 @@ protected function buildForm() 'attr' => array('class' => 'tinymce'), "constraints" => array( ), - "label" =>Translator::getInstance()->trans('Summary'), + "label" =>Translator::getInstance()->trans('Summary', [], Selection::DOMAIN_NAME), "required" => false, ) ) @@ -66,7 +82,7 @@ protected function buildForm() 'attr' => array('class' => 'tinymce'), "constraints" => array( ), - "label" =>Translator::getInstance()->trans('Description'), + "label" =>Translator::getInstance()->trans('Description', [], Selection::DOMAIN_NAME), "required" => false, ) ) @@ -77,12 +93,30 @@ protected function buildForm() 'attr' => array('class' => 'tinymce'), "constraints" => array( ), - "label" => Translator::getInstance()->trans('Conclusion'), + "label" => Translator::getInstance()->trans('Conclusion', [], Selection::DOMAIN_NAME), "required" => false, ) ) ; + } + public function checkDuplicateCode($value, ExecutionContextInterface $context) + { + $data = $context->getRoot()->getData(); + + $count = SelectionContainerQuery::create() + ->filterById($data['selection_container_id'], Criteria::NOT_EQUAL) + ->filterByCode($value)->count(); + + if ($count > 0) { + $context->addViolation( + Translator::getInstance()->trans( + "A selection container with code %code already exists. Please enter a different code.", + ['%code' => $value], + Selection::DOMAIN_NAME + ) + ); + } } /** diff --git a/Form/SelectionCreateForm.php b/Form/SelectionCreateForm.php index bbb158d..6d10429 100644 --- a/Form/SelectionCreateForm.php +++ b/Form/SelectionCreateForm.php @@ -3,9 +3,13 @@ namespace Selection\Form; +use Selection\Model\SelectionQuery; +use Selection\Selection; use Symfony\Component\Form\Extension\Core\Type\HiddenType; use Symfony\Component\Form\Extension\Core\Type\NumberType; use Symfony\Component\Validator\Constraints\NotBlank; +use Symfony\Component\Validator\Context\ExecutionContextInterface; +use Thelia\Core\Translation\Translator; use Thelia\Form\BaseForm; class SelectionCreateForm extends BaseForm @@ -23,7 +27,19 @@ protected function buildForm() "required" => false ) ); + } + public function checkDuplicateCode($value, ExecutionContextInterface $context) + { + if (SelectionQuery::create()->filterByCode($value)->count() > 0) { + $context->addViolation( + Translator::getInstance()->trans( + "A selection with code %code already exists. Please enter a different code.", + ['%code' => $value], + Selection::DOMAIN_NAME + ) + ); + } } /** diff --git a/Form/SelectionUpdateForm.php b/Form/SelectionUpdateForm.php index f65cfb6..1037979 100644 --- a/Form/SelectionUpdateForm.php +++ b/Form/SelectionUpdateForm.php @@ -2,8 +2,11 @@ namespace Selection\Form; +use Propel\Runtime\ActiveQuery\Criteria; use Propel\Runtime\Exception\PropelException; use Selection\Model\SelectionContainerQuery; +use Selection\Model\SelectionQuery; +use Selection\Selection; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\Extension\Core\Type\TextareaType; @@ -11,6 +14,7 @@ use Symfony\Component\Form\FormEvent; use Symfony\Component\Form\FormEvents; use Symfony\Component\Validator\Constraints; +use Symfony\Component\Validator\Context\ExecutionContextInterface; use Thelia\Core\Translation\Translator; use Thelia\Form\BaseForm; use Thelia\Log\Tlog; @@ -37,34 +41,44 @@ protected function buildForm() "constraints" => array( new Constraints\NotBlank() ), - "label" => Translator::getInstance()->trans('Selection reference'), + "label" => Translator::getInstance()->trans('Selection reference', [], Selection::DOMAIN_NAME), "required" => false, "read_only" => true, ) ) + ->add( + 'selection_code', + TextType::class, + array( + "constraints" => array( + new Constraints\NotBlank(), + new Constraints\Callback([ + "methods" => [ + [$this, "checkDuplicateCode"], + ] + ]), + ), + "label" => Translator::getInstance()->trans('Selection code', [], Selection::DOMAIN_NAME), + ) + ) ->add( 'selection_container', ChoiceType::class, [ 'choices' => $this->containersArray, -// 'placeholder' => true, //NOT WORK 'multiple' => false, 'expanded' => false, - 'choice_label' => function($key, - /** @noinspection PhpUnusedParameterInspection */ - $index, - /** @noinspection PhpUnusedParameterInspection */ - $value) { + 'choice_label' => function ($key, $index, $value) { return $key; }, - 'choice_value' => function($key) { + 'choice_value' => function ($key) { if (array_key_exists($key, $this->containersArray)) { return $this->containersArray[$key]; } return '0'; }, - "label" => Translator::getInstance()->trans('Container'), + "label" => Translator::getInstance()->trans('Container', [], Selection::DOMAIN_NAME), 'required' => false, 'empty_data' => null, ] @@ -74,7 +88,7 @@ protected function buildForm() TextType::class, [ "constraints" => [], - "label" => Translator::getInstance()->trans('Title'), + "label" => Translator::getInstance()->trans('Title', [], Selection::DOMAIN_NAME), "required" => false, ] ) @@ -84,7 +98,7 @@ protected function buildForm() array( 'attr' => array('class' => 'tinymce'), "constraints" => [], - "label" =>Translator::getInstance()->trans('Summary'), + "label" =>Translator::getInstance()->trans('Summary', [], Selection::DOMAIN_NAME), "required" => false, ) ) @@ -94,7 +108,7 @@ protected function buildForm() array( 'attr' => array('class' => 'tinymce'), "constraints" => [], - "label" =>Translator::getInstance()->trans('Description'), + "label" =>Translator::getInstance()->trans('Description', [], Selection::DOMAIN_NAME), "required" => false, ) ) @@ -104,7 +118,7 @@ protected function buildForm() array( 'attr' => array('class' => 'tinymce'), "constraints" => [], - "label" => Translator::getInstance()->trans('Conclusion'), + "label" => Translator::getInstance()->trans('Conclusion', [], Selection::DOMAIN_NAME), "required" => false, ) ); @@ -113,10 +127,9 @@ protected function buildForm() //these 2 event listeners are a hack $this->formBuilder->addEventListener( FormEvents::SUBMIT, - function (FormEvent $event) - { + function (FormEvent $event) { $data = $event->getData(); - $selectionContainerWrongValue = $data['selection_container']; + $selectionContainerWrongValue = $data['selection_container']; $selectionContainerValue = $this->containersArray[$selectionContainerWrongValue]; $data['selection_container_id'] = $selectionContainerValue; $event->setData($data); @@ -125,8 +138,7 @@ function (FormEvent $event) $this->formBuilder->addEventListener( FormEvents::PRE_SET_DATA, - function (FormEvent $event) - { + function (FormEvent $event) { $data = $event->getData(); if (!array_key_exists('selection_container', $data)) { return; @@ -136,7 +148,24 @@ function (FormEvent $event) $event->setData($data); } ); + } + + public function checkDuplicateCode($value, ExecutionContextInterface $context) + { + $data = $context->getRoot()->getData(); + + $count = SelectionQuery::create() + ->filterById($data['selection_id'], Criteria::NOT_EQUAL) + ->filterByCode($value)->count(); + if ($count > 0) { + $context->addViolation( + Translator::getInstance()->trans( + "A selection with code %code already exists. Please enter a different code.", + array('%code' => $value) + ) + ); + } } /** @@ -149,12 +178,10 @@ public function getName() private function initContainers() { - /** @noinspection PhpUndefinedMethodInspection */ - /** @noinspection PhpUndefinedFieldInspection */ $lang = $this->request->getSession() ? $this->request->getSession()->getLang(true) : $this->request->lang = Lang::getDefaultLanguage(); $containers = SelectionContainerQuery::getAll($lang); $this->containersArray = []; - $this->containersArray['-'] = null; //because placeholder is not working + $this->containersArray[Translator::getInstance()->trans('None', [], Selection::DOMAIN_NAME)] = null; //because placeholder is not working foreach ($containers as $container) { try { $this->containersArray[$container->getVirtualColumn("i18n_TITLE")] = $container->getId(); diff --git a/Hook/BackHook.php b/Hook/BackHook.php index 9db2b82..3bf4f85 100644 --- a/Hook/BackHook.php +++ b/Hook/BackHook.php @@ -26,7 +26,7 @@ public function onMainTopMenuTools(HookRenderBlockEvent $event) 'id' => 'tools_menu_selection', 'class' => '', 'url' => URL::getInstance()->absoluteUrl('/admin/selection'), - 'title' => $this->trans('Selection', [], Selection::DOMAIN_NAME) + 'title' => $this->trans('Selections', [], Selection::DOMAIN_NAME) ] ); } diff --git a/I18n/fr_FR.php b/I18n/fr_FR.php index 06027c8..3ee66a0 100644 --- a/I18n/fr_FR.php +++ b/I18n/fr_FR.php @@ -5,7 +5,9 @@ 'Container' => 'Conteneur', 'Description' => 'Description', 'Selection' => 'Sélection', + 'Selection code' => 'Code de la sélection', 'Selection reference' => 'Référence de la sélection', 'Summary' => 'Résumé', 'Title' => 'Titre', + 'Selections' => 'Séléctions', ); diff --git a/Loop/SelectionContainerLoop.php b/Loop/SelectionContainerLoop.php index 9e9b582..6c6f3de 100644 --- a/Loop/SelectionContainerLoop.php +++ b/Loop/SelectionContainerLoop.php @@ -8,7 +8,6 @@ namespace Selection\Loop; - use Propel\Runtime\ActiveQuery\Criteria; use Propel\Runtime\Exception\PropelException; use Selection\Model\Map\SelectionContainerAssociatedSelectionTableMap; @@ -27,8 +26,54 @@ use Thelia\Type\BooleanOrBothType; use Thelia\Type\TypeCollection; +/** + * Class SelectionContainerLoop + * @package Selection\Loop + * @method int[] getExclude() + * @method int[] getId() + * @method int getSelectionId() + * @method string[] getExcludeCode() + * @method string[] getCode() + * @method string getTitle() + * @method int[] getPosition() + * @method bool|string getVisible() + + */ class SelectionContainerLoop extends BaseI18nLoop implements PropelSearchLoopInterface { + /*** + * @return ArgumentCollection + */ + protected function getArgDefinitions() + { + return new ArgumentCollection( + Argument::createIntListTypeArgument('id'), + Argument::createAnyListTypeArgument('code'), + Argument::createAnyListTypeArgument('exclude_code'), + Argument::createIntTypeArgument('selection_id'), + Argument::createBooleanTypeArgument('need_selection_count'), + Argument::createBooleanOrBothTypeArgument('visible', true), + Argument::createAnyTypeArgument('title'), + Argument::createIntListTypeArgument('position'), + Argument::createIntListTypeArgument('exclude'), + new Argument( + 'order', + new TypeCollection( + new Type\EnumListType(array( + 'id', 'id_reverse', + 'code', 'code_reverse', + 'alpha', 'alpha_reverse', + 'manual', 'manual_reverse', + 'visible', 'visible_reverse', + 'created', 'created_reverse', + 'updated', 'updated_reverse', + 'random' + )) + ), + 'manual' + ) + ); + } public function buildModelCriteria() { @@ -37,22 +82,26 @@ public function buildModelCriteria() /* manage translations */ $this->configureI18nProcessing($search, array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM', 'META_TITLE', 'META_DESCRIPTION')); - /** @noinspection PhpUndefinedMethodInspection */ + if (null !== $code = $this->getCode()) { + $search->filterByCode($code, Criteria::IN); + } + + if (null !== $excludeCode = $this->getExcludeCode()) { + $search->filterByCode($excludeCode, Criteria::NOT_IN); + } + if (null !== $exclude = $this->getExclude()) { $search->filterById($exclude, Criteria::NOT_IN); } - /** @noinspection PhpUndefinedMethodInspection */ if (null !== $id = $this->getId()) { $search->filterById($id, Criteria::IN); } - /** @noinspection PhpUndefinedMethodInspection */ if (null !== $position = $this->getPosition()) { $search->filterByPosition($position, Criteria::IN); } - /** @noinspection PhpUndefinedMethodInspection */ if (null !== $title = $this->getTitle()) { //find all selections that match exactly this title and find with all locales. try { @@ -71,13 +120,11 @@ public function buildModelCriteria() } } - /** @noinspection PhpUndefinedMethodInspection */ $visible = $this->getVisible(); if (BooleanOrBothType::ANY !== $visible) { $search->filterByVisible($visible ? 1 : 0); } - /** @noinspection PhpUndefinedMethodInspection */ if (null !== $selectionId = $this->getSelectionId()) { $search->innerJoinSelectionContainerAssociatedSelection(SelectionContainerAssociatedSelectionTableMap::TABLE_NAME); $search->where(SelectionContainerAssociatedSelectionTableMap::SELECTION_ID . Criteria::EQUAL . $selectionId); @@ -94,6 +141,12 @@ public function buildModelCriteria() case "id_reverse": $search->orderById(Criteria::DESC); break; + case "code": + $search->orderByCode(Criteria::ASC); + break; + case "code_reverse": + $search->orderByCode(Criteria::DESC); + break; case "alpha": $search->addAscendingOrderByColumn('i18n_TITLE'); break; @@ -147,11 +200,13 @@ public function parseResults(LoopResult $loopResult) $needSelectionCount = $this->getNeedSelectionCount() === null || !$this->getNeedSelectionCount(); /** @var SelectionContainer $selectionContainer */ foreach ($loopResult->getResultDataCollection() as $selectionContainer) { - $loopResultRow = new LoopResultRow($selectionContainer); + $loopResultRow = new LoopResultRow($selectionContainer); + /** @noinspection PhpUndefinedMethodInspection */ $loopResultRow ->set("SELECTION_CONTAINER_ID", $selectionContainer->getId()) ->set("SELECTION_CONTAINER_URL", $this->getReturnUrl() ? $selectionContainer->getUrl($this->locale) : null) + ->set("SELECTION_CONTAINER_CODE", $selectionContainer->getCode()) ->set("SELECTION_CONTAINER_TITLE", $selectionContainer->geti18n_TITLE()) ->set("SELECTION_CONTAINER_META_TITLE", $selectionContainer->geti18n_META_TITLE()) ->set("SELECTION_CONTAINER_POSITION", $selectionContainer->getPosition()) @@ -167,39 +222,9 @@ public function parseResults(LoopResult $loopResult) $childCount = $associatedSelectionsQuery->find()->count(); $loopResultRow->set("SELECTION_COUNT", $childCount); } + $loopResult->addRow($loopResultRow); } return $loopResult; } - - /*** - * @return ArgumentCollection - */ - protected function getArgDefinitions() - { - return new ArgumentCollection( - Argument::createIntListTypeArgument('id'), - Argument::createIntTypeArgument('selection_id'), - Argument::createBooleanTypeArgument('need_selection_count'), - Argument::createBooleanOrBothTypeArgument('visible', true), - Argument::createAnyTypeArgument('title'), - Argument::createIntListTypeArgument('position'), - Argument::createIntListTypeArgument('exclude'), - new Argument( - 'order', - new TypeCollection( - new Type\EnumListType(array( - 'id', 'id_reverse', - 'alpha', 'alpha_reverse', - 'manual', 'manual_reverse', - 'visible', 'visible_reverse', - 'created', 'created_reverse', - 'updated', 'updated_reverse', - 'random' - )) - ), - 'manual' - ) - ); - } -} \ No newline at end of file +} diff --git a/Loop/SelectionLoop.php b/Loop/SelectionLoop.php index ea23c1e..a68efc4 100644 --- a/Loop/SelectionLoop.php +++ b/Loop/SelectionLoop.php @@ -26,6 +26,8 @@ * {@inheritdoc} * @method int[] getExclude() * @method int[] getId() + * @method string[] getExcludeCode() + * @method string[] getCode() * @method string getTitle() * @method int[] getPosition() * @method bool|string getVisible() @@ -43,6 +45,8 @@ protected function getArgDefinitions() { return new ArgumentCollection( Argument::createIntListTypeArgument('id'), + Argument::createAnyListTypeArgument('code'), + Argument::createAnyListTypeArgument('exclude_code'), Argument::createIntTypeArgument('container_id'), Argument::createBooleanTypeArgument('without_container'), Argument::createBooleanOrBothTypeArgument('visible', true), @@ -54,6 +58,7 @@ protected function getArgDefinitions() new TypeCollection( new Type\EnumListType(array( 'id', 'id_reverse', + 'code', 'code_reverse', 'alpha', 'alpha_reverse', 'manual', 'manual_reverse', 'visible', 'visible_reverse', @@ -78,6 +83,14 @@ public function buildModelCriteria() /* manage translations */ $this->configureI18nProcessing($search, array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM', 'META_TITLE', 'META_DESCRIPTION')); + if (null !== $code = $this->getCode()) { + $search->filterByCode($code, Criteria::IN); + } + + if (null !== $excludeCode = $this->getExcludeCode()) { + $search->filterByCode($excludeCode, Criteria::NOT_IN); + } + if (null !== $exclude = $this->getExclude()) { $search->filterById($exclude, Criteria::NOT_IN); } @@ -135,6 +148,12 @@ public function buildModelCriteria() case "id_reverse": $search->orderById(Criteria::DESC); break; + case "code": + $search->orderByCode(Criteria::ASC); + break; + case "code_reverse": + $search->orderByCode(Criteria::DESC); + break; case "alpha": $search->addAscendingOrderByColumn('i18n_TITLE'); break; @@ -194,6 +213,7 @@ public function parseResults(LoopResult $loopResult) ->set("SELECTION_ID", $selection->getId()) ->set("SELECTION_URL", $this->getReturnUrl() ? $selection->getUrl($this->locale) : null) ->set("SELECTION_TITLE", $selection->geti18n_TITLE()) + ->set("SELECTION_CODE", $selection->getCode()) ->set("SELECTION_META_TITLE", $selection->geti18n_META_TITLE()) ->set("SELECTION_POSITION", $selection->getPosition()) ->set("SELECTION_VISIBLE", $selection->getVisible()) @@ -201,8 +221,8 @@ public function parseResults(LoopResult $loopResult) ->set("SELECTION_META_DESCRIPTION", $selection->geti18n_META_DESCRIPTION()) ->set("SELECTION_POSTSCRIPTUM", $selection->geti18n_POSTSCRIPTUM()) ->set("SELECTION_CHAPO", $selection->geti18n_CHAPO()) - ->set("SELECTION_CONTAINER_ID", $selection->getSelectionContainerAssociatedSelections() - ); + ->set("SELECTION_CONTAINER_ID", $selection->getSelectionContainerAssociatedSelections()) + ; $loopResult->addRow($loopResultRow); } diff --git a/Readme.md b/Readme.md index de9bea6..2068442 100644 --- a/Readme.md +++ b/Readme.md @@ -54,6 +54,8 @@ This loop returns a list of selections. You can use it to display the selections |Variable |Description | |--- |--- | |**id** | A string containing the IDs of all the selections you wish to display. To get the ID of the current rewritten URL, use : $app->request->get('selection_id') in your template| +|**code** | A string containing one or more codes of the selections you wish to display.| +|**exclude_code** | A string containing one or more codes of the selections you wish to exclude from the loop results.| |**title** | The title of the selection you wish to display | |**visible** | Whether your selection will be visible or not. Default : true | |**position** | The position of the selection you wish to display | @@ -68,6 +70,7 @@ This loop returns a list of selections. You can use it to display the selections |Variable |Description | |--- |--- | |**SELECTION_ID** | The ID of the current Selection | +|**SELECTION_CODE** | The code of the current Selection | |**SELECTION_TITLE** | The title of the current Selection | |**SELECTION_DESCRIPTION** | The description of the current Selection | |**SELECTION_CHAPO** | The chapo of the current Selection | @@ -82,6 +85,7 @@ This loop returns a list of selections. You can use it to display the selections {loop name="selection_list" type="selection_list" visible=true id='1,4'} This selection id : {$SELECTION_ID} This selection title : {$SELECTION_TITLE} + This selection code : {$SELECTION_CODE} This selection status : {$SELECTION_VISIBLE} This selection description : {$SELECTION_DESCRIPTION} This selection chapo : {$SELECTION_CHAPO} @@ -120,7 +124,9 @@ This loop returns a list of selections containers. You can use it to display the |Variable |Description | |--- |--- | -|**id** | A string containing the IDs of all the selections you wish to display. To get the ID of the current rewritten URL, use : $app->request->get('selection_id') in your template| +|**id** | A string containing the IDs of all the selections containers you wish to display. To get the ID of the current rewritten URL, use : $app->request->get('selection_id') in your template| +|**code** | A string containing one or more codes of the selection containers you wish to display.| +|**exclude_code** | A string containing one or more codes of the selection containers you wish to exclude from the loop results.| |**selection_id** | The selection id to find |**need_selection_count** | boolean indicating if we want to have the number of selection inside this container |**title** | The title of the selection you wish to display | @@ -136,6 +142,7 @@ This loop returns a list of selections containers. You can use it to display the |--- |--- | |**SELECTION_CONTAINER_ID** | The ID of the current container | |**SELECTION_CONTAINER_TITLE** | The title of the current container | +|**SELECTION_CONTAINER_CODE** | The code of the current container | |**SELECTION_CONTAINER_DESCRIPTION** | The description of the current container | |**SELECTION_CONTAINER_CHAPO** | The chapo of the current container | |**SELECTION_CONTAINER_POSTSCRIPTUM** | The postscriptum of the current container | diff --git a/Selection.php b/Selection.php index 9681e8a..83c301f 100644 --- a/Selection.php +++ b/Selection.php @@ -13,8 +13,8 @@ namespace Selection; use Propel\Runtime\Connection\ConnectionInterface; -use Selection\Model\SelectionImageQuery; use Selection\Model\SelectionContentQuery; +use Selection\Model\SelectionImageQuery; use Selection\Model\SelectionProductQuery; use Selection\Model\SelectionQuery; use Symfony\Component\Finder\Finder; @@ -32,33 +32,14 @@ class Selection extends BaseModule const RESOURCES_SELECTION = 'admin.selection'; const CONFIG_ALLOW_PROFILE_ID = 'admin_profile_id'; - public function preActivation(ConnectionInterface $con = null) - { - $injectSql = false; - - try { - $item = SelectionQuery::create()->findOne(); - } catch (\Exception $ex) { - // The table does not exist - $injectSql = true; - } - - if (true === $injectSql) { - $database = new Database($con); - $database->insertSql(null, [__DIR__ . '/Config/thelia.sql']); - } - - - return true; - } - + /** + * @param ConnectionInterface|null $con + * @throws \Propel\Runtime\Exception\PropelException + */ public function postActivation(ConnectionInterface $con = null) { try { SelectionQuery::create()->findOne(); - SelectionProductQuery::create()->findOne(); - SelectionImageQuery::create()->findOne(); - SelectionContentQuery::create()->findOne(); } catch (\Exception $e) { $database = new Database($con); $database->insertSql(null, [__DIR__ . '/Config/thelia.sql']); @@ -70,6 +51,10 @@ public function postActivation(ConnectionInterface $con = null) self::setConfigValue(self::CONFIG_ALLOW_PROFILE_ID, ''); } + /** + * @param ConnectionInterface|null $con + * @param false $deleteModuleData + */ public function destroy(ConnectionInterface $con = null, $deleteModuleData = false) { $database = new Database($con); @@ -94,6 +79,10 @@ public function update($currentVersion, $newVersion, ConnectionInterface $con = } } + /** + * @param $code + * @throws \Propel\Runtime\Exception\PropelException + */ protected function addRessource($code) { if (null === ResourceQuery::create()->findOneByCode($code)) { diff --git a/templates/backOffice/default/container-edit.html b/templates/backOffice/default/container-edit.html index f2004a9..890f7bc 100644 --- a/templates/backOffice/default/container-edit.html +++ b/templates/backOffice/default/container-edit.html @@ -79,6 +79,7 @@
{render_form_field field="selection_container_id"} + {render_form_field field="selection_container_code"} {render_form_field field="selection_container_title"} {render_form_field field="selection_container_chapo"} {render_form_field field="selection_container_description" extra_class="wysiwyg"} diff --git a/templates/backOffice/default/selection-edit.html b/templates/backOffice/default/selection-edit.html index 05282d9..a760c3f 100644 --- a/templates/backOffice/default/selection-edit.html +++ b/templates/backOffice/default/selection-edit.html @@ -74,6 +74,7 @@
{render_form_field field="selection_id"} + {render_form_field field="selection_code"} {render_form_field field="selection_container"} {render_form_field field="selection_title"} {render_form_field field="selection_chapo"} diff --git a/templates/backOffice/default/selection-list-containers.html b/templates/backOffice/default/selection-list-containers.html index 13b3399..0b04d80 100644 --- a/templates/backOffice/default/selection-list-containers.html +++ b/templates/backOffice/default/selection-list-containers.html @@ -16,6 +16,7 @@
+ + +
{intl l='ID' d='selection.bo.default'} {intl l="Code" d='selection.bo.default'} {intl l="Title" d='selection.bo.default'} {admin_sortable_header @@ -40,12 +41,21 @@ {/loop} + + {loop type="auth" name="can_change" role="ADMIN" resource="admin.selection"} + {$SELECTION_CONTAINER_CODE} + {/loop} + {elseloop rel="can_change"} + {$SELECTION_CONTAINER_CODE} + {/elseloop} + {loop type="auth" name="can_change" role="ADMIN" resource="admin.selection"} {$SELECTION_CONTAINER_TITLE} {/loop} {elseloop rel="can_change"} - {$SELECTION_CONTAINER_TITLE} + {$SELECTION_CONTAINER_TITLE} {/elseloop} @@ -100,33 +110,25 @@ {form name="admin.selection.container.create"} {capture "selection_container_creation_dialog"} - {form_hidden_fields form=$form} + {form_hidden_fields exclude='locale'} {render_form_field form=$form field="success_url" value="{url path='/admin/selection/'}"} - {render_form_field field="title"} - {form_field form=$form field='chapo'} -
- -
- -
-
- {/form_field} - {form_field form=$form field='description'} -
- -
- -
-
- {/form_field} - {form_field form=$form field='postscriptum'} -
- -
- -
+ {render_form_field field="code"} + {loop type="lang" name="default-lang" default_only=1} + {* Switch edition to the current locale *} + + + {render_form_field field="locale" value=$LOCALE} + + {custom_render_form_field field="title"} +
+ + {$TITLE}
- {/form_field} + {/custom_render_form_field} + {/loop} + {render_form_field field='chapo'} + {render_form_field field='description' extra_class='wysiwyg'} + {render_form_field field='postscriptum'} {/capture} {include file = "includes/generic-create-dialog.html" diff --git a/templates/backOffice/default/selection-list-selections.html b/templates/backOffice/default/selection-list-selections.html index c8a53bc..01db9af 100644 --- a/templates/backOffice/default/selection-list-selections.html +++ b/templates/backOffice/default/selection-list-selections.html @@ -27,6 +27,7 @@
{intl l='ID' d='selection.bo.default'} {intl l="Code" d='selection.bo.default'} {intl l="Title" d='selection.bo.default'} {admin_sortable_header @@ -51,12 +52,19 @@ {/loop} + + {loop type="auth" name="can_change" role="ADMIN" resource="admin.selection"} + {$SELECTION_CODE} + {/loop} + {elseloop rel="can_change"} + {$SELECTION_CODE} + {/elseloop} {loop type="auth" name="can_change" role="ADMIN" resource="admin.selection"} {$SELECTION_TITLE} {/loop} {elseloop rel="can_change"} - {$SELECTION_TITLE} + {$SELECTION_TITLE} {/elseloop} @@ -111,8 +119,21 @@ {form name="admin.selection.create"} {capture "selection_creation_dialog"} - {form_hidden_fields form=$form} - {render_form_field field="title"} + {form_hidden_fields exclude="locale"} + {render_form_field field="code"} + {loop type="lang" name="default-lang" default_only=1} + {* Switch edition to the default locale *} + + + {render_form_field field="locale" value=$LOCALE} + + {custom_render_form_field field="title"} +
+ + {$TITLE} +
+ {/custom_render_form_field} + {/loop} {render_form_field field="container_id" value=$selected_container_id} {render_form_field field='chapo'} {render_form_field field='description' extra_class='wysiwyg'} diff --git a/templates/backOffice/default/selectionContentRelated.html b/templates/backOffice/default/selectionContentRelated.html index f371fa6..3af21a9 100644 --- a/templates/backOffice/default/selectionContentRelated.html +++ b/templates/backOffice/default/selectionContentRelated.html @@ -29,7 +29,7 @@
@@ -73,4 +73,4 @@
- \ No newline at end of file +