Merge branch 'master' of github.com:thelia/thelia

This commit is contained in:
Manuel Raynaud
2013-09-12 15:44:29 +02:00
8 changed files with 228 additions and 44 deletions

View File

@@ -50,6 +50,7 @@ class AttributeAv extends BaseAction implements EventSubscriberInterface
$attribute
->setDispatcher($this->getDispatcher())
->setAttributeId($event->getAttributeId())
->setLocale($event->getLocale())
->setTitle($event->getTitle())
@@ -57,11 +58,6 @@ class AttributeAv extends BaseAction implements EventSubscriberInterface
;
$event->setAttributeAv($attribute);
// Add atribute to all product templates if required
if ($event->getAddToAllTemplates() != 0) {
// TODO: add to all product template
}
}
/**

View File

@@ -70,7 +70,8 @@
<form name="thelia.admin.attribute.creation" class="Thelia\Form\AttributeCreationForm"/>
<form name="thelia.admin.attribute.modification" class="Thelia\Form\AttributeModificationForm"/>
<form name="thelia.admin.attribute-value.creation" class="Thelia\Form\AttributeValueCreationForm"/>
<form name="thelia.admin.attributeav.creation" class="Thelia\Form\AttributeAvCreationForm"/>
</forms>

View File

@@ -0,0 +1,180 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Controller\Admin;
use Thelia\Core\Event\AttributeAvDeleteEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Core\Event\AttributeAvUpdateEvent;
use Thelia\Core\Event\AttributeAvCreateEvent;
use Thelia\Model\AttributeAvQuery;
use Thelia\Form\AttributeAvModificationForm;
use Thelia\Form\AttributeAvCreationForm;
use Thelia\Core\Event\UpdatePositionEvent;
/**
* Manages attributes-av sent by mail
*
* @author Franck Allimant <franck@cqfdev.fr>
*/
class AttributeAvController extends AbstractCrudController
{
public function __construct() {
parent::__construct(
'attribute',
'manual',
'admin.configuration.attributes-av.view',
'admin.configuration.attributes-av.create',
'admin.configuration.attributes-av.update',
'admin.configuration.attributes-av.delete',
TheliaEvents::ATTRIBUTE_AV_CREATE,
TheliaEvents::ATTRIBUTE_AV_UPDATE,
TheliaEvents::ATTRIBUTE_AV_DELETE,
null, // No visibility toggle
TheliaEvents::ATTRIBUTE_AV_UPDATE_POSITION
);
}
protected function getCreationForm() {
return new AttributeAvCreationForm($this->getRequest());
}
protected function getUpdateForm() {
return new AttributeAvModificationForm($this->getRequest());
}
protected function getCreationEvent($formData) {
$createEvent = new AttributeAvCreateEvent();
$createEvent
->setAttributeId($formData['attribute_id'])
->setTitle($formData['title'])
->setLocale($formData["locale"])
;
return $createEvent;
}
protected function getUpdateEvent($formData) {
$changeEvent = new AttributeAvUpdateEvent($formData['id']);
// Create and dispatch the change event
$changeEvent
->setLocale($formData["locale"])
->setTitle($formData['title'])
->setChapo($formData['chapo'])
->setDescription($formData['description'])
->setPostscriptum($formData['postscriptum'])
;
return $changeEvent;
}
protected function createUpdatePositionEvent($positionChangeMode, $positionValue) {
return new UpdatePositionEvent(
$this->getRequest()->get('attributeav_id', null),
$positionChangeMode,
$positionValue
);
}
protected function getDeleteEvent() {
return new AttributeAvDeleteEvent($this->getRequest()->get('attributeav_id'));
}
protected function eventContainsObject($event) {
return $event->hasAttributeAv();
}
protected function hydrateObjectForm($object) {
$data = array(
'id' => $object->getId(),
'locale' => $object->getLocale(),
'title' => $object->getTitle(),
'chapo' => $object->getChapo(),
'description' => $object->getDescription(),
'postscriptum' => $object->getPostscriptum()
);
// Setup the object form
return new AttributeAvModificationForm($this->getRequest(), "form", $data);
}
protected function getObjectFromEvent($event) {
return $event->hasAttributeAv() ? $event->getAttributeAv() : null;
}
protected function getExistingObject() {
return AttributeAvQuery::create()
->joinWithI18n($this->getCurrentEditionLocale())
->findOneById($this->getRequest()->get('attributeav_id'));
}
protected function getObjectLabel($object) {
return $object->getTitle();
}
protected function getObjectId($object) {
return $object->getId();
}
protected function getViewArguments() {
return array(
'attribute_id' => $this->getRequest()->get('attribute_id'),
'order' => $this->getCurrentListOrder()
);
}
protected function renderListTemplate($currentOrder) {
// We always return to the attribute edition form
return $this->render(
'attribute-edit',
$this->getViewArguments()
);
}
protected function renderEditionTemplate() {
// We always return to the attribute edition form
return $this->render('attribute-edit', $this->getViewArguments());
}
protected function redirectToEditionTemplate() {
// We always return to the attribute edition form
$this->redirectToRoute(
"admin.configuration.attributes.update",
$this->getViewArguments()
);
}
protected function redirectToListTemplate() {
$this->redirectToRoute(
"admin.configuration.attributes.update",
$this->getViewArguments()
);
}
}

View File

@@ -28,7 +28,7 @@ use Symfony\Component\Validator\ExecutionContextInterface;
use Symfony\Component\Validator\Constraints\NotBlank;
use Thelia\Core\Translation\Translator;
class AttributeValueCreationForm extends BaseForm
class AttributeAvCreationForm extends BaseForm
{
protected function buildForm()
{
@@ -57,6 +57,6 @@ class AttributeValueCreationForm extends BaseForm
public function getName()
{
return "thelia_attribute_value_creation";
return "thelia_attributeav_creation";
}
}

View File

@@ -43,6 +43,10 @@ class AttributeModificationForm extends AttributeCreationForm
)
)
))
->add('attribute_values', 'collection', array(
'type' => 'text',
'options' => array('required' => false)
))
;
// Add standard description fields

View File

@@ -3,7 +3,7 @@
namespace Thelia\Model;
use Thelia\Model\Base\AttributeAv as BaseAttributeAv;
use Thelia\Core\Event\AttributeValueEvent;
use Thelia\Core\Event\AttributeAvEvent;
use Propel\Runtime\Connection\ConnectionInterface;
use Thelia\Core\Event\TheliaEvents;
use Propel\Runtime\ActiveQuery\Criteria;
@@ -11,21 +11,14 @@ use Propel\Runtime\ActiveQuery\Criteria;
class AttributeAv extends BaseAttributeAv {
use \Thelia\Model\Tools\ModelEventDispatcherTrait;
use \Thelia\Model\Tools\PositionManagementTrait;
/**
* Get the position of the next inserted object
* when dealing with position, be sure to work insite the current attribute.
*/
public function getNextPosition($parent = null) {
$last = $this->createQuery()
->filterByAttributeId($this->getAttributeId())
->orderByPosition(Criteria::DESC)
->limit(1)
->findOne()
;
return $last != null ? $last->getPosition() + 1 : 1;
protected function addCriteriaToPositionQuery($query) {
$query->filterByAttributeId($this->getAttributeId());
}
/**
@@ -33,11 +26,11 @@ class AttributeAv extends BaseAttributeAv {
*/
public function preInsert(ConnectionInterface $con = null)
{
$this->dispatchEvent(TheliaEvents::BEFORE_CREATEATTRIBUTE_VALUE, new AttributeValueEvent($this));
// Set the current position for the new object
$this->setPosition($this->getNextPosition());
$this->dispatchEvent(TheliaEvents::BEFORE_CREATEATTRIBUTE_AV, new AttributeAvEvent($this));
return true;
}
@@ -46,7 +39,7 @@ class AttributeAv extends BaseAttributeAv {
*/
public function postInsert(ConnectionInterface $con = null)
{
$this->dispatchEvent(TheliaEvents::AFTER_CREATEATTRIBUTE_VALUE, new AttributeValueEvent($this));
$this->dispatchEvent(TheliaEvents::AFTER_CREATEATTRIBUTE_AV, new AttributeAvEvent($this));
}
/**
@@ -54,7 +47,7 @@ class AttributeAv extends BaseAttributeAv {
*/
public function preUpdate(ConnectionInterface $con = null)
{
$this->dispatchEvent(TheliaEvents::BEFORE_UPDATEATTRIBUTE_VALUE, new AttributeValueEvent($this));
$this->dispatchEvent(TheliaEvents::BEFORE_UPDATEATTRIBUTE_AV, new AttributeAvEvent($this));
return true;
}
@@ -64,7 +57,7 @@ class AttributeAv extends BaseAttributeAv {
*/
public function postUpdate(ConnectionInterface $con = null)
{
$this->dispatchEvent(TheliaEvents::AFTER_UPDATEATTRIBUTE_VALUE, new AttributeValueEvent($this));
$this->dispatchEvent(TheliaEvents::AFTER_UPDATEATTRIBUTE_AV, new AttributeAvEvent($this));
}
/**
@@ -72,7 +65,7 @@ class AttributeAv extends BaseAttributeAv {
*/
public function preDelete(ConnectionInterface $con = null)
{
$this->dispatchEvent(TheliaEvents::BEFORE_DELETEATTRIBUTE_VALUE, new AttributeValueEvent($this));
$this->dispatchEvent(TheliaEvents::BEFORE_DELETEATTRIBUTE_AV, new AttributeAvEvent($this));
return true;
}
@@ -82,6 +75,6 @@ class AttributeAv extends BaseAttributeAv {
*/
public function postDelete(ConnectionInterface $con = null)
{
$this->dispatchEvent(TheliaEvents::AFTER_DELETEATTRIBUTE_VALUE, new AttributeValueEvent($this));
$this->dispatchEvent(TheliaEvents::AFTER_DELETEATTRIBUTE_AV, new AttributeAvEvent($this));
}
}

View File

@@ -45,29 +45,34 @@ trait PositionManagementTrait {
return $class->getConstant('DATABASE_NAME');
}
/**
* Implementors may add some search criteria (e.g., parent id) to the queries
* used to change/get position by overloading this method.
*/
protected function addCriteriaToPositionQuery($query) {
// Add required criteria here...
}
/**
* Get the position of the next inserted object
*/
public function getNextPosition($parent = null) {
public function getNextPosition() {
$query = $this->createQuery()
->orderByPosition(Criteria::DESC)
->limit(1);
if ($parent !== null) $query->filterByParent($parent);
$this->addCriteriaToPositionQuery($query);
$last = $query->findOne()
;
$last = $query->findOne();
return $last != null ? $last->getPosition() + 1 : 1;
return $last != null ? $last->getPosition() + 1 : 1;
}
/**
* Move up a object
*/
public function movePositionUp() {
echo "move up !";
$this->movePositionUpOrDown(true);
}
@@ -91,7 +96,7 @@ trait PositionManagementTrait {
// Find object to exchange position with
$search = $this->createQuery();
if (method_exists($this, 'getParent')) $search->filterByParent($this->getParent());
$this->addCriteriaToPositionQuery($search);
// Up or down ?
if ($up === true) {
@@ -152,7 +157,7 @@ trait PositionManagementTrait {
// Find categories to offset
$search = $this->createQuery();
if (method_exists($this, 'getParent')) $search->filterByParent($this->getParent());
$this->addCriteriaToPositionQuery($search);
if ($newPosition > $current_position) {
// The new position is after the current position -> we will offset + 1 all categories located between us and the new position

View File

@@ -61,7 +61,7 @@
{intl l='Attribute values'}
{loop type="auth" name="can_create" roles="ADMIN" permissions="admin.configuration.attribute-values.create"}
{loop type="auth" name="can_create" roles="ADMIN" permissions="admin.configuration.attribute-av.create"}
<span class="pull-right">
<a data-toggle="modal" href="#creation_dialog" title="Add a new attribute value" class="btn btn-default btn-primary">
<span class="glyphicon glyphicon-plus-sign"></span>
@@ -125,8 +125,8 @@
<td class="text-center">
{admin_position_block
permission="admin.attributes.edit"
path="/admin/configuration/attributes/update-value-position"
url_parameter="attribute_id"
path={url path='/admin/configuration/attributes-av/update-position' attribute_id=$attribute_id}
url_parameter="attributeav_id"
in_place_edit_class="positionChange"
position="$POSITION"
id="$ID"
@@ -137,7 +137,11 @@
<td class="actions">
<div class="btn-group">
<a class="btn btn-default btn-xs value-delete" title="{intl l='Delete this value'}" href="#delete_dialog" data-id="{$ID}" data-toggle="modal"><span class="glyphicon glyphicon-trash"></span></a>
{loop type="auth" name="can_create" roles="ADMIN" permissions="admin.configuration.attribute-av.delete"}
<a class="btn btn-default btn-xs value-delete" title="{intl l='Delete this value'}" href="#delete_dialog" data-id="{$ID}" data-toggle="modal">
<span class="glyphicon glyphicon-trash"></span>
</a>
{/loop}
</div>
</td>
</tr>
@@ -181,7 +185,7 @@
{* Adding a new attribute *}
{form name="thelia.admin.attribute-value.creation"}
{form name="thelia.admin.attributeav.creation"}
{* Capture the dialog body, to pass it to the generic dialog *}
@@ -232,7 +236,7 @@
dialog_ok_label = {intl l="Create this value"}
form_action = {url path='/admin/configuration/attributes-av'}
form_action = {url path='/admin/configuration/attributes-av/create'}
form_enctype = {form_enctype form=$form}
form_error_message = $form_error_message
}
@@ -241,7 +245,8 @@
{* Delete value confirmation dialog *}
{capture "delete_dialog"}
<input type="hidden" name="attribute_value_id" id="value_delete_id" value="" />
<input type="hidden" name="attribute_id" value="{$attribute_id}" />
<input type="hidden" name="attributeav_id" id="value_delete_id" value="" />
{/capture}
{include
@@ -275,7 +280,7 @@
{include
file = "includes/generic-js-dialog.html"
dialog_id = "creation_dialog"
form_name = "thelia.admin.attribute-value.creation"
form_name = "thelia.admin.attributeav.creation"
}
{* Inline editing of object position using bootstrap-editable *}
@@ -288,7 +293,7 @@
placement : 'left',
success : function(response, newValue) {
// The URL template
var url = "{url path='/admin/configuration/attributes/update-value-position' attribute_value_id='__ID__' position='__POS__'}";
var url = "{url path='/admin/configuration/attributes-av/update-position' attributeav_id='__ID__' position='__POS__' attribute_id=$attribute_id}";
// Perform subtitutions
url = url.replace('__ID__', $(this).data('id')).replace('__POS__', newValue);