AttributesAv management

This commit is contained in:
franck
2013-09-12 15:43:37 +02:00
parent 83f4e8b356
commit 8ad0dc7b21
8 changed files with 228 additions and 44 deletions

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));
}
}