From 9ee8b2b75fff9ef9d9c0ed725d7fb66fa199ed64 Mon Sep 17 00:00:00 2001 From: gmorel Date: Mon, 23 Sep 2013 18:13:12 +0200 Subject: [PATCH] WIP : upload document : add forms --- .../Form/CategoryDocumentModification.php | 54 +++++++ .../Form/ContentDocumentModification.php | 54 +++++++ .../Form/FolderDocumentModification.php | 54 +++++++ .../Form/Image/DocumentModification.php | 138 ++++++++++++++++++ .../Thelia/Form/Image/ImageModification.php | 67 ++------- .../Form/ProductDocumentModification.php | 54 +++++++ .../default/includes/image-upload-form.html | 2 +- 7 files changed, 370 insertions(+), 53 deletions(-) create mode 100644 core/lib/Thelia/Form/CategoryDocumentModification.php create mode 100644 core/lib/Thelia/Form/ContentDocumentModification.php create mode 100644 core/lib/Thelia/Form/FolderDocumentModification.php create mode 100644 core/lib/Thelia/Form/Image/DocumentModification.php create mode 100644 core/lib/Thelia/Form/ProductDocumentModification.php diff --git a/core/lib/Thelia/Form/CategoryDocumentModification.php b/core/lib/Thelia/Form/CategoryDocumentModification.php new file mode 100644 index 000000000..47c637df0 --- /dev/null +++ b/core/lib/Thelia/Form/CategoryDocumentModification.php @@ -0,0 +1,54 @@ +. */ +/* */ +/*************************************************************************************/ +namespace Thelia\Form; + + +use Thelia\Core\Translation\Translator; +use Thelia\Form\Image\DocumentModification; +use Thelia\Form\Image\ImageModification; + +/** + * Created by JetBrains PhpStorm. + * Date: 9/18/13 + * Time: 3:56 PM + * + * Form allowing to process an document collection + * + * @package Image + * @author Guillaume MOREL + * + */ +class CategoryDocumentModification extends DocumentModification +{ + + /** + * Get form name + * This name must be unique + * + * @return string + */ + public function getName() + { + return 'thelia_category_document_modification'; + } +} diff --git a/core/lib/Thelia/Form/ContentDocumentModification.php b/core/lib/Thelia/Form/ContentDocumentModification.php new file mode 100644 index 000000000..748eec0ec --- /dev/null +++ b/core/lib/Thelia/Form/ContentDocumentModification.php @@ -0,0 +1,54 @@ +. */ +/* */ +/*************************************************************************************/ +namespace Thelia\Form; + + +use Thelia\Core\Translation\Translator; +use Thelia\Form\Image\DocumentModification; +use Thelia\Form\Image\ImageModification; + +/** + * Created by JetBrains PhpStorm. + * Date: 9/18/13 + * Time: 3:56 PM + * + * Form allowing to process a file + * + * @package File + * @author Guillaume MOREL + * + */ +class ContentDocumentModification extends DocumentModification +{ + + /** + * Get form name + * This name must be unique + * + * @return string + */ + public function getName() + { + return 'thelia_content_document_modification'; + } +} diff --git a/core/lib/Thelia/Form/FolderDocumentModification.php b/core/lib/Thelia/Form/FolderDocumentModification.php new file mode 100644 index 000000000..bbf57ab9d --- /dev/null +++ b/core/lib/Thelia/Form/FolderDocumentModification.php @@ -0,0 +1,54 @@ +. */ +/* */ +/*************************************************************************************/ +namespace Thelia\Form; + + +use Thelia\Core\Translation\Translator; +use Thelia\Form\Image\DocumentModification; +use Thelia\Form\Image\ImageModification; + +/** + * Created by JetBrains PhpStorm. + * Date: 9/18/13 + * Time: 3:56 PM + * + * Form allowing to process a file + * + * @package Image + * @author Guillaume MOREL + * + */ +class FolderDocumentModification extends DocumentModification +{ + + /** + * Get form name + * This name must be unique + * + * @return string + */ + public function getName() + { + return 'thelia_folder_document_modification'; + } +} diff --git a/core/lib/Thelia/Form/Image/DocumentModification.php b/core/lib/Thelia/Form/Image/DocumentModification.php new file mode 100644 index 000000000..412da0660 --- /dev/null +++ b/core/lib/Thelia/Form/Image/DocumentModification.php @@ -0,0 +1,138 @@ +. */ +/* */ +/*************************************************************************************/ +namespace Thelia\Form\Image; + +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\Validator\Constraints\Image; +use Symfony\Component\Validator\Constraints\NotBlank; +use Thelia\Core\Translation\Translator; +use Thelia\Form\BaseForm; + +/** + * Created by JetBrains PhpStorm. + * Date: 9/18/13 + * Time: 3:56 PM + * + * Form allowing to process a file + * @todo refactor make all document using propel inheritance and factorise image behaviour into one single clean action + * + * @package File + * @author Guillaume MOREL + * + */ +abstract class DocumentModification extends BaseForm +{ + /** + * + * in this function you add all the fields you need for your Form. + * Form this you have to call add method on $this->form attribute : + * + * $this->form->add('name', 'text') + * ->add('email', 'email', array( + * 'attr' => array( + * 'class' => 'field' + * ), + * 'label' => 'email', + * 'constraints' => array( + * new NotBlank() + * ) + * ) + * ) + * ->add('age', 'integer'); + * + * @return null + */ + protected function buildForm() + { + $this->formBuilder->add( + 'file', + 'file', + array( + 'constraints' => array(), + 'label' => Translator::getInstance()->trans('File'), + 'label_attr' => array( + 'for' => 'file' + ) + ) + ); + + $this->formBuilder + ->add( + 'title', + 'text', + array( + 'constraints' => array( + new NotBlank() + ), + 'label' => Translator::getInstance()->trans('Title'), + 'label_attr' => array( + 'for' => 'title' + ) + ) + ) + ->add( + 'description', + 'text', + array( + 'constraints' => array(), + 'label' => Translator::getInstance()->trans('Description'), + 'label_attr' => array( + 'for' => 'description' + ) + ) + ) + ->add( + 'chapo', + 'text', + array( + 'constraints' => array(), + 'label' => Translator::getInstance()->trans('Chapo'), + 'label_attr' => array( + 'for' => 'chapo' + ) + ) + ) + ->add( + 'postscriptum', + 'text', + array( + 'constraints' => array(), + 'label' => Translator::getInstance()->trans('Post Scriptum'), + 'label_attr' => array( + 'for' => 'postscriptum' + ) + ) + ) + ->add( + 'postscriptum', + 'text', + array( + 'constraints' => array(), + 'label' => Translator::getInstance()->trans('Post Scriptum'), + 'label_attr' => array( + 'for' => 'postscriptum' + ) + ) + ); + } +} diff --git a/core/lib/Thelia/Form/Image/ImageModification.php b/core/lib/Thelia/Form/Image/ImageModification.php index 4d0d10694..99e12d72c 100644 --- a/core/lib/Thelia/Form/Image/ImageModification.php +++ b/core/lib/Thelia/Form/Image/ImageModification.php @@ -43,15 +43,6 @@ use Thelia\Form\BaseForm; abstract class ImageModification extends BaseForm { -// public function __construct(Request $request, $type= "form", $data = array(), $options = array(), $isUpdate = false) -// { -// parent::__construct($request, $type, $data, $options); -// $this->setIsUpdate($isUpdate); -// } - -// /** @var bool Flag for update/create mode */ -// protected $isUpdate = false; - /** * * in this function you add all the fields you need for your Form. @@ -74,27 +65,24 @@ abstract class ImageModification extends BaseForm */ protected function buildForm() { -// if (false === $this->isUpdate) { - $this->formBuilder->add( - 'file', - 'file', - array( - 'constraints' => array( -// new NotBlank(), - new Image( - array( - 'minWidth' => 200, - 'minHeight' => 200 - ) + $this->formBuilder->add( + 'file', + 'file', + array( + 'constraints' => array( + new Image( + array( + 'minWidth' => 200, + 'minHeight' => 200 ) - ), - 'label' => Translator::getInstance()->trans('File'), - 'label_attr' => array( - 'for' => 'file' ) + ), + 'label' => Translator::getInstance()->trans('File'), + 'label_attr' => array( + 'for' => 'file' ) - ); -// } + ) + ); $this->formBuilder ->add( @@ -154,30 +142,5 @@ abstract class ImageModification extends BaseForm ) ) ); - - } - -// /** -// * Set form in update or create mode -// * -// * @param boolean $isUpdate -// */ -// public function setIsUpdate($isUpdate) -// { -// $this->isUpdate = $isUpdate; -// } -// -// /** -// * Get for mode -// * -// * @return boolean -// */ -// public function getIsUpdate() -// { -// return $this->isUpdate; -// } - - - } diff --git a/core/lib/Thelia/Form/ProductDocumentModification.php b/core/lib/Thelia/Form/ProductDocumentModification.php new file mode 100644 index 000000000..1a9bc5467 --- /dev/null +++ b/core/lib/Thelia/Form/ProductDocumentModification.php @@ -0,0 +1,54 @@ +. */ +/* */ +/*************************************************************************************/ +namespace Thelia\Form; + + +use Thelia\Core\Translation\Translator; +use Thelia\Form\Image\DocumentModification; +use Thelia\Form\Image\ImageModification; + +/** + * Created by JetBrains PhpStorm. + * Date: 9/18/13 + * Time: 3:56 PM + * + * Form allowing to process a file + * + * @package File + * @author Guillaume MOREL + * + */ +class ProductDocumentModification extends DocumentModification +{ + + /** + * Get form name + * This name must be unique + * + * @return string + */ + public function getName() + { + return 'thelia_product_document_modification'; + } +} diff --git a/templates/admin/default/includes/image-upload-form.html b/templates/admin/default/includes/image-upload-form.html index 8f885fec7..00915e8a7 100644 --- a/templates/admin/default/includes/image-upload-form.html +++ b/templates/admin/default/includes/image-upload-form.html @@ -10,7 +10,7 @@ Parameters:
- +