Merge branch 'master' of https://github.com/thelia/thelia into coupon
# By Manuel Raynaud (18) and others # Via franck (9) and others * 'master' of https://github.com/thelia/thelia: (39 commits) Working : Working : Working : Working : Fixed minor visual glitches Working : Resize countries flag + Add bootstrap-switch fix test suite clear asset cache in cache:cler command Added a 'development mode' to assetic smarty plugin rewriting router use good Request object Added Tools\URL test case, and a test case superclass for initializing Tools\URL remove unused UrlWritin controller create router for rewriting matching customer substitutions fix typo in front id Working : For attributes on labels Working : For attributes on labels add label_attr attribute to form smarty plugin start refactorin rewriting routing ... Conflicts: core/lib/Thelia/Config/Resources/routing/front.xml templates/admin/default/assets/less/thelia/bootstrap-editable.less templates/admin/default/categories.html
This commit is contained in:
@@ -2,21 +2,73 @@
|
||||
|
||||
namespace Thelia\Model;
|
||||
|
||||
use Propel\Runtime\Connection\ConnectionInterface;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Thelia\Core\Event\AddressEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Model\Base\Address as BaseAddress;
|
||||
|
||||
class Address extends BaseAddress {
|
||||
use \Thelia\Model\Tools\ModelEventDispatcherTrait;
|
||||
|
||||
protected $dispatcher;
|
||||
|
||||
public function setDispatcher(EventDispatcherInterface $dispatcher)
|
||||
/**
|
||||
* Code to be run before inserting to database
|
||||
* @param ConnectionInterface $con
|
||||
* @return boolean
|
||||
*/
|
||||
public function preInsert(ConnectionInterface $con = null)
|
||||
{
|
||||
$this->dispatcher = $dispatcher;
|
||||
$this->dispatchEvent(TheliaEvents::BEFORE_CREATEADDRESS, new AddressEvent($this));
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getDispatcher()
|
||||
/**
|
||||
* Code to be run after inserting to database
|
||||
* @param ConnectionInterface $con
|
||||
*/
|
||||
public function postInsert(ConnectionInterface $con = null)
|
||||
{
|
||||
return $this->dispatcher;
|
||||
$this->dispatchEvent(TheliaEvents::AFTER_CREATEADDRESS, new AddressEvent($this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Code to be run before updating the object in database
|
||||
* @param ConnectionInterface $con
|
||||
* @return boolean
|
||||
*/
|
||||
public function preUpdate(ConnectionInterface $con = null)
|
||||
{
|
||||
$this->dispatchEvent(TheliaEvents::BEFORE_UPDATEADDRESS, new AddressEvent($this));
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Code to be run after updating the object in database
|
||||
* @param ConnectionInterface $con
|
||||
*/
|
||||
public function postUpdate(ConnectionInterface $con = null)
|
||||
{
|
||||
$this->dispatchEvent(TheliaEvents::AFTER_UPDATEADDRESS, new AddressEvent($this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Code to be run before deleting the object in database
|
||||
* @param ConnectionInterface $con
|
||||
* @return boolean
|
||||
*/
|
||||
public function preDelete(ConnectionInterface $con = null)
|
||||
{
|
||||
$this->dispatchEvent(TheliaEvents::BEFORE_DELETEADDRESS, new AddressEvent($this));
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Code to be run after deleting the object in database
|
||||
* @param ConnectionInterface $con
|
||||
*/
|
||||
public function postDelete(ConnectionInterface $con = null)
|
||||
{
|
||||
$this->dispatchEvent(TheliaEvents::AFTER_DELETEADDRESS, new AddressEvent($this));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -85,10 +85,40 @@ abstract class Lang implements ActiveRecordInterface
|
||||
protected $url;
|
||||
|
||||
/**
|
||||
* The value for the position field.
|
||||
* @var int
|
||||
* The value for the date_format field.
|
||||
* @var string
|
||||
*/
|
||||
protected $position;
|
||||
protected $date_format;
|
||||
|
||||
/**
|
||||
* The value for the time_format field.
|
||||
* @var string
|
||||
*/
|
||||
protected $time_format;
|
||||
|
||||
/**
|
||||
* The value for the datetime_format field.
|
||||
* @var string
|
||||
*/
|
||||
protected $datetime_format;
|
||||
|
||||
/**
|
||||
* The value for the decimal_separator field.
|
||||
* @var string
|
||||
*/
|
||||
protected $decimal_separator;
|
||||
|
||||
/**
|
||||
* The value for the thousands_separator field.
|
||||
* @var string
|
||||
*/
|
||||
protected $thousands_separator;
|
||||
|
||||
/**
|
||||
* The value for the decimals field.
|
||||
* @var string
|
||||
*/
|
||||
protected $decimals;
|
||||
|
||||
/**
|
||||
* The value for the by_default field.
|
||||
@@ -96,6 +126,12 @@ abstract class Lang implements ActiveRecordInterface
|
||||
*/
|
||||
protected $by_default;
|
||||
|
||||
/**
|
||||
* The value for the position field.
|
||||
* @var int
|
||||
*/
|
||||
protected $position;
|
||||
|
||||
/**
|
||||
* The value for the created_at field.
|
||||
* @var string
|
||||
@@ -426,14 +462,69 @@ abstract class Lang implements ActiveRecordInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the [position] column value.
|
||||
* Get the [date_format] column value.
|
||||
*
|
||||
* @return int
|
||||
* @return string
|
||||
*/
|
||||
public function getPosition()
|
||||
public function getDateFormat()
|
||||
{
|
||||
|
||||
return $this->position;
|
||||
return $this->date_format;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the [time_format] column value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTimeFormat()
|
||||
{
|
||||
|
||||
return $this->time_format;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the [datetime_format] column value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDatetimeFormat()
|
||||
{
|
||||
|
||||
return $this->datetime_format;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the [decimal_separator] column value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDecimalSeparator()
|
||||
{
|
||||
|
||||
return $this->decimal_separator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the [thousands_separator] column value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getThousandsSeparator()
|
||||
{
|
||||
|
||||
return $this->thousands_separator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the [decimals] column value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDecimals()
|
||||
{
|
||||
|
||||
return $this->decimals;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -447,6 +538,17 @@ abstract class Lang implements ActiveRecordInterface
|
||||
return $this->by_default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the [position] column value.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getPosition()
|
||||
{
|
||||
|
||||
return $this->position;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the [optionally formatted] temporal [created_at] column value.
|
||||
*
|
||||
@@ -593,25 +695,130 @@ abstract class Lang implements ActiveRecordInterface
|
||||
} // setUrl()
|
||||
|
||||
/**
|
||||
* Set the value of [position] column.
|
||||
* Set the value of [date_format] column.
|
||||
*
|
||||
* @param int $v new value
|
||||
* @param string $v new value
|
||||
* @return \Thelia\Model\Lang The current object (for fluent API support)
|
||||
*/
|
||||
public function setPosition($v)
|
||||
public function setDateFormat($v)
|
||||
{
|
||||
if ($v !== null) {
|
||||
$v = (int) $v;
|
||||
$v = (string) $v;
|
||||
}
|
||||
|
||||
if ($this->position !== $v) {
|
||||
$this->position = $v;
|
||||
$this->modifiedColumns[] = LangTableMap::POSITION;
|
||||
if ($this->date_format !== $v) {
|
||||
$this->date_format = $v;
|
||||
$this->modifiedColumns[] = LangTableMap::DATE_FORMAT;
|
||||
}
|
||||
|
||||
|
||||
return $this;
|
||||
} // setPosition()
|
||||
} // setDateFormat()
|
||||
|
||||
/**
|
||||
* Set the value of [time_format] column.
|
||||
*
|
||||
* @param string $v new value
|
||||
* @return \Thelia\Model\Lang The current object (for fluent API support)
|
||||
*/
|
||||
public function setTimeFormat($v)
|
||||
{
|
||||
if ($v !== null) {
|
||||
$v = (string) $v;
|
||||
}
|
||||
|
||||
if ($this->time_format !== $v) {
|
||||
$this->time_format = $v;
|
||||
$this->modifiedColumns[] = LangTableMap::TIME_FORMAT;
|
||||
}
|
||||
|
||||
|
||||
return $this;
|
||||
} // setTimeFormat()
|
||||
|
||||
/**
|
||||
* Set the value of [datetime_format] column.
|
||||
*
|
||||
* @param string $v new value
|
||||
* @return \Thelia\Model\Lang The current object (for fluent API support)
|
||||
*/
|
||||
public function setDatetimeFormat($v)
|
||||
{
|
||||
if ($v !== null) {
|
||||
$v = (string) $v;
|
||||
}
|
||||
|
||||
if ($this->datetime_format !== $v) {
|
||||
$this->datetime_format = $v;
|
||||
$this->modifiedColumns[] = LangTableMap::DATETIME_FORMAT;
|
||||
}
|
||||
|
||||
|
||||
return $this;
|
||||
} // setDatetimeFormat()
|
||||
|
||||
/**
|
||||
* Set the value of [decimal_separator] column.
|
||||
*
|
||||
* @param string $v new value
|
||||
* @return \Thelia\Model\Lang The current object (for fluent API support)
|
||||
*/
|
||||
public function setDecimalSeparator($v)
|
||||
{
|
||||
if ($v !== null) {
|
||||
$v = (string) $v;
|
||||
}
|
||||
|
||||
if ($this->decimal_separator !== $v) {
|
||||
$this->decimal_separator = $v;
|
||||
$this->modifiedColumns[] = LangTableMap::DECIMAL_SEPARATOR;
|
||||
}
|
||||
|
||||
|
||||
return $this;
|
||||
} // setDecimalSeparator()
|
||||
|
||||
/**
|
||||
* Set the value of [thousands_separator] column.
|
||||
*
|
||||
* @param string $v new value
|
||||
* @return \Thelia\Model\Lang The current object (for fluent API support)
|
||||
*/
|
||||
public function setThousandsSeparator($v)
|
||||
{
|
||||
if ($v !== null) {
|
||||
$v = (string) $v;
|
||||
}
|
||||
|
||||
if ($this->thousands_separator !== $v) {
|
||||
$this->thousands_separator = $v;
|
||||
$this->modifiedColumns[] = LangTableMap::THOUSANDS_SEPARATOR;
|
||||
}
|
||||
|
||||
|
||||
return $this;
|
||||
} // setThousandsSeparator()
|
||||
|
||||
/**
|
||||
* Set the value of [decimals] column.
|
||||
*
|
||||
* @param string $v new value
|
||||
* @return \Thelia\Model\Lang The current object (for fluent API support)
|
||||
*/
|
||||
public function setDecimals($v)
|
||||
{
|
||||
if ($v !== null) {
|
||||
$v = (string) $v;
|
||||
}
|
||||
|
||||
if ($this->decimals !== $v) {
|
||||
$this->decimals = $v;
|
||||
$this->modifiedColumns[] = LangTableMap::DECIMALS;
|
||||
}
|
||||
|
||||
|
||||
return $this;
|
||||
} // setDecimals()
|
||||
|
||||
/**
|
||||
* Set the value of [by_default] column.
|
||||
@@ -634,6 +841,27 @@ abstract class Lang implements ActiveRecordInterface
|
||||
return $this;
|
||||
} // setByDefault()
|
||||
|
||||
/**
|
||||
* Set the value of [position] column.
|
||||
*
|
||||
* @param int $v new value
|
||||
* @return \Thelia\Model\Lang The current object (for fluent API support)
|
||||
*/
|
||||
public function setPosition($v)
|
||||
{
|
||||
if ($v !== null) {
|
||||
$v = (int) $v;
|
||||
}
|
||||
|
||||
if ($this->position !== $v) {
|
||||
$this->position = $v;
|
||||
$this->modifiedColumns[] = LangTableMap::POSITION;
|
||||
}
|
||||
|
||||
|
||||
return $this;
|
||||
} // setPosition()
|
||||
|
||||
/**
|
||||
* Sets the value of [created_at] column to a normalized version of the date/time value specified.
|
||||
*
|
||||
@@ -728,19 +956,37 @@ abstract class Lang implements ActiveRecordInterface
|
||||
$col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : LangTableMap::translateFieldName('Url', TableMap::TYPE_PHPNAME, $indexType)];
|
||||
$this->url = (null !== $col) ? (string) $col : null;
|
||||
|
||||
$col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : LangTableMap::translateFieldName('Position', TableMap::TYPE_PHPNAME, $indexType)];
|
||||
$this->position = (null !== $col) ? (int) $col : null;
|
||||
$col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : LangTableMap::translateFieldName('DateFormat', TableMap::TYPE_PHPNAME, $indexType)];
|
||||
$this->date_format = (null !== $col) ? (string) $col : null;
|
||||
|
||||
$col = $row[TableMap::TYPE_NUM == $indexType ? 6 + $startcol : LangTableMap::translateFieldName('ByDefault', TableMap::TYPE_PHPNAME, $indexType)];
|
||||
$col = $row[TableMap::TYPE_NUM == $indexType ? 6 + $startcol : LangTableMap::translateFieldName('TimeFormat', TableMap::TYPE_PHPNAME, $indexType)];
|
||||
$this->time_format = (null !== $col) ? (string) $col : null;
|
||||
|
||||
$col = $row[TableMap::TYPE_NUM == $indexType ? 7 + $startcol : LangTableMap::translateFieldName('DatetimeFormat', TableMap::TYPE_PHPNAME, $indexType)];
|
||||
$this->datetime_format = (null !== $col) ? (string) $col : null;
|
||||
|
||||
$col = $row[TableMap::TYPE_NUM == $indexType ? 8 + $startcol : LangTableMap::translateFieldName('DecimalSeparator', TableMap::TYPE_PHPNAME, $indexType)];
|
||||
$this->decimal_separator = (null !== $col) ? (string) $col : null;
|
||||
|
||||
$col = $row[TableMap::TYPE_NUM == $indexType ? 9 + $startcol : LangTableMap::translateFieldName('ThousandsSeparator', TableMap::TYPE_PHPNAME, $indexType)];
|
||||
$this->thousands_separator = (null !== $col) ? (string) $col : null;
|
||||
|
||||
$col = $row[TableMap::TYPE_NUM == $indexType ? 10 + $startcol : LangTableMap::translateFieldName('Decimals', TableMap::TYPE_PHPNAME, $indexType)];
|
||||
$this->decimals = (null !== $col) ? (string) $col : null;
|
||||
|
||||
$col = $row[TableMap::TYPE_NUM == $indexType ? 11 + $startcol : LangTableMap::translateFieldName('ByDefault', TableMap::TYPE_PHPNAME, $indexType)];
|
||||
$this->by_default = (null !== $col) ? (int) $col : null;
|
||||
|
||||
$col = $row[TableMap::TYPE_NUM == $indexType ? 7 + $startcol : LangTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)];
|
||||
$col = $row[TableMap::TYPE_NUM == $indexType ? 12 + $startcol : LangTableMap::translateFieldName('Position', TableMap::TYPE_PHPNAME, $indexType)];
|
||||
$this->position = (null !== $col) ? (int) $col : null;
|
||||
|
||||
$col = $row[TableMap::TYPE_NUM == $indexType ? 13 + $startcol : LangTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)];
|
||||
if ($col === '0000-00-00 00:00:00') {
|
||||
$col = null;
|
||||
}
|
||||
$this->created_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null;
|
||||
|
||||
$col = $row[TableMap::TYPE_NUM == $indexType ? 8 + $startcol : LangTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)];
|
||||
$col = $row[TableMap::TYPE_NUM == $indexType ? 14 + $startcol : LangTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)];
|
||||
if ($col === '0000-00-00 00:00:00') {
|
||||
$col = null;
|
||||
}
|
||||
@@ -753,7 +999,7 @@ abstract class Lang implements ActiveRecordInterface
|
||||
$this->ensureConsistency();
|
||||
}
|
||||
|
||||
return $startcol + 9; // 9 = LangTableMap::NUM_HYDRATE_COLUMNS.
|
||||
return $startcol + 15; // 15 = LangTableMap::NUM_HYDRATE_COLUMNS.
|
||||
|
||||
} catch (Exception $e) {
|
||||
throw new PropelException("Error populating \Thelia\Model\Lang object", 0, $e);
|
||||
@@ -988,12 +1234,30 @@ abstract class Lang implements ActiveRecordInterface
|
||||
if ($this->isColumnModified(LangTableMap::URL)) {
|
||||
$modifiedColumns[':p' . $index++] = 'URL';
|
||||
}
|
||||
if ($this->isColumnModified(LangTableMap::POSITION)) {
|
||||
$modifiedColumns[':p' . $index++] = 'POSITION';
|
||||
if ($this->isColumnModified(LangTableMap::DATE_FORMAT)) {
|
||||
$modifiedColumns[':p' . $index++] = 'DATE_FORMAT';
|
||||
}
|
||||
if ($this->isColumnModified(LangTableMap::TIME_FORMAT)) {
|
||||
$modifiedColumns[':p' . $index++] = 'TIME_FORMAT';
|
||||
}
|
||||
if ($this->isColumnModified(LangTableMap::DATETIME_FORMAT)) {
|
||||
$modifiedColumns[':p' . $index++] = 'DATETIME_FORMAT';
|
||||
}
|
||||
if ($this->isColumnModified(LangTableMap::DECIMAL_SEPARATOR)) {
|
||||
$modifiedColumns[':p' . $index++] = 'DECIMAL_SEPARATOR';
|
||||
}
|
||||
if ($this->isColumnModified(LangTableMap::THOUSANDS_SEPARATOR)) {
|
||||
$modifiedColumns[':p' . $index++] = 'THOUSANDS_SEPARATOR';
|
||||
}
|
||||
if ($this->isColumnModified(LangTableMap::DECIMALS)) {
|
||||
$modifiedColumns[':p' . $index++] = 'DECIMALS';
|
||||
}
|
||||
if ($this->isColumnModified(LangTableMap::BY_DEFAULT)) {
|
||||
$modifiedColumns[':p' . $index++] = 'BY_DEFAULT';
|
||||
}
|
||||
if ($this->isColumnModified(LangTableMap::POSITION)) {
|
||||
$modifiedColumns[':p' . $index++] = 'POSITION';
|
||||
}
|
||||
if ($this->isColumnModified(LangTableMap::CREATED_AT)) {
|
||||
$modifiedColumns[':p' . $index++] = 'CREATED_AT';
|
||||
}
|
||||
@@ -1026,12 +1290,30 @@ abstract class Lang implements ActiveRecordInterface
|
||||
case 'URL':
|
||||
$stmt->bindValue($identifier, $this->url, PDO::PARAM_STR);
|
||||
break;
|
||||
case 'POSITION':
|
||||
$stmt->bindValue($identifier, $this->position, PDO::PARAM_INT);
|
||||
case 'DATE_FORMAT':
|
||||
$stmt->bindValue($identifier, $this->date_format, PDO::PARAM_STR);
|
||||
break;
|
||||
case 'TIME_FORMAT':
|
||||
$stmt->bindValue($identifier, $this->time_format, PDO::PARAM_STR);
|
||||
break;
|
||||
case 'DATETIME_FORMAT':
|
||||
$stmt->bindValue($identifier, $this->datetime_format, PDO::PARAM_STR);
|
||||
break;
|
||||
case 'DECIMAL_SEPARATOR':
|
||||
$stmt->bindValue($identifier, $this->decimal_separator, PDO::PARAM_STR);
|
||||
break;
|
||||
case 'THOUSANDS_SEPARATOR':
|
||||
$stmt->bindValue($identifier, $this->thousands_separator, PDO::PARAM_STR);
|
||||
break;
|
||||
case 'DECIMALS':
|
||||
$stmt->bindValue($identifier, $this->decimals, PDO::PARAM_STR);
|
||||
break;
|
||||
case 'BY_DEFAULT':
|
||||
$stmt->bindValue($identifier, $this->by_default, PDO::PARAM_INT);
|
||||
break;
|
||||
case 'POSITION':
|
||||
$stmt->bindValue($identifier, $this->position, PDO::PARAM_INT);
|
||||
break;
|
||||
case 'CREATED_AT':
|
||||
$stmt->bindValue($identifier, $this->created_at ? $this->created_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR);
|
||||
break;
|
||||
@@ -1116,15 +1398,33 @@ abstract class Lang implements ActiveRecordInterface
|
||||
return $this->getUrl();
|
||||
break;
|
||||
case 5:
|
||||
return $this->getPosition();
|
||||
return $this->getDateFormat();
|
||||
break;
|
||||
case 6:
|
||||
return $this->getByDefault();
|
||||
return $this->getTimeFormat();
|
||||
break;
|
||||
case 7:
|
||||
return $this->getCreatedAt();
|
||||
return $this->getDatetimeFormat();
|
||||
break;
|
||||
case 8:
|
||||
return $this->getDecimalSeparator();
|
||||
break;
|
||||
case 9:
|
||||
return $this->getThousandsSeparator();
|
||||
break;
|
||||
case 10:
|
||||
return $this->getDecimals();
|
||||
break;
|
||||
case 11:
|
||||
return $this->getByDefault();
|
||||
break;
|
||||
case 12:
|
||||
return $this->getPosition();
|
||||
break;
|
||||
case 13:
|
||||
return $this->getCreatedAt();
|
||||
break;
|
||||
case 14:
|
||||
return $this->getUpdatedAt();
|
||||
break;
|
||||
default:
|
||||
@@ -1160,10 +1460,16 @@ abstract class Lang implements ActiveRecordInterface
|
||||
$keys[2] => $this->getCode(),
|
||||
$keys[3] => $this->getLocale(),
|
||||
$keys[4] => $this->getUrl(),
|
||||
$keys[5] => $this->getPosition(),
|
||||
$keys[6] => $this->getByDefault(),
|
||||
$keys[7] => $this->getCreatedAt(),
|
||||
$keys[8] => $this->getUpdatedAt(),
|
||||
$keys[5] => $this->getDateFormat(),
|
||||
$keys[6] => $this->getTimeFormat(),
|
||||
$keys[7] => $this->getDatetimeFormat(),
|
||||
$keys[8] => $this->getDecimalSeparator(),
|
||||
$keys[9] => $this->getThousandsSeparator(),
|
||||
$keys[10] => $this->getDecimals(),
|
||||
$keys[11] => $this->getByDefault(),
|
||||
$keys[12] => $this->getPosition(),
|
||||
$keys[13] => $this->getCreatedAt(),
|
||||
$keys[14] => $this->getUpdatedAt(),
|
||||
);
|
||||
$virtualColumns = $this->virtualColumns;
|
||||
foreach($virtualColumns as $key => $virtualColumn)
|
||||
@@ -1220,15 +1526,33 @@ abstract class Lang implements ActiveRecordInterface
|
||||
$this->setUrl($value);
|
||||
break;
|
||||
case 5:
|
||||
$this->setPosition($value);
|
||||
$this->setDateFormat($value);
|
||||
break;
|
||||
case 6:
|
||||
$this->setByDefault($value);
|
||||
$this->setTimeFormat($value);
|
||||
break;
|
||||
case 7:
|
||||
$this->setCreatedAt($value);
|
||||
$this->setDatetimeFormat($value);
|
||||
break;
|
||||
case 8:
|
||||
$this->setDecimalSeparator($value);
|
||||
break;
|
||||
case 9:
|
||||
$this->setThousandsSeparator($value);
|
||||
break;
|
||||
case 10:
|
||||
$this->setDecimals($value);
|
||||
break;
|
||||
case 11:
|
||||
$this->setByDefault($value);
|
||||
break;
|
||||
case 12:
|
||||
$this->setPosition($value);
|
||||
break;
|
||||
case 13:
|
||||
$this->setCreatedAt($value);
|
||||
break;
|
||||
case 14:
|
||||
$this->setUpdatedAt($value);
|
||||
break;
|
||||
} // switch()
|
||||
@@ -1260,10 +1584,16 @@ abstract class Lang implements ActiveRecordInterface
|
||||
if (array_key_exists($keys[2], $arr)) $this->setCode($arr[$keys[2]]);
|
||||
if (array_key_exists($keys[3], $arr)) $this->setLocale($arr[$keys[3]]);
|
||||
if (array_key_exists($keys[4], $arr)) $this->setUrl($arr[$keys[4]]);
|
||||
if (array_key_exists($keys[5], $arr)) $this->setPosition($arr[$keys[5]]);
|
||||
if (array_key_exists($keys[6], $arr)) $this->setByDefault($arr[$keys[6]]);
|
||||
if (array_key_exists($keys[7], $arr)) $this->setCreatedAt($arr[$keys[7]]);
|
||||
if (array_key_exists($keys[8], $arr)) $this->setUpdatedAt($arr[$keys[8]]);
|
||||
if (array_key_exists($keys[5], $arr)) $this->setDateFormat($arr[$keys[5]]);
|
||||
if (array_key_exists($keys[6], $arr)) $this->setTimeFormat($arr[$keys[6]]);
|
||||
if (array_key_exists($keys[7], $arr)) $this->setDatetimeFormat($arr[$keys[7]]);
|
||||
if (array_key_exists($keys[8], $arr)) $this->setDecimalSeparator($arr[$keys[8]]);
|
||||
if (array_key_exists($keys[9], $arr)) $this->setThousandsSeparator($arr[$keys[9]]);
|
||||
if (array_key_exists($keys[10], $arr)) $this->setDecimals($arr[$keys[10]]);
|
||||
if (array_key_exists($keys[11], $arr)) $this->setByDefault($arr[$keys[11]]);
|
||||
if (array_key_exists($keys[12], $arr)) $this->setPosition($arr[$keys[12]]);
|
||||
if (array_key_exists($keys[13], $arr)) $this->setCreatedAt($arr[$keys[13]]);
|
||||
if (array_key_exists($keys[14], $arr)) $this->setUpdatedAt($arr[$keys[14]]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1280,8 +1610,14 @@ abstract class Lang implements ActiveRecordInterface
|
||||
if ($this->isColumnModified(LangTableMap::CODE)) $criteria->add(LangTableMap::CODE, $this->code);
|
||||
if ($this->isColumnModified(LangTableMap::LOCALE)) $criteria->add(LangTableMap::LOCALE, $this->locale);
|
||||
if ($this->isColumnModified(LangTableMap::URL)) $criteria->add(LangTableMap::URL, $this->url);
|
||||
if ($this->isColumnModified(LangTableMap::POSITION)) $criteria->add(LangTableMap::POSITION, $this->position);
|
||||
if ($this->isColumnModified(LangTableMap::DATE_FORMAT)) $criteria->add(LangTableMap::DATE_FORMAT, $this->date_format);
|
||||
if ($this->isColumnModified(LangTableMap::TIME_FORMAT)) $criteria->add(LangTableMap::TIME_FORMAT, $this->time_format);
|
||||
if ($this->isColumnModified(LangTableMap::DATETIME_FORMAT)) $criteria->add(LangTableMap::DATETIME_FORMAT, $this->datetime_format);
|
||||
if ($this->isColumnModified(LangTableMap::DECIMAL_SEPARATOR)) $criteria->add(LangTableMap::DECIMAL_SEPARATOR, $this->decimal_separator);
|
||||
if ($this->isColumnModified(LangTableMap::THOUSANDS_SEPARATOR)) $criteria->add(LangTableMap::THOUSANDS_SEPARATOR, $this->thousands_separator);
|
||||
if ($this->isColumnModified(LangTableMap::DECIMALS)) $criteria->add(LangTableMap::DECIMALS, $this->decimals);
|
||||
if ($this->isColumnModified(LangTableMap::BY_DEFAULT)) $criteria->add(LangTableMap::BY_DEFAULT, $this->by_default);
|
||||
if ($this->isColumnModified(LangTableMap::POSITION)) $criteria->add(LangTableMap::POSITION, $this->position);
|
||||
if ($this->isColumnModified(LangTableMap::CREATED_AT)) $criteria->add(LangTableMap::CREATED_AT, $this->created_at);
|
||||
if ($this->isColumnModified(LangTableMap::UPDATED_AT)) $criteria->add(LangTableMap::UPDATED_AT, $this->updated_at);
|
||||
|
||||
@@ -1351,8 +1687,14 @@ abstract class Lang implements ActiveRecordInterface
|
||||
$copyObj->setCode($this->getCode());
|
||||
$copyObj->setLocale($this->getLocale());
|
||||
$copyObj->setUrl($this->getUrl());
|
||||
$copyObj->setPosition($this->getPosition());
|
||||
$copyObj->setDateFormat($this->getDateFormat());
|
||||
$copyObj->setTimeFormat($this->getTimeFormat());
|
||||
$copyObj->setDatetimeFormat($this->getDatetimeFormat());
|
||||
$copyObj->setDecimalSeparator($this->getDecimalSeparator());
|
||||
$copyObj->setThousandsSeparator($this->getThousandsSeparator());
|
||||
$copyObj->setDecimals($this->getDecimals());
|
||||
$copyObj->setByDefault($this->getByDefault());
|
||||
$copyObj->setPosition($this->getPosition());
|
||||
$copyObj->setCreatedAt($this->getCreatedAt());
|
||||
$copyObj->setUpdatedAt($this->getUpdatedAt());
|
||||
if ($makeNew) {
|
||||
@@ -1393,8 +1735,14 @@ abstract class Lang implements ActiveRecordInterface
|
||||
$this->code = null;
|
||||
$this->locale = null;
|
||||
$this->url = null;
|
||||
$this->position = null;
|
||||
$this->date_format = null;
|
||||
$this->time_format = null;
|
||||
$this->datetime_format = null;
|
||||
$this->decimal_separator = null;
|
||||
$this->thousands_separator = null;
|
||||
$this->decimals = null;
|
||||
$this->by_default = null;
|
||||
$this->position = null;
|
||||
$this->created_at = null;
|
||||
$this->updated_at = null;
|
||||
$this->alreadyInSave = false;
|
||||
|
||||
@@ -23,8 +23,14 @@ use Thelia\Model\Map\LangTableMap;
|
||||
* @method ChildLangQuery orderByCode($order = Criteria::ASC) Order by the code column
|
||||
* @method ChildLangQuery orderByLocale($order = Criteria::ASC) Order by the locale column
|
||||
* @method ChildLangQuery orderByUrl($order = Criteria::ASC) Order by the url column
|
||||
* @method ChildLangQuery orderByPosition($order = Criteria::ASC) Order by the position column
|
||||
* @method ChildLangQuery orderByDateFormat($order = Criteria::ASC) Order by the date_format column
|
||||
* @method ChildLangQuery orderByTimeFormat($order = Criteria::ASC) Order by the time_format column
|
||||
* @method ChildLangQuery orderByDatetimeFormat($order = Criteria::ASC) Order by the datetime_format column
|
||||
* @method ChildLangQuery orderByDecimalSeparator($order = Criteria::ASC) Order by the decimal_separator column
|
||||
* @method ChildLangQuery orderByThousandsSeparator($order = Criteria::ASC) Order by the thousands_separator column
|
||||
* @method ChildLangQuery orderByDecimals($order = Criteria::ASC) Order by the decimals column
|
||||
* @method ChildLangQuery orderByByDefault($order = Criteria::ASC) Order by the by_default column
|
||||
* @method ChildLangQuery orderByPosition($order = Criteria::ASC) Order by the position column
|
||||
* @method ChildLangQuery orderByCreatedAt($order = Criteria::ASC) Order by the created_at column
|
||||
* @method ChildLangQuery orderByUpdatedAt($order = Criteria::ASC) Order by the updated_at column
|
||||
*
|
||||
@@ -33,8 +39,14 @@ use Thelia\Model\Map\LangTableMap;
|
||||
* @method ChildLangQuery groupByCode() Group by the code column
|
||||
* @method ChildLangQuery groupByLocale() Group by the locale column
|
||||
* @method ChildLangQuery groupByUrl() Group by the url column
|
||||
* @method ChildLangQuery groupByPosition() Group by the position column
|
||||
* @method ChildLangQuery groupByDateFormat() Group by the date_format column
|
||||
* @method ChildLangQuery groupByTimeFormat() Group by the time_format column
|
||||
* @method ChildLangQuery groupByDatetimeFormat() Group by the datetime_format column
|
||||
* @method ChildLangQuery groupByDecimalSeparator() Group by the decimal_separator column
|
||||
* @method ChildLangQuery groupByThousandsSeparator() Group by the thousands_separator column
|
||||
* @method ChildLangQuery groupByDecimals() Group by the decimals column
|
||||
* @method ChildLangQuery groupByByDefault() Group by the by_default column
|
||||
* @method ChildLangQuery groupByPosition() Group by the position column
|
||||
* @method ChildLangQuery groupByCreatedAt() Group by the created_at column
|
||||
* @method ChildLangQuery groupByUpdatedAt() Group by the updated_at column
|
||||
*
|
||||
@@ -50,8 +62,14 @@ use Thelia\Model\Map\LangTableMap;
|
||||
* @method ChildLang findOneByCode(string $code) Return the first ChildLang filtered by the code column
|
||||
* @method ChildLang findOneByLocale(string $locale) Return the first ChildLang filtered by the locale column
|
||||
* @method ChildLang findOneByUrl(string $url) Return the first ChildLang filtered by the url column
|
||||
* @method ChildLang findOneByPosition(int $position) Return the first ChildLang filtered by the position column
|
||||
* @method ChildLang findOneByDateFormat(string $date_format) Return the first ChildLang filtered by the date_format column
|
||||
* @method ChildLang findOneByTimeFormat(string $time_format) Return the first ChildLang filtered by the time_format column
|
||||
* @method ChildLang findOneByDatetimeFormat(string $datetime_format) Return the first ChildLang filtered by the datetime_format column
|
||||
* @method ChildLang findOneByDecimalSeparator(string $decimal_separator) Return the first ChildLang filtered by the decimal_separator column
|
||||
* @method ChildLang findOneByThousandsSeparator(string $thousands_separator) Return the first ChildLang filtered by the thousands_separator column
|
||||
* @method ChildLang findOneByDecimals(string $decimals) Return the first ChildLang filtered by the decimals column
|
||||
* @method ChildLang findOneByByDefault(int $by_default) Return the first ChildLang filtered by the by_default column
|
||||
* @method ChildLang findOneByPosition(int $position) Return the first ChildLang filtered by the position column
|
||||
* @method ChildLang findOneByCreatedAt(string $created_at) Return the first ChildLang filtered by the created_at column
|
||||
* @method ChildLang findOneByUpdatedAt(string $updated_at) Return the first ChildLang filtered by the updated_at column
|
||||
*
|
||||
@@ -60,8 +78,14 @@ use Thelia\Model\Map\LangTableMap;
|
||||
* @method array findByCode(string $code) Return ChildLang objects filtered by the code column
|
||||
* @method array findByLocale(string $locale) Return ChildLang objects filtered by the locale column
|
||||
* @method array findByUrl(string $url) Return ChildLang objects filtered by the url column
|
||||
* @method array findByPosition(int $position) Return ChildLang objects filtered by the position column
|
||||
* @method array findByDateFormat(string $date_format) Return ChildLang objects filtered by the date_format column
|
||||
* @method array findByTimeFormat(string $time_format) Return ChildLang objects filtered by the time_format column
|
||||
* @method array findByDatetimeFormat(string $datetime_format) Return ChildLang objects filtered by the datetime_format column
|
||||
* @method array findByDecimalSeparator(string $decimal_separator) Return ChildLang objects filtered by the decimal_separator column
|
||||
* @method array findByThousandsSeparator(string $thousands_separator) Return ChildLang objects filtered by the thousands_separator column
|
||||
* @method array findByDecimals(string $decimals) Return ChildLang objects filtered by the decimals column
|
||||
* @method array findByByDefault(int $by_default) Return ChildLang objects filtered by the by_default column
|
||||
* @method array findByPosition(int $position) Return ChildLang objects filtered by the position column
|
||||
* @method array findByCreatedAt(string $created_at) Return ChildLang objects filtered by the created_at column
|
||||
* @method array findByUpdatedAt(string $updated_at) Return ChildLang objects filtered by the updated_at column
|
||||
*
|
||||
@@ -152,7 +176,7 @@ abstract class LangQuery extends ModelCriteria
|
||||
*/
|
||||
protected function findPkSimple($key, $con)
|
||||
{
|
||||
$sql = 'SELECT ID, TITLE, CODE, LOCALE, URL, POSITION, BY_DEFAULT, CREATED_AT, UPDATED_AT FROM lang WHERE ID = :p0';
|
||||
$sql = 'SELECT ID, TITLE, CODE, LOCALE, URL, DATE_FORMAT, TIME_FORMAT, DATETIME_FORMAT, DECIMAL_SEPARATOR, THOUSANDS_SEPARATOR, DECIMALS, BY_DEFAULT, POSITION, CREATED_AT, UPDATED_AT FROM lang WHERE ID = :p0';
|
||||
try {
|
||||
$stmt = $con->prepare($sql);
|
||||
$stmt->bindValue(':p0', $key, PDO::PARAM_INT);
|
||||
@@ -399,44 +423,177 @@ abstract class LangQuery extends ModelCriteria
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the query on the position column
|
||||
* Filter the query on the date_format column
|
||||
*
|
||||
* Example usage:
|
||||
* <code>
|
||||
* $query->filterByPosition(1234); // WHERE position = 1234
|
||||
* $query->filterByPosition(array(12, 34)); // WHERE position IN (12, 34)
|
||||
* $query->filterByPosition(array('min' => 12)); // WHERE position > 12
|
||||
* $query->filterByDateFormat('fooValue'); // WHERE date_format = 'fooValue'
|
||||
* $query->filterByDateFormat('%fooValue%'); // WHERE date_format LIKE '%fooValue%'
|
||||
* </code>
|
||||
*
|
||||
* @param mixed $position The value to use as filter.
|
||||
* Use scalar values for equality.
|
||||
* Use array values for in_array() equivalent.
|
||||
* Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
|
||||
* @param string $dateFormat The value to use as filter.
|
||||
* Accepts wildcards (* and % trigger a LIKE)
|
||||
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
|
||||
*
|
||||
* @return ChildLangQuery The current query, for fluid interface
|
||||
*/
|
||||
public function filterByPosition($position = null, $comparison = null)
|
||||
public function filterByDateFormat($dateFormat = null, $comparison = null)
|
||||
{
|
||||
if (is_array($position)) {
|
||||
$useMinMax = false;
|
||||
if (isset($position['min'])) {
|
||||
$this->addUsingAlias(LangTableMap::POSITION, $position['min'], Criteria::GREATER_EQUAL);
|
||||
$useMinMax = true;
|
||||
}
|
||||
if (isset($position['max'])) {
|
||||
$this->addUsingAlias(LangTableMap::POSITION, $position['max'], Criteria::LESS_EQUAL);
|
||||
$useMinMax = true;
|
||||
}
|
||||
if ($useMinMax) {
|
||||
return $this;
|
||||
}
|
||||
if (null === $comparison) {
|
||||
if (null === $comparison) {
|
||||
if (is_array($dateFormat)) {
|
||||
$comparison = Criteria::IN;
|
||||
} elseif (preg_match('/[\%\*]/', $dateFormat)) {
|
||||
$dateFormat = str_replace('*', '%', $dateFormat);
|
||||
$comparison = Criteria::LIKE;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->addUsingAlias(LangTableMap::POSITION, $position, $comparison);
|
||||
return $this->addUsingAlias(LangTableMap::DATE_FORMAT, $dateFormat, $comparison);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the query on the time_format column
|
||||
*
|
||||
* Example usage:
|
||||
* <code>
|
||||
* $query->filterByTimeFormat('fooValue'); // WHERE time_format = 'fooValue'
|
||||
* $query->filterByTimeFormat('%fooValue%'); // WHERE time_format LIKE '%fooValue%'
|
||||
* </code>
|
||||
*
|
||||
* @param string $timeFormat The value to use as filter.
|
||||
* Accepts wildcards (* and % trigger a LIKE)
|
||||
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
|
||||
*
|
||||
* @return ChildLangQuery The current query, for fluid interface
|
||||
*/
|
||||
public function filterByTimeFormat($timeFormat = null, $comparison = null)
|
||||
{
|
||||
if (null === $comparison) {
|
||||
if (is_array($timeFormat)) {
|
||||
$comparison = Criteria::IN;
|
||||
} elseif (preg_match('/[\%\*]/', $timeFormat)) {
|
||||
$timeFormat = str_replace('*', '%', $timeFormat);
|
||||
$comparison = Criteria::LIKE;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->addUsingAlias(LangTableMap::TIME_FORMAT, $timeFormat, $comparison);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the query on the datetime_format column
|
||||
*
|
||||
* Example usage:
|
||||
* <code>
|
||||
* $query->filterByDatetimeFormat('fooValue'); // WHERE datetime_format = 'fooValue'
|
||||
* $query->filterByDatetimeFormat('%fooValue%'); // WHERE datetime_format LIKE '%fooValue%'
|
||||
* </code>
|
||||
*
|
||||
* @param string $datetimeFormat The value to use as filter.
|
||||
* Accepts wildcards (* and % trigger a LIKE)
|
||||
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
|
||||
*
|
||||
* @return ChildLangQuery The current query, for fluid interface
|
||||
*/
|
||||
public function filterByDatetimeFormat($datetimeFormat = null, $comparison = null)
|
||||
{
|
||||
if (null === $comparison) {
|
||||
if (is_array($datetimeFormat)) {
|
||||
$comparison = Criteria::IN;
|
||||
} elseif (preg_match('/[\%\*]/', $datetimeFormat)) {
|
||||
$datetimeFormat = str_replace('*', '%', $datetimeFormat);
|
||||
$comparison = Criteria::LIKE;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->addUsingAlias(LangTableMap::DATETIME_FORMAT, $datetimeFormat, $comparison);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the query on the decimal_separator column
|
||||
*
|
||||
* Example usage:
|
||||
* <code>
|
||||
* $query->filterByDecimalSeparator('fooValue'); // WHERE decimal_separator = 'fooValue'
|
||||
* $query->filterByDecimalSeparator('%fooValue%'); // WHERE decimal_separator LIKE '%fooValue%'
|
||||
* </code>
|
||||
*
|
||||
* @param string $decimalSeparator The value to use as filter.
|
||||
* Accepts wildcards (* and % trigger a LIKE)
|
||||
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
|
||||
*
|
||||
* @return ChildLangQuery The current query, for fluid interface
|
||||
*/
|
||||
public function filterByDecimalSeparator($decimalSeparator = null, $comparison = null)
|
||||
{
|
||||
if (null === $comparison) {
|
||||
if (is_array($decimalSeparator)) {
|
||||
$comparison = Criteria::IN;
|
||||
} elseif (preg_match('/[\%\*]/', $decimalSeparator)) {
|
||||
$decimalSeparator = str_replace('*', '%', $decimalSeparator);
|
||||
$comparison = Criteria::LIKE;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->addUsingAlias(LangTableMap::DECIMAL_SEPARATOR, $decimalSeparator, $comparison);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the query on the thousands_separator column
|
||||
*
|
||||
* Example usage:
|
||||
* <code>
|
||||
* $query->filterByThousandsSeparator('fooValue'); // WHERE thousands_separator = 'fooValue'
|
||||
* $query->filterByThousandsSeparator('%fooValue%'); // WHERE thousands_separator LIKE '%fooValue%'
|
||||
* </code>
|
||||
*
|
||||
* @param string $thousandsSeparator The value to use as filter.
|
||||
* Accepts wildcards (* and % trigger a LIKE)
|
||||
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
|
||||
*
|
||||
* @return ChildLangQuery The current query, for fluid interface
|
||||
*/
|
||||
public function filterByThousandsSeparator($thousandsSeparator = null, $comparison = null)
|
||||
{
|
||||
if (null === $comparison) {
|
||||
if (is_array($thousandsSeparator)) {
|
||||
$comparison = Criteria::IN;
|
||||
} elseif (preg_match('/[\%\*]/', $thousandsSeparator)) {
|
||||
$thousandsSeparator = str_replace('*', '%', $thousandsSeparator);
|
||||
$comparison = Criteria::LIKE;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->addUsingAlias(LangTableMap::THOUSANDS_SEPARATOR, $thousandsSeparator, $comparison);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the query on the decimals column
|
||||
*
|
||||
* Example usage:
|
||||
* <code>
|
||||
* $query->filterByDecimals('fooValue'); // WHERE decimals = 'fooValue'
|
||||
* $query->filterByDecimals('%fooValue%'); // WHERE decimals LIKE '%fooValue%'
|
||||
* </code>
|
||||
*
|
||||
* @param string $decimals The value to use as filter.
|
||||
* Accepts wildcards (* and % trigger a LIKE)
|
||||
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
|
||||
*
|
||||
* @return ChildLangQuery The current query, for fluid interface
|
||||
*/
|
||||
public function filterByDecimals($decimals = null, $comparison = null)
|
||||
{
|
||||
if (null === $comparison) {
|
||||
if (is_array($decimals)) {
|
||||
$comparison = Criteria::IN;
|
||||
} elseif (preg_match('/[\%\*]/', $decimals)) {
|
||||
$decimals = str_replace('*', '%', $decimals);
|
||||
$comparison = Criteria::LIKE;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->addUsingAlias(LangTableMap::DECIMALS, $decimals, $comparison);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -480,6 +637,47 @@ abstract class LangQuery extends ModelCriteria
|
||||
return $this->addUsingAlias(LangTableMap::BY_DEFAULT, $byDefault, $comparison);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the query on the position column
|
||||
*
|
||||
* Example usage:
|
||||
* <code>
|
||||
* $query->filterByPosition(1234); // WHERE position = 1234
|
||||
* $query->filterByPosition(array(12, 34)); // WHERE position IN (12, 34)
|
||||
* $query->filterByPosition(array('min' => 12)); // WHERE position > 12
|
||||
* </code>
|
||||
*
|
||||
* @param mixed $position The value to use as filter.
|
||||
* Use scalar values for equality.
|
||||
* Use array values for in_array() equivalent.
|
||||
* Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
|
||||
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
|
||||
*
|
||||
* @return ChildLangQuery The current query, for fluid interface
|
||||
*/
|
||||
public function filterByPosition($position = null, $comparison = null)
|
||||
{
|
||||
if (is_array($position)) {
|
||||
$useMinMax = false;
|
||||
if (isset($position['min'])) {
|
||||
$this->addUsingAlias(LangTableMap::POSITION, $position['min'], Criteria::GREATER_EQUAL);
|
||||
$useMinMax = true;
|
||||
}
|
||||
if (isset($position['max'])) {
|
||||
$this->addUsingAlias(LangTableMap::POSITION, $position['max'], Criteria::LESS_EQUAL);
|
||||
$useMinMax = true;
|
||||
}
|
||||
if ($useMinMax) {
|
||||
return $this;
|
||||
}
|
||||
if (null === $comparison) {
|
||||
$comparison = Criteria::IN;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->addUsingAlias(LangTableMap::POSITION, $position, $comparison);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the query on the created_at column
|
||||
*
|
||||
|
||||
@@ -13,6 +13,8 @@ class Category extends BaseCategory
|
||||
{
|
||||
use \Thelia\Model\Tools\ModelEventDispatcherTrait;
|
||||
|
||||
use \Thelia\Model\Tools\PositionManagementTrait;
|
||||
|
||||
/**
|
||||
* @return int number of child for the current category
|
||||
*/
|
||||
@@ -23,7 +25,7 @@ class Category extends BaseCategory
|
||||
|
||||
public function getUrl($locale)
|
||||
{
|
||||
return URL::init()->retrieve('category', $this->getId(), $locale)->toString();
|
||||
return URL::getInstance()->retrieve('category', $this->getId(), $locale)->toString();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,18 +48,6 @@ class Category extends BaseCategory
|
||||
$this->save();
|
||||
}
|
||||
|
||||
public function getNextPosition($parent) {
|
||||
|
||||
$last = CategoryQuery::create()
|
||||
->filterByParent($parent)
|
||||
->orderByPosition(Criteria::DESC)
|
||||
->limit(1)
|
||||
->findOne()
|
||||
;
|
||||
|
||||
return $last != null ? $last->getPosition() + 1 : 1;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* count all products for current category and sub categories
|
||||
|
||||
@@ -9,6 +9,6 @@ class Content extends BaseContent
|
||||
{
|
||||
public function getUrl($locale)
|
||||
{
|
||||
return URL::init()->retrieve('content', $this->getId(), $locale)->toString();
|
||||
return URL::getInstance()->retrieve('content', $this->getId(), $locale)->toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@ class Currency extends BaseCurrency {
|
||||
|
||||
use \Thelia\Model\Tools\ModelEventDispatcherTrait;
|
||||
|
||||
use \Thelia\Model\Tools\PositionManagementTrait;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@@ -18,6 +20,9 @@ class Currency extends BaseCurrency {
|
||||
{
|
||||
$this->dispatchEvent(TheliaEvents::BEFORE_CREATECURRENCY, new CurrencyEvent($this));
|
||||
|
||||
// Set the current position for the new object
|
||||
$this->setPosition($this->getNextPosition());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Thelia\Model;
|
||||
|
||||
use Symfony\Component\Config\Definition\Exception\Exception;
|
||||
use Propel\Runtime\Exception\PropelException;
|
||||
use Thelia\Model\AddressQuery;
|
||||
use Thelia\Model\Base\Customer as BaseCustomer;
|
||||
|
||||
@@ -115,7 +115,7 @@ class Customer extends BaseCustomer implements UserInterface
|
||||
|
||||
$con->commit();
|
||||
|
||||
} catch(Exception $e) {
|
||||
} catch(PropelException $e) {
|
||||
$con->rollback();
|
||||
throw $e;
|
||||
}
|
||||
@@ -225,7 +225,7 @@ class Customer extends BaseCustomer implements UserInterface
|
||||
*/
|
||||
public function preUpdate(ConnectionInterface $con = null)
|
||||
{
|
||||
$this->dispatchEvent(TheliaEvents::BEFORE_CHANGECUSTOMER, new CustomerEvent($this));
|
||||
$this->dispatchEvent(TheliaEvents::BEFORE_UPDATECUSTOMER, new CustomerEvent($this));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -234,7 +234,7 @@ class Customer extends BaseCustomer implements UserInterface
|
||||
*/
|
||||
public function postUpdate(ConnectionInterface $con = null)
|
||||
{
|
||||
$this->dispatchEvent(TheliaEvents::AFTER_CHANGECUSTOMER, new CustomerEvent($this));
|
||||
$this->dispatchEvent(TheliaEvents::AFTER_UPDATECUSTOMER, new CustomerEvent($this));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,7 +17,7 @@ class Folder extends BaseFolder
|
||||
|
||||
public function getUrl($locale)
|
||||
{
|
||||
return URL::init()->retrieve('folder', $this->getId(), $locale)->toString();
|
||||
return URL::getInstance()->retrieve('folder', $this->getId(), $locale)->toString();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,48 +9,15 @@ class Lang extends BaseLang {
|
||||
/**
|
||||
* Return the default language object, using a local variable to cache it.
|
||||
*
|
||||
* @throws RuntimeException
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
private static $default_lang = null;
|
||||
|
||||
public static function getDefaultLanguage() {
|
||||
|
||||
if (self::$default_lang == null) {
|
||||
$default_lang = LangQuery::create()->findOneByByDefault(true);
|
||||
|
||||
if ($default_lang == null) throw new RuntimeException("No default language is defined. Please define one.");
|
||||
}
|
||||
$default_lang = LangQuery::create()->findOneByByDefault(1);
|
||||
|
||||
if ($default_lang == null) throw new \RuntimeException("No default language is defined. Please define one.");
|
||||
|
||||
return $default_lang;
|
||||
}
|
||||
|
||||
public function getDateFormat()
|
||||
{
|
||||
return "d/m/Y";
|
||||
}
|
||||
|
||||
public function getTimeFormat()
|
||||
{
|
||||
return "H:i:s";
|
||||
}
|
||||
|
||||
public function getDateTimeFormat()
|
||||
{
|
||||
return "d/m/Y H:i:s";
|
||||
}
|
||||
|
||||
public function getDecimalSeparator()
|
||||
{
|
||||
return ".";
|
||||
}
|
||||
|
||||
public function getThousandsSeparator()
|
||||
{
|
||||
return " ";
|
||||
}
|
||||
|
||||
public function getDecimals()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ class LangTableMap extends TableMap
|
||||
/**
|
||||
* The total number of columns
|
||||
*/
|
||||
const NUM_COLUMNS = 9;
|
||||
const NUM_COLUMNS = 15;
|
||||
|
||||
/**
|
||||
* The number of lazy-loaded columns
|
||||
@@ -67,7 +67,7 @@ class LangTableMap extends TableMap
|
||||
/**
|
||||
* The number of columns to hydrate (NUM_COLUMNS - NUM_LAZY_LOAD_COLUMNS)
|
||||
*/
|
||||
const NUM_HYDRATE_COLUMNS = 9;
|
||||
const NUM_HYDRATE_COLUMNS = 15;
|
||||
|
||||
/**
|
||||
* the column name for the ID field
|
||||
@@ -95,15 +95,45 @@ class LangTableMap extends TableMap
|
||||
const URL = 'lang.URL';
|
||||
|
||||
/**
|
||||
* the column name for the POSITION field
|
||||
* the column name for the DATE_FORMAT field
|
||||
*/
|
||||
const POSITION = 'lang.POSITION';
|
||||
const DATE_FORMAT = 'lang.DATE_FORMAT';
|
||||
|
||||
/**
|
||||
* the column name for the TIME_FORMAT field
|
||||
*/
|
||||
const TIME_FORMAT = 'lang.TIME_FORMAT';
|
||||
|
||||
/**
|
||||
* the column name for the DATETIME_FORMAT field
|
||||
*/
|
||||
const DATETIME_FORMAT = 'lang.DATETIME_FORMAT';
|
||||
|
||||
/**
|
||||
* the column name for the DECIMAL_SEPARATOR field
|
||||
*/
|
||||
const DECIMAL_SEPARATOR = 'lang.DECIMAL_SEPARATOR';
|
||||
|
||||
/**
|
||||
* the column name for the THOUSANDS_SEPARATOR field
|
||||
*/
|
||||
const THOUSANDS_SEPARATOR = 'lang.THOUSANDS_SEPARATOR';
|
||||
|
||||
/**
|
||||
* the column name for the DECIMALS field
|
||||
*/
|
||||
const DECIMALS = 'lang.DECIMALS';
|
||||
|
||||
/**
|
||||
* the column name for the BY_DEFAULT field
|
||||
*/
|
||||
const BY_DEFAULT = 'lang.BY_DEFAULT';
|
||||
|
||||
/**
|
||||
* the column name for the POSITION field
|
||||
*/
|
||||
const POSITION = 'lang.POSITION';
|
||||
|
||||
/**
|
||||
* the column name for the CREATED_AT field
|
||||
*/
|
||||
@@ -126,12 +156,12 @@ class LangTableMap extends TableMap
|
||||
* e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id'
|
||||
*/
|
||||
protected static $fieldNames = array (
|
||||
self::TYPE_PHPNAME => array('Id', 'Title', 'Code', 'Locale', 'Url', 'Position', 'ByDefault', 'CreatedAt', 'UpdatedAt', ),
|
||||
self::TYPE_STUDLYPHPNAME => array('id', 'title', 'code', 'locale', 'url', 'position', 'byDefault', 'createdAt', 'updatedAt', ),
|
||||
self::TYPE_COLNAME => array(LangTableMap::ID, LangTableMap::TITLE, LangTableMap::CODE, LangTableMap::LOCALE, LangTableMap::URL, LangTableMap::POSITION, LangTableMap::BY_DEFAULT, LangTableMap::CREATED_AT, LangTableMap::UPDATED_AT, ),
|
||||
self::TYPE_RAW_COLNAME => array('ID', 'TITLE', 'CODE', 'LOCALE', 'URL', 'POSITION', 'BY_DEFAULT', 'CREATED_AT', 'UPDATED_AT', ),
|
||||
self::TYPE_FIELDNAME => array('id', 'title', 'code', 'locale', 'url', 'position', 'by_default', 'created_at', 'updated_at', ),
|
||||
self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, )
|
||||
self::TYPE_PHPNAME => array('Id', 'Title', 'Code', 'Locale', 'Url', 'DateFormat', 'TimeFormat', 'DatetimeFormat', 'DecimalSeparator', 'ThousandsSeparator', 'Decimals', 'ByDefault', 'Position', 'CreatedAt', 'UpdatedAt', ),
|
||||
self::TYPE_STUDLYPHPNAME => array('id', 'title', 'code', 'locale', 'url', 'dateFormat', 'timeFormat', 'datetimeFormat', 'decimalSeparator', 'thousandsSeparator', 'decimals', 'byDefault', 'position', 'createdAt', 'updatedAt', ),
|
||||
self::TYPE_COLNAME => array(LangTableMap::ID, LangTableMap::TITLE, LangTableMap::CODE, LangTableMap::LOCALE, LangTableMap::URL, LangTableMap::DATE_FORMAT, LangTableMap::TIME_FORMAT, LangTableMap::DATETIME_FORMAT, LangTableMap::DECIMAL_SEPARATOR, LangTableMap::THOUSANDS_SEPARATOR, LangTableMap::DECIMALS, LangTableMap::BY_DEFAULT, LangTableMap::POSITION, LangTableMap::CREATED_AT, LangTableMap::UPDATED_AT, ),
|
||||
self::TYPE_RAW_COLNAME => array('ID', 'TITLE', 'CODE', 'LOCALE', 'URL', 'DATE_FORMAT', 'TIME_FORMAT', 'DATETIME_FORMAT', 'DECIMAL_SEPARATOR', 'THOUSANDS_SEPARATOR', 'DECIMALS', 'BY_DEFAULT', 'POSITION', 'CREATED_AT', 'UPDATED_AT', ),
|
||||
self::TYPE_FIELDNAME => array('id', 'title', 'code', 'locale', 'url', 'date_format', 'time_format', 'datetime_format', 'decimal_separator', 'thousands_separator', 'decimals', 'by_default', 'position', 'created_at', 'updated_at', ),
|
||||
self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, )
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -141,12 +171,12 @@ class LangTableMap extends TableMap
|
||||
* e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0
|
||||
*/
|
||||
protected static $fieldKeys = array (
|
||||
self::TYPE_PHPNAME => array('Id' => 0, 'Title' => 1, 'Code' => 2, 'Locale' => 3, 'Url' => 4, 'Position' => 5, 'ByDefault' => 6, 'CreatedAt' => 7, 'UpdatedAt' => 8, ),
|
||||
self::TYPE_STUDLYPHPNAME => array('id' => 0, 'title' => 1, 'code' => 2, 'locale' => 3, 'url' => 4, 'position' => 5, 'byDefault' => 6, 'createdAt' => 7, 'updatedAt' => 8, ),
|
||||
self::TYPE_COLNAME => array(LangTableMap::ID => 0, LangTableMap::TITLE => 1, LangTableMap::CODE => 2, LangTableMap::LOCALE => 3, LangTableMap::URL => 4, LangTableMap::POSITION => 5, LangTableMap::BY_DEFAULT => 6, LangTableMap::CREATED_AT => 7, LangTableMap::UPDATED_AT => 8, ),
|
||||
self::TYPE_RAW_COLNAME => array('ID' => 0, 'TITLE' => 1, 'CODE' => 2, 'LOCALE' => 3, 'URL' => 4, 'POSITION' => 5, 'BY_DEFAULT' => 6, 'CREATED_AT' => 7, 'UPDATED_AT' => 8, ),
|
||||
self::TYPE_FIELDNAME => array('id' => 0, 'title' => 1, 'code' => 2, 'locale' => 3, 'url' => 4, 'position' => 5, 'by_default' => 6, 'created_at' => 7, 'updated_at' => 8, ),
|
||||
self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, )
|
||||
self::TYPE_PHPNAME => array('Id' => 0, 'Title' => 1, 'Code' => 2, 'Locale' => 3, 'Url' => 4, 'DateFormat' => 5, 'TimeFormat' => 6, 'DatetimeFormat' => 7, 'DecimalSeparator' => 8, 'ThousandsSeparator' => 9, 'Decimals' => 10, 'ByDefault' => 11, 'Position' => 12, 'CreatedAt' => 13, 'UpdatedAt' => 14, ),
|
||||
self::TYPE_STUDLYPHPNAME => array('id' => 0, 'title' => 1, 'code' => 2, 'locale' => 3, 'url' => 4, 'dateFormat' => 5, 'timeFormat' => 6, 'datetimeFormat' => 7, 'decimalSeparator' => 8, 'thousandsSeparator' => 9, 'decimals' => 10, 'byDefault' => 11, 'position' => 12, 'createdAt' => 13, 'updatedAt' => 14, ),
|
||||
self::TYPE_COLNAME => array(LangTableMap::ID => 0, LangTableMap::TITLE => 1, LangTableMap::CODE => 2, LangTableMap::LOCALE => 3, LangTableMap::URL => 4, LangTableMap::DATE_FORMAT => 5, LangTableMap::TIME_FORMAT => 6, LangTableMap::DATETIME_FORMAT => 7, LangTableMap::DECIMAL_SEPARATOR => 8, LangTableMap::THOUSANDS_SEPARATOR => 9, LangTableMap::DECIMALS => 10, LangTableMap::BY_DEFAULT => 11, LangTableMap::POSITION => 12, LangTableMap::CREATED_AT => 13, LangTableMap::UPDATED_AT => 14, ),
|
||||
self::TYPE_RAW_COLNAME => array('ID' => 0, 'TITLE' => 1, 'CODE' => 2, 'LOCALE' => 3, 'URL' => 4, 'DATE_FORMAT' => 5, 'TIME_FORMAT' => 6, 'DATETIME_FORMAT' => 7, 'DECIMAL_SEPARATOR' => 8, 'THOUSANDS_SEPARATOR' => 9, 'DECIMALS' => 10, 'BY_DEFAULT' => 11, 'POSITION' => 12, 'CREATED_AT' => 13, 'UPDATED_AT' => 14, ),
|
||||
self::TYPE_FIELDNAME => array('id' => 0, 'title' => 1, 'code' => 2, 'locale' => 3, 'url' => 4, 'date_format' => 5, 'time_format' => 6, 'datetime_format' => 7, 'decimal_separator' => 8, 'thousands_separator' => 9, 'decimals' => 10, 'by_default' => 11, 'position' => 12, 'created_at' => 13, 'updated_at' => 14, ),
|
||||
self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, )
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -170,8 +200,14 @@ class LangTableMap extends TableMap
|
||||
$this->addColumn('CODE', 'Code', 'VARCHAR', false, 10, null);
|
||||
$this->addColumn('LOCALE', 'Locale', 'VARCHAR', false, 45, null);
|
||||
$this->addColumn('URL', 'Url', 'VARCHAR', false, 255, null);
|
||||
$this->addColumn('POSITION', 'Position', 'INTEGER', false, null, null);
|
||||
$this->addColumn('DATE_FORMAT', 'DateFormat', 'VARCHAR', false, 45, null);
|
||||
$this->addColumn('TIME_FORMAT', 'TimeFormat', 'VARCHAR', false, 45, null);
|
||||
$this->addColumn('DATETIME_FORMAT', 'DatetimeFormat', 'VARCHAR', false, 45, null);
|
||||
$this->addColumn('DECIMAL_SEPARATOR', 'DecimalSeparator', 'VARCHAR', false, 45, null);
|
||||
$this->addColumn('THOUSANDS_SEPARATOR', 'ThousandsSeparator', 'VARCHAR', false, 45, null);
|
||||
$this->addColumn('DECIMALS', 'Decimals', 'VARCHAR', false, 45, null);
|
||||
$this->addColumn('BY_DEFAULT', 'ByDefault', 'TINYINT', false, null, null);
|
||||
$this->addColumn('POSITION', 'Position', 'INTEGER', false, null, null);
|
||||
$this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null);
|
||||
$this->addColumn('UPDATED_AT', 'UpdatedAt', 'TIMESTAMP', false, null, null);
|
||||
} // initialize()
|
||||
@@ -339,8 +375,14 @@ class LangTableMap extends TableMap
|
||||
$criteria->addSelectColumn(LangTableMap::CODE);
|
||||
$criteria->addSelectColumn(LangTableMap::LOCALE);
|
||||
$criteria->addSelectColumn(LangTableMap::URL);
|
||||
$criteria->addSelectColumn(LangTableMap::POSITION);
|
||||
$criteria->addSelectColumn(LangTableMap::DATE_FORMAT);
|
||||
$criteria->addSelectColumn(LangTableMap::TIME_FORMAT);
|
||||
$criteria->addSelectColumn(LangTableMap::DATETIME_FORMAT);
|
||||
$criteria->addSelectColumn(LangTableMap::DECIMAL_SEPARATOR);
|
||||
$criteria->addSelectColumn(LangTableMap::THOUSANDS_SEPARATOR);
|
||||
$criteria->addSelectColumn(LangTableMap::DECIMALS);
|
||||
$criteria->addSelectColumn(LangTableMap::BY_DEFAULT);
|
||||
$criteria->addSelectColumn(LangTableMap::POSITION);
|
||||
$criteria->addSelectColumn(LangTableMap::CREATED_AT);
|
||||
$criteria->addSelectColumn(LangTableMap::UPDATED_AT);
|
||||
} else {
|
||||
@@ -349,8 +391,14 @@ class LangTableMap extends TableMap
|
||||
$criteria->addSelectColumn($alias . '.CODE');
|
||||
$criteria->addSelectColumn($alias . '.LOCALE');
|
||||
$criteria->addSelectColumn($alias . '.URL');
|
||||
$criteria->addSelectColumn($alias . '.POSITION');
|
||||
$criteria->addSelectColumn($alias . '.DATE_FORMAT');
|
||||
$criteria->addSelectColumn($alias . '.TIME_FORMAT');
|
||||
$criteria->addSelectColumn($alias . '.DATETIME_FORMAT');
|
||||
$criteria->addSelectColumn($alias . '.DECIMAL_SEPARATOR');
|
||||
$criteria->addSelectColumn($alias . '.THOUSANDS_SEPARATOR');
|
||||
$criteria->addSelectColumn($alias . '.DECIMALS');
|
||||
$criteria->addSelectColumn($alias . '.BY_DEFAULT');
|
||||
$criteria->addSelectColumn($alias . '.POSITION');
|
||||
$criteria->addSelectColumn($alias . '.CREATED_AT');
|
||||
$criteria->addSelectColumn($alias . '.UPDATED_AT');
|
||||
}
|
||||
|
||||
@@ -9,6 +9,6 @@ class Product extends BaseProduct
|
||||
{
|
||||
public function getUrl($locale)
|
||||
{
|
||||
return URL::init()->retrieve('product', $this->getId(), $locale)->toString();
|
||||
return URL::getInstance()->retrieve('product', $this->getId(), $locale)->toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,6 +44,11 @@ trait ModelEventDispatcherTrait {
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDispatcher()
|
||||
{
|
||||
return $this->dispatcher;
|
||||
}
|
||||
|
||||
protected function dispatchEvent($eventName, ActionEvent $event)
|
||||
{
|
||||
if (!is_null($this->dispatcher)) {
|
||||
|
||||
190
core/lib/Thelia/Model/Tools/PositionManagementTrait.php
Normal file
190
core/lib/Thelia/Model/Tools/PositionManagementTrait.php
Normal file
@@ -0,0 +1,190 @@
|
||||
<?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\Model\Tools;
|
||||
|
||||
use Propel\Runtime\ActiveQuery\PropelQuery;
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use Propel\Runtime\Propel;
|
||||
|
||||
trait PositionManagementTrait {
|
||||
|
||||
/**
|
||||
* Create an instancer of this object query
|
||||
*/
|
||||
private function createQuery() {
|
||||
return PropelQuery::from(__CLASS__);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the database name from this object's table map.
|
||||
*/
|
||||
private function getDatabaseNameFromMap() {
|
||||
$class = new \ReflectionClass(self::TABLE_MAP);
|
||||
|
||||
return $class->getConstant('DATABASE_NAME');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the position of the next inserted object
|
||||
*/
|
||||
public function getNextPosition($parent = null) {
|
||||
|
||||
$query = $this->createQuery()
|
||||
->orderByPosition(Criteria::DESC)
|
||||
->limit(1);
|
||||
|
||||
if ($parent !== null) $last->filterByParent($parent);
|
||||
|
||||
$last = $query->findOne()
|
||||
;
|
||||
|
||||
return $last != null ? $last->getPosition() + 1 : 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move up a object
|
||||
*/
|
||||
public function movePositionUp() {
|
||||
$this->movePositionUpOrDown(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move down a object
|
||||
*/
|
||||
public function movePositionDown() {
|
||||
$this->movePositionUpOrDown(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move up or down a object
|
||||
*
|
||||
* @param the exchange mode: go up (POSITION_UP) or go down (POSITION_DOWN)
|
||||
*/
|
||||
protected function movePositionUpOrDown($up = true)
|
||||
{
|
||||
// The current position of the object
|
||||
$my_position = $this->getPosition();
|
||||
|
||||
// Find object to exchange position with
|
||||
$search = $this->createQuery();
|
||||
|
||||
if (method_exists($this, 'getParent')) $search->filterByParent($this->getParent());
|
||||
|
||||
// Up or down ?
|
||||
if ($up === true) {
|
||||
// Find the object immediately before me
|
||||
$search->filterByPosition(array('max' => $my_position-1))->orderByPosition(Criteria::DESC);
|
||||
}
|
||||
else {
|
||||
// Find the object immediately after me
|
||||
$search->filterByPosition(array('min' => $my_position+1))->orderByPosition(Criteria::ASC);
|
||||
}
|
||||
|
||||
$result = $search->findOne();
|
||||
|
||||
// If we found the proper object, exchange their positions
|
||||
if ($result) {
|
||||
|
||||
$cnx = Propel::getWriteConnection($this->getDatabaseName());
|
||||
|
||||
$cnx->beginTransaction();
|
||||
|
||||
try {
|
||||
$this
|
||||
->setPosition($result->getPosition())
|
||||
->save()
|
||||
;
|
||||
|
||||
$result->setDispatcher($this->getDispatcher())->setPosition($my_position)->save();
|
||||
|
||||
$cnx->commit();
|
||||
} catch (Exception $e) {
|
||||
$cnx->rollback();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Simply return the database name, from the constant in the MAP class.
|
||||
*/
|
||||
protected function getDatabaseName() {
|
||||
// Find DATABASE_NAME constant
|
||||
$mapClassName = self::TABLE_MAP;
|
||||
|
||||
return $mapClassName::DATABASE_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes object position
|
||||
*
|
||||
* @param newPosition
|
||||
*/
|
||||
public function changeAbsolutePosition($newPosition)
|
||||
{
|
||||
// The current position
|
||||
$current_position = $this->getPosition();
|
||||
|
||||
if ($newPosition != null && $newPosition > 0 && $newPosition != $current_position) {
|
||||
|
||||
// Find categories to offset
|
||||
$search = $this->createQuery();
|
||||
|
||||
if (method_exists($this, 'getParent')) $search->filterByParent($this->getParent());
|
||||
|
||||
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
|
||||
$search->filterByPosition(array('min' => 1+$current_position, 'max' => $newPosition));
|
||||
|
||||
$delta = -1;
|
||||
} else {
|
||||
// The new position is brefore the current position -> we will offset - 1 all categories located between us and the new position
|
||||
$search->filterByPosition(array('min' => $newPosition, 'max' => $current_position - 1));
|
||||
|
||||
$delta = 1;
|
||||
}
|
||||
|
||||
$results = $search->find();
|
||||
|
||||
$cnx = Propel::getWriteConnection($this->getDatabaseName());
|
||||
|
||||
$cnx->beginTransaction();
|
||||
|
||||
try {
|
||||
foreach ($results as $result) {
|
||||
$result->setDispatcher($this->getDispatcher())->setPosition($result->getPosition() + $delta)->save($cnx);
|
||||
}
|
||||
|
||||
$this
|
||||
->setPosition($newPosition)
|
||||
->save($cnx)
|
||||
;
|
||||
|
||||
$cnx->commit();
|
||||
} catch (Exception $e) {
|
||||
$cnx->rollback();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user