diff --git a/core/lib/Thelia/Action/Content.php b/core/lib/Thelia/Action/Content.php new file mode 100644 index 000000000..4c8810a40 --- /dev/null +++ b/core/lib/Thelia/Action/Content.php @@ -0,0 +1,112 @@ +. */ +/* */ +/*************************************************************************************/ + +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; + + +/** + * Class Content + * @package Thelia\Action + * @author manuel raynaud + */ +class Content extends BaseAction implements EventSubscriberInterface +{ + + public function create(ContentCreateEvent $event) + { + $content = new ContentModel(); + + $content + ->setVisible($event->getVisible()) + ->setLocale($event->getLocale()) + ->setTitle($event->getTitle()) + ->create($event->getDefaultFolder()) + ; + + $event->setContent($content); + } + + /** + * process update content + * + * @param ContentUpdateEvent $event + */ + 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 @@ + + + + + diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index c9e1be4d4..3f41ef294 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -230,8 +230,9 @@ Thelia\Controller\Admin\FolderController::createAction - + Thelia\Controller\Admin\FolderController::updateAction + \d+ @@ -250,6 +251,21 @@ Thelia\Controller\Admin\FolderController::updatePositionAction + + + Thelia\Controller\Admin\ContentController::createAction + + + + Thelia\Controller\Admin\ContentController::updateAction + \d+ + + + + Thelia\Controller\Admin\ContentController::processUpdateAction + + + diff --git a/core/lib/Thelia/Controller/Admin/ContentController.php b/core/lib/Thelia/Controller/Admin/ContentController.php new file mode 100644 index 000000000..9d20830a8 --- /dev/null +++ b/core/lib/Thelia/Controller/Admin/ContentController.php @@ -0,0 +1,289 @@ +. */ +/* */ +/*************************************************************************************/ + +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; + + +/** + * Class ContentController + * @package Thelia\Controller\Admin + * @author manuel raynaud + */ +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() + { + return new ContentCreationForm($this->getRequest()); + } + + /** + * Return the update form for this object + */ + protected function getUpdateForm() + { + return new ContentModificationForm($this->getRequest()); + } + + /** + * Hydrate the update form for this object, before passing it to the update template + * + * @param \Thelia\Form\ContentModificationForm $object + */ + protected function hydrateObjectForm($object) + { + // 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()), + ); + + // Setup the object form + return new ContentModificationForm($this->getRequest(), "form", $data); + } + + /** + * Creates the creation event with the provided form data + * + * @param unknown $formData + */ + protected function getCreationEvent($formData) + { + $contentCreateEvent = new ContentCreateEvent(); + + $contentCreateEvent + ->setLocale($formData['locale']) + ->setDefaultFolder($formData['default_folder']) + ->setTitle($formData['title']) + ->setVisible($formData['visible']) + ; + + return $contentCreateEvent; + } + + /** + * Creates the update event with the provided form data + * + * @param unknown $formData + */ + protected function getUpdateEvent($formData) + { + $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; + } + + /** + * 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 \Thelia\Core\Event\Content\ContentEvent $event + */ + protected function eventContainsObject($event) + { + return $event->hasContent(); + } + + /** + * Get the created object from an event. + * + * @param $event \Thelia\Core\Event\Content\ContentEvent + * + * @return null|\Thelia\Model\Content + */ + protected function getObjectFromEvent($event) + { + return $event->getContent(); + } + + /** + * Load an existing object from the database + * + * @return \Thelia\Model\Content + */ + protected function getExistingObject() + { + 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 $object \Thelia\Model\Content + * + * @return string content title + * + */ + protected function getObjectLabel($object) + { + return $object->getTitle(); + } + + /** + * Returns the object ID from the object + * + * @param $object \Thelia\Model\Content + * + * @return int content id + */ + protected function getObjectId($object) + { + 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; + } + + /** + * Render the main list template + * + * @param unknown $currentOrder, if any, null otherwise. + */ + protected function renderListTemplate($currentOrder) + { + $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') + ); + } + + /** + * Render the edition template + */ + protected function renderEditionTemplate() + { + return $this->render('content-edit', $this->getEditionArguments()); + } + + /** + * Redirect to the edition template + */ + protected function redirectToEditionTemplate() + { + $this->redirect($this->getRoute('admin.content.update', $this->getEditionArguments())); + } + + /** + * Redirect to the list template + */ + protected function redirectToListTemplate() + { + $this->redirectToRoute( + 'admin.content.default', + 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/Controller/Admin/FolderController.php b/core/lib/Thelia/Controller/Admin/FolderController.php index db8a83e48..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,14 +228,14 @@ 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, - 'folder_id' => $this->getRequest()->get('folder_id', 0) + 'content_order' => $content_order, + '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()) ); } @@ -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())); } /** @@ -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/core/lib/Thelia/Core/Event/Content/ContentCreateEvent.php b/core/lib/Thelia/Core/Event/Content/ContentCreateEvent.php new file mode 100644 index 000000000..5e2e7f0ea --- /dev/null +++ b/core/lib/Thelia/Core/Event/Content/ContentCreateEvent.php @@ -0,0 +1,124 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Event\Content; + + +/** + * Class ContentCreateEvent + * @package Thelia\Core\Event\Content + * @author manuel raynaud + */ +class ContentCreateEvent extends ContentEvent +{ + protected $title; + protected $default_folder; + 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 $default_folder + * + * @return $this + */ + public function setDefaultFolder($default_folder) + { + $this->default_folder = $default_folder; + + return $this; + } + + /** + * @return mixed + */ + public function getDefaultFolder() + { + return $this->default_folder; + } + + + + + /** + * @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 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 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 diff --git a/core/lib/Thelia/Core/Event/TheliaEvents.php b/core/lib/Thelia/Core/Event/TheliaEvents.php index d41b6b5cd..efff47b9e 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.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_createContent"; + const AFTER_CREATECONTENT = "action.after_createContent"; + + const BEFORE_DELETECONTENT = "action.before_deleteContent"; + const AFTER_DELETECONTENT = "action.after_deleteContent"; + + const BEFORE_UPDATECONTENT = "action.before_updateContent"; + const AFTER_UPDATECONTENT = "action.after_updateContent"; + // -- Categories Associated Content ---------------------------------------- const BEFORE_CREATECATEGORY_ASSOCIATED_CONTENT = "action.before_createCategoryAssociatedContent"; 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/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); diff --git a/core/lib/Thelia/Form/ContentCreationForm.php b/core/lib/Thelia/Form/ContentCreationForm.php index 8d8c2d1ca..df8838f59 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( @@ -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/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))))) diff --git a/core/lib/Thelia/Model/Content.php b/core/lib/Thelia/Model/Content.php index 10ed2afe3..69ef7d6d7 100755 --- a/core/lib/Thelia/Model/Content.php +++ b/core/lib/Thelia/Model/Content.php @@ -2,7 +2,12 @@ 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\ContentFolderQuery; +use Thelia\Model\Map\ContentTableMap; use Thelia\Tools\URL; use Propel\Runtime\Connection\ConnectionInterface; @@ -30,13 +35,78 @@ class Content extends BaseContent // and generate the position relative to this folder } - /** - * {@inheritDoc} - */ - public function preInsert(ConnectionInterface $con = null) + public function getDefaultFolderId() { - $this->setPosition($this->getNextPosition()); + // Find default folder + $default_folder = ContentFolderQuery::create() + ->filterByContentId($this->getId()) + ->filterByDefaultFolder(true) + ->findOne(); + + 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); + + $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(); + + $this->dispatchEvent(TheliaEvents::AFTER_CREATECONTENT,new ContentEvent($this)); + } catch(\Exception $ex) { + + $con->rollback(); + + throw $ex; + } + } + + + 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)); + } } diff --git a/templates/admin/default/content-edit.html b/templates/admin/default/content-edit.html new file mode 100644 index 000000000..a7b55dfb8 --- /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='default_folder'} +
+ + + + +
+ {/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 diff --git a/templates/admin/default/folder-edit.html b/templates/admin/default/folder-edit.html index ebbc8582a..76670ed88 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..fca34ba21 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,10 +143,10 @@
{* 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"} - + {/loop} {loop type="auth" name="can_delete" roles="ADMIN" permissions="admin.folders.delete"} @@ -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}
{* 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} @@ -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'}" } @@ -256,13 +256,13 @@
{$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} @@ -344,11 +344,11 @@ {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'} - + {/form_field} {form_field form=$form field='title'} @@ -412,15 +412,15 @@ {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'} - + {/form_field} {form_field form=$form field='title'} @@ -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 } @@ -498,7 +498,7 @@ {capture "content_delete_dialog"} - + {module_include location='content_delete_form'}