From b27d5c3414b3511b69395f2b6ff805976aad18d8 Mon Sep 17 00:00:00 2001 From: Vincent Lopes-Vicente Date: Fri, 1 Feb 2019 17:28:12 +0100 Subject: [PATCH] Add image type --- Action/AttributeTypeAction.php | 13 ++ AttributeType.php | 26 +++ CHANGELOG.md | 4 + Config/insert.sql | 4 +- Config/module.xml | 2 +- Config/routing.xml | 9 + Config/schema.xml | 3 + Config/thelia.sql | 19 +- Config/update/1.3.0.sql | 4 + .../AttributeTypeAttributeAvController.php | 152 +++++++++++++- Controller/AttributeTypeController.php | 11 +- Event/AttributeTypeEvents.php | 1 + Form/AttributeTypeAvMetaUpdateForm.php | 62 ++++++ Form/AttributeTypeCreateForm.php | 26 ++- Form/AttributeTypeUpdateForm.php | 2 +- Hook/AttributeEditHook.php | 21 +- I18n/backOffice/default/fr_FR.php | 20 +- I18n/fr_FR.php | 15 ++ Loop/AttributeTypeLoop.php | 3 + Model/Base/AttributeType.php | 192 +++++++++++++++++- Model/Base/AttributeTypeQuery.php | 137 ++++++++++++- Model/Map/AttributeTypeTableMap.php | 52 +++-- Readme.md | 5 +- .../attribute-type/configuration-js.html | 97 +++++---- .../hook/attribute-edit-js.html | 47 ++++- .../attribute-type/include/form-generic.html | 28 +++ .../attribute-type/include/form-meta.html | 125 ++++++++++-- 27 files changed, 974 insertions(+), 106 deletions(-) create mode 100644 Config/update/1.3.0.sql diff --git a/Action/AttributeTypeAction.php b/Action/AttributeTypeAction.php index 7aa56a6..a3d2723 100644 --- a/Action/AttributeTypeAction.php +++ b/Action/AttributeTypeAction.php @@ -98,6 +98,16 @@ public function metaUpdate(AttributeTypeAvMetaEvent $event) $event->getAttributeTypeAvMeta()->save($event->getConnectionInterface()); } + /** + * @param AttributeTypeAvMetaEvent $event + * @throws \Exception + * @throws \Propel\Runtime\Exception\PropelException + */ + public function metaDelete(AttributeTypeAvMetaEvent $event) + { + $event->getAttributeTypeAvMeta()->delete($event->getConnectionInterface()); + } + /** * Returns an array of event names this subscriber wants to listen to. * @@ -141,6 +151,9 @@ public static function getSubscribedEvents() ), AttributeTypeEvents::ATTRIBUTE_TYPE_AV_META_UPDATE => array( 'metaUpdate', 128 + ), + AttributeTypeEvents::ATTRIBUTE_TYPE_AV_META_DELETE => array( + 'metaDelete', 128 ) ); } diff --git a/AttributeType.php b/AttributeType.php index 06a9ff2..a3aaca1 100644 --- a/AttributeType.php +++ b/AttributeType.php @@ -13,6 +13,7 @@ namespace AttributeType; use Propel\Runtime\Connection\ConnectionInterface; +use Symfony\Component\Finder\Finder; use Thelia\Core\Template\TemplateDefinition; use Thelia\Module\BaseModule; use Thelia\Install\Database; @@ -28,6 +29,11 @@ class AttributeType extends BaseModule const RESERVED_SLUG = 'id,attribute_id,id_translater,locale,title,chapo,description,postscriptum,position'; + const ATTRIBUTE_TYPE_AV_IMAGE_FOLDER = 'attribute_type_av_images'; + + /** @var string */ + const UPDATE_PATH = __DIR__ . DS . 'Config' . DS . 'update'; + /** * @param ConnectionInterface $con */ @@ -40,6 +46,26 @@ public function postActivation(ConnectionInterface $con = null) } } + /** + * @param $currentVersion + * @param $newVersion + * @param ConnectionInterface|null $con + */ + public function update($currentVersion, $newVersion, ConnectionInterface $con = null) + { + $finder = (new Finder())->files()->name('#.*?\.sql#')->sortByName()->in(self::UPDATE_PATH); + if ($finder->count() === 0) { + return; + } + $database = new Database($con); + /** @var \Symfony\Component\Finder\SplFileInfo $updateSQLFile */ + foreach ($finder as $updateSQLFile) { + if (version_compare($currentVersion, str_replace('.sql', '', $updateSQLFile->getFilename()), '<')) { + $database->insertSql(null, [$updateSQLFile->getPathname()]); + } + } + } + /** * @return array */ diff --git a/CHANGELOG.md b/CHANGELOG.md index 0fc79f6..38141b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 1.3.0 + +- Add image field type (with uploads !) + # 1.2.3 - Resolve #8 Add method addOutputFields diff --git a/Config/insert.sql b/Config/insert.sql index 1c71afe..6370efb 100644 --- a/Config/insert.sql +++ b/Config/insert.sql @@ -1,7 +1,7 @@ SELECT @max_id := IFNULL(MAX(`id`),0) FROM `attribute_type`; -INSERT INTO `attribute_type` (`id`, `slug`, `has_attribute_av_value`, `is_multilingual_attribute_av_value`, `pattern`, `css_class`, `input_type`, `max`, `min`, `step`, `created_at`, `updated_at`) VALUES -(@max_id + 1, 'color', 1, 0, '#([a-f]|[A-F]|[0-9]){3}(([a-f]|[A-F]|[0-9]){3})?\\\\b', NULL, 'color', NULL, NULL, NULL, NOW(), NOW()); +INSERT INTO `attribute_type` (`id`, `slug`, `has_attribute_av_value`, `is_multilingual_attribute_av_value`, `pattern`, `css_class`, `input_type`, `max`, `min`, `step`, `image_max_width`, `image_max_height`, `image_ratio`, `created_at`, `updated_at`) VALUES +(@max_id + 1, 'color', 1, 0, '#([a-f]|[A-F]|[0-9]){3}(([a-f]|[A-F]|[0-9]){3})?\\\\b', NULL, 'color', NULL, NULL, NULL, NULL, NULL, NULL, NOW(), NOW()); INSERT INTO `attribute_type_i18n` (`id`, `locale`, `title`, `description`) VALUES (@max_id + 1, 'cs_CZ', 'barva', 'hexadecimální barva'), diff --git a/Config/module.xml b/Config/module.xml index b79b078..b16200c 100644 --- a/Config/module.xml +++ b/Config/module.xml @@ -16,7 +16,7 @@ en_US fr_FR - 1.2.3 + 1.3.0 Gilles Bourgeat gilles.bourgeat@gmail.com diff --git a/Config/routing.xml b/Config/routing.xml index 680b98b..bd064a9 100644 --- a/Config/routing.xml +++ b/Config/routing.xml @@ -55,4 +55,13 @@ \d+ + + AttributeType\Controller\AttributeTypeAttributeAvController::deleteMetaAction + \d+ + \d+ + \d+ + \d+ + _delete + + diff --git a/Config/schema.xml b/Config/schema.xml index 57c4a42..c795d97 100644 --- a/Config/schema.xml +++ b/Config/schema.xml @@ -14,6 +14,9 @@ + + + diff --git a/Config/thelia.sql b/Config/thelia.sql index 9e8acd5..bf0a1ce 100644 --- a/Config/thelia.sql +++ b/Config/thelia.sql @@ -7,7 +7,9 @@ SET FOREIGN_KEY_CHECKS = 0; -- attribute_type -- --------------------------------------------------------------------- -CREATE TABLE IF NOT EXISTS `attribute_type` +DROP TABLE IF EXISTS `attribute_type`; + +CREATE TABLE `attribute_type` ( `id` INTEGER NOT NULL AUTO_INCREMENT, `slug` VARCHAR(50), @@ -19,6 +21,9 @@ CREATE TABLE IF NOT EXISTS `attribute_type` `max` FLOAT, `min` FLOAT, `step` FLOAT, + `image_max_width` FLOAT, + `image_max_height` FLOAT, + `image_ratio` FLOAT, `created_at` DATETIME, `updated_at` DATETIME, PRIMARY KEY (`id`), @@ -29,7 +34,9 @@ CREATE TABLE IF NOT EXISTS `attribute_type` -- attribute_attribute_type -- --------------------------------------------------------------------- -CREATE TABLE IF NOT EXISTS `attribute_attribute_type` +DROP TABLE IF EXISTS `attribute_attribute_type`; + +CREATE TABLE `attribute_attribute_type` ( `id` INTEGER NOT NULL AUTO_INCREMENT, `attribute_id` INTEGER NOT NULL, @@ -53,7 +60,9 @@ CREATE TABLE IF NOT EXISTS `attribute_attribute_type` -- attribute_type_av_meta -- --------------------------------------------------------------------- -CREATE TABLE IF NOT EXISTS `attribute_type_av_meta` +DROP TABLE IF EXISTS `attribute_type_av_meta`; + +CREATE TABLE `attribute_type_av_meta` ( `id` INTEGER NOT NULL AUTO_INCREMENT, `attribute_av_id` INTEGER NOT NULL, @@ -79,7 +88,9 @@ CREATE TABLE IF NOT EXISTS `attribute_type_av_meta` -- attribute_type_i18n -- --------------------------------------------------------------------- -CREATE TABLE IF NOT EXISTS `attribute_type_i18n` +DROP TABLE IF EXISTS `attribute_type_i18n`; + +CREATE TABLE `attribute_type_i18n` ( `id` INTEGER NOT NULL, `locale` VARCHAR(5) DEFAULT 'en_US' NOT NULL, diff --git a/Config/update/1.3.0.sql b/Config/update/1.3.0.sql new file mode 100644 index 0000000..0afd75c --- /dev/null +++ b/Config/update/1.3.0.sql @@ -0,0 +1,4 @@ +ALTER TABLE attribute_type + ADD `image_max_width` FLOAT AFTER `step`, + ADD `image_max_height` FLOAT AFTER `image_max_width`, + ADD `image_ratio` FLOAT AFTER `image_max_height`; \ No newline at end of file diff --git a/Controller/AttributeTypeAttributeAvController.php b/Controller/AttributeTypeAttributeAvController.php index b227389..ae0ed9e 100644 --- a/Controller/AttributeTypeAttributeAvController.php +++ b/Controller/AttributeTypeAttributeAvController.php @@ -8,14 +8,20 @@ namespace AttributeType\Controller; +use AttributeType\AttributeType; use AttributeType\Event\AttributeTypeEvents; use AttributeType\Event\AttributeTypeAvMetaEvent; +use AttributeType\Form\AttributeTypeAvMetaUpdateForm; use AttributeType\Model\AttributeAttributeType; use AttributeType\Model\AttributeAttributeTypeQuery; use AttributeType\Model\AttributeTypeAvMeta; use AttributeType\Model\AttributeTypeAvMetaQuery; +use AttributeType\Model\AttributeTypeQuery; +use Symfony\Component\Filesystem\Filesystem; +use Symfony\Component\HttpFoundation\File\UploadedFile; use Thelia\Core\Security\AccessManager; use Thelia\Core\Security\Resource\AdminResources; +use Thelia\Files\Exception\ProcessFileException; use Thelia\Model\Lang; use Thelia\Model\LangQuery; @@ -52,28 +58,94 @@ public function updateMetaAction($attribute_id) foreach ($attributeAvs as $attributeAvId => $attributeAv) { foreach ($attributeAv['lang'] as $langId => $lang) { foreach ($lang['attribute_type'] as $attributeTypeId => $value) { - $this->dispatchEvent( - $this->getAttributeAttributeType($attributeTypeId, $attribute_id), - $attributeAvId, - $langId, - $value - ); + $values = []; + $values[$langId] = $value; + $attributeType = AttributeTypeQuery::create() + ->findOneById($attributeTypeId); + + if ($attributeType->getInputType() === "image") { + if (null === $value) { + continue; + } + + $uploadedFileName = $this->uploadFile($value); + $values[$langId] = $uploadedFileName; + + if (!$attributeType->getIsMultilingualAttributeAvValue()) { + $activeLangs = LangQuery::create() + ->filterByActive(1) + ->find(); + /** @var Lang $lang */ + foreach ($activeLangs as $lang) { + $values[$lang->getId()] = $uploadedFileName; + } + } + } + + foreach ($values as $langId => $langValue) { + $this->dispatchEvent( + $this->getAttributeAttributeType($attributeTypeId, $attribute_id), + $attributeAvId, + $langId, + $langValue + ); + } } } } + $this->resetUpdateForm(); return $this->generateSuccessRedirect($form); } catch (\Exception $e) { $this->setupFormErrorContext( $this->getTranslator()->trans("%obj modification", array('%obj' => $this->objectName)), $e->getMessage(), - $form + $form, + $e ); return $this->viewAttribute($attribute_id); } } + public function deleteMetaAction($attribute_id, $attribute_type_id, $attribute_av_id, $lang_id) + { + if (null !== $response = $this->checkAuth(array(AdminResources::ATTRIBUTE), null, AccessManager::DELETE)) { + return $response; + } + $form = $this->createForm("attribute_type.delete"); + try { + $this->validateForm($form); + $attributeType = AttributeTypeQuery::create() + ->findOneById($attribute_type_id); + $attributeAttributeType = $this->getAttributeAttributeType($attribute_type_id, $attribute_id); + $eventName = AttributeTypeEvents::ATTRIBUTE_TYPE_AV_META_DELETE; + $attributeAvMetaQuery = AttributeTypeAvMetaQuery::create() + ->filterByAttributeAvId($attribute_av_id) + ->filterByAttributeAttributeTypeId($attributeAttributeType->getId()); + if ($attributeType->getIsMultilingualAttributeAvValue()) { + $attributeAvMetaQuery->filterByLocale($this->getLocale($lang_id)); + } + $attributeAvMetas = $attributeAvMetaQuery->find(); + foreach ($attributeAvMetas as $attributeAvMeta) { + $this->dispatch( + $eventName, + (new AttributeTypeAvMetaEvent($attributeAvMeta)) + ); + } + $this->resetUpdateForm(); + return $this->generateSuccessRedirect($form); + } catch (\Exception $e) { + $this->setupFormErrorContext( + $this->getTranslator()->trans("%obj modification", array('%obj' => $this->objectName)), + $e->getMessage(), + $form, + $e + ); + return $this->viewAttribute($attribute_id); + } + } + /** * @param AttributeAttributeType $attributeAttributeType * @param int $attributeAvId @@ -148,4 +220,70 @@ protected function getLocale($langId) return $this->langs[$langId]->getLocale(); } + + /** + * @param UploadedFile $file + * @return string + */ + protected function uploadFile(UploadedFile $file) + { + if ($file->getError() == UPLOAD_ERR_INI_SIZE) { + $message = $this->getTranslator() + ->trans( + 'File is too large, please retry with a file having a size less than %size%.', + array('%size%' => ini_get('upload_max_filesize')), + 'core' + ); + throw new ProcessFileException($message, 403); + } + $validMimeTypes = [ + 'image/jpeg' => ["jpg", "jpeg"], + 'image/png' => ["png"], + 'image/gif' => ["gif"] + ]; + $mimeType = $file->getMimeType(); + if (!isset($validMimeTypes[$mimeType])) { + $message = $this->getTranslator() + ->trans( + 'Only files having the following mime type are allowed: %types%', + [ '%types%' => implode(', ', array_keys($validMimeTypes))] + ); + throw new ProcessFileException($message, 415); + } + $regex = "#^(.+)\.(".implode("|", $validMimeTypes[$mimeType]).")$#i"; + $realFileName = $file->getClientOriginalName(); + if (!preg_match($regex, $realFileName)) { + $message = $this->getTranslator() + ->trans( + "There's a conflict between your file extension \"%ext\" and the mime type \"%mime\"", + [ + '%mime' => $mimeType, + '%ext' => $file->getClientOriginalExtension() + ] + ); + throw new ProcessFileException($message, 415); + } + $fileSystem = new Filesystem(); + $fileSystem->mkdir(THELIA_WEB_DIR. DS .AttributeType::ATTRIBUTE_TYPE_AV_IMAGE_FOLDER); + $fileName = $this->generateUniqueFileName().'_'.$realFileName; + $file->move(THELIA_WEB_DIR. DS .AttributeType::ATTRIBUTE_TYPE_AV_IMAGE_FOLDER, $fileName); + return DS . AttributeType::ATTRIBUTE_TYPE_AV_IMAGE_FOLDER. DS .$fileName; + } + + /** + * @return string + */ + protected function generateUniqueFileName() + { + // md5() reduces the similarity of the file names generated by + // uniqid(), which is based on timestamps + return substr(md5(uniqid()), 0, 10); + } + + protected function resetUpdateForm() { + $this->getParserContext()->remove(AttributeTypeAvMetaUpdateForm::class.':form'); + $theliaFormErrors = $this->getRequest()->getSession()->get('thelia.form-errors'); + unset($theliaFormErrors[AttributeTypeAvMetaUpdateForm::class.':form']); + $this->getRequest()->getSession()->set('thelia.form-errors', $theliaFormErrors); + } } diff --git a/Controller/AttributeTypeController.php b/Controller/AttributeTypeController.php index c444e5d..454db5e 100644 --- a/Controller/AttributeTypeController.php +++ b/Controller/AttributeTypeController.php @@ -85,6 +85,9 @@ public function viewAction($id) 'min' => $attributeType->getMin(), 'max' => $attributeType->getMax(), 'step' => $attributeType->getStep(), + 'image_max_width' => $attributeType->getImageMaxWidth(), + 'image_max_height' => $attributeType->getImageMaxHeight(), + 'image_ratio' => $attributeType->getImageRatio(), 'title' => $title, 'description' => $description )); @@ -254,6 +257,9 @@ public function copyAction($id) 'min' => $attributeType->getMin(), 'max' => $attributeType->getMax(), 'step' => $attributeType->getStep(), + 'image_max_width' => $attributeType->getImageMaxWidth(), + 'image_max_height' => $attributeType->getImageMaxHeight(), + 'image_ratio' => $attributeType->getImageRatio(), 'title' => $title, 'description' => $description )); @@ -294,7 +300,10 @@ protected function hydrateAttributeTypeByForm($form, $id = null) ->setInputType($data['input_type']) ->setMin($data['min']) ->setMax($data['max']) - ->setStep($data['step']); + ->setStep($data['step']) + ->setImageMaxWidth($data['image_max_width']) + ->setImageMaxHeight($data['image_max_height']) + ->setImageRatio($data['image_ratio']); foreach ($data['title'] as $langId => $title) { $attributeType diff --git a/Event/AttributeTypeEvents.php b/Event/AttributeTypeEvents.php index daba3f3..7da25d2 100644 --- a/Event/AttributeTypeEvents.php +++ b/Event/AttributeTypeEvents.php @@ -22,4 +22,5 @@ class AttributeTypeEvents const ATTRIBUTE_TYPE_DISSOCIATE = 'attribute.type.dissociate'; const ATTRIBUTE_TYPE_AV_META_UPDATE = 'attribute.type.av.meta.update'; const ATTRIBUTE_TYPE_AV_META_CREATE = 'attribute.type.av.meta.create'; + const ATTRIBUTE_TYPE_AV_META_DELETE = 'attribute.type.av.meta.delete'; } diff --git a/Form/AttributeTypeAvMetaUpdateForm.php b/Form/AttributeTypeAvMetaUpdateForm.php index 5601bd4..5b00bfd 100644 --- a/Form/AttributeTypeAvMetaUpdateForm.php +++ b/Form/AttributeTypeAvMetaUpdateForm.php @@ -10,7 +10,11 @@ use AttributeType\AttributeType; use AttributeType\Form\Type\I18nType; +use AttributeType\Model\AttributeTypeQuery; +use Symfony\Component\HttpFoundation\File\UploadedFile; +use Symfony\Component\Validator\Constraints\Callback; use Symfony\Component\Validator\Constraints\NotBlank; +use Symfony\Component\Validator\Context\ExecutionContextInterface; use Thelia\Core\Translation\Translator; /** @@ -43,6 +47,13 @@ protected function buildForm() 'collection', array( 'type' => new I18nType(), + 'constraints' => array( + new Callback(array( + "methods" => array( + array($this, + "checkImageSize"), + )) + )), 'allow_add' => true, 'allow_delete' => true, 'label_attr' => array( @@ -65,4 +76,55 @@ protected function buildForm() ) ); } + + /** + * @param $value + * @param ExecutionContextInterface $context + */ + public function checkImageSize($value, ExecutionContextInterface $context) + { + foreach ($value as $attributeAvId => $attributeAv) { + foreach ($attributeAv['lang'] as $langId => $lang) { + foreach ($lang['attribute_type'] as $attributeTypeId => $value) { + if (!$value instanceof UploadedFile) { + continue; + } + $attributeType = AttributeTypeQuery::create() + ->findOneById($attributeTypeId); + $size = getimagesize($value); + list($width, $height) = $size; + if (null !== $attributeType->getImageMaxWidth() && $width > $attributeType->getImageMaxWidth()) { + $context->addViolation(Translator::getInstance()->trans(Translator::getInstance() + ->trans( + "Your image is too large (maximum %width px)", + [ + '%width' => $attributeType->getImageMaxWidth(), + ] + )) + ); + } + if (null !== $attributeType->getImageMaxHeight() && $height > $attributeType->getImageMaxHeight()) { + $context->addViolation(Translator::getInstance()->trans(Translator::getInstance() + ->trans( + "Your image is too tall (maximum %height px)", + [ + '%height' => $attributeType->getImageMaxHeight(), + ] + )) + ); + } + if (null !== $attributeType->getImageRatio() && ($width/$height) !== $attributeType->getImageRatio()) { + $context->addViolation(Translator::getInstance()->trans(Translator::getInstance() + ->trans( + "Bad image ratio (%ratio required)", + [ + '%ratio' => $attributeType->getImageRatio(), + ] + )) + ); + } + } + } + } + } } diff --git a/Form/AttributeTypeCreateForm.php b/Form/AttributeTypeCreateForm.php index d6018f3..539ad09 100644 --- a/Form/AttributeTypeCreateForm.php +++ b/Form/AttributeTypeCreateForm.php @@ -12,7 +12,7 @@ use Symfony\Component\Validator\Constraints\NotBlank; use Symfony\Component\Validator\Constraints\Callback; use AttributeType\AttributeType; -use Symfony\Component\Validator\ExecutionContextInterface; +use Symfony\Component\Validator\Context\ExecutionContextInterface; use Thelia\Core\Translation\Translator; /** @@ -127,7 +127,8 @@ protected function buildForm() 'color' => Translator::getInstance()->trans('Type color', array(), AttributeType::MODULE_DOMAIN), 'number' => Translator::getInstance()->trans('Type number', array(), AttributeType::MODULE_DOMAIN), 'range' => Translator::getInstance()->trans('Type range', array(), AttributeType::MODULE_DOMAIN), - 'url' => Translator::getInstance()->trans('Type url', array(), AttributeType::MODULE_DOMAIN) + 'url' => Translator::getInstance()->trans('Type url', array(), AttributeType::MODULE_DOMAIN), + 'image' => Translator::getInstance()->trans('Type image', array(), AttributeType::MODULE_DOMAIN) ) )) ->add('min', 'text', array( @@ -150,6 +151,27 @@ protected function buildForm() 'label_attr' => array( 'for' => 'step' ) + )) + ->add('image_max_width', 'number', array( + 'required' => true, + 'label' => Translator::getInstance()->trans('Image max width', array(), AttributeType::MODULE_DOMAIN), + 'label_attr' => array( + 'for' => 'image_max_width' + ) + )) + ->add('image_max_height', 'number', array( + 'required' => true, + 'label' => Translator::getInstance()->trans('Image max height', array(), AttributeType::MODULE_DOMAIN), + 'label_attr' => array( + 'for' => 'image_max_height' + ) + )) + ->add('image_ratio', 'number', array( + 'required' => true, + 'label' => Translator::getInstance()->trans('Image ratio', array(), AttributeType::MODULE_DOMAIN), + 'label_attr' => array( + 'for' => 'image_ratio' + ) )); } diff --git a/Form/AttributeTypeUpdateForm.php b/Form/AttributeTypeUpdateForm.php index c7b3173..31178c7 100644 --- a/Form/AttributeTypeUpdateForm.php +++ b/Form/AttributeTypeUpdateForm.php @@ -9,7 +9,7 @@ namespace AttributeType\Form; use Symfony\Component\Validator\Constraints\NotBlank; -use Symfony\Component\Validator\ExecutionContextInterface; +use Symfony\Component\Validator\Context\ExecutionContextInterface; /** * Class AttributeTypeUpdateForm diff --git a/Hook/AttributeEditHook.php b/Hook/AttributeEditHook.php index 7d71cf0..c434b6c 100644 --- a/Hook/AttributeEditHook.php +++ b/Hook/AttributeEditHook.php @@ -20,6 +20,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface; use Thelia\Core\Event\Hook\HookRenderEvent; use Thelia\Core\Hook\BaseHook; +use Thelia\Core\Template\ParserContext; use Thelia\Core\Thelia; use Thelia\Model\AttributeAv; use Thelia\Model\AttributeAvQuery; @@ -51,13 +52,19 @@ public function onAttributeEditBottom(HookRenderEvent $event) { $data = $this->hydrateForm($event->getArgument('attribute_id')); - $form = new AttributeTypeAvMetaUpdateForm( - $this->getRequest(), - 'form', - $data, - array(), - $this->container - ); + /** @var ParserContext $parserContext */ + $parserContext = $this->container->get('thelia.parser.context'); + $form = $parserContext->getForm('attribute_type_av_meta.update', AttributeTypeAvMetaUpdateForm::class, 'form'); + + if (!$form) { + $form = new AttributeTypeAvMetaUpdateForm( + $this->getRequest(), + 'form', + $data, + array(), + $this->container + ); + } $this->container->get('thelia.parser.context')->addForm($form); diff --git a/I18n/backOffice/default/fr_FR.php b/I18n/backOffice/default/fr_FR.php index 1004788..5538ee3 100644 --- a/I18n/backOffice/default/fr_FR.php +++ b/I18n/backOffice/default/fr_FR.php @@ -4,11 +4,13 @@ 'Action' => 'Action', 'Activate attribute av value' => 'Activer les valeurs pour les déclinaisons', 'Are you sure you want to delete this attribute type ?' => 'Etes-vous sûr de vouloir supprimer ce type de déclinaison ?', + 'Are you sure you want to delete this attribute type value meta ?' => 'Êtes vous sûr de vouloir supprimer cette valeur de caractéristique ?', 'Associate action' => 'Associer', 'Attribute av multilingual value' => 'Valeurs par langue activées', 'Attribute type' => 'Type de déclinaison', 'Attributes types' => 'Types de déclinaisons', 'Close action' => 'Fermer', + 'Configuration' => 'Configuration', 'Copy action' => 'Copier', 'Create a new attribute type' => 'Créer un nouveau type de déclinaison', 'Create action' => 'Créer', @@ -17,6 +19,8 @@ 'Currently, none of the attributes types are available' => 'Actuellement, aucun type de déclinaison est disponible', 'Delete action' => 'Supprimer', 'Delete attribute type' => 'Supprimer le type de déclinaison', + 'Delete attribute type value meta' => 'Supprimer valeur de déclinaison', + 'Description' => 'Description', 'Dissociate action' => 'Dissocier', 'Dissociate attribute type' => 'Dissocier du type de déclinaison', 'Dissociate the attribute with the attribute type ?' => 'Dissocier la déclinaison du type de déclinaison ?', @@ -26,9 +30,16 @@ 'Enter slug' => 'Slug', 'Enter title' => 'Titre', 'Help !!!' => 'Aide !!!', + 'Home' => 'Accueil', + 'ID' => 'ID', + 'Image maximum height in pixels' => 'Largeur maximum de l\'image en pixels', + 'Image maximum width in pixels' => 'Hauteur maximum de l\'image en pixels', + 'Image ratio/1, given by width/height (ex 1.77 = equal to 16:9 ratio)' => 'Ratio/1 de l\'image, donné par largeur/hauteur (ex 1,77 égale à un ratio de 16:9)', 'Input type applied to the input field' => 'Type de champ pour les valeurs', 'Maximum value applied to the input field' => 'Valeur maximum appliquée sur le champ', 'Minimum value applied to the input field' => 'Valeur minimum appliquée sur le champ', + 'Modules' => 'Modules', + 'Must be single, and only numbers, lowercase letters, underscore' => 'Doit être unique et ne comporter que des chiffres, des lettres minuscules ou trait de soulignement', 'Must be single, and only numbers, lowercase letters, underscore. Maximum length 50 characters.' => 'Peut être composé de chiffres, lettres minuscules et underscores. Longueur maximum 50 caractères.', 'No' => 'Aucun', 'No attribute type for this attribute' => 'Aucun type de déclinaison associé à cette déclinaison', @@ -38,11 +49,16 @@ 'Select an attribute type' => 'Selectionner un type de déclinaison', 'Slug' => 'Slug', 'Step applied to the input field' => 'Etape appliquée sur le champ', + 'The data of the form have been modified, do not forget to validate these modifications !!!' => 'Les données du formulaire ont été modifiées, n\'oubliez pas de valider ces modifications !!!', + 'The data of the form have been modified, if you continue without having validate your modifications all will be lost. Continue ?' => 'The data of the form have been modified, if you continue without having validate your modifications all will be lost. Continue ?\' => \'Les données du formulaire ont été modifiées, si vous continuez sans avoir valider vos modification tout sera perdu. Continuer ?', 'The values will be unique for each language' => 'Les valeurs sont uniques par langue', + 'Title' => 'Titre', 'To ask for help' => 'Pour demander de l\'aide', + 'Tutorial' => 'Tutoriel', 'Update action' => 'Mettre à jour', 'Update attribute type' => 'Mettre à jour le type de déclinaison', 'Used by' => 'Utilisé par', - "http://thelia-school.com/create-types-of-features-and-attributes.html" => "http://thelia-school.com/types-de-caracteristiques-et-declinaisons-avec-featuretype-et-attributetype.html", - "Tutorial" => "Tutoriel", + 'Value' => 'Valeur', + 'Yes' => 'Oui', + 'http://thelia-school.com/create-types-of-features-and-attributes.html' => 'http://thelia-school.com/types-de-caracteristiques-et-declinaisons-avec-featuretype-et-attributetype.html', ); diff --git a/I18n/fr_FR.php b/I18n/fr_FR.php index 268058c..a68f9d7 100644 --- a/I18n/fr_FR.php +++ b/I18n/fr_FR.php @@ -1,24 +1,39 @@ '%obj modification', 'Attribute not found' => 'La déclinaison n\'a pas été trouvé', 'Attribute type not found' => 'Le type de déclinaison n\'a pas été trouvé', + 'Bad image ratio (%ratio required)' => 'Mauvais ratio d\'image (%ratio requis)', + 'Description' => 'Description', + 'File is too large, please retry with a file having a size less than %size%.' => 'Fichier trop volumineux, veuillez réessayer avec un fichier plus petit que %size%.', 'Has attribute av value' => 'Activer l\'ajout de valeur', + 'Image max height' => 'Hauteur d\'image maximum', + 'Image max width' => 'Largeur d\'image maximum', + 'Image ratio' => 'Ratio de l\'image', 'Input css class' => 'Classe CSS', 'Input max' => 'Valeur maximum', 'Input min' => 'Valeur minimum', 'Input step' => 'Etape', 'Input type' => 'Type de champ', 'Multilingual value' => 'Activer les valeurs par langue', + 'Only files having the following mime type are allowed: %types%' => 'Seulement les fichiers avec le mime type suivant sont acceptés : %types%', + 'Pattern' => 'Pattern', 'Slug' => 'Slug', 'The attribute slug <%slug> already exists' => 'Le slug <%slug> existe déjà', 'The attribute slug <%slug> is reserved' => 'Le slug <%slug> est réservé', 'The slug is not valid' => 'Le slug n\'est pas valide', + 'There\'s a conflict between your file extension "%ext" and the mime type "%mime"' => 'Il y a un conflit entre votre extension "%ext" et le mime type "%mime"', + 'Title' => 'Titre', 'Type boolean' => 'Type boolean', 'Type color' => 'Type couleur', + 'Type image' => 'Type image', 'Type number' => 'Type nombre', 'Type range' => 'Type plage', 'Type text' => 'Type text', 'Type textarea' => 'Textarea', 'Type url' => 'Type url', + 'Your image is too large (maximum %width px)' => 'Votre image est trop large (maximum %width px)', + 'Your image is too tall (maximum %height px)' => 'Votre image est trop grande (maximum %height px)', + 'copy' => 'copie', ); diff --git a/Loop/AttributeTypeLoop.php b/Loop/AttributeTypeLoop.php index b670e67..7b77b8c 100644 --- a/Loop/AttributeTypeLoop.php +++ b/Loop/AttributeTypeLoop.php @@ -168,6 +168,9 @@ public function parseResults(LoopResult $loopResult) ->set("MIN", $entry->getMin()) ->set("MAX", $entry->getMax()) ->set("STEP", $entry->getStep()) + ->set("IMAGE_MAX_WIDTH", $entry->getImageMaxWidth()) + ->set("IMAGE_MAX_HEIGHT", $entry->getImageMaxHeight()) + ->set("IMAGE_RATIO", $entry->getImageRatio()) ->set("IS_MULTILINGUAL_ATTRIBUTE_AV_VALUE", $entry->getIsMultilingualAttributeAvValue()) ->set("HAS_ATTRIBUTE_AV_VALUE", $entry->getHasAttributeAvValue()) ; diff --git a/Model/Base/AttributeType.php b/Model/Base/AttributeType.php index c6e8130..2d9a143 100644 --- a/Model/Base/AttributeType.php +++ b/Model/Base/AttributeType.php @@ -129,6 +129,24 @@ abstract class AttributeType implements ActiveRecordInterface */ protected $step; + /** + * The value for the image_max_width field. + * @var double + */ + protected $image_max_width; + + /** + * The value for the image_max_height field. + * @var double + */ + protected $image_max_height; + + /** + * The value for the image_ratio field. + * @var double + */ + protected $image_ratio; + /** * The value for the created_at field. * @var string @@ -586,6 +604,39 @@ public function getStep() return $this->step; } + /** + * Get the [image_max_width] column value. + * + * @return double + */ + public function getImageMaxWidth() + { + + return $this->image_max_width; + } + + /** + * Get the [image_max_height] column value. + * + * @return double + */ + public function getImageMaxHeight() + { + + return $this->image_max_height; + } + + /** + * Get the [image_ratio] column value. + * + * @return double + */ + public function getImageRatio() + { + + return $this->image_ratio; + } + /** * Get the [optionally formatted] temporal [created_at] column value. * @@ -836,6 +887,69 @@ public function setStep($v) return $this; } // setStep() + /** + * Set the value of [image_max_width] column. + * + * @param double $v new value + * @return \AttributeType\Model\AttributeType The current object (for fluent API support) + */ + public function setImageMaxWidth($v) + { + if ($v !== null) { + $v = (double) $v; + } + + if ($this->image_max_width !== $v) { + $this->image_max_width = $v; + $this->modifiedColumns[AttributeTypeTableMap::IMAGE_MAX_WIDTH] = true; + } + + + return $this; + } // setImageMaxWidth() + + /** + * Set the value of [image_max_height] column. + * + * @param double $v new value + * @return \AttributeType\Model\AttributeType The current object (for fluent API support) + */ + public function setImageMaxHeight($v) + { + if ($v !== null) { + $v = (double) $v; + } + + if ($this->image_max_height !== $v) { + $this->image_max_height = $v; + $this->modifiedColumns[AttributeTypeTableMap::IMAGE_MAX_HEIGHT] = true; + } + + + return $this; + } // setImageMaxHeight() + + /** + * Set the value of [image_ratio] column. + * + * @param double $v new value + * @return \AttributeType\Model\AttributeType The current object (for fluent API support) + */ + public function setImageRatio($v) + { + if ($v !== null) { + $v = (double) $v; + } + + if ($this->image_ratio !== $v) { + $this->image_ratio = $v; + $this->modifiedColumns[AttributeTypeTableMap::IMAGE_RATIO] = true; + } + + + return $this; + } // setImageRatio() + /** * Sets the value of [created_at] column to a normalized version of the date/time value specified. * @@ -953,13 +1067,22 @@ public function hydrate($row, $startcol = 0, $rehydrate = false, $indexType = Ta $col = $row[TableMap::TYPE_NUM == $indexType ? 9 + $startcol : AttributeTypeTableMap::translateFieldName('Step', TableMap::TYPE_PHPNAME, $indexType)]; $this->step = (null !== $col) ? (double) $col : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 10 + $startcol : AttributeTypeTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 10 + $startcol : AttributeTypeTableMap::translateFieldName('ImageMaxWidth', TableMap::TYPE_PHPNAME, $indexType)]; + $this->image_max_width = (null !== $col) ? (double) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 11 + $startcol : AttributeTypeTableMap::translateFieldName('ImageMaxHeight', TableMap::TYPE_PHPNAME, $indexType)]; + $this->image_max_height = (null !== $col) ? (double) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 12 + $startcol : AttributeTypeTableMap::translateFieldName('ImageRatio', TableMap::TYPE_PHPNAME, $indexType)]; + $this->image_ratio = (null !== $col) ? (double) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 13 + $startcol : AttributeTypeTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)]; if ($col === '0000-00-00 00:00:00') { $col = null; } $this->created_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 11 + $startcol : AttributeTypeTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 14 + $startcol : AttributeTypeTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)]; if ($col === '0000-00-00 00:00:00') { $col = null; } @@ -972,7 +1095,7 @@ public function hydrate($row, $startcol = 0, $rehydrate = false, $indexType = Ta $this->ensureConsistency(); } - return $startcol + 12; // 12 = AttributeTypeTableMap::NUM_HYDRATE_COLUMNS. + return $startcol + 15; // 15 = AttributeTypeTableMap::NUM_HYDRATE_COLUMNS. } catch (Exception $e) { throw new PropelException("Error populating \AttributeType\Model\AttributeType object", 0, $e); @@ -1260,6 +1383,15 @@ protected function doInsert(ConnectionInterface $con) if ($this->isColumnModified(AttributeTypeTableMap::STEP)) { $modifiedColumns[':p' . $index++] = 'STEP'; } + if ($this->isColumnModified(AttributeTypeTableMap::IMAGE_MAX_WIDTH)) { + $modifiedColumns[':p' . $index++] = 'IMAGE_MAX_WIDTH'; + } + if ($this->isColumnModified(AttributeTypeTableMap::IMAGE_MAX_HEIGHT)) { + $modifiedColumns[':p' . $index++] = 'IMAGE_MAX_HEIGHT'; + } + if ($this->isColumnModified(AttributeTypeTableMap::IMAGE_RATIO)) { + $modifiedColumns[':p' . $index++] = 'IMAGE_RATIO'; + } if ($this->isColumnModified(AttributeTypeTableMap::CREATED_AT)) { $modifiedColumns[':p' . $index++] = 'CREATED_AT'; } @@ -1307,6 +1439,15 @@ protected function doInsert(ConnectionInterface $con) case 'STEP': $stmt->bindValue($identifier, $this->step, PDO::PARAM_STR); break; + case 'IMAGE_MAX_WIDTH': + $stmt->bindValue($identifier, $this->image_max_width, PDO::PARAM_STR); + break; + case 'IMAGE_MAX_HEIGHT': + $stmt->bindValue($identifier, $this->image_max_height, PDO::PARAM_STR); + break; + case 'IMAGE_RATIO': + $stmt->bindValue($identifier, $this->image_ratio, PDO::PARAM_STR); + break; case 'CREATED_AT': $stmt->bindValue($identifier, $this->created_at ? $this->created_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR); break; @@ -1406,9 +1547,18 @@ public function getByPosition($pos) return $this->getStep(); break; case 10: - return $this->getCreatedAt(); + return $this->getImageMaxWidth(); break; case 11: + return $this->getImageMaxHeight(); + break; + case 12: + return $this->getImageRatio(); + break; + case 13: + return $this->getCreatedAt(); + break; + case 14: return $this->getUpdatedAt(); break; default: @@ -1450,8 +1600,11 @@ public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColum $keys[7] => $this->getMax(), $keys[8] => $this->getMin(), $keys[9] => $this->getStep(), - $keys[10] => $this->getCreatedAt(), - $keys[11] => $this->getUpdatedAt(), + $keys[10] => $this->getImageMaxWidth(), + $keys[11] => $this->getImageMaxHeight(), + $keys[12] => $this->getImageRatio(), + $keys[13] => $this->getCreatedAt(), + $keys[14] => $this->getUpdatedAt(), ); $virtualColumns = $this->virtualColumns; foreach ($virtualColumns as $key => $virtualColumn) { @@ -1530,9 +1683,18 @@ public function setByPosition($pos, $value) $this->setStep($value); break; case 10: - $this->setCreatedAt($value); + $this->setImageMaxWidth($value); break; case 11: + $this->setImageMaxHeight($value); + break; + case 12: + $this->setImageRatio($value); + break; + case 13: + $this->setCreatedAt($value); + break; + case 14: $this->setUpdatedAt($value); break; } // switch() @@ -1569,8 +1731,11 @@ public function fromArray($arr, $keyType = TableMap::TYPE_PHPNAME) if (array_key_exists($keys[7], $arr)) $this->setMax($arr[$keys[7]]); if (array_key_exists($keys[8], $arr)) $this->setMin($arr[$keys[8]]); if (array_key_exists($keys[9], $arr)) $this->setStep($arr[$keys[9]]); - if (array_key_exists($keys[10], $arr)) $this->setCreatedAt($arr[$keys[10]]); - if (array_key_exists($keys[11], $arr)) $this->setUpdatedAt($arr[$keys[11]]); + if (array_key_exists($keys[10], $arr)) $this->setImageMaxWidth($arr[$keys[10]]); + if (array_key_exists($keys[11], $arr)) $this->setImageMaxHeight($arr[$keys[11]]); + if (array_key_exists($keys[12], $arr)) $this->setImageRatio($arr[$keys[12]]); + if (array_key_exists($keys[13], $arr)) $this->setCreatedAt($arr[$keys[13]]); + if (array_key_exists($keys[14], $arr)) $this->setUpdatedAt($arr[$keys[14]]); } /** @@ -1592,6 +1757,9 @@ public function buildCriteria() if ($this->isColumnModified(AttributeTypeTableMap::MAX)) $criteria->add(AttributeTypeTableMap::MAX, $this->max); if ($this->isColumnModified(AttributeTypeTableMap::MIN)) $criteria->add(AttributeTypeTableMap::MIN, $this->min); if ($this->isColumnModified(AttributeTypeTableMap::STEP)) $criteria->add(AttributeTypeTableMap::STEP, $this->step); + if ($this->isColumnModified(AttributeTypeTableMap::IMAGE_MAX_WIDTH)) $criteria->add(AttributeTypeTableMap::IMAGE_MAX_WIDTH, $this->image_max_width); + if ($this->isColumnModified(AttributeTypeTableMap::IMAGE_MAX_HEIGHT)) $criteria->add(AttributeTypeTableMap::IMAGE_MAX_HEIGHT, $this->image_max_height); + if ($this->isColumnModified(AttributeTypeTableMap::IMAGE_RATIO)) $criteria->add(AttributeTypeTableMap::IMAGE_RATIO, $this->image_ratio); if ($this->isColumnModified(AttributeTypeTableMap::CREATED_AT)) $criteria->add(AttributeTypeTableMap::CREATED_AT, $this->created_at); if ($this->isColumnModified(AttributeTypeTableMap::UPDATED_AT)) $criteria->add(AttributeTypeTableMap::UPDATED_AT, $this->updated_at); @@ -1666,6 +1834,9 @@ public function copyInto($copyObj, $deepCopy = false, $makeNew = true) $copyObj->setMax($this->getMax()); $copyObj->setMin($this->getMin()); $copyObj->setStep($this->getStep()); + $copyObj->setImageMaxWidth($this->getImageMaxWidth()); + $copyObj->setImageMaxHeight($this->getImageMaxHeight()); + $copyObj->setImageRatio($this->getImageRatio()); $copyObj->setCreatedAt($this->getCreatedAt()); $copyObj->setUpdatedAt($this->getUpdatedAt()); @@ -2218,6 +2389,9 @@ public function clear() $this->max = null; $this->min = null; $this->step = null; + $this->image_max_width = null; + $this->image_max_height = null; + $this->image_ratio = null; $this->created_at = null; $this->updated_at = null; $this->alreadyInSave = false; diff --git a/Model/Base/AttributeTypeQuery.php b/Model/Base/AttributeTypeQuery.php index 0aa5352..81f3ea5 100644 --- a/Model/Base/AttributeTypeQuery.php +++ b/Model/Base/AttributeTypeQuery.php @@ -32,6 +32,9 @@ * @method ChildAttributeTypeQuery orderByMax($order = Criteria::ASC) Order by the max column * @method ChildAttributeTypeQuery orderByMin($order = Criteria::ASC) Order by the min column * @method ChildAttributeTypeQuery orderByStep($order = Criteria::ASC) Order by the step column + * @method ChildAttributeTypeQuery orderByImageMaxWidth($order = Criteria::ASC) Order by the image_max_width column + * @method ChildAttributeTypeQuery orderByImageMaxHeight($order = Criteria::ASC) Order by the image_max_height column + * @method ChildAttributeTypeQuery orderByImageRatio($order = Criteria::ASC) Order by the image_ratio column * @method ChildAttributeTypeQuery orderByCreatedAt($order = Criteria::ASC) Order by the created_at column * @method ChildAttributeTypeQuery orderByUpdatedAt($order = Criteria::ASC) Order by the updated_at column * @@ -45,6 +48,9 @@ * @method ChildAttributeTypeQuery groupByMax() Group by the max column * @method ChildAttributeTypeQuery groupByMin() Group by the min column * @method ChildAttributeTypeQuery groupByStep() Group by the step column + * @method ChildAttributeTypeQuery groupByImageMaxWidth() Group by the image_max_width column + * @method ChildAttributeTypeQuery groupByImageMaxHeight() Group by the image_max_height column + * @method ChildAttributeTypeQuery groupByImageRatio() Group by the image_ratio column * @method ChildAttributeTypeQuery groupByCreatedAt() Group by the created_at column * @method ChildAttributeTypeQuery groupByUpdatedAt() Group by the updated_at column * @@ -73,6 +79,9 @@ * @method ChildAttributeType findOneByMax(double $max) Return the first ChildAttributeType filtered by the max column * @method ChildAttributeType findOneByMin(double $min) Return the first ChildAttributeType filtered by the min column * @method ChildAttributeType findOneByStep(double $step) Return the first ChildAttributeType filtered by the step column + * @method ChildAttributeType findOneByImageMaxWidth(double $image_max_width) Return the first ChildAttributeType filtered by the image_max_width column + * @method ChildAttributeType findOneByImageMaxHeight(double $image_max_height) Return the first ChildAttributeType filtered by the image_max_height column + * @method ChildAttributeType findOneByImageRatio(double $image_ratio) Return the first ChildAttributeType filtered by the image_ratio column * @method ChildAttributeType findOneByCreatedAt(string $created_at) Return the first ChildAttributeType filtered by the created_at column * @method ChildAttributeType findOneByUpdatedAt(string $updated_at) Return the first ChildAttributeType filtered by the updated_at column * @@ -86,6 +95,9 @@ * @method array findByMax(double $max) Return ChildAttributeType objects filtered by the max column * @method array findByMin(double $min) Return ChildAttributeType objects filtered by the min column * @method array findByStep(double $step) Return ChildAttributeType objects filtered by the step column + * @method array findByImageMaxWidth(double $image_max_width) Return ChildAttributeType objects filtered by the image_max_width column + * @method array findByImageMaxHeight(double $image_max_height) Return ChildAttributeType objects filtered by the image_max_height column + * @method array findByImageRatio(double $image_ratio) Return ChildAttributeType objects filtered by the image_ratio column * @method array findByCreatedAt(string $created_at) Return ChildAttributeType objects filtered by the created_at column * @method array findByUpdatedAt(string $updated_at) Return ChildAttributeType objects filtered by the updated_at column * @@ -176,7 +188,7 @@ public function findPk($key, $con = null) */ protected function findPkSimple($key, $con) { - $sql = 'SELECT ID, SLUG, HAS_ATTRIBUTE_AV_VALUE, IS_MULTILINGUAL_ATTRIBUTE_AV_VALUE, PATTERN, CSS_CLASS, INPUT_TYPE, MAX, MIN, STEP, CREATED_AT, UPDATED_AT FROM attribute_type WHERE ID = :p0'; + $sql = 'SELECT ID, SLUG, HAS_ATTRIBUTE_AV_VALUE, IS_MULTILINGUAL_ATTRIBUTE_AV_VALUE, PATTERN, CSS_CLASS, INPUT_TYPE, MAX, MIN, STEP, IMAGE_MAX_WIDTH, IMAGE_MAX_HEIGHT, IMAGE_RATIO, CREATED_AT, UPDATED_AT FROM attribute_type WHERE ID = :p0'; try { $stmt = $con->prepare($sql); $stmt->bindValue(':p0', $key, PDO::PARAM_INT); @@ -627,6 +639,129 @@ public function filterByStep($step = null, $comparison = null) return $this->addUsingAlias(AttributeTypeTableMap::STEP, $step, $comparison); } + /** + * Filter the query on the image_max_width column + * + * Example usage: + * + * $query->filterByImageMaxWidth(1234); // WHERE image_max_width = 1234 + * $query->filterByImageMaxWidth(array(12, 34)); // WHERE image_max_width IN (12, 34) + * $query->filterByImageMaxWidth(array('min' => 12)); // WHERE image_max_width > 12 + * + * + * @param mixed $imageMaxWidth The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildAttributeTypeQuery The current query, for fluid interface + */ + public function filterByImageMaxWidth($imageMaxWidth = null, $comparison = null) + { + if (is_array($imageMaxWidth)) { + $useMinMax = false; + if (isset($imageMaxWidth['min'])) { + $this->addUsingAlias(AttributeTypeTableMap::IMAGE_MAX_WIDTH, $imageMaxWidth['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($imageMaxWidth['max'])) { + $this->addUsingAlias(AttributeTypeTableMap::IMAGE_MAX_WIDTH, $imageMaxWidth['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(AttributeTypeTableMap::IMAGE_MAX_WIDTH, $imageMaxWidth, $comparison); + } + + /** + * Filter the query on the image_max_height column + * + * Example usage: + * + * $query->filterByImageMaxHeight(1234); // WHERE image_max_height = 1234 + * $query->filterByImageMaxHeight(array(12, 34)); // WHERE image_max_height IN (12, 34) + * $query->filterByImageMaxHeight(array('min' => 12)); // WHERE image_max_height > 12 + * + * + * @param mixed $imageMaxHeight The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildAttributeTypeQuery The current query, for fluid interface + */ + public function filterByImageMaxHeight($imageMaxHeight = null, $comparison = null) + { + if (is_array($imageMaxHeight)) { + $useMinMax = false; + if (isset($imageMaxHeight['min'])) { + $this->addUsingAlias(AttributeTypeTableMap::IMAGE_MAX_HEIGHT, $imageMaxHeight['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($imageMaxHeight['max'])) { + $this->addUsingAlias(AttributeTypeTableMap::IMAGE_MAX_HEIGHT, $imageMaxHeight['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(AttributeTypeTableMap::IMAGE_MAX_HEIGHT, $imageMaxHeight, $comparison); + } + + /** + * Filter the query on the image_ratio column + * + * Example usage: + * + * $query->filterByImageRatio(1234); // WHERE image_ratio = 1234 + * $query->filterByImageRatio(array(12, 34)); // WHERE image_ratio IN (12, 34) + * $query->filterByImageRatio(array('min' => 12)); // WHERE image_ratio > 12 + * + * + * @param mixed $imageRatio The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildAttributeTypeQuery The current query, for fluid interface + */ + public function filterByImageRatio($imageRatio = null, $comparison = null) + { + if (is_array($imageRatio)) { + $useMinMax = false; + if (isset($imageRatio['min'])) { + $this->addUsingAlias(AttributeTypeTableMap::IMAGE_RATIO, $imageRatio['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($imageRatio['max'])) { + $this->addUsingAlias(AttributeTypeTableMap::IMAGE_RATIO, $imageRatio['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(AttributeTypeTableMap::IMAGE_RATIO, $imageRatio, $comparison); + } + /** * Filter the query on the created_at column * diff --git a/Model/Map/AttributeTypeTableMap.php b/Model/Map/AttributeTypeTableMap.php index 8d630d4..78b6748 100644 --- a/Model/Map/AttributeTypeTableMap.php +++ b/Model/Map/AttributeTypeTableMap.php @@ -58,7 +58,7 @@ class AttributeTypeTableMap extends TableMap /** * The total number of columns */ - const NUM_COLUMNS = 12; + const NUM_COLUMNS = 15; /** * The number of lazy-loaded columns @@ -68,7 +68,7 @@ class AttributeTypeTableMap extends TableMap /** * The number of columns to hydrate (NUM_COLUMNS - NUM_LAZY_LOAD_COLUMNS) */ - const NUM_HYDRATE_COLUMNS = 12; + const NUM_HYDRATE_COLUMNS = 15; /** * the column name for the ID field @@ -120,6 +120,21 @@ class AttributeTypeTableMap extends TableMap */ const STEP = 'attribute_type.STEP'; + /** + * the column name for the IMAGE_MAX_WIDTH field + */ + const IMAGE_MAX_WIDTH = 'attribute_type.IMAGE_MAX_WIDTH'; + + /** + * the column name for the IMAGE_MAX_HEIGHT field + */ + const IMAGE_MAX_HEIGHT = 'attribute_type.IMAGE_MAX_HEIGHT'; + + /** + * the column name for the IMAGE_RATIO field + */ + const IMAGE_RATIO = 'attribute_type.IMAGE_RATIO'; + /** * the column name for the CREATED_AT field */ @@ -151,12 +166,12 @@ class AttributeTypeTableMap extends TableMap * e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id' */ protected static $fieldNames = array ( - self::TYPE_PHPNAME => array('Id', 'Slug', 'HasAttributeAvValue', 'IsMultilingualAttributeAvValue', 'Pattern', 'CssClass', 'InputType', 'Max', 'Min', 'Step', 'CreatedAt', 'UpdatedAt', ), - self::TYPE_STUDLYPHPNAME => array('id', 'slug', 'hasAttributeAvValue', 'isMultilingualAttributeAvValue', 'pattern', 'cssClass', 'inputType', 'max', 'min', 'step', 'createdAt', 'updatedAt', ), - self::TYPE_COLNAME => array(AttributeTypeTableMap::ID, AttributeTypeTableMap::SLUG, AttributeTypeTableMap::HAS_ATTRIBUTE_AV_VALUE, AttributeTypeTableMap::IS_MULTILINGUAL_ATTRIBUTE_AV_VALUE, AttributeTypeTableMap::PATTERN, AttributeTypeTableMap::CSS_CLASS, AttributeTypeTableMap::INPUT_TYPE, AttributeTypeTableMap::MAX, AttributeTypeTableMap::MIN, AttributeTypeTableMap::STEP, AttributeTypeTableMap::CREATED_AT, AttributeTypeTableMap::UPDATED_AT, ), - self::TYPE_RAW_COLNAME => array('ID', 'SLUG', 'HAS_ATTRIBUTE_AV_VALUE', 'IS_MULTILINGUAL_ATTRIBUTE_AV_VALUE', 'PATTERN', 'CSS_CLASS', 'INPUT_TYPE', 'MAX', 'MIN', 'STEP', 'CREATED_AT', 'UPDATED_AT', ), - self::TYPE_FIELDNAME => array('id', 'slug', 'has_attribute_av_value', 'is_multilingual_attribute_av_value', 'pattern', 'css_class', 'input_type', 'max', 'min', 'step', 'created_at', 'updated_at', ), - self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ) + self::TYPE_PHPNAME => array('Id', 'Slug', 'HasAttributeAvValue', 'IsMultilingualAttributeAvValue', 'Pattern', 'CssClass', 'InputType', 'Max', 'Min', 'Step', 'ImageMaxWidth', 'ImageMaxHeight', 'ImageRatio', 'CreatedAt', 'UpdatedAt', ), + self::TYPE_STUDLYPHPNAME => array('id', 'slug', 'hasAttributeAvValue', 'isMultilingualAttributeAvValue', 'pattern', 'cssClass', 'inputType', 'max', 'min', 'step', 'imageMaxWidth', 'imageMaxHeight', 'imageRatio', 'createdAt', 'updatedAt', ), + self::TYPE_COLNAME => array(AttributeTypeTableMap::ID, AttributeTypeTableMap::SLUG, AttributeTypeTableMap::HAS_ATTRIBUTE_AV_VALUE, AttributeTypeTableMap::IS_MULTILINGUAL_ATTRIBUTE_AV_VALUE, AttributeTypeTableMap::PATTERN, AttributeTypeTableMap::CSS_CLASS, AttributeTypeTableMap::INPUT_TYPE, AttributeTypeTableMap::MAX, AttributeTypeTableMap::MIN, AttributeTypeTableMap::STEP, AttributeTypeTableMap::IMAGE_MAX_WIDTH, AttributeTypeTableMap::IMAGE_MAX_HEIGHT, AttributeTypeTableMap::IMAGE_RATIO, AttributeTypeTableMap::CREATED_AT, AttributeTypeTableMap::UPDATED_AT, ), + self::TYPE_RAW_COLNAME => array('ID', 'SLUG', 'HAS_ATTRIBUTE_AV_VALUE', 'IS_MULTILINGUAL_ATTRIBUTE_AV_VALUE', 'PATTERN', 'CSS_CLASS', 'INPUT_TYPE', 'MAX', 'MIN', 'STEP', 'IMAGE_MAX_WIDTH', 'IMAGE_MAX_HEIGHT', 'IMAGE_RATIO', 'CREATED_AT', 'UPDATED_AT', ), + self::TYPE_FIELDNAME => array('id', 'slug', 'has_attribute_av_value', 'is_multilingual_attribute_av_value', 'pattern', 'css_class', 'input_type', 'max', 'min', 'step', 'image_max_width', 'image_max_height', 'image_ratio', 'created_at', 'updated_at', ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, ) ); /** @@ -166,12 +181,12 @@ class AttributeTypeTableMap extends TableMap * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 */ protected static $fieldKeys = array ( - self::TYPE_PHPNAME => array('Id' => 0, 'Slug' => 1, 'HasAttributeAvValue' => 2, 'IsMultilingualAttributeAvValue' => 3, 'Pattern' => 4, 'CssClass' => 5, 'InputType' => 6, 'Max' => 7, 'Min' => 8, 'Step' => 9, 'CreatedAt' => 10, 'UpdatedAt' => 11, ), - self::TYPE_STUDLYPHPNAME => array('id' => 0, 'slug' => 1, 'hasAttributeAvValue' => 2, 'isMultilingualAttributeAvValue' => 3, 'pattern' => 4, 'cssClass' => 5, 'inputType' => 6, 'max' => 7, 'min' => 8, 'step' => 9, 'createdAt' => 10, 'updatedAt' => 11, ), - self::TYPE_COLNAME => array(AttributeTypeTableMap::ID => 0, AttributeTypeTableMap::SLUG => 1, AttributeTypeTableMap::HAS_ATTRIBUTE_AV_VALUE => 2, AttributeTypeTableMap::IS_MULTILINGUAL_ATTRIBUTE_AV_VALUE => 3, AttributeTypeTableMap::PATTERN => 4, AttributeTypeTableMap::CSS_CLASS => 5, AttributeTypeTableMap::INPUT_TYPE => 6, AttributeTypeTableMap::MAX => 7, AttributeTypeTableMap::MIN => 8, AttributeTypeTableMap::STEP => 9, AttributeTypeTableMap::CREATED_AT => 10, AttributeTypeTableMap::UPDATED_AT => 11, ), - self::TYPE_RAW_COLNAME => array('ID' => 0, 'SLUG' => 1, 'HAS_ATTRIBUTE_AV_VALUE' => 2, 'IS_MULTILINGUAL_ATTRIBUTE_AV_VALUE' => 3, 'PATTERN' => 4, 'CSS_CLASS' => 5, 'INPUT_TYPE' => 6, 'MAX' => 7, 'MIN' => 8, 'STEP' => 9, 'CREATED_AT' => 10, 'UPDATED_AT' => 11, ), - self::TYPE_FIELDNAME => array('id' => 0, 'slug' => 1, 'has_attribute_av_value' => 2, 'is_multilingual_attribute_av_value' => 3, 'pattern' => 4, 'css_class' => 5, 'input_type' => 6, 'max' => 7, 'min' => 8, 'step' => 9, 'created_at' => 10, 'updated_at' => 11, ), - self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ) + self::TYPE_PHPNAME => array('Id' => 0, 'Slug' => 1, 'HasAttributeAvValue' => 2, 'IsMultilingualAttributeAvValue' => 3, 'Pattern' => 4, 'CssClass' => 5, 'InputType' => 6, 'Max' => 7, 'Min' => 8, 'Step' => 9, 'ImageMaxWidth' => 10, 'ImageMaxHeight' => 11, 'ImageRatio' => 12, 'CreatedAt' => 13, 'UpdatedAt' => 14, ), + self::TYPE_STUDLYPHPNAME => array('id' => 0, 'slug' => 1, 'hasAttributeAvValue' => 2, 'isMultilingualAttributeAvValue' => 3, 'pattern' => 4, 'cssClass' => 5, 'inputType' => 6, 'max' => 7, 'min' => 8, 'step' => 9, 'imageMaxWidth' => 10, 'imageMaxHeight' => 11, 'imageRatio' => 12, 'createdAt' => 13, 'updatedAt' => 14, ), + self::TYPE_COLNAME => array(AttributeTypeTableMap::ID => 0, AttributeTypeTableMap::SLUG => 1, AttributeTypeTableMap::HAS_ATTRIBUTE_AV_VALUE => 2, AttributeTypeTableMap::IS_MULTILINGUAL_ATTRIBUTE_AV_VALUE => 3, AttributeTypeTableMap::PATTERN => 4, AttributeTypeTableMap::CSS_CLASS => 5, AttributeTypeTableMap::INPUT_TYPE => 6, AttributeTypeTableMap::MAX => 7, AttributeTypeTableMap::MIN => 8, AttributeTypeTableMap::STEP => 9, AttributeTypeTableMap::IMAGE_MAX_WIDTH => 10, AttributeTypeTableMap::IMAGE_MAX_HEIGHT => 11, AttributeTypeTableMap::IMAGE_RATIO => 12, AttributeTypeTableMap::CREATED_AT => 13, AttributeTypeTableMap::UPDATED_AT => 14, ), + self::TYPE_RAW_COLNAME => array('ID' => 0, 'SLUG' => 1, 'HAS_ATTRIBUTE_AV_VALUE' => 2, 'IS_MULTILINGUAL_ATTRIBUTE_AV_VALUE' => 3, 'PATTERN' => 4, 'CSS_CLASS' => 5, 'INPUT_TYPE' => 6, 'MAX' => 7, 'MIN' => 8, 'STEP' => 9, 'IMAGE_MAX_WIDTH' => 10, 'IMAGE_MAX_HEIGHT' => 11, 'IMAGE_RATIO' => 12, 'CREATED_AT' => 13, 'UPDATED_AT' => 14, ), + self::TYPE_FIELDNAME => array('id' => 0, 'slug' => 1, 'has_attribute_av_value' => 2, 'is_multilingual_attribute_av_value' => 3, 'pattern' => 4, 'css_class' => 5, 'input_type' => 6, 'max' => 7, 'min' => 8, 'step' => 9, 'image_max_width' => 10, 'image_max_height' => 11, 'image_ratio' => 12, 'created_at' => 13, 'updated_at' => 14, ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, ) ); /** @@ -200,6 +215,9 @@ public function initialize() $this->addColumn('MAX', 'Max', 'FLOAT', false, null, null); $this->addColumn('MIN', 'Min', 'FLOAT', false, null, null); $this->addColumn('STEP', 'Step', 'FLOAT', false, null, null); + $this->addColumn('IMAGE_MAX_WIDTH', 'ImageMaxWidth', 'FLOAT', false, null, null); + $this->addColumn('IMAGE_MAX_HEIGHT', 'ImageMaxHeight', 'FLOAT', false, null, null); + $this->addColumn('IMAGE_RATIO', 'ImageRatio', 'FLOAT', false, null, null); $this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null); $this->addColumn('UPDATED_AT', 'UpdatedAt', 'TIMESTAMP', false, null, null); } // initialize() @@ -386,6 +404,9 @@ public static function addSelectColumns(Criteria $criteria, $alias = null) $criteria->addSelectColumn(AttributeTypeTableMap::MAX); $criteria->addSelectColumn(AttributeTypeTableMap::MIN); $criteria->addSelectColumn(AttributeTypeTableMap::STEP); + $criteria->addSelectColumn(AttributeTypeTableMap::IMAGE_MAX_WIDTH); + $criteria->addSelectColumn(AttributeTypeTableMap::IMAGE_MAX_HEIGHT); + $criteria->addSelectColumn(AttributeTypeTableMap::IMAGE_RATIO); $criteria->addSelectColumn(AttributeTypeTableMap::CREATED_AT); $criteria->addSelectColumn(AttributeTypeTableMap::UPDATED_AT); } else { @@ -399,6 +420,9 @@ public static function addSelectColumns(Criteria $criteria, $alias = null) $criteria->addSelectColumn($alias . '.MAX'); $criteria->addSelectColumn($alias . '.MIN'); $criteria->addSelectColumn($alias . '.STEP'); + $criteria->addSelectColumn($alias . '.IMAGE_MAX_WIDTH'); + $criteria->addSelectColumn($alias . '.IMAGE_MAX_HEIGHT'); + $criteria->addSelectColumn($alias . '.IMAGE_RATIO'); $criteria->addSelectColumn($alias . '.CREATED_AT'); $criteria->addSelectColumn($alias . '.UPDATED_AT'); } diff --git a/Readme.md b/Readme.md index 5b7abe7..ee63787 100644 --- a/Readme.md +++ b/Readme.md @@ -28,7 +28,7 @@ Thelia >= 2.1 Add it in your main thelia composer.json file ``` -composer require thelia/attribute-type-module:~1.2.0 +composer require thelia/attribute-type-module:~1.3.0 ``` ## Usage @@ -73,6 +73,9 @@ composer require thelia/attribute-type-module:~1.2.0 |MIN | The attribute type minimum value | |MAX | The attribute type maximum value | |STEP | The attribute type step value | +|IMAGE_MAX_WIDTH | The max width for image (in px) | +|IMAGE_MAX_HEIGHT | The max height for image (in px) | +|IMAGE_RATIO | The image ratio required | |IS_MULTILINGUAL_ATTRIBUTE_AV_VALUE | Indicates whether the values are unique for each language | |HAS_ATTRIBUTE_AV_VALUE | Indicates whether the type attribute has values for each attribute av | diff --git a/templates/backOffice/default/attribute-type/configuration-js.html b/templates/backOffice/default/attribute-type/configuration-js.html index b9ad0f9..720d18a 100644 --- a/templates/backOffice/default/attribute-type/configuration-js.html +++ b/templates/backOffice/default/attribute-type/configuration-js.html @@ -28,7 +28,10 @@ ',#atcf-css_class' + ',#atcf-min' + ',#atcf-max' + - ',#atcf-step') + ',#atcf-step' + + ',#atcf-image_max_width' + + ',#atcf-image_max_height' + + ',#atcf-image_ratio') .parents('.col-md-6'); if (this.checked) { @@ -40,25 +43,36 @@ }); $module.on('change', '#atcf-input_type', function(){ - var val = $(this).val(); + var val = $(this).val(); - var $fields = $module.find('.js-modal-create') - .find('#atcf-min, #atcf-max, #atcf-step') - .parents('.col-md-6'); - - var $pattern = $module.find('.js-modal-create #atcf-pattern').parents('.col-md-6'); + if (!$module.find('#atcf-has_attribute_av_value').is(':checked')) { + return; + } - if (val == 'text' || val == 'color' || val == 'url' || val == 'textarea' || val == "boolean") { - $fields.addClass('hide'); - if (val == 'textarea' || val == 'boolean' || !$module.find('#atcf-has_attribute_av_value').is(':checked')) { - $pattern.addClass('hide'); - } else { - $pattern.removeClass('hide'); + var $patternField = $module.find('.js-modal-create #atcf-pattern').parents('.col-md-6'); + var $numericFields = $module.find('.js-modal-create') + .find('#atcf-min, #atcf-max, #atcf-step') + .parents('.col-md-6'); + var $imageFields = $module.find('.js-modal-create') + .find('#atcf-image_max_width, #atcf-image_max_height, #atcf-image_ratio') + .parents('.col-md-6'); + if (val == 'text' || val == 'color' || val == 'url') { + $numericFields.addClass('hide'); + $imageFields.addClass('hide'); + $patternField.removeClass('hide'); + } else if (val == 'textarea' || val == 'boolean') { + $patternField.addClass('hide'); + $numericFields.addClass('hide'); + $imageFields.addClass('hide'); + } else if(val == 'range' || val == 'number') { + $imageFields.addClass('hide'); + $numericFields.removeClass('hide'); + $patternField.removeClass('hide'); + } else if(val == 'image') { + $numericFields.addClass('hide'); + $imageFields.removeClass('hide'); + $patternField.removeClass('hide'); } - } else { - $fields.removeClass('hide'); - $pattern.removeClass('hide'); - } }); /*****************************************/ @@ -110,7 +124,11 @@ ',#atuf-css_class' + ',#atuf-min' + ',#atuf-max' + - ',#atuf-step') + ',#atuf-step' + + ',#atuf-image_max_width' + + ',#atuf-image_max_height' + + ',#atuf-image_ratio' + ) .parents('.col-md-6'); if (this.checked) { @@ -122,25 +140,36 @@ }); $module.on('change', '#atuf-input_type', function(){ - var val = $(this).val(); - - var $fields = $module.find('.js-modal-edit') - .find('#atuf-min, #atuf-max, #atuf-step') - .parents('.col-md-6'); + if (!$module.find('#atuf-has_attribute_av_value').is(':checked')) { + return; + } - var $pattern = $module.find('.js-modal-edit #atuf-pattern').parents('.col-md-6'); - if (val == 'text' || val == 'color' || val == 'url' || val == 'textarea' || val == "boolean") { - $fields.addClass('hide'); - if (val == 'textarea' || val == 'boolean' || !$module.find('#atuf-has_attribute_av_value').is(':checked')) { - $pattern.addClass('hide'); - } else { - $pattern.removeClass('hide'); + var val = $(this).val(); + var $patternField = $module.find('.js-modal-edit #atuf-pattern').parents('.col-md-6'); + var $numericFields = $module.find('.js-modal-edit') + .find('#atuf-min, #atuf-max, #atuf-step') + .parents('.col-md-6'); + var $imageFields = $module.find('.js-modal-edit') + .find('#atuf-image_max_width, #atuf-image_max_height, #atuf-image_ratio') + .parents('.col-md-6'); + if (val == 'text' || val == 'color' || val == 'url') { + $numericFields.addClass('hide'); + $imageFields.addClass('hide'); + $patternField.removeClass('hide'); + } else if (val == 'textarea' || val == 'boolean') { + $patternField.addClass('hide'); + $numericFields.addClass('hide'); + $imageFields.addClass('hide'); + } else if(val == 'range' || val == 'number') { + $imageFields.addClass('hide'); + $numericFields.removeClass('hide'); + $patternField.removeClass('hide'); + } else if(val == 'image') { + $numericFields.addClass('hide'); + $imageFields.removeClass('hide'); + $patternField.removeClass('hide'); } - } else { - $fields.removeClass('hide'); - $pattern.removeClass('hide'); - } }); /*****************************************/ /************ Attribute copy *************/ diff --git a/templates/backOffice/default/attribute-type/hook/attribute-edit-js.html b/templates/backOffice/default/attribute-type/hook/attribute-edit-js.html index b169b06..2d52dc4 100644 --- a/templates/backOffice/default/attribute-type/hook/attribute-edit-js.html +++ b/templates/backOffice/default/attribute-type/hook/attribute-edit-js.html @@ -1,6 +1,13 @@ \ No newline at end of file diff --git a/templates/backOffice/default/attribute-type/include/form-generic.html b/templates/backOffice/default/attribute-type/include/form-generic.html index 90e99a8..7a6c555 100644 --- a/templates/backOffice/default/attribute-type/include/form-generic.html +++ b/templates/backOffice/default/attribute-type/include/form-generic.html @@ -139,6 +139,34 @@ {/form_field} +
+ {form_field form=$form field='image_max_width'} +
+ + + {intl l="Image maximum width in pixels" d="attributetype.bo.default"} +
+ {/form_field} +
+
+ {form_field form=$form field='image_max_height'} +
+ + + {intl l="Image maximum height in pixels" d="attributetype.bo.default"} +
+ {/form_field} +
+
+ {form_field form=$form field='image_ratio'} +
+ + + {intl l="Image ratio/1, given by width/height (ex 1.77 = equal to 16:9 ratio)" d="attributetype.bo.default"} +
+ {/form_field} +
+ {hook name="attribute-type.form-bottom" attribute_type_id=$attribute_type_id} diff --git a/templates/backOffice/default/attribute-type/include/form-meta.html b/templates/backOffice/default/attribute-type/include/form-meta.html index b70e7f4..6ebdddf 100644 --- a/templates/backOffice/default/attribute-type/include/form-meta.html +++ b/templates/backOffice/default/attribute-type/include/form-meta.html @@ -1,7 +1,7 @@ {$prefix = 'aamu-'} {form name="attribute_type_av_meta.update"} -
+ {form_hidden_fields form=$form} {form_field form=$form field='success_url'} @@ -72,27 +72,58 @@ {loop type="attribute_type" name="attribute_type_input" attribute_id=$attribute_id lang=$lang_id} {if $HAS_ATTRIBUTE_AV_VALUE} -
{form_field form=$form field='attribute_av' value_key=$ID} {if $INPUT_TYPE == "textarea"} - +
+ +
{elseif $INPUT_TYPE == "boolean"} - +
+ +
+ {elseif $INPUT_TYPE == "image"} +
+ {$imageExist = !!$form_meta_data['attribute_av'][$attribute_av_id]['lang'][$lang_id]['attribute_type'][$ID]} +
+ + {if $imageExist} + + {/if} +
+ +
{else} - + +
{/if} {/form_field} @@ -120,10 +152,65 @@
+
-{/form} \ No newline at end of file +{/form} + + + +{form name="attribute_type.delete"} +
+ {form_hidden_fields form=$form} + + {form_field form=$form field='success_url'} + + {/form_field} + + +
+{/form} + + \ No newline at end of file