Finished attributes management
This commit is contained in:
@@ -37,6 +37,8 @@ use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Model\AttributeAv;
|
||||
use Thelia\Model\AttributeAvQuery;
|
||||
use Thelia\Core\Event\UpdatePositionEvent;
|
||||
use Thelia\Core\Event\CategoryEvent;
|
||||
use Thelia\Core\Event\AttributeEvent;
|
||||
|
||||
class Attribute extends BaseAction implements EventSubscriberInterface
|
||||
{
|
||||
@@ -133,6 +135,24 @@ class Attribute extends BaseAction implements EventSubscriberInterface
|
||||
}
|
||||
}
|
||||
|
||||
public function addToAllTemplates(AttributeEvent $event)
|
||||
{
|
||||
$templates = ProductTemplateAttributeQuery::create()->find();
|
||||
|
||||
foreach($templates as $template) {
|
||||
$pat = new ProductTemplateAttribute();
|
||||
|
||||
$pat->setTemplate($template->getId())
|
||||
->setAttributeId($event->getAttribute()->getId())
|
||||
->save();
|
||||
}
|
||||
}
|
||||
|
||||
public function removeFromAllTemplates(AttributeEvent $event)
|
||||
{
|
||||
// Delete this attribute from all product templates
|
||||
ProductTemplateAttributeQuery::create()->filterByAttributeId($event->getAttribute()->getId())->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
@@ -144,6 +164,10 @@ class Attribute extends BaseAction implements EventSubscriberInterface
|
||||
TheliaEvents::ATTRIBUTE_UPDATE => array("update", 128),
|
||||
TheliaEvents::ATTRIBUTE_DELETE => array("delete", 128),
|
||||
TheliaEvents::ATTRIBUTE_UPDATE_POSITION => array("updatePosition", 128),
|
||||
|
||||
TheliaEvents::ATTRIBUTE_REMOVE_FROM_ALL_TEMPLATES => array("removeFromAllTemplates", 128),
|
||||
TheliaEvents::ATTRIBUTE_ADD_TO_ALL_TEMPLATES => array("addToAllTemplates", 128),
|
||||
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -236,6 +236,14 @@
|
||||
<default key="_controller">Thelia\Controller\Admin\AttributeController::updatePositionAction</default>
|
||||
</route>
|
||||
|
||||
<route id="admin.configuration.attributes.rem-from-all" path="/admin/configuration/attributes/remove-from-all-templates">
|
||||
<default key="_controller">Thelia\Controller\Admin\AttributeController::removeFromAllTemplates</default>
|
||||
</route>
|
||||
|
||||
<route id="admin.configuration.attributes.add-to-all" path="/admin/configuration/attributes/add-to-all-templates">
|
||||
<default key="_controller">Thelia\Controller\Admin\AttributeController::addToAllTemplates</default>
|
||||
</route>
|
||||
|
||||
|
||||
<route id="admin.configuration.attributes-av.create" path="/admin/configuration/attributes-av/create">
|
||||
<default key="_controller">Thelia\Controller\Admin\AttributeAvController::createAction</default>
|
||||
|
||||
@@ -38,6 +38,7 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
|
||||
// List ordering
|
||||
protected $defaultListOrder;
|
||||
protected $orderRequestParameterName;
|
||||
|
||||
// Permissions
|
||||
protected $viewPermissionIdentifier;
|
||||
@@ -74,6 +75,7 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
$objectName,
|
||||
|
||||
$defaultListOrder = null,
|
||||
$orderRequestParameterName = null,
|
||||
|
||||
$viewPermissionIdentifier,
|
||||
$createPermissionIdentifier,
|
||||
@@ -89,8 +91,9 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
$this->objectName = $objectName;
|
||||
|
||||
$this->defaultListOrder = $defaultListOrder;
|
||||
$this->orderRequestParameterName = $orderRequestParameterName;
|
||||
|
||||
$this->viewPermissionIdentifier = $viewPermissionIdentifier;
|
||||
$this->viewPermissionIdentifier = $viewPermissionIdentifier;
|
||||
$this->createPermissionIdentifier = $createPermissionIdentifier;
|
||||
$this->updatePermissionIdentifier = $updatePermissionIdentifier;
|
||||
$this->deletePermissionIdentifier = $deletePermissionIdentifier;
|
||||
@@ -194,36 +197,56 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
protected abstract function redirectToListTemplate();
|
||||
|
||||
|
||||
protected function createUpdatePositionEvent($positionChangeMode, $positionValue) {
|
||||
protected function createUpdatePositionEvent($positionChangeMode, $positionValue)
|
||||
{
|
||||
throw new \LogicException ("Position Update is not supported for this object");
|
||||
}
|
||||
|
||||
protected function createToggleVisibilityEvent() {
|
||||
|
||||
protected function createToggleVisibilityEvent()
|
||||
{
|
||||
throw new \LogicException ("Toggle Visibility is not supported for this object");
|
||||
}
|
||||
|
||||
/**
|
||||
* Put in this method post object creation processing if required.
|
||||
*
|
||||
* @param unknown $createdObject the created object
|
||||
*/
|
||||
protected function performAdditionalCreateAction($createdObject)
|
||||
{
|
||||
// Nothing to do
|
||||
}
|
||||
|
||||
/**
|
||||
* Put in this method post object update processing if required.
|
||||
*
|
||||
* @param unknown $updatedObject the updated object
|
||||
*/
|
||||
protected function performAdditionalUpdateAction($updatedObject)
|
||||
{
|
||||
// Nothing to do
|
||||
}
|
||||
|
||||
/**
|
||||
* Put in this method post object delete processing if required.
|
||||
*
|
||||
* @param unknown $deletedObject the deleted object
|
||||
*/
|
||||
protected function performAdditionalDeleteAction($deletedObject)
|
||||
{
|
||||
// Nothing to do
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the current list order identifier, updating it in the same time.
|
||||
*/
|
||||
protected function getCurrentListOrder($update_session = true) {
|
||||
|
||||
$order = null;
|
||||
|
||||
if ($this->defaultListOrder) {
|
||||
|
||||
$orderSessionIdentifier = sprintf("admin.%s.currentListOrder", $this->objectName);
|
||||
|
||||
// Find the current order
|
||||
$order = $this->getRequest()->get(
|
||||
'order',
|
||||
$this->getSession()->get($orderSessionIdentifier, $this->defaultListOrder)
|
||||
);
|
||||
|
||||
if ($update_session) $this->getSession()->set($orderSessionIdentifier, $order);
|
||||
}
|
||||
|
||||
return $order;
|
||||
protected function getCurrentListOrder($update_session = true)
|
||||
{
|
||||
return $this->getListOrderFromSession(
|
||||
$this->objectName,
|
||||
$this->orderRequestParameterName,
|
||||
$this->defaultListOrder
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -283,6 +306,8 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
$this->adminLogAppend(sprintf("%s %s (ID %s) created", ucfirst($this->objectName), $this->getObjectLabel($createdObject), $this->getObjectId($createdObject)));
|
||||
}
|
||||
|
||||
$this->performAdditionalCreateAction($createdObject);
|
||||
|
||||
// Substitute _ID_ in the URL with the ID of the created object
|
||||
$successUrl = str_replace('_ID_', $this->getObjectId($createdObject), $creationForm->getSuccessUrl());
|
||||
|
||||
@@ -317,7 +342,7 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
if (null !== $response = $this->checkAuth($this->updatePermissionIdentifier)) return $response;
|
||||
|
||||
// Load the object
|
||||
$object = $this->getExistingObject($this->getRequest());
|
||||
$object = $this->getExistingObject();
|
||||
|
||||
if ($object != null) {
|
||||
|
||||
@@ -368,6 +393,8 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
$this->adminLogAppend(sprintf("%s %s (ID %s) modified", ucfirst($this->objectName), $this->getObjectLabel($changedObject), $this->getObjectId($changedObject)));
|
||||
}
|
||||
|
||||
$this->performAdditionalUpdateAction($changedObject);
|
||||
|
||||
// If we have to stay on the same page, do not redirect to the succesUrl,
|
||||
// just redirect to the edit page again.
|
||||
if ($this->getRequest()->get('save_mode') == 'stay') {
|
||||
@@ -467,6 +494,7 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
$this->adminLogAppend(
|
||||
sprintf("%s %s (ID %s) deleted", ucfirst($this->objectName), $this->getObjectLabel($deletedObject), $this->getObjectId($deletedObject)));
|
||||
}
|
||||
$this->performAdditionalDeleteAction($deletedObject);
|
||||
|
||||
$this->redirectToListTemplate();
|
||||
}
|
||||
|
||||
@@ -39,10 +39,12 @@ use Thelia\Core\Event\UpdatePositionEvent;
|
||||
*/
|
||||
class AttributeAvController extends AbstractCrudController
|
||||
{
|
||||
public function __construct() {
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(
|
||||
'attribute',
|
||||
'attributeav',
|
||||
'manual',
|
||||
'order',
|
||||
|
||||
'admin.configuration.attributes-av.view',
|
||||
'admin.configuration.attributes-av.create',
|
||||
@@ -57,15 +59,18 @@ class AttributeAvController extends AbstractCrudController
|
||||
);
|
||||
}
|
||||
|
||||
protected function getCreationForm() {
|
||||
protected function getCreationForm()
|
||||
{
|
||||
return new AttributeAvCreationForm($this->getRequest());
|
||||
}
|
||||
|
||||
protected function getUpdateForm() {
|
||||
protected function getUpdateForm()
|
||||
{
|
||||
return new AttributeAvModificationForm($this->getRequest());
|
||||
}
|
||||
|
||||
protected function getCreationEvent($formData) {
|
||||
protected function getCreationEvent($formData)
|
||||
{
|
||||
$createEvent = new AttributeAvCreateEvent();
|
||||
|
||||
$createEvent
|
||||
@@ -77,8 +82,8 @@ class AttributeAvController extends AbstractCrudController
|
||||
return $createEvent;
|
||||
}
|
||||
|
||||
protected function getUpdateEvent($formData) {
|
||||
|
||||
protected function getUpdateEvent($formData)
|
||||
{
|
||||
$changeEvent = new AttributeAvUpdateEvent($formData['id']);
|
||||
|
||||
// Create and dispatch the change event
|
||||
@@ -93,8 +98,8 @@ class AttributeAvController extends AbstractCrudController
|
||||
return $changeEvent;
|
||||
}
|
||||
|
||||
protected function createUpdatePositionEvent($positionChangeMode, $positionValue) {
|
||||
|
||||
protected function createUpdatePositionEvent($positionChangeMode, $positionValue)
|
||||
{
|
||||
return new UpdatePositionEvent(
|
||||
$this->getRequest()->get('attributeav_id', null),
|
||||
$positionChangeMode,
|
||||
@@ -102,16 +107,18 @@ class AttributeAvController extends AbstractCrudController
|
||||
);
|
||||
}
|
||||
|
||||
protected function getDeleteEvent() {
|
||||
protected function getDeleteEvent()
|
||||
{
|
||||
return new AttributeAvDeleteEvent($this->getRequest()->get('attributeav_id'));
|
||||
}
|
||||
|
||||
protected function eventContainsObject($event) {
|
||||
protected function eventContainsObject($event)
|
||||
{
|
||||
return $event->hasAttributeAv();
|
||||
}
|
||||
|
||||
protected function hydrateObjectForm($object) {
|
||||
|
||||
protected function hydrateObjectForm($object)
|
||||
{
|
||||
$data = array(
|
||||
'id' => $object->getId(),
|
||||
'locale' => $object->getLocale(),
|
||||
@@ -125,32 +132,38 @@ class AttributeAvController extends AbstractCrudController
|
||||
return new AttributeAvModificationForm($this->getRequest(), "form", $data);
|
||||
}
|
||||
|
||||
protected function getObjectFromEvent($event) {
|
||||
protected function getObjectFromEvent($event)
|
||||
{
|
||||
return $event->hasAttributeAv() ? $event->getAttributeAv() : null;
|
||||
}
|
||||
|
||||
protected function getExistingObject() {
|
||||
protected function getExistingObject()
|
||||
{
|
||||
return AttributeAvQuery::create()
|
||||
->joinWithI18n($this->getCurrentEditionLocale())
|
||||
->findOneById($this->getRequest()->get('attributeav_id'));
|
||||
}
|
||||
|
||||
protected function getObjectLabel($object) {
|
||||
protected function getObjectLabel($object)
|
||||
{
|
||||
return $object->getTitle();
|
||||
}
|
||||
|
||||
protected function getObjectId($object) {
|
||||
protected function getObjectId($object)
|
||||
{
|
||||
return $object->getId();
|
||||
}
|
||||
|
||||
protected function getViewArguments() {
|
||||
protected function getViewArguments()
|
||||
{
|
||||
return array(
|
||||
'attribute_id' => $this->getRequest()->get('attribute_id'),
|
||||
'order' => $this->getCurrentListOrder()
|
||||
);
|
||||
}
|
||||
|
||||
protected function renderListTemplate($currentOrder) {
|
||||
protected function renderListTemplate($currentOrder)
|
||||
{
|
||||
// We always return to the attribute edition form
|
||||
return $this->render(
|
||||
'attribute-edit',
|
||||
@@ -158,12 +171,14 @@ class AttributeAvController extends AbstractCrudController
|
||||
);
|
||||
}
|
||||
|
||||
protected function renderEditionTemplate() {
|
||||
protected function renderEditionTemplate()
|
||||
{
|
||||
// We always return to the attribute edition form
|
||||
return $this->render('attribute-edit', $this->getViewArguments());
|
||||
}
|
||||
|
||||
protected function redirectToEditionTemplate() {
|
||||
protected function redirectToEditionTemplate()
|
||||
{
|
||||
// We always return to the attribute edition form
|
||||
$this->redirectToRoute(
|
||||
"admin.configuration.attributes.update",
|
||||
@@ -171,7 +186,8 @@ class AttributeAvController extends AbstractCrudController
|
||||
);
|
||||
}
|
||||
|
||||
protected function redirectToListTemplate() {
|
||||
protected function redirectToListTemplate()
|
||||
{
|
||||
$this->redirectToRoute(
|
||||
"admin.configuration.attributes.update",
|
||||
$this->getViewArguments()
|
||||
|
||||
@@ -31,6 +31,10 @@ use Thelia\Model\AttributeQuery;
|
||||
use Thelia\Form\AttributeModificationForm;
|
||||
use Thelia\Form\AttributeCreationForm;
|
||||
use Thelia\Core\Event\UpdatePositionEvent;
|
||||
use Thelia\Model\AttributeAv;
|
||||
use Thelia\Model\AttributeAvQuery;
|
||||
use Thelia\Core\Event\AttributeAvUpdateEvent;
|
||||
use Thelia\Core\Event\AttributeEvent;
|
||||
|
||||
/**
|
||||
* Manages attributes sent by mail
|
||||
@@ -39,10 +43,12 @@ use Thelia\Core\Event\UpdatePositionEvent;
|
||||
*/
|
||||
class AttributeController extends AbstractCrudController
|
||||
{
|
||||
public function __construct() {
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(
|
||||
'attribute',
|
||||
'manual',
|
||||
'order',
|
||||
|
||||
'admin.configuration.attributes.view',
|
||||
'admin.configuration.attributes.create',
|
||||
@@ -57,15 +63,18 @@ class AttributeController extends AbstractCrudController
|
||||
);
|
||||
}
|
||||
|
||||
protected function getCreationForm() {
|
||||
protected function getCreationForm()
|
||||
{
|
||||
return new AttributeCreationForm($this->getRequest());
|
||||
}
|
||||
|
||||
protected function getUpdateForm() {
|
||||
protected function getUpdateForm()
|
||||
{
|
||||
return new AttributeModificationForm($this->getRequest());
|
||||
}
|
||||
|
||||
protected function getCreationEvent($formData) {
|
||||
protected function getCreationEvent($formData)
|
||||
{
|
||||
$createEvent = new AttributeCreateEvent();
|
||||
|
||||
$createEvent
|
||||
@@ -77,8 +86,8 @@ class AttributeController extends AbstractCrudController
|
||||
return $createEvent;
|
||||
}
|
||||
|
||||
protected function getUpdateEvent($formData) {
|
||||
|
||||
protected function getUpdateEvent($formData)
|
||||
{
|
||||
$changeEvent = new AttributeUpdateEvent($formData['id']);
|
||||
|
||||
// Create and dispatch the change event
|
||||
@@ -93,8 +102,31 @@ class AttributeController extends AbstractCrudController
|
||||
return $changeEvent;
|
||||
}
|
||||
|
||||
protected function createUpdatePositionEvent($positionChangeMode, $positionValue) {
|
||||
/**
|
||||
* Process the attributes values (fix it in future version to integrate it in the attribute form as a collection)
|
||||
*
|
||||
* @see \Thelia\Controller\Admin\AbstractCrudController::performAdditionalUpdateAction()
|
||||
*/
|
||||
protected function performAdditionalUpdateAction($updatedObject)
|
||||
{
|
||||
$attr_values = $this->getRequest()->get('attribute_values', null);
|
||||
|
||||
if ($attr_values !== null) {
|
||||
|
||||
foreach($attr_values as $id => $value) {
|
||||
|
||||
$event = new AttributeAvUpdateEvent($id);
|
||||
|
||||
$event->setTitle($value);
|
||||
$event->setLocale($this->getCurrentEditionLocale());
|
||||
|
||||
$this->dispatch(TheliaEvents::ATTRIBUTE_AV_UPDATE, $event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function createUpdatePositionEvent($positionChangeMode, $positionValue)
|
||||
{
|
||||
return new UpdatePositionEvent(
|
||||
$this->getRequest()->get('attribute_id', null),
|
||||
$positionChangeMode,
|
||||
@@ -102,15 +134,18 @@ class AttributeController extends AbstractCrudController
|
||||
);
|
||||
}
|
||||
|
||||
protected function getDeleteEvent() {
|
||||
protected function getDeleteEvent()
|
||||
{
|
||||
return new AttributeDeleteEvent($this->getRequest()->get('attribute_id'));
|
||||
}
|
||||
|
||||
protected function eventContainsObject($event) {
|
||||
protected function eventContainsObject($event)
|
||||
{
|
||||
return $event->hasAttribute();
|
||||
}
|
||||
|
||||
protected function hydrateObjectForm($object) {
|
||||
protected function hydrateObjectForm($object)
|
||||
{
|
||||
|
||||
$data = array(
|
||||
'id' => $object->getId(),
|
||||
@@ -121,44 +156,132 @@ class AttributeController extends AbstractCrudController
|
||||
'postscriptum' => $object->getPostscriptum()
|
||||
);
|
||||
|
||||
// Setup attributes values
|
||||
/*
|
||||
* FIXME : doesn't work. "We get a This form should not contain extra fields." error
|
||||
$attr_av_list = AttributeAvQuery::create()
|
||||
->joinWithI18n($this->getCurrentEditionLocale())
|
||||
->filterByAttributeId($object->getId())
|
||||
->find();
|
||||
|
||||
$attr_array = array();
|
||||
|
||||
foreach($attr_av_list as $attr_av) {
|
||||
$attr_array[$attr_av->getId()] = $attr_av->getTitle();
|
||||
}
|
||||
|
||||
$data['attribute_values'] = $attr_array;
|
||||
*/
|
||||
|
||||
// Setup the object form
|
||||
return new AttributeModificationForm($this->getRequest(), "form", $data);
|
||||
}
|
||||
|
||||
protected function getObjectFromEvent($event) {
|
||||
protected function getObjectFromEvent($event)
|
||||
{
|
||||
return $event->hasAttribute() ? $event->getAttribute() : null;
|
||||
}
|
||||
|
||||
protected function getExistingObject() {
|
||||
protected function getExistingObject()
|
||||
{
|
||||
return AttributeQuery::create()
|
||||
->joinWithI18n($this->getCurrentEditionLocale())
|
||||
->findOneById($this->getRequest()->get('attribute_id'));
|
||||
}
|
||||
|
||||
protected function getObjectLabel($object) {
|
||||
protected function getObjectLabel($object)
|
||||
{
|
||||
return $object->getTitle();
|
||||
}
|
||||
|
||||
protected function getObjectId($object) {
|
||||
protected function getObjectId($object)
|
||||
{
|
||||
return $object->getId();
|
||||
}
|
||||
|
||||
protected function renderListTemplate($currentOrder) {
|
||||
protected function renderListTemplate($currentOrder)
|
||||
{
|
||||
return $this->render('attributes', array('order' => $currentOrder));
|
||||
}
|
||||
|
||||
protected function renderEditionTemplate() {
|
||||
return $this->render('attribute-edit', array('attribute_id' => $this->getRequest()->get('attribute_id')));
|
||||
}
|
||||
|
||||
protected function redirectToEditionTemplate() {
|
||||
$this->redirectToRoute(
|
||||
"admin.configuration.attributes.update",
|
||||
array('attribute_id' => $this->getRequest()->get('attribute_id'))
|
||||
protected function renderEditionTemplate()
|
||||
{
|
||||
return $this->render(
|
||||
'attribute-edit',
|
||||
array(
|
||||
'attribute_id' => $this->getRequest()->get('attribute_id'),
|
||||
'attributeav_order' => $this->getAttributeAvListOrder()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
protected function redirectToListTemplate() {
|
||||
protected function redirectToEditionTemplate()
|
||||
{
|
||||
$this->redirectToRoute(
|
||||
"admin.configuration.attributes.update",
|
||||
array(
|
||||
'attribute_id' => $this->getRequest()->get('attribute_id'),
|
||||
'attributeav_order' => $this->getAttributeAvListOrder()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
protected function redirectToListTemplate()
|
||||
{
|
||||
$this->redirectToRoute('admin.configuration.attributes.default');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Attribute value list order.
|
||||
*
|
||||
* @return string the current list order
|
||||
*/
|
||||
protected function getAttributeAvListOrder()
|
||||
{
|
||||
return $this->getListOrderFromSession(
|
||||
'attributeav',
|
||||
'attributeav_order',
|
||||
'manual'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add or Remove from all product templates
|
||||
*/
|
||||
protected function addRemoveFromAllTemplates($eventType)
|
||||
{
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth("admin.configuration.attributes.update")) return $response;
|
||||
|
||||
try {
|
||||
if (null !== $object = $this->getExistingObject()) {
|
||||
|
||||
$event = new AttributeEvent($object);
|
||||
|
||||
$this->dispatch($eventType, $event);
|
||||
}
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
// Any error
|
||||
return $this->errorPage($ex);
|
||||
}
|
||||
|
||||
$this->redirectToListTemplate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove from all product templates
|
||||
*/
|
||||
public function removeFromAllTemplates()
|
||||
{
|
||||
return $this->addRemoveFromAllTemplates(TheliaEvents::ATTRIBUTE_REMOVE_FROM_ALL_TEMPLATES);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add to all product templates
|
||||
*/
|
||||
public function addToAllTemplates()
|
||||
{
|
||||
return $this->addRemoveFromAllTemplates(TheliaEvents::ATTRIBUTE_ADD_TO_ALL_TEMPLATES);
|
||||
}
|
||||
}
|
||||
@@ -97,7 +97,7 @@ class BaseAdminController extends BaseController
|
||||
protected function errorPage($message)
|
||||
{
|
||||
if ($message instanceof \Exception) {
|
||||
$message = sprintf($this->getTranslator()->trans("Sorry, an error occured: %msg"), array('msg' => $message->getMessage()));
|
||||
$message = $this->getTranslator()->trans("Sorry, an error occured: %msg", array('%msg' => $message->getMessage()));
|
||||
}
|
||||
|
||||
return $this->render('general_error', array(
|
||||
@@ -273,6 +273,35 @@ class BaseAdminController extends BaseController
|
||||
return $this->getCurrentEditionLang()->getLocale();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the current list order identifier for a given object name,
|
||||
* updating in using the current request.
|
||||
*
|
||||
* @param unknown $objectName the object name (e.g. 'attribute', 'message')
|
||||
* @param unknown $requestParameterName the name of the request parameter that defines the list order
|
||||
* @param unknown $defaultListOrder the default order to use, if none is defined
|
||||
* @param string $updateSession if true, the session will be updated with the current order.
|
||||
*
|
||||
* @return String the current liste order.
|
||||
*/
|
||||
protected function getListOrderFromSession($objectName, $requestParameterName, $defaultListOrder, $updateSession = true) {
|
||||
|
||||
$order = $defaultListOrder;
|
||||
|
||||
$orderSessionIdentifier = sprintf("admin.%s.currentListOrder", $objectName);
|
||||
|
||||
// Find the current order
|
||||
$order = $this->getRequest()->get(
|
||||
$requestParameterName,
|
||||
$this->getSession()->get($orderSessionIdentifier, $defaultListOrder)
|
||||
);
|
||||
|
||||
if ($updateSession) $this->getSession()->set($orderSessionIdentifier, $order);
|
||||
|
||||
return $order;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the given template, and returns the result as an Http Response.
|
||||
*
|
||||
@@ -314,7 +343,7 @@ class BaseAdminController extends BaseController
|
||||
'edit_language_id' => $edition_language->getId(),
|
||||
'edit_language_locale' => $edition_language->getLocale(),
|
||||
|
||||
'current_url' => htmlspecialchars($this->getRequest()->getUri())
|
||||
'current_url' => $this->getRequest()->getUri()
|
||||
));
|
||||
|
||||
// Update the current edition language in session
|
||||
|
||||
@@ -43,6 +43,7 @@ class ConfigController extends AbstractCrudController
|
||||
parent::__construct(
|
||||
'variable',
|
||||
'name',
|
||||
'order',
|
||||
|
||||
'admin.configuration.variables.view',
|
||||
'admin.configuration.variables.create',
|
||||
|
||||
@@ -43,6 +43,7 @@ class CurrencyController extends AbstractCrudController
|
||||
parent::__construct(
|
||||
'currency',
|
||||
'manual',
|
||||
'order',
|
||||
|
||||
'admin.configuration.currencies.view',
|
||||
'admin.configuration.currencies.create',
|
||||
|
||||
@@ -37,10 +37,12 @@ use Thelia\Form\MessageCreationForm;
|
||||
*/
|
||||
class MessageController extends AbstractCrudController
|
||||
{
|
||||
public function __construct() {
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(
|
||||
'message',
|
||||
null,
|
||||
null, // no sort order change
|
||||
null, // no sort order change
|
||||
|
||||
'admin.configuration.messages.view',
|
||||
'admin.configuration.messages.create',
|
||||
@@ -55,15 +57,18 @@ class MessageController extends AbstractCrudController
|
||||
);
|
||||
}
|
||||
|
||||
protected function getCreationForm() {
|
||||
protected function getCreationForm()
|
||||
{
|
||||
return new MessageCreationForm($this->getRequest());
|
||||
}
|
||||
|
||||
protected function getUpdateForm() {
|
||||
protected function getUpdateForm()
|
||||
{
|
||||
return new MessageModificationForm($this->getRequest());
|
||||
}
|
||||
|
||||
protected function getCreationEvent($formData) {
|
||||
protected function getCreationEvent($formData)
|
||||
{
|
||||
$createEvent = new MessageCreateEvent();
|
||||
|
||||
$createEvent
|
||||
@@ -76,7 +81,8 @@ class MessageController extends AbstractCrudController
|
||||
return $createEvent;
|
||||
}
|
||||
|
||||
protected function getUpdateEvent($formData) {
|
||||
protected function getUpdateEvent($formData)
|
||||
{
|
||||
$changeEvent = new MessageUpdateEvent($formData['id']);
|
||||
|
||||
// Create and dispatch the change event
|
||||
@@ -93,16 +99,18 @@ class MessageController extends AbstractCrudController
|
||||
return $changeEvent;
|
||||
}
|
||||
|
||||
protected function getDeleteEvent() {
|
||||
protected function getDeleteEvent()
|
||||
{
|
||||
return new MessageDeleteEvent($this->getRequest()->get('message_id'));
|
||||
}
|
||||
|
||||
protected function eventContainsObject($event) {
|
||||
protected function eventContainsObject($event)
|
||||
{
|
||||
return $event->hasMessage();
|
||||
}
|
||||
|
||||
protected function hydrateObjectForm($object) {
|
||||
|
||||
protected function hydrateObjectForm($object)
|
||||
{
|
||||
// Prepare the data that will hydrate the form
|
||||
$data = array(
|
||||
'id' => $object->getId(),
|
||||
@@ -119,40 +127,48 @@ class MessageController extends AbstractCrudController
|
||||
return new MessageModificationForm($this->getRequest(), "form", $data);
|
||||
}
|
||||
|
||||
protected function getObjectFromEvent($event) {
|
||||
protected function getObjectFromEvent($event)
|
||||
{
|
||||
return $event->hasMessage() ? $event->getMessage() : null;
|
||||
}
|
||||
|
||||
protected function getExistingObject() {
|
||||
protected function getExistingObject()
|
||||
{
|
||||
return MessageQuery::create()
|
||||
->joinWithI18n($this->getCurrentEditionLocale())
|
||||
->findOneById($this->getRequest()->get('message_id'));
|
||||
}
|
||||
|
||||
protected function getObjectLabel($object) {
|
||||
protected function getObjectLabel($object)
|
||||
{
|
||||
return $object->getName();
|
||||
}
|
||||
|
||||
protected function getObjectId($object) {
|
||||
protected function getObjectId($object)
|
||||
{
|
||||
return $object->getId();
|
||||
}
|
||||
|
||||
protected function renderListTemplate($currentOrder) {
|
||||
protected function renderListTemplate($currentOrder)
|
||||
{
|
||||
return $this->render('messages');
|
||||
}
|
||||
|
||||
protected function renderEditionTemplate() {
|
||||
protected function renderEditionTemplate()
|
||||
{
|
||||
return $this->render('message-edit', array('message_id' => $this->getRequest()->get('message_id')));
|
||||
}
|
||||
|
||||
protected function redirectToEditionTemplate() {
|
||||
protected function redirectToEditionTemplate()
|
||||
{
|
||||
$this->redirectToRoute(
|
||||
"admin.configuration.messages.update",
|
||||
array('message_id' => $this->getRequest()->get('message_id'))
|
||||
);
|
||||
}
|
||||
|
||||
protected function redirectToListTemplate() {
|
||||
protected function redirectToListTemplate()
|
||||
{
|
||||
$this->redirectToRoute('admin.configuration.messages.default');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -369,6 +369,9 @@ final class TheliaEvents
|
||||
const ATTRIBUTE_DELETE = "action.deleteAttribute";
|
||||
const ATTRIBUTE_UPDATE_POSITION = "action.updateAttributePosition";
|
||||
|
||||
const ATTRIBUTE_REMOVE_FROM_ALL_TEMPLATES = "action.addAttributeToAllTemplate";
|
||||
const ATTRIBUTE_ADD_TO_ALL_TEMPLATES = "action.removeAttributeFromAllTemplate";
|
||||
|
||||
const BEFORE_CREATEATTRIBUTE = "action.before_createAttribute";
|
||||
const AFTER_CREATEATTRIBUTE = "action.after_createAttribute";
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ class AttributeAvailability extends BaseI18nLoop
|
||||
new Argument(
|
||||
'order',
|
||||
new TypeCollection(
|
||||
new Type\EnumListType(array('alpha', 'alpha_reverse', 'manual', 'manual_reverse'))
|
||||
new Type\EnumListType(array('id', 'id_reverse', 'alpha', 'alpha_reverse', 'manual', 'manual_reverse'))
|
||||
),
|
||||
'manual'
|
||||
)
|
||||
@@ -100,6 +100,12 @@ class AttributeAvailability extends BaseI18nLoop
|
||||
|
||||
foreach ($orders as $order) {
|
||||
switch ($order) {
|
||||
case 'id':
|
||||
$search->orderById(Criteria::ASC);
|
||||
break;
|
||||
case 'id_reverse':
|
||||
$search->orderById(Criteria::DESC);
|
||||
break;
|
||||
case "alpha":
|
||||
$search->addAscendingOrderByColumn('i18n_TITLE');
|
||||
break;
|
||||
|
||||
@@ -106,6 +106,9 @@ class AdminUtilities extends AbstractSmartyPlugin
|
||||
// The column label
|
||||
$label = $this->getParam($params, 'label');
|
||||
|
||||
// The request parameter
|
||||
$request_parameter_name = $this->getParam($params, 'request_parameter_name', 'order');
|
||||
|
||||
if ($current_order == $order) {
|
||||
$icon = 'up';
|
||||
$order_change = $reverse_order;
|
||||
@@ -121,7 +124,7 @@ class AdminUtilities extends AbstractSmartyPlugin
|
||||
else
|
||||
$output = '';
|
||||
|
||||
return sprintf('%s<a href="%s">%s</a>', $output, URL::getInstance()->absoluteUrl($path, array('order' => $order_change)), $label);
|
||||
return sprintf('%s<a href="%s">%s</a>', $output, URL::getInstance()->absoluteUrl($path, array($request_parameter_name => $order_change)), $label);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -112,6 +112,37 @@ class Form extends AbstractSmartyPlugin
|
||||
}
|
||||
}
|
||||
|
||||
protected function assignFieldValues($template, $fieldName, $fieldValue, $fieldVars)
|
||||
{
|
||||
$template->assign("name", $fieldName);
|
||||
|
||||
$template->assign("value", $fieldValue);
|
||||
|
||||
// If Checkbox input type
|
||||
if ($fieldVars['checked'] !== null) {
|
||||
$this->renderFormFieldCheckBox($template, $formFieldView['checked']);
|
||||
}
|
||||
|
||||
$template->assign("label", $fieldVars["label"]);
|
||||
$template->assign("label_attr", $fieldVars["label_attr"]);
|
||||
|
||||
$errors = $fieldVars["errors"];
|
||||
|
||||
$template->assign("error", empty($errors) ? false : true);
|
||||
|
||||
if (! empty($errors)) {
|
||||
$this->assignFieldErrorVars($template, $errors);
|
||||
}
|
||||
|
||||
$attr = array();
|
||||
|
||||
foreach ($fieldVars["attr"] as $key => $value) {
|
||||
$attr[] = sprintf('%s="%s"', $key, $value);
|
||||
}
|
||||
|
||||
$template->assign("attr", implode(" ", $attr));
|
||||
}
|
||||
|
||||
public function renderFormField($params, $content, \Smarty_Internal_Template $template, &$repeat)
|
||||
{
|
||||
if ($repeat) {
|
||||
@@ -120,32 +151,29 @@ class Form extends AbstractSmartyPlugin
|
||||
|
||||
$template->assign("options", $formFieldView->vars);
|
||||
|
||||
$template->assign("name", $formFieldView->vars["full_name"]);
|
||||
$template->assign("value", $formFieldView->vars["value"]);
|
||||
$value = $formFieldView->vars["value"];
|
||||
/* FIXME: doesnt work. We got "This form should not contain extra fields." error.
|
||||
// We have a collection
|
||||
if (is_array($value)) {
|
||||
|
||||
// If Checkbox input type
|
||||
if ($formFieldView->vars['checked'] !== null) {
|
||||
$this->renderFormFieldCheckBox($template, $formFieldView);
|
||||
$key = $this->getParam($params, 'value_key');
|
||||
|
||||
if ($key != null) {
|
||||
|
||||
if (isset($value[$key])) {
|
||||
|
||||
$name = sprintf("%s[%s]", $formFieldView->vars["full_name"], $key);
|
||||
$val = $value[$key];
|
||||
|
||||
$this->assignFieldValues($template, $name, $val, $formFieldView->vars);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$template->assign("label", $formFieldView->vars["label"]);
|
||||
$template->assign("label_attr", $formFieldView->vars["label_attr"]);
|
||||
|
||||
$errors = $formFieldView->vars["errors"];
|
||||
|
||||
$template->assign("error", empty($errors) ? false : true);
|
||||
|
||||
if (! empty($errors)) {
|
||||
$this->assignFieldErrorVars($template, $errors);
|
||||
else {
|
||||
$this->assignFieldValues($template, $formFieldView->vars["full_name"], $fieldVars["value"], $formFieldView->vars);
|
||||
}
|
||||
|
||||
$attr = array();
|
||||
|
||||
foreach ($formFieldView->vars["attr"] as $key => $value) {
|
||||
$attr[] = sprintf('%s="%s"', $key, $value);
|
||||
}
|
||||
|
||||
$template->assign("attr", implode(" ", $attr));
|
||||
*/
|
||||
$this->assignFieldValues($template, $formFieldView->vars["full_name"], $formFieldView->vars["value"], $formFieldView->vars);
|
||||
|
||||
$formFieldView->setRendered();
|
||||
} else {
|
||||
@@ -275,12 +303,12 @@ class Form extends AbstractSmartyPlugin
|
||||
* @param \Smarty_Internal_Template $template
|
||||
* @param $formFieldView
|
||||
*/
|
||||
public function renderFormFieldCheckBox(\Smarty_Internal_Template $template, $formFieldView)
|
||||
public function renderFormFieldCheckBox(\Smarty_Internal_Template $template, $isChecked)
|
||||
{
|
||||
$template->assign("value", 0);
|
||||
if ($formFieldView->vars['checked']) {
|
||||
if ($isChecked) {
|
||||
$template->assign("value", 1);
|
||||
}
|
||||
$template->assign("value", $formFieldView->vars['checked']);
|
||||
$template->assign("value", $isChecked);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,6 +54,7 @@ class UrlGenerator extends AbstractSmartyPlugin
|
||||
$url = URL::getInstance()->absoluteUrl($path, $this->getArgsFromParam($params, array('path', 'target')));
|
||||
|
||||
if ($target != null) $url .= '#'.$target;
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
|
||||
@@ -43,10 +43,12 @@ class AttributeModificationForm extends AttributeCreationForm
|
||||
)
|
||||
)
|
||||
))
|
||||
/* FIXME: doesn't work
|
||||
->add('attribute_values', 'collection', array(
|
||||
'type' => 'text',
|
||||
'options' => array('required' => false)
|
||||
))
|
||||
*/
|
||||
;
|
||||
|
||||
// Add standard description fields
|
||||
|
||||
Reference in New Issue
Block a user