From 962081c17d8e0f6fd7a21f5b810768445f6046ec Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Sat, 21 Sep 2013 13:42:00 +0200 Subject: [PATCH 01/15] use placeholder in folder update route --- core/lib/Thelia/Config/Resources/routing/admin.xml | 3 ++- core/lib/Thelia/Controller/Admin/FolderController.php | 2 +- templates/admin/default/folder-edit.html | 6 +++--- templates/admin/default/folders.html | 4 ++-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index 0b129fd0b..ead09c166 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -200,8 +200,9 @@ Thelia\Controller\Admin\FolderController::createAction - + Thelia\Controller\Admin\FolderController::updateAction + \d+ diff --git a/core/lib/Thelia/Controller/Admin/FolderController.php b/core/lib/Thelia/Controller/Admin/FolderController.php index db8a83e48..92fe49389 100644 --- a/core/lib/Thelia/Controller/Admin/FolderController.php +++ b/core/lib/Thelia/Controller/Admin/FolderController.php @@ -312,7 +312,7 @@ class FolderController extends AbstractCrudController */ protected function redirectToEditionTemplate() { - $this->redirectToRoute("admin.folders.update", $this->getEditionArguments()); + $this->redirect($this->getRoute('admin.folders.update', $this->getEditionArguments())); } /** diff --git a/templates/admin/default/folder-edit.html b/templates/admin/default/folder-edit.html index 26795b7aa..1821f3bcc 100644 --- a/templates/admin/default/folder-edit.html +++ b/templates/admin/default/folder-edit.html @@ -21,7 +21,7 @@
{if $HAS_PREVIOUS != 0} - + {else} {/if} @@ -29,7 +29,7 @@ {if $HAS_NEXT != 0} - + {else} {/if} @@ -67,7 +67,7 @@ {form_hidden_fields form=$form} {form_field form=$form field='success_url'} - + {/form_field} {form_field form=$form field='locale'} diff --git a/templates/admin/default/folders.html b/templates/admin/default/folders.html index 4cb4eca12..ae24568c8 100644 --- a/templates/admin/default/folders.html +++ b/templates/admin/default/folders.html @@ -146,7 +146,7 @@ {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.folders.edit"} - + {/loop} {loop type="auth" name="can_delete" roles="ADMIN" permissions="admin.folders.delete"} @@ -344,7 +344,7 @@ {form_field form=$form field='success_url'} {* on success, redirect to the edition page, _ID_ is replaced with the created object ID, see controller *} - + {/form_field} {form_field form=$form field='parent'} From bb796f08b698211407d442d939ea57cf0d9518d5 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Sat, 21 Sep 2013 13:55:12 +0200 Subject: [PATCH 02/15] change folder_id parm by parent in list folder view --- .../Controller/Admin/FolderController.php | 10 +++--- templates/admin/default/folders.html | 32 +++++++++---------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/core/lib/Thelia/Controller/Admin/FolderController.php b/core/lib/Thelia/Controller/Admin/FolderController.php index 92fe49389..67dd39b38 100644 --- a/core/lib/Thelia/Controller/Admin/FolderController.php +++ b/core/lib/Thelia/Controller/Admin/FolderController.php @@ -235,7 +235,7 @@ class FolderController extends AbstractCrudController array( 'folder_order' => $currentOrder, 'content_order' => $product_order, - 'folder_id' => $this->getRequest()->get('folder_id', 0) + 'parent' => $this->getRequest()->get('parent', 0) )); } @@ -267,7 +267,7 @@ class FolderController extends AbstractCrudController // Redirect to parent category list $this->redirectToRoute( 'admin.folders.default', - array('folder_id' => $updateEvent->getFolder()->getParent()) + array('parent' => $updateEvent->getFolder()->getParent()) ); } } @@ -283,7 +283,7 @@ class FolderController extends AbstractCrudController // Redirect to parent category list $this->redirectToRoute( 'admin.folders.default', - array('folder_id' => $deleteEvent->getFolder()->getParent()) + array('parent' => $deleteEvent->getFolder()->getParent()) ); } @@ -300,7 +300,7 @@ class FolderController extends AbstractCrudController // Redirect to parent category list $this->redirectToRoute( 'admin.folders.default', - array('folder_id' => $folder->getParent()) + array('parent' => $folder->getParent()) ); } @@ -322,7 +322,7 @@ class FolderController extends AbstractCrudController { $this->redirectToRoute( 'admin.folders.default', - array('folder_id' => $this->getRequest()->get('folder_id', 0)) + array('parent' => $this->getRequest()->get('parent', 0)) ); } } \ No newline at end of file diff --git a/templates/admin/default/folders.html b/templates/admin/default/folders.html index ae24568c8..658919208 100644 --- a/templates/admin/default/folders.html +++ b/templates/admin/default/folders.html @@ -20,7 +20,7 @@ @@ -50,7 +50,7 @@ current_order=$folder_order order='id' reverse_order='id_reverse' - path={url path='/admin/folders' folder_id=$folder_id} + path={url path='/admin/folders' parent=$parent} request_parameter_name='folder_order' label="{intl l='ID'}" } @@ -63,7 +63,7 @@ current_order=$folder_order order='alpha' reverse_order='alpha_reverse' - path={url path='/admin/folders' folder_id=$folder_id} + path={url path='/admin/folders' parent=$parent} request_parameter_name='folder_order' label="{intl l='Folder title'}" } @@ -76,7 +76,7 @@ current_order=$folder_order order='visible' reverse_order='visible_reverse' - path={url path='/admin/folders' folder_id=$folder_id} + path={url path='/admin/folders' parent=$parent} request_parameter_name='folder_order' label="{intl l='Online'}" } @@ -87,7 +87,7 @@ current_order=$folder_order order='manual' reverse_order='manual_reverse' - path={url path='/admin/folders' folder_id=$folder_id} + path={url path='/admin/folders' parent=$parent} request_parameter_name='folder_order' label="{intl l='Position'}" } @@ -98,18 +98,18 @@ - {loop name="folder_list" type="folder" visible="*" parent=$folder_id order=$folder_order backend_context="1" lang=$lang_id} + {loop name="folder_list" type="folder" visible="*" parent=$parent order=$folder_order backend_context="1" lang=$lang_id} @@ -143,7 +143,7 @@
{* display parent folder name, and get current folder ID *} - {loop name="folder_title" type="folder" visible="*" id=$folder_id} + {loop name="folder_title" type="folder" visible="*" id=$parent} {intl l="Folders in %fold" fold=$TITLE} {$fold_id = $ID} {/loop} @@ -29,7 +29,7 @@ {/elseloop}
- + {$TITLE}
{$ID} {loop type="image" name="folder_image" source="folder" source_id="$ID" limit="1" width="50" height="50" resize_mode="crop" backend_context="1"} - {$TITLE} + {$TITLE} {/loop} - + {$TITLE}
- + {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.folders.edit"} @@ -191,7 +191,7 @@ - {loop name="content_list" type="content" visible="*" folder_default=$folder_id order=$content_order} + {loop name="content_list" type="content" visible="*" folder_default=$parent order=$content_order} @@ -348,7 +348,7 @@ {/form_field} {form_field form=$form field='parent'} - + {/form_field} {form_field form=$form field='title'} @@ -412,7 +412,7 @@ {form_hidden_fields form=$form} {* Be sure to get the folder_id, even if the form could not be validated *} - + {form_field form=$form field='success_url'} {* on success, redirect to the edition page, _ID_ is replaced with the created object ID, see controller *} @@ -420,7 +420,7 @@ {/form_field} {form_field form=$form field='default_folder'} - + {/form_field} {form_field form=$form field='title'} @@ -498,7 +498,7 @@ {capture "content_delete_dialog"} - + {module_include location='content_delete_form'} From 52efd79fb5bad0a78e7df8ecd1fdaedc95034a8b Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Sat, 21 Sep 2013 14:10:08 +0200 Subject: [PATCH 03/15] create content controller --- .../Thelia/Config/Resources/routing/admin.xml | 6 + .../Controller/Admin/ContentController.php | 169 ++++++++++++++++++ templates/admin/default/folders.html | 10 +- 3 files changed, 180 insertions(+), 5 deletions(-) create mode 100644 core/lib/Thelia/Controller/Admin/ContentController.php diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index ead09c166..a94c0b4fe 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -221,6 +221,12 @@ Thelia\Controller\Admin\FolderController::updatePositionAction + + + Thelia\Controller\Admin\ContentController::updateAction + \d+ + + diff --git a/core/lib/Thelia/Controller/Admin/ContentController.php b/core/lib/Thelia/Controller/Admin/ContentController.php new file mode 100644 index 000000000..f0abe9a73 --- /dev/null +++ b/core/lib/Thelia/Controller/Admin/ContentController.php @@ -0,0 +1,169 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Controller\Admin; + + +/** + * Class ContentController + * @package Thelia\Controller\Admin + * @author manuel raynaud + */ +class ContentController extends AbstractCrudController { + + /** + * Return the creation form for this object + */ + protected function getCreationForm() + { + // TODO: Implement getCreationForm() method. + } + + /** + * Return the update form for this object + */ + protected function getUpdateForm() + { + // TODO: Implement getUpdateForm() method. + } + + /** + * Hydrate the update form for this object, before passing it to the update template + * + * @param unknown $object + */ + protected function hydrateObjectForm($object) + { + // TODO: Implement hydrateObjectForm() method. + } + + /** + * Creates the creation event with the provided form data + * + * @param unknown $formData + */ + protected function getCreationEvent($formData) + { + // TODO: Implement getCreationEvent() method. + } + + /** + * Creates the update event with the provided form data + * + * @param unknown $formData + */ + protected function getUpdateEvent($formData) + { + // TODO: Implement getUpdateEvent() method. + } + + /** + * Creates the delete event with the provided form data + */ + protected function getDeleteEvent() + { + // TODO: Implement getDeleteEvent() method. + } + + /** + * Return true if the event contains the object, e.g. the action has updated the object in the event. + * + * @param unknown $event + */ + protected function eventContainsObject($event) + { + // TODO: Implement eventContainsObject() method. + } + + /** + * Get the created object from an event. + * + * @param unknown $createEvent + */ + protected function getObjectFromEvent($event) + { + // TODO: Implement getObjectFromEvent() method. + } + + /** + * Load an existing object from the database + */ + protected function getExistingObject() + { + // TODO: Implement getExistingObject() method. + } + + /** + * Returns the object label form the object event (name, title, etc.) + * + * @param unknown $object + */ + protected function getObjectLabel($object) + { + // TODO: Implement getObjectLabel() method. + } + + /** + * Returns the object ID from the object + * + * @param unknown $object + */ + protected function getObjectId($object) + { + // TODO: Implement getObjectId() method. + } + + /** + * Render the main list template + * + * @param unknown $currentOrder, if any, null otherwise. + */ + protected function renderListTemplate($currentOrder) + { + // TODO: Implement renderListTemplate() method. + } + + /** + * Render the edition template + */ + protected function renderEditionTemplate() + { + // TODO: Implement renderEditionTemplate() method. + } + + /** + * Redirect to the edition template + */ + protected function redirectToEditionTemplate() + { + // TODO: Implement redirectToEditionTemplate() method. + } + + /** + * Redirect to the list template + */ + protected function redirectToListTemplate() + { + // TODO: Implement redirectToListTemplate() method. + } +} \ No newline at end of file diff --git a/templates/admin/default/folders.html b/templates/admin/default/folders.html index 658919208..b7d435e88 100644 --- a/templates/admin/default/folders.html +++ b/templates/admin/default/folders.html @@ -214,7 +214,7 @@ current_order=$content_order order='id' reverse_order='id_reverse' - path={url path='/admin/folders' id_folder=$folder_id target='contents'} + path={url path='/admin/folders' parent=$parent target='contents'} label="{intl l='ID'}" } @@ -225,7 +225,7 @@ current_order=$content_order order='alpha' reverse_order='alpha_reverse' - path={url path='/admin/folders' id_folder=$folder_id target='contents'} + path={url path='/admin/folders' parent=$parent target='contents'} label="{intl l='Content title'}" } @@ -236,7 +236,7 @@ current_order=$content_order order='visible' reverse_order='visible_reverse' - path={url path='/admin/folders' id_folder=$folder_id target='contents'} + path={url path='/admin/folders' parent=$parent target='contents'} label="{intl l='Online'}" } @@ -246,7 +246,7 @@ current_order=$content_order order='manual' reverse_order='manual_reverse' - path={url path='/admin/folders' id_folder=$folder_id target='contents'} + path={url path='/admin/folders' parent=$parent target='contents'} label="{intl l='Position'}" } @@ -262,7 +262,7 @@
{* display parent folder name *} - {loop name="folder_title" type="folder" visible="*" id=$folder_id} + {loop name="folder_title" type="folder" visible="*" id=$parent} {intl l="Contents in %fold" fold=$TITLE} {/loop} @@ -256,7 +256,7 @@
{$ID} {loop type="image" name="folder_image" source="content" source_id="$ID" limit="1" width="50" height="50" resize_mode="crop" backend_context="1"} - + {$TITLE} {/loop} From 423860932fcf33df320dc3e42220f967f4136be2 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Sat, 21 Sep 2013 14:32:01 +0200 Subject: [PATCH 04/15] create contentModificationForm --- .../Controller/Admin/ContentController.php | 48 +++++++++++++-- core/lib/Thelia/Core/Event/TheliaEvents.php | 20 ++++++ core/lib/Thelia/Form/ContentCreationForm.php | 2 +- .../Thelia/Form/ContentModificationForm.php | 61 +++++++++++++++++++ .../Thelia/Form/FolderModificationForm.php | 2 +- 5 files changed, 126 insertions(+), 7 deletions(-) create mode 100644 core/lib/Thelia/Form/ContentModificationForm.php diff --git a/core/lib/Thelia/Controller/Admin/ContentController.php b/core/lib/Thelia/Controller/Admin/ContentController.php index f0abe9a73..78ee63391 100644 --- a/core/lib/Thelia/Controller/Admin/ContentController.php +++ b/core/lib/Thelia/Controller/Admin/ContentController.php @@ -22,6 +22,9 @@ /*************************************************************************************/ namespace Thelia\Controller\Admin; +use Thelia\Core\Event\TheliaEvents; +use Thelia\Form\ContentCreationForm; +use Thelia\Form\ContentModificationForm; /** @@ -29,14 +32,35 @@ namespace Thelia\Controller\Admin; * @package Thelia\Controller\Admin * @author manuel raynaud */ -class ContentController extends AbstractCrudController { +class ContentController extends AbstractCrudController +{ + + public function __construct() + { + parent::__construct( + 'content', + 'manual', + 'content_order', + + 'admin.content.default', + 'admin.content.create', + 'admin.content.update', + 'admin.content.delete', + + TheliaEvents::CONTENT_CREATE, + TheliaEvents::CONTENT_UPDATE, + TheliaEvents::CONTENT_DELETE, + TheliaEvents::CONTENT_TOGGLE_VISIBILITY, + TheliaEvents::CONTENT_UPDATE_POSITION + ); + } /** * Return the creation form for this object */ protected function getCreationForm() { - // TODO: Implement getCreationForm() method. + return new ContentCreationForm($this->getRequest()); } /** @@ -44,17 +68,31 @@ class ContentController extends AbstractCrudController { */ protected function getUpdateForm() { - // TODO: Implement getUpdateForm() method. + return new ContentModificationForm($this->getRequest()); } /** * Hydrate the update form for this object, before passing it to the update template * - * @param unknown $object + * @param \Thelia\Form\ContentModificationForm $object */ protected function hydrateObjectForm($object) { - // TODO: Implement hydrateObjectForm() method. + // Prepare the data that will hydrate the form + $data = array( + 'id' => $object->getId(), + 'locale' => $object->getLocale(), + 'title' => $object->getTitle(), + 'chapo' => $object->getChapo(), + 'description' => $object->getDescription(), + 'postscriptum' => $object->getPostscriptum(), + 'visible' => $object->getVisible(), + 'url' => $object->getRewrittenUrl($this->getCurrentEditionLocale()), + 'parent' => $object->getParent() + ); + + // Setup the object form + return new ContentModificationForm($this->getRequest(), "form", $data); } /** diff --git a/core/lib/Thelia/Core/Event/TheliaEvents.php b/core/lib/Thelia/Core/Event/TheliaEvents.php index 01c2495f8..346b41c3b 100755 --- a/core/lib/Thelia/Core/Event/TheliaEvents.php +++ b/core/lib/Thelia/Core/Event/TheliaEvents.php @@ -185,6 +185,26 @@ final class TheliaEvents const BEFORE_UPDATEFOLDER = "action.before_updateFolder"; const AFTER_UPDATEFOLDER = "action.after_updateFolder"; + // -- content management ----------------------------------------------- + + const CONTENT_CREATE = "action.createFolder"; + const CONTENT_UPDATE = "action.updateFolder"; + const CONTENT_DELETE = "action.deleteFolder"; + const CONTENT_TOGGLE_VISIBILITY = "action.toggleFolderVisibility"; + const CONTENT_UPDATE_POSITION = "action.updateFolderPosition"; + +// const FOLDER_ADD_CONTENT = "action.categoryAddContent"; +// const FOLDER_REMOVE_CONTENT = "action.categoryRemoveContent"; + + const BEFORE_CREATECONTENT = "action.before_createFolder"; + const AFTER_CREATECONTENT = "action.after_createFolder"; + + const BEFORE_DELETECONTENT = "action.before_deleteFolder"; + const AFTER_DELETECONTENT = "action.after_deleteFolder"; + + const BEFORE_UPDATECONTENT = "action.before_updateFolder"; + const AFTER_UPDATECONTENT = "action.after_updateFolder"; + // -- Categories Associated Content ---------------------------------------- const BEFORE_CREATECATEGORY_ASSOCIATED_CONTENT = "action.before_createCategoryAssociatedContent"; diff --git a/core/lib/Thelia/Form/ContentCreationForm.php b/core/lib/Thelia/Form/ContentCreationForm.php index 8d8c2d1ca..2a4743bf8 100644 --- a/core/lib/Thelia/Form/ContentCreationForm.php +++ b/core/lib/Thelia/Form/ContentCreationForm.php @@ -27,7 +27,7 @@ use Thelia\Core\Translation\Translator; class ContentCreationForm extends BaseForm { - protected function buildForm($change_mode = false) + protected function buildForm() { $this->formBuilder ->add("title", "text", array( diff --git a/core/lib/Thelia/Form/ContentModificationForm.php b/core/lib/Thelia/Form/ContentModificationForm.php new file mode 100644 index 000000000..38ad4e2cf --- /dev/null +++ b/core/lib/Thelia/Form/ContentModificationForm.php @@ -0,0 +1,61 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Form; + +use Symfony\Component\Validator\Constraints\GreaterThan; +use Symfony\Component\Validator\Constraints\NotBlank; +use Thelia\Core\Translation\Translator; +use Thelia\Form\StandardDescriptionFieldsTrait; + +/** + * Class ContentModificationForm + * @package Thelia\Form + * @author manuel raynaud + */ +class ContentModificationForm extends ContentCreationForm { + use StandardDescriptionFieldsTrait; + + protected function buildForm() + { + parent::buildForm(); + + $this->formBuilder + ->add("id", "hidden", array("constraints" => array(new GreaterThan(array('value' => 0))))) + + ->add("url", "text", array( + "label" => Translator::getInstance()->trans("Rewriten URL *"), + "constraints" => array(new NotBlank()), + "label_attr" => array("for" => "rewritten_url") + )) + ; + + // Add standard description fields, excluding title and locale, which a re defined in parent class + $this->addStandardDescFields(array('title', 'locale')); + } + + public function getName() + { + return "thelia_content_modification"; + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Form/FolderModificationForm.php b/core/lib/Thelia/Form/FolderModificationForm.php index e075ea827..0ff90868c 100644 --- a/core/lib/Thelia/Form/FolderModificationForm.php +++ b/core/lib/Thelia/Form/FolderModificationForm.php @@ -32,7 +32,7 @@ class FolderModificationForm extends FolderCreationForm protected function buildForm() { - parent::buildForm(true); + parent::buildForm(); $this->formBuilder ->add("id", "hidden", array("constraints" => array(new GreaterThan(array('value' => 0))))) From 444cee8e822ea3a6a31937da9edea857e0f18338 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Sat, 21 Sep 2013 14:35:01 +0200 Subject: [PATCH 05/15] create ContentEvent --- .../Core/Event/Content/ContentEvent.php | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 core/lib/Thelia/Core/Event/Content/ContentEvent.php diff --git a/core/lib/Thelia/Core/Event/Content/ContentEvent.php b/core/lib/Thelia/Core/Event/Content/ContentEvent.php new file mode 100644 index 000000000..0949348e3 --- /dev/null +++ b/core/lib/Thelia/Core/Event/Content/ContentEvent.php @@ -0,0 +1,73 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Event\Content; +use Thelia\Core\Event\ActionEvent; +use Thelia\Model\Content; + + +/** + * Class ContentEvent + * @package Thelia\Core\Event\Content + * @author manuel raynaud + */ +class ContentEvent extends ActionEvent +{ + /** + * @var \Thelia\Model\Content + */ + protected $content; + + function __construct(Content $content = null) + { + $this->content = $content; + } + + /** + * @param \Thelia\Model\Content $content + */ + public function setContent(Content $content) + { + $this->content = $content; + + return $this; + } + + /** + * @return \Thelia\Model\Content + */ + public function getContent() + { + return $this->content; + } + + /** + * check if content exists + * + * @return bool + */ + public function hasContent() + { + return null !== $this->content; + } +} \ No newline at end of file From 09abedeb9feea514e6d8bf09cb91733c0d428f5c Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Sat, 21 Sep 2013 14:37:20 +0200 Subject: [PATCH 06/15] create contentCreateEvent --- .../Core/Event/Content/ContentCreateEvent.php | 121 ++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 core/lib/Thelia/Core/Event/Content/ContentCreateEvent.php diff --git a/core/lib/Thelia/Core/Event/Content/ContentCreateEvent.php b/core/lib/Thelia/Core/Event/Content/ContentCreateEvent.php new file mode 100644 index 000000000..75a1fce78 --- /dev/null +++ b/core/lib/Thelia/Core/Event/Content/ContentCreateEvent.php @@ -0,0 +1,121 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Event\Content; + + +/** + * Class ContentCreateEvent + * @package Thelia\Core\Event\Content + * @author manuel raynaud + */ +class ContentCreateEvent extends ContentEvent +{ + protected $title; + protected $parent; + protected $locale; + protected $visible; + + /** + * @param mixed $locale + * + * @return $this + */ + public function setLocale($locale) + { + $this->locale = $locale; + + return $this; + } + + /** + * @return mixed + */ + public function getLocale() + { + return $this->locale; + } + + /** + * @param mixed $parent + * + * @return $this + */ + public function setParent($parent) + { + $this->parent = $parent; + + return $this; + } + + /** + * @return mixed + */ + public function getParent() + { + return $this->parent; + } + + /** + * @param mixed $visible + * + * @return $this + */ + public function setVisible($visible) + { + $this->visible = $visible; + + return $this; + } + + /** + * @return mixed + */ + public function getVisible() + { + return $this->visible; + } + + /** + * @param mixed $title + * + * @return $this + */ + public function setTitle($title) + { + $this->title = $title; + + return $this; + } + + /** + * @return mixed + */ + public function getTitle() + { + return $this->title; + } + + + +} \ No newline at end of file From 4ec55e5acae79f0bf120ff184a35c1eaef606c56 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Sat, 21 Sep 2013 14:40:35 +0200 Subject: [PATCH 07/15] create contentUpdateEvent --- .../Core/Event/Content/ContentUpdateEvent.php | 150 ++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100644 core/lib/Thelia/Core/Event/Content/ContentUpdateEvent.php diff --git a/core/lib/Thelia/Core/Event/Content/ContentUpdateEvent.php b/core/lib/Thelia/Core/Event/Content/ContentUpdateEvent.php new file mode 100644 index 000000000..f7c75a01f --- /dev/null +++ b/core/lib/Thelia/Core/Event/Content/ContentUpdateEvent.php @@ -0,0 +1,150 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Event\Content; + + +/** + * Class ContentUpdateEvent + * @package Thelia\Core\Event\Content + * @author manuel raynaud + */ +class ContentUpdateEvent extends ContentCreateEvent +{ + protected $content_id; + + protected $chapo; + protected $description; + protected $postscriptum; + + protected $url; + + function __construct($content_id) + { + $this->content_id = $content_id; + } + + /** + * @param mixed $chapo + * + * @return $this + */ + public function setChapo($chapo) + { + $this->chapo = $chapo; + + return $this; + } + + /** + * @return mixed + */ + public function getChapo() + { + return $this->chapo; + } + + /** + * @param mixed $content_id + * + * @return $this + */ + public function setContentId($content_id) + { + $this->content_id = $content_id; + + return $this; + } + + /** + * @return mixed + */ + public function getContentId() + { + return $this->content_id; + } + + /** + * @param mixed $description + * + * @return $this + */ + public function setDescription($description) + { + $this->description = $description; + + return $this; + } + + /** + * @return mixed + */ + public function getDescription() + { + return $this->description; + } + + /** + * @param mixed $postscriptum + * + * @return $this + */ + public function setPostscriptum($postscriptum) + { + $this->postscriptum = $postscriptum; + + return $this; + } + + /** + * @return mixed + */ + public function getPostscriptum() + { + return $this->postscriptum; + } + + /** + * @param mixed $url + * + * @return $this + */ + public function setUrl($url) + { + $this->url = $url; + + return $this; + } + + /** + * @return mixed + */ + public function getUrl() + { + return $this->url; + } + + + + +} \ No newline at end of file From 849c7dd20b549088f920e1e4b3042b7ef5bdeb14 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Sat, 21 Sep 2013 15:20:06 +0200 Subject: [PATCH 08/15] display content modification page --- .../Controller/Admin/ContentController.php | 96 ++++- .../Controller/Admin/FolderController.php | 8 +- .../Core/Event/Content/ContentCreateEvent.php | 15 +- core/lib/Thelia/Model/Content.php | 6 + templates/admin/default/content-edit.html | 344 ++++++++++++++++++ 5 files changed, 443 insertions(+), 26 deletions(-) create mode 100644 templates/admin/default/content-edit.html diff --git a/core/lib/Thelia/Controller/Admin/ContentController.php b/core/lib/Thelia/Controller/Admin/ContentController.php index 78ee63391..d3706e479 100644 --- a/core/lib/Thelia/Controller/Admin/ContentController.php +++ b/core/lib/Thelia/Controller/Admin/ContentController.php @@ -22,9 +22,12 @@ /*************************************************************************************/ namespace Thelia\Controller\Admin; +use Thelia\Core\Event\Content\ContentCreateEvent; +use Thelia\Core\Event\Content\ContentUpdateEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Form\ContentCreationForm; use Thelia\Form\ContentModificationForm; +use Thelia\Model\ContentQuery; /** @@ -88,7 +91,6 @@ class ContentController extends AbstractCrudController 'postscriptum' => $object->getPostscriptum(), 'visible' => $object->getVisible(), 'url' => $object->getRewrittenUrl($this->getCurrentEditionLocale()), - 'parent' => $object->getParent() ); // Setup the object form @@ -102,7 +104,14 @@ class ContentController extends AbstractCrudController */ protected function getCreationEvent($formData) { - // TODO: Implement getCreationEvent() method. + $contentCreateEvent = new ContentCreateEvent(); + + $contentCreateEvent + ->setLocale($formData['locale']) + ->setDefaultFolder($formData['default_controller']) + ->setTitle($formData['title']) + ->setVisible($formData['visible']) + ; } /** @@ -112,7 +121,19 @@ class ContentController extends AbstractCrudController */ protected function getUpdateEvent($formData) { - // TODO: Implement getUpdateEvent() method. + $contentUpdateEvent = new ContentUpdateEvent($formData['id']); + + $contentUpdateEvent + ->setLocale($formData['locale']) + ->setTitle($formData['title']) + ->setChapo($formData['chapo']) + ->setDescription($formData['description']) + ->setPostscriptum($formData['postscriptum']) + ->setVisible($formData['visible']) + ->setUrl($formData['url']) + ->setDefaultFolder($formData['default_folder']); + + return $contentUpdateEvent; } /** @@ -126,49 +147,75 @@ class ContentController extends AbstractCrudController /** * Return true if the event contains the object, e.g. the action has updated the object in the event. * - * @param unknown $event + * @param \Thelia\Core\Event\Content\ContentEvent $event */ protected function eventContainsObject($event) { - // TODO: Implement eventContainsObject() method. + return $event->hasContent(); } /** * Get the created object from an event. * - * @param unknown $createEvent + * @param $event \Thelia\Core\Event\Content\ContentEvent + * + * @return null|\Thelia\Model\Content */ protected function getObjectFromEvent($event) { - // TODO: Implement getObjectFromEvent() method. + return $event->getContent(); } /** * Load an existing object from the database + * + * @return \Thelia\Model\Content */ protected function getExistingObject() { - // TODO: Implement getExistingObject() method. + return ContentQuery::create() + ->joinWithI18n($this->getCurrentEditionLocale()) + ->findOneById($this->getRequest()->get('content_id', 0)); } /** * Returns the object label form the object event (name, title, etc.) * - * @param unknown $object + * @param $object \Thelia\Model\Content + * + * @return string content title + * */ protected function getObjectLabel($object) { - // TODO: Implement getObjectLabel() method. + return $object->getTitle(); } /** * Returns the object ID from the object * - * @param unknown $object + * @param $object \Thelia\Model\Content + * + * @return int content id */ protected function getObjectId($object) { - // TODO: Implement getObjectId() method. + return $object->getId(); + } + + protected function getFolderId() + { + $folderId = $this->getRequest()->get('folder_id', null); + + if(null === $folderId) { + $content = $this->getExistingObject(); + + if($content) { + $folderId = $content->getDefaultFolderId(); + } + } + + return $folderId ?: 0; } /** @@ -178,7 +225,21 @@ class ContentController extends AbstractCrudController */ protected function renderListTemplate($currentOrder) { - // TODO: Implement renderListTemplate() method. + $this->getListOrderFromSession('content', 'content_order', 'manual'); + + return $this->render('folders', + array( + 'content_order' => $currentOrder, + 'parent' => $this->getFolderId() + )); + } + + protected function getEditionArguments() + { + return array( + 'content_id' => $this->getRequest()->get('content_id', 0), + 'current_tab' => $this->getRequest()->get('current_tab', 'general') + ); } /** @@ -186,7 +247,7 @@ class ContentController extends AbstractCrudController */ protected function renderEditionTemplate() { - // TODO: Implement renderEditionTemplate() method. + return $this->render('content-edit', $this->getEditionArguments()); } /** @@ -194,7 +255,7 @@ class ContentController extends AbstractCrudController */ protected function redirectToEditionTemplate() { - // TODO: Implement redirectToEditionTemplate() method. + $this->redirect($this->getRoute('admin.content.update', $this->getEditionArguments())); } /** @@ -202,6 +263,9 @@ class ContentController extends AbstractCrudController */ protected function redirectToListTemplate() { - // TODO: Implement redirectToListTemplate() method. + $this->redirectToRoute( + 'admin.content.default', + array('parent' => $this->getFolderId()) + ); } } \ No newline at end of file diff --git a/core/lib/Thelia/Controller/Admin/FolderController.php b/core/lib/Thelia/Controller/Admin/FolderController.php index 67dd39b38..9f2190442 100644 --- a/core/lib/Thelia/Controller/Admin/FolderController.php +++ b/core/lib/Thelia/Controller/Admin/FolderController.php @@ -174,7 +174,7 @@ class FolderController extends AbstractCrudController /** * Return true if the event contains the object, e.g. the action has updated the object in the event. * - * @param unknown $event + * @param \Thelia\Core\Event\FolderEvent $event */ protected function eventContainsObject($event) { @@ -228,13 +228,13 @@ class FolderController extends AbstractCrudController */ protected function renderListTemplate($currentOrder) { - // Get product order - $product_order = $this->getListOrderFromSession('content', 'content_order', 'manual'); + // Get content order + $content_order = $this->getListOrderFromSession('content', 'content_order', 'manual'); return $this->render('folders', array( 'folder_order' => $currentOrder, - 'content_order' => $product_order, + 'content_order' => $content_order, 'parent' => $this->getRequest()->get('parent', 0) )); } diff --git a/core/lib/Thelia/Core/Event/Content/ContentCreateEvent.php b/core/lib/Thelia/Core/Event/Content/ContentCreateEvent.php index 75a1fce78..5e2e7f0ea 100644 --- a/core/lib/Thelia/Core/Event/Content/ContentCreateEvent.php +++ b/core/lib/Thelia/Core/Event/Content/ContentCreateEvent.php @@ -32,7 +32,7 @@ namespace Thelia\Core\Event\Content; class ContentCreateEvent extends ContentEvent { protected $title; - protected $parent; + protected $default_folder; protected $locale; protected $visible; @@ -57,13 +57,13 @@ class ContentCreateEvent extends ContentEvent } /** - * @param mixed $parent + * @param mixed $default_folder * * @return $this */ - public function setParent($parent) + public function setDefaultFolder($default_folder) { - $this->parent = $parent; + $this->default_folder = $default_folder; return $this; } @@ -71,11 +71,14 @@ class ContentCreateEvent extends ContentEvent /** * @return mixed */ - public function getParent() + public function getDefaultFolder() { - return $this->parent; + return $this->default_folder; } + + + /** * @param mixed $visible * diff --git a/core/lib/Thelia/Model/Content.php b/core/lib/Thelia/Model/Content.php index 10ed2afe3..ca1978e65 100755 --- a/core/lib/Thelia/Model/Content.php +++ b/core/lib/Thelia/Model/Content.php @@ -30,6 +30,12 @@ class Content extends BaseContent // and generate the position relative to this folder } + public function getDefaultFolderId() + { + //@TODO update contentFolder Table, adding by_default column + } + + /** * {@inheritDoc} */ diff --git a/templates/admin/default/content-edit.html b/templates/admin/default/content-edit.html new file mode 100644 index 000000000..97fc02d70 --- /dev/null +++ b/templates/admin/default/content-edit.html @@ -0,0 +1,344 @@ +{extends file="admin-layout.tpl"} + +{block name="check-permissions"}admin.content.view{/block} + +{block name="page-title"}{intl l='Edit content'}{/block} + +{block name="main-content"} +
+
+ + {* include file="includes/folder-breadcrumb.html" editing_category="true" *} + +
+ {loop name="content_edit" type="content" visible="*" id="{$content_id}" backend_context="1" lang="$edit_language_id"} +
+
+
+ {intl l='Edit content %title' title=$TITLE} +
+ +
+ + {if $HAS_PREVIOUS != 0} + + {else} + + {/if} + + + + {if $HAS_NEXT != 0} + + {else} + + {/if} +
+
+ +
+
+ + + +
+ +
+ +
+ + {form name="thelia.admin.content.modification"} +
+ + {include file="includes/inner-form-toolbar.html" close_url="{url path='/admin/folders' parent=0}"} + + {* Be sure to get the folder ID, even if the form could not be validated *} + + + + + {form_hidden_fields form=$form} + + {form_field form=$form field='success_url'} + + {/form_field} + + {form_field form=$form field='locale'} + + {/form_field} + + {if $form_error}
{$form_error_message}
{/if} + + {include file="includes/standard-description-form-fields.html"} + + {form_field form=$form field='url'} +
+ + + +
+ {/form_field} + + {*
+
+ {form_field form=$form field='parent'} +
+ + + + +
+ {/form_field} +
+ +
+ {form_field form=$form field='visible'} +
+ +
+ +
+
+ {/form_field} +
+
*} + +
+
+
+   +
+

{intl l='Colder created on %date_create. Last modification: %date_change' date_create="{format_date date=$CREATE_DATE}" date_change="{format_date date=$UPDATE_DATE}"}

+
+
+
+
+ +
+ {/form} +
+
+ +
+
+
+ +
+ + + + + + + + + {module_include location='folder_contents_table_header'} + + + + + + + {*loop name="assigned_contents" type="associated_content" folder="$folder_id" backend_context="1" lang="$edit_language_id"} + + + + + + {module_include location='folder_contents_table_row'} + + + + {/loop} + + {elseloop rel="assigned_contents"} + + + + {/elseloop*} + +
{intl l='ID'}{intl l='Attribute title'}{intl l="Actions"}
{$ID} + {$TITLE} + +
+ {loop type="auth" name="can_create" roles="ADMIN" permissions="admin.configuration.folder.content.delete"} + + + + {/loop} +
+
+
+ {intl l="This folder contains no contents"} +
+
+
+
+ +
+
+ +
+
+ +
+
+
+
+
+
+ {/loop} +
+
+
+ + +{* Delete related content confirmation dialog *} + + {capture "delete_content_dialog"} + + + + + + {/capture} + + {include + file = "includes/generic-confirm-dialog.html" + + dialog_id = "delete_content_dialog" + dialog_title = {intl l="Remove related content"} + dialog_message = {intl l="Do you really want to remove this related content ?"} + +form_action = {url path='/admin/folders/related-content/delete'} +form_content = {$smarty.capture.delete_content_dialog nofilter} +} +{/block} + +{block name="javascript-initialization"} + +{/block} \ No newline at end of file From 7680fb42cc67804d5118c794b8d05d6b2fce8b02 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Sat, 21 Sep 2013 15:24:44 +0200 Subject: [PATCH 09/15] dispatch event in pre/post crud method for content model --- core/lib/Thelia/Model/Content.php | 33 +++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/core/lib/Thelia/Model/Content.php b/core/lib/Thelia/Model/Content.php index ca1978e65..0f57742c2 100755 --- a/core/lib/Thelia/Model/Content.php +++ b/core/lib/Thelia/Model/Content.php @@ -2,6 +2,8 @@ namespace Thelia\Model; +use Thelia\Core\Event\Content\ContentEvent; +use Thelia\Core\Event\TheliaEvents; use Thelia\Model\Base\Content as BaseContent; use Thelia\Tools\URL; use Propel\Runtime\Connection\ConnectionInterface; @@ -43,6 +45,37 @@ class Content extends BaseContent { $this->setPosition($this->getNextPosition()); + $this->dispatchEvent(TheliaEvents::BEFORE_CREATECONTENT, new ContentEvent($this)); + return true; } + + public function postInsert(ConnectionInterface $con = null) + { + $this->dispatchEvent(TheliaEvents::AFTER_CREATECONTENT, new ContentEvent($this)); + } + + public function preUpdate(ConnectionInterface $con = null) + { + $this->dispatchEvent(TheliaEvents::BEFORE_UPDATECONTENT, new ContentEvent($this)); + + return true; + } + + public function postUpdate(ConnectionInterface $con = null) + { + $this->dispatchEvent(TheliaEvents::AFTER_UPDATECONTENT, new ContentEvent($this)); + } + + public function preDelete(ConnectionInterface $con = null) + { + $this->dispatchEvent(TheliaEvents::BEFORE_DELETECONTENT, new ContentEvent($this)); + + return true; + } + + public function postDelete(ConnectionInterface $con = null) + { + $this->dispatchEvent(TheliaEvents::AFTER_DELETECONTENT, new ContentEvent($this)); + } } From f44b7daf8c12c42d43323c7a9d45f4ef85954bab Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Sat, 21 Sep 2013 15:32:27 +0200 Subject: [PATCH 10/15] create content listener for crud management --- core/lib/Thelia/Action/Content.php | 90 +++++++++++++++++++++ core/lib/Thelia/Config/Resources/action.xml | 5 ++ 2 files changed, 95 insertions(+) create mode 100644 core/lib/Thelia/Action/Content.php diff --git a/core/lib/Thelia/Action/Content.php b/core/lib/Thelia/Action/Content.php new file mode 100644 index 000000000..1fa91fa15 --- /dev/null +++ b/core/lib/Thelia/Action/Content.php @@ -0,0 +1,90 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Action; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Thelia\Core\Event\Content\ContentUpdateEvent; +use Thelia\Core\Event\TheliaEvents; +use Thelia\Model\ContentQuery; + + +/** + * Class Content + * @package Thelia\Action + * @author manuel raynaud + */ +class Content extends BaseAction implements EventSubscriberInterface +{ + + public function update(ContentUpdateEvent $event) + { + if (null !== $content = ContentQuery::create()->findPk($event->getContentId())) { + $content->setDispatcher($this->getDispatcher()); + + $content + ->setVisible($event->getVisible()) + ->setLocale($event->getLocale()) + ->setTitle($event->getTitle()) + ->setDescription($event->getDescription()) + ->setChapo($event->getChapo()) + ->setPostscriptum($event->getPostscriptum()) + ->save() + ; + + $event->setContent($content); + } + } + + /** + * Returns an array of event names this subscriber wants to listen to. + * + * The array keys are event names and the value can be: + * + * * The method name to call (priority defaults to 0) + * * An array composed of the method name to call and the priority + * * An array of arrays composed of the method names to call and respective + * priorities, or 0 if unset + * + * For instance: + * + * * array('eventName' => 'methodName') + * * array('eventName' => array('methodName', $priority)) + * * array('eventName' => array(array('methodName1', $priority), array('methodName2')) + * + * @return array The event names to listen to + * + * @api + */ + public static function getSubscribedEvents() + { + return array( + TheliaEvents::CONTENT_CREATE => array("create", 128), + TheliaEvents::CONTENT_UPDATE => array("update", 128), + TheliaEvents::CONTENT_DELETE => array("delete", 128), + TheliaEvents::CONTENT_TOGGLE_VISIBILITY => array("toggleVisibility", 128), + + TheliaEvents::CONTENT_UPDATE_POSITION => array("updatePosition", 128), + ); + } + +} \ No newline at end of file diff --git a/core/lib/Thelia/Config/Resources/action.xml b/core/lib/Thelia/Config/Resources/action.xml index 801e68c6b..15839df95 100755 --- a/core/lib/Thelia/Config/Resources/action.xml +++ b/core/lib/Thelia/Config/Resources/action.xml @@ -102,6 +102,11 @@ + + + + + From 1da66ece29770a80b9c5c30717fc9606524277e1 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Sat, 21 Sep 2013 16:07:25 +0200 Subject: [PATCH 11/15] update default param of content model --- .../Thelia/Config/Resources/routing/admin.xml | 5 +++++ .../Controller/Admin/ContentController.php | 16 ++++++++++++++ core/lib/Thelia/Core/Event/TheliaEvents.php | 22 +++++++++---------- .../lib/Thelia/Core/Template/Loop/Content.php | 1 + core/lib/Thelia/Form/ContentCreationForm.php | 4 +++- core/lib/Thelia/Model/Content.php | 3 ++- templates/admin/default/content-edit.html | 10 ++++----- 7 files changed, 43 insertions(+), 18 deletions(-) diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index a94c0b4fe..8ced3500a 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -227,6 +227,11 @@ \d+ + + Thelia\Controller\Admin\ContentController::processUpdateAction + + + diff --git a/core/lib/Thelia/Controller/Admin/ContentController.php b/core/lib/Thelia/Controller/Admin/ContentController.php index d3706e479..176115a1f 100644 --- a/core/lib/Thelia/Controller/Admin/ContentController.php +++ b/core/lib/Thelia/Controller/Admin/ContentController.php @@ -268,4 +268,20 @@ class ContentController extends AbstractCrudController array('parent' => $this->getFolderId()) ); } + + /** + * @param \Thelia\Core\Event\Content\ContentUpdateEvent $updateEvent + * @return Response|void + */ + protected function performAdditionalUpdateAction($updateEvent) + { + if ($this->getRequest()->get('save_mode') != 'stay') { + + // Redirect to parent category list + $this->redirectToRoute( + 'admin.folders.default', + array('parent' => $this->getFolderId()) + ); + } + } } \ No newline at end of file diff --git a/core/lib/Thelia/Core/Event/TheliaEvents.php b/core/lib/Thelia/Core/Event/TheliaEvents.php index 346b41c3b..ee49d239b 100755 --- a/core/lib/Thelia/Core/Event/TheliaEvents.php +++ b/core/lib/Thelia/Core/Event/TheliaEvents.php @@ -187,23 +187,23 @@ final class TheliaEvents // -- content management ----------------------------------------------- - const CONTENT_CREATE = "action.createFolder"; - const CONTENT_UPDATE = "action.updateFolder"; - const CONTENT_DELETE = "action.deleteFolder"; - const CONTENT_TOGGLE_VISIBILITY = "action.toggleFolderVisibility"; - const CONTENT_UPDATE_POSITION = "action.updateFolderPosition"; + const CONTENT_CREATE = "action.createContent"; + const CONTENT_UPDATE = "action.updateContent"; + const CONTENT_DELETE = "action.deleteContent"; + const CONTENT_TOGGLE_VISIBILITY = "action.toggleContentVisibility"; + const CONTENT_UPDATE_POSITION = "action.updateContentPosition"; // const FOLDER_ADD_CONTENT = "action.categoryAddContent"; // const FOLDER_REMOVE_CONTENT = "action.categoryRemoveContent"; - const BEFORE_CREATECONTENT = "action.before_createFolder"; - const AFTER_CREATECONTENT = "action.after_createFolder"; + const BEFORE_CREATECONTENT = "action.before_createContent"; + const AFTER_CREATECONTENT = "action.after_createContent"; - const BEFORE_DELETECONTENT = "action.before_deleteFolder"; - const AFTER_DELETECONTENT = "action.after_deleteFolder"; + const BEFORE_DELETECONTENT = "action.before_deleteContent"; + const AFTER_DELETECONTENT = "action.after_deleteContent"; - const BEFORE_UPDATECONTENT = "action.before_updateFolder"; - const AFTER_UPDATECONTENT = "action.after_updateFolder"; + const BEFORE_UPDATECONTENT = "action.before_updateContent"; + const AFTER_UPDATECONTENT = "action.after_updateContent"; // -- Categories Associated Content ---------------------------------------- diff --git a/core/lib/Thelia/Core/Template/Loop/Content.php b/core/lib/Thelia/Core/Template/Loop/Content.php index a29cb2e60..0136f4e9c 100755 --- a/core/lib/Thelia/Core/Template/Loop/Content.php +++ b/core/lib/Thelia/Core/Template/Loop/Content.php @@ -234,6 +234,7 @@ class Content extends BaseI18nLoop ->set("DESCRIPTION", $content->getVirtualColumn('i18n_DESCRIPTION')) ->set("POSTSCRIPTUM", $content->getVirtualColumn('i18n_POSTSCRIPTUM')) ->set("POSITION", $content->getPosition()) + ->set("DEFAULT_FOLDER", $content->getDefaultFolderId()) ->set("URL", $content->getUrl($locale)) ; diff --git a/core/lib/Thelia/Form/ContentCreationForm.php b/core/lib/Thelia/Form/ContentCreationForm.php index 2a4743bf8..df8838f59 100644 --- a/core/lib/Thelia/Form/ContentCreationForm.php +++ b/core/lib/Thelia/Form/ContentCreationForm.php @@ -40,9 +40,11 @@ class ContentCreationForm extends BaseForm ) )) ->add("default_folder", "integer", array( + "label" => Translator::getInstance()->trans("Default folder *"), "constraints" => array( new NotBlank() - ) + ), + "label_attr" => array("for" => "default_folder") )) ->add("locale", "text", array( "constraints" => array( diff --git a/core/lib/Thelia/Model/Content.php b/core/lib/Thelia/Model/Content.php index 0f57742c2..79c66dc0f 100755 --- a/core/lib/Thelia/Model/Content.php +++ b/core/lib/Thelia/Model/Content.php @@ -34,7 +34,8 @@ class Content extends BaseContent public function getDefaultFolderId() { - //@TODO update contentFolder Table, adding by_default column + //@TODO update contentFolder Table, adding by_default column and change this code for returnin good value + return $this->getFolders()->getFirst()->getId(); } diff --git a/templates/admin/default/content-edit.html b/templates/admin/default/content-edit.html index 97fc02d70..e8ef4a5b1 100644 --- a/templates/admin/default/content-edit.html +++ b/templates/admin/default/content-edit.html @@ -88,9 +88,9 @@ {/form_field} - {*
+
- {form_field form=$form field='parent'} + {form_field form=$form field='default_folder'}
@@ -123,7 +123,7 @@
{/form_field}
-
*} +
From 4e3768e0e960063b6c6dac6b2370e0c10966c2b4 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Sat, 21 Sep 2013 16:38:22 +0200 Subject: [PATCH 12/15] allow to create new content --- core/lib/Thelia/Action/Content.php | 23 +++++++++++++++++++ .../Thelia/Config/Resources/routing/admin.xml | 4 ++++ .../Controller/Admin/ContentController.php | 4 +++- core/lib/Thelia/Model/Content.php | 9 ++++++-- templates/admin/default/folders.html | 6 ++--- 5 files changed, 40 insertions(+), 6 deletions(-) diff --git a/core/lib/Thelia/Action/Content.php b/core/lib/Thelia/Action/Content.php index 1fa91fa15..57ba90867 100644 --- a/core/lib/Thelia/Action/Content.php +++ b/core/lib/Thelia/Action/Content.php @@ -23,9 +23,12 @@ namespace Thelia\Action; use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Thelia\Core\Event\Content\ContentCreateEvent; use Thelia\Core\Event\Content\ContentUpdateEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Model\ContentQuery; +use Thelia\Model\Content as ContentModel; +use Thelia\Model\FolderQuery; /** @@ -36,6 +39,26 @@ use Thelia\Model\ContentQuery; class Content extends BaseAction implements EventSubscriberInterface { + public function create(ContentCreateEvent $event) + { + $content = new ContentModel(); + + $content + ->setVisible($event->getVisible()) + ->setLocale($event->getLocale()) + ->setTitle($event->getTitle()) + ->addFolder(FolderQuery::create()->findPk($event->getDefaultFolder())) + ->save() + ; + + $event->setContent($content); + } + + /** + * process update content + * + * @param ContentUpdateEvent $event + */ public function update(ContentUpdateEvent $event) { if (null !== $content = ContentQuery::create()->findPk($event->getContentId())) { diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index 8ced3500a..838bd6da8 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -222,6 +222,10 @@ + + Thelia\Controller\Admin\ContentController::createAction + + Thelia\Controller\Admin\ContentController::updateAction \d+ diff --git a/core/lib/Thelia/Controller/Admin/ContentController.php b/core/lib/Thelia/Controller/Admin/ContentController.php index 176115a1f..9d20830a8 100644 --- a/core/lib/Thelia/Controller/Admin/ContentController.php +++ b/core/lib/Thelia/Controller/Admin/ContentController.php @@ -108,10 +108,12 @@ class ContentController extends AbstractCrudController $contentCreateEvent ->setLocale($formData['locale']) - ->setDefaultFolder($formData['default_controller']) + ->setDefaultFolder($formData['default_folder']) ->setTitle($formData['title']) ->setVisible($formData['visible']) ; + + return $contentCreateEvent; } /** diff --git a/core/lib/Thelia/Model/Content.php b/core/lib/Thelia/Model/Content.php index 79c66dc0f..47e90ab09 100755 --- a/core/lib/Thelia/Model/Content.php +++ b/core/lib/Thelia/Model/Content.php @@ -34,8 +34,13 @@ class Content extends BaseContent public function getDefaultFolderId() { - //@TODO update contentFolder Table, adding by_default column and change this code for returnin good value - return $this->getFolders()->getFirst()->getId(); + // Find default folder + $default_folder = ContentFolderQuery::create() + ->filterByContentId($this->getId()) + ->filterByDefaultFolder(true) + ->findOne(); + + return $default_folder == null ? 0 : $default_folder->getFolderId(); } diff --git a/templates/admin/default/folders.html b/templates/admin/default/folders.html index b7d435e88..fca34ba21 100644 --- a/templates/admin/default/folders.html +++ b/templates/admin/default/folders.html @@ -412,11 +412,11 @@ {form_hidden_fields form=$form} {* Be sure to get the folder_id, even if the form could not be validated *} - + {form_field form=$form field='success_url'} {* on success, redirect to the edition page, _ID_ is replaced with the created object ID, see controller *} - + {/form_field} {form_field form=$form field='default_folder'} @@ -468,7 +468,7 @@ dialog_ok_label = {intl l="Create this content"} - form_action = {url path='/admin/contents/create'} + form_action = {url path='/admin/content/create'} form_enctype = {form_enctype form=$form} form_error_message = $form_error_message } From 04e0da56e7d3954e46758c9c61b2f53a5aebfb45 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Sat, 21 Sep 2013 16:58:38 +0200 Subject: [PATCH 13/15] fix issue, default foler is set on content creation --- core/lib/Thelia/Action/Content.php | 3 +-- core/lib/Thelia/Model/Content.php | 30 +++++++++++++++++++++++ templates/admin/default/content-edit.html | 6 ++--- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/core/lib/Thelia/Action/Content.php b/core/lib/Thelia/Action/Content.php index 57ba90867..4c8810a40 100644 --- a/core/lib/Thelia/Action/Content.php +++ b/core/lib/Thelia/Action/Content.php @@ -47,8 +47,7 @@ class Content extends BaseAction implements EventSubscriberInterface ->setVisible($event->getVisible()) ->setLocale($event->getLocale()) ->setTitle($event->getTitle()) - ->addFolder(FolderQuery::create()->findPk($event->getDefaultFolder())) - ->save() + ->create($event->getDefaultFolder()) ; $event->setContent($content); diff --git a/core/lib/Thelia/Model/Content.php b/core/lib/Thelia/Model/Content.php index 47e90ab09..508913a97 100755 --- a/core/lib/Thelia/Model/Content.php +++ b/core/lib/Thelia/Model/Content.php @@ -2,9 +2,11 @@ namespace Thelia\Model; +use Propel\Runtime\Propel; use Thelia\Core\Event\Content\ContentEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Model\Base\Content as BaseContent; +use Thelia\Model\Map\ContentTableMap; use Thelia\Tools\URL; use Propel\Runtime\Connection\ConnectionInterface; @@ -43,6 +45,34 @@ class Content extends BaseContent return $default_folder == null ? 0 : $default_folder->getFolderId(); } + public function create($defaultFolderId) + { + $con = Propel::getWriteConnection(ContentTableMap::DATABASE_NAME); + + $con->beginTransaction(); + + $this->dispatchEvent(TheliaEvents::BEFORE_CREATECONTENT, new ContentEvent($this)); + + try { + $this->save($con); + + $cf = new ContentFolder(); + $cf->setContentId($this->getId()) + ->setFolderId($defaultFolderId) + ->setDefaultFolder(1) + ->save($con); + + $this->setPosition($this->getNextPosition())->save($con); + + $con->commit(); + } catch(\Exception $ex) { + + $con->rollback(); + + throw $ex; + } + } + /** * {@inheritDoc} diff --git a/templates/admin/default/content-edit.html b/templates/admin/default/content-edit.html index e8ef4a5b1..a7b55dfb8 100644 --- a/templates/admin/default/content-edit.html +++ b/templates/admin/default/content-edit.html @@ -100,10 +100,10 @@
From ac435b8f8762eade7fd3568eced6e4535cbf6508 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Sat, 21 Sep 2013 17:04:05 +0200 Subject: [PATCH 14/15] fire event on insert content in createmethod --- core/lib/Thelia/Model/Content.php | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/core/lib/Thelia/Model/Content.php b/core/lib/Thelia/Model/Content.php index 508913a97..69ef7d6d7 100755 --- a/core/lib/Thelia/Model/Content.php +++ b/core/lib/Thelia/Model/Content.php @@ -6,6 +6,7 @@ use Propel\Runtime\Propel; use Thelia\Core\Event\Content\ContentEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Model\Base\Content as BaseContent; +use Thelia\Model\ContentFolderQuery; use Thelia\Model\Map\ContentTableMap; use Thelia\Tools\URL; use Propel\Runtime\Connection\ConnectionInterface; @@ -45,6 +46,15 @@ class Content extends BaseContent return $default_folder == null ? 0 : $default_folder->getFolderId(); } + public function setDefaultFolder($folderId) + { +/* ContentFolderQuery::create() + ->filterByContentId($this->getId) + ->update(array("DefaultFolder" => 0));*/ + + return $this; + } + public function create($defaultFolderId) { $con = Propel::getWriteConnection(ContentTableMap::DATABASE_NAME); @@ -65,6 +75,8 @@ class Content extends BaseContent $this->setPosition($this->getNextPosition())->save($con); $con->commit(); + + $this->dispatchEvent(TheliaEvents::AFTER_CREATECONTENT,new ContentEvent($this)); } catch(\Exception $ex) { $con->rollback(); @@ -74,23 +86,6 @@ class Content extends BaseContent } - /** - * {@inheritDoc} - */ - public function preInsert(ConnectionInterface $con = null) - { - $this->setPosition($this->getNextPosition()); - - $this->dispatchEvent(TheliaEvents::BEFORE_CREATECONTENT, new ContentEvent($this)); - - return true; - } - - public function postInsert(ConnectionInterface $con = null) - { - $this->dispatchEvent(TheliaEvents::AFTER_CREATECONTENT, new ContentEvent($this)); - } - public function preUpdate(ConnectionInterface $con = null) { $this->dispatchEvent(TheliaEvents::BEFORE_UPDATECONTENT, new ContentEvent($this)); From d015c8c3b8a70e04dd8e65de872433e8d8b3d303 Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Mon, 23 Sep 2013 11:24:30 +0200 Subject: [PATCH 15/15] cache dataccessfunctions --- .../Smarty/Plugins/DataAccessFunctions.php | 58 ++++++++++++------- 1 file changed, 38 insertions(+), 20 deletions(-) diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/DataAccessFunctions.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/DataAccessFunctions.php index fe203e7b8..f39c2a768 100755 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/DataAccessFunctions.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/DataAccessFunctions.php @@ -56,6 +56,8 @@ class DataAccessFunctions extends AbstractSmartyPlugin protected $request; protected $dispatcher; + private static $dataAccessCache = array(); + public function __construct(Request $request, SecurityContext $securityContext, ParserContext $parserContext, ContainerAwareEventDispatcher $dispatcher) { $this->securityContext = $securityContext; @@ -160,7 +162,12 @@ class DataAccessFunctions extends AbstractSmartyPlugin public function countryDataAccess($params, $smarty) { - $defaultCountry = CountryQuery::create()->findOneByByDefault(1); + if(array_key_exists('defaultCountry', self::$dataAccessCache)) { + $defaultCountry = self::$dataAccessCache['defaultCountry']; + } else { + $defaultCountry = CountryQuery::create()->findOneByByDefault(1); + self::$dataAccessCache['defaultCountry'] = $defaultCountry; + } switch($params["attr"]) { case "default": @@ -170,6 +177,13 @@ class DataAccessFunctions extends AbstractSmartyPlugin public function cartDataAccess($params, $smarty) { + if(array_key_exists('currentCountry', self::$dataAccessCache)) { + $currentCountry = self::$dataAccessCache['currentCountry']; + } else { + $currentCountry = CountryQuery::create()->findOneById(64); // @TODO : make it magic + self::$dataAccessCache['currentCountry'] = $currentCountry; + } + $cart = $this->getCart($this->request); $result = ""; switch($params["attr"]) { @@ -180,9 +194,7 @@ class DataAccessFunctions extends AbstractSmartyPlugin $result = $cart->getTotalAmount(); break; case "total_taxed_price": - $result = $cart->getTaxedAmount( - CountryQuery::create()->findOneById(64) // @TODO : make it magic - ); + $result = $cart->getTaxedAmount($currentCountry); break; } @@ -234,24 +246,30 @@ class DataAccessFunctions extends AbstractSmartyPlugin */ protected function dataAccessWithI18n($objectLabel, $params, ModelCriteria $search, $columns = array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM'), $foreignTable = null, $foreignKey = 'ID') { - $lang = $this->getNormalizedParam($params, array('lang')); - if ($lang === null) { - $lang = $this->request->getSession()->getLang()->getId(); + if(array_key_exists('data_' . $objectLabel, self::$dataAccessCache)) { + $data = self::$dataAccessCache['data_' . $objectLabel]; + } else { + $lang = $this->getNormalizedParam($params, array('lang')); + if ($lang === null) { + $lang = $this->request->getSession()->getLang()->getId(); + } + + ModelCriteriaTools::getI18n( + false, + $lang, + $search, + $this->request->getSession()->getLang()->getLocale(), + $columns, + $foreignTable, + $foreignKey, + true + ); + + $data = $search->findOne(); + + self::$dataAccessCache['data_' . $objectLabel] = $data; } - ModelCriteriaTools::getI18n( - false, - $lang, - $search, - $this->request->getSession()->getLang()->getLocale(), - $columns, - $foreignTable, - $foreignKey, - true - ); - - $data = $search->findOne(); - $noGetterData = array(); foreach ($columns as $column) { $noGetterData[$column] = $data->getVirtualColumn('i18n_' . $column);