diff --git a/core/lib/Thelia/Model/Base/Order.php b/core/lib/Thelia/Model/Base/Order.php index 596829b3e..dae3d317b 100644 --- a/core/lib/Thelia/Model/Base/Order.php +++ b/core/lib/Thelia/Model/Base/Order.php @@ -35,7 +35,10 @@ use Thelia\Model\OrderProductQuery as ChildOrderProductQuery; use Thelia\Model\OrderQuery as ChildOrderQuery; use Thelia\Model\OrderStatus as ChildOrderStatus; use Thelia\Model\OrderStatusQuery as ChildOrderStatusQuery; +use Thelia\Model\OrderVersion as ChildOrderVersion; +use Thelia\Model\OrderVersionQuery as ChildOrderVersionQuery; use Thelia\Model\Map\OrderTableMap; +use Thelia\Model\Map\OrderVersionTableMap; abstract class Order implements ActiveRecordInterface { @@ -185,6 +188,25 @@ abstract class Order implements ActiveRecordInterface */ protected $updated_at; + /** + * The value for the version field. + * Note: this column has a database default value of: 0 + * @var int + */ + protected $version; + + /** + * The value for the version_created_at field. + * @var string + */ + protected $version_created_at; + + /** + * The value for the version_created_by field. + * @var string + */ + protected $version_created_by; + /** * @var Currency */ @@ -237,6 +259,12 @@ abstract class Order implements ActiveRecordInterface protected $collOrderCoupons; protected $collOrderCouponsPartial; + /** + * @var ObjectCollection|ChildOrderVersion[] Collection to store aggregation of ChildOrderVersion objects. + */ + protected $collOrderVersions; + protected $collOrderVersionsPartial; + /** * Flag to prevent endless save loop, if this object is referenced * by another object which falls in this transaction. @@ -245,6 +273,14 @@ abstract class Order implements ActiveRecordInterface */ protected $alreadyInSave = false; + // versionable behavior + + + /** + * @var bool + */ + protected $enforceVersion = false; + /** * An array of objects scheduled for deletion. * @var ObjectCollection @@ -257,11 +293,30 @@ abstract class Order implements ActiveRecordInterface */ protected $orderCouponsScheduledForDeletion = null; + /** + * An array of objects scheduled for deletion. + * @var ObjectCollection + */ + protected $orderVersionsScheduledForDeletion = null; + + /** + * Applies default values to this object. + * This method should be called from the object's constructor (or + * equivalent initialization method). + * @see __construct() + */ + public function applyDefaultValues() + { + $this->version = 0; + } + /** * Initializes internal state of Thelia\Model\Base\Order object. + * @see applyDefaults() */ public function __construct() { + $this->applyDefaultValues(); } /** @@ -751,6 +806,48 @@ abstract class Order implements ActiveRecordInterface } } + /** + * Get the [version] column value. + * + * @return int + */ + public function getVersion() + { + + return $this->version; + } + + /** + * Get the [optionally formatted] temporal [version_created_at] column value. + * + * + * @param string $format The date/time format string (either date()-style or strftime()-style). + * If format is NULL, then the raw \DateTime object will be returned. + * + * @return mixed Formatted date/time value as string or \DateTime object (if format is NULL), NULL if column is NULL, and 0 if column value is 0000-00-00 00:00:00 + * + * @throws PropelException - if unable to parse/validate the date/time value. + */ + public function getVersionCreatedAt($format = NULL) + { + if ($format === null) { + return $this->version_created_at; + } else { + return $this->version_created_at instanceof \DateTime ? $this->version_created_at->format($format) : null; + } + } + + /** + * Get the [version_created_by] column value. + * + * @return string + */ + public function getVersionCreatedBy() + { + + return $this->version_created_by; + } + /** * Set the value of [id] column. * @@ -1182,6 +1279,69 @@ abstract class Order implements ActiveRecordInterface return $this; } // setUpdatedAt() + /** + * Set the value of [version] column. + * + * @param int $v new value + * @return \Thelia\Model\Order The current object (for fluent API support) + */ + public function setVersion($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->version !== $v) { + $this->version = $v; + $this->modifiedColumns[OrderTableMap::VERSION] = true; + } + + + return $this; + } // setVersion() + + /** + * Sets the value of [version_created_at] column to a normalized version of the date/time value specified. + * + * @param mixed $v string, integer (timestamp), or \DateTime value. + * Empty strings are treated as NULL. + * @return \Thelia\Model\Order The current object (for fluent API support) + */ + public function setVersionCreatedAt($v) + { + $dt = PropelDateTime::newInstance($v, null, '\DateTime'); + if ($this->version_created_at !== null || $dt !== null) { + if ($dt !== $this->version_created_at) { + $this->version_created_at = $dt; + $this->modifiedColumns[OrderTableMap::VERSION_CREATED_AT] = true; + } + } // if either are not null + + + return $this; + } // setVersionCreatedAt() + + /** + * Set the value of [version_created_by] column. + * + * @param string $v new value + * @return \Thelia\Model\Order The current object (for fluent API support) + */ + public function setVersionCreatedBy($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->version_created_by !== $v) { + $this->version_created_by = $v; + $this->modifiedColumns[OrderTableMap::VERSION_CREATED_BY] = true; + } + + + return $this; + } // setVersionCreatedBy() + /** * Indicates whether the columns in this object are only set to default values. * @@ -1192,6 +1352,10 @@ abstract class Order implements ActiveRecordInterface */ public function hasOnlyDefaultValues() { + if ($this->version !== 0) { + return false; + } + // otherwise, everything was equal, so return TRUE return true; } // hasOnlyDefaultValues() @@ -1284,6 +1448,18 @@ abstract class Order implements ActiveRecordInterface $col = null; } $this->updated_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 19 + $startcol : OrderTableMap::translateFieldName('Version', TableMap::TYPE_PHPNAME, $indexType)]; + $this->version = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 20 + $startcol : OrderTableMap::translateFieldName('VersionCreatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + if ($col === '0000-00-00 00:00:00') { + $col = null; + } + $this->version_created_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 21 + $startcol : OrderTableMap::translateFieldName('VersionCreatedBy', TableMap::TYPE_PHPNAME, $indexType)]; + $this->version_created_by = (null !== $col) ? (string) $col : null; $this->resetModified(); $this->setNew(false); @@ -1292,7 +1468,7 @@ abstract class Order implements ActiveRecordInterface $this->ensureConsistency(); } - return $startcol + 19; // 19 = OrderTableMap::NUM_HYDRATE_COLUMNS. + return $startcol + 22; // 22 = OrderTableMap::NUM_HYDRATE_COLUMNS. } catch (Exception $e) { throw new PropelException("Error populating \Thelia\Model\Order object", 0, $e); @@ -1389,6 +1565,8 @@ abstract class Order implements ActiveRecordInterface $this->collOrderCoupons = null; + $this->collOrderVersions = null; + } // if (deep) } @@ -1457,6 +1635,14 @@ abstract class Order implements ActiveRecordInterface $isInsert = $this->isNew(); try { $ret = $this->preSave($con); + // versionable behavior + if ($this->isVersioningNecessary()) { + $this->setVersion($this->isNew() ? 1 : $this->getLastVersionNumber($con) + 1); + if (!$this->isColumnModified(OrderTableMap::VERSION_CREATED_AT)) { + $this->setVersionCreatedAt(time()); + } + $createVersion = true; // for postSave hook + } if ($isInsert) { $ret = $ret && $this->preInsert($con); // timestampable behavior @@ -1481,6 +1667,10 @@ abstract class Order implements ActiveRecordInterface $this->postUpdate($con); } $this->postSave($con); + // versionable behavior + if (isset($createVersion)) { + $this->addVersion($con); + } OrderTableMap::addInstanceToPool($this); } else { $affectedRows = 0; @@ -1617,6 +1807,23 @@ abstract class Order implements ActiveRecordInterface } } + if ($this->orderVersionsScheduledForDeletion !== null) { + if (!$this->orderVersionsScheduledForDeletion->isEmpty()) { + \Thelia\Model\OrderVersionQuery::create() + ->filterByPrimaryKeys($this->orderVersionsScheduledForDeletion->getPrimaryKeys(false)) + ->delete($con); + $this->orderVersionsScheduledForDeletion = null; + } + } + + if ($this->collOrderVersions !== null) { + foreach ($this->collOrderVersions as $referrerFK) { + if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) { + $affectedRows += $referrerFK->save($con); + } + } + } + $this->alreadyInSave = false; } @@ -1700,6 +1907,15 @@ abstract class Order implements ActiveRecordInterface if ($this->isColumnModified(OrderTableMap::UPDATED_AT)) { $modifiedColumns[':p' . $index++] = '`UPDATED_AT`'; } + if ($this->isColumnModified(OrderTableMap::VERSION)) { + $modifiedColumns[':p' . $index++] = '`VERSION`'; + } + if ($this->isColumnModified(OrderTableMap::VERSION_CREATED_AT)) { + $modifiedColumns[':p' . $index++] = '`VERSION_CREATED_AT`'; + } + if ($this->isColumnModified(OrderTableMap::VERSION_CREATED_BY)) { + $modifiedColumns[':p' . $index++] = '`VERSION_CREATED_BY`'; + } $sql = sprintf( 'INSERT INTO `order` (%s) VALUES (%s)', @@ -1768,6 +1984,15 @@ abstract class Order implements ActiveRecordInterface case '`UPDATED_AT`': $stmt->bindValue($identifier, $this->updated_at ? $this->updated_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR); break; + case '`VERSION`': + $stmt->bindValue($identifier, $this->version, PDO::PARAM_INT); + break; + case '`VERSION_CREATED_AT`': + $stmt->bindValue($identifier, $this->version_created_at ? $this->version_created_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR); + break; + case '`VERSION_CREATED_BY`': + $stmt->bindValue($identifier, $this->version_created_by, PDO::PARAM_STR); + break; } } $stmt->execute(); @@ -1887,6 +2112,15 @@ abstract class Order implements ActiveRecordInterface case 18: return $this->getUpdatedAt(); break; + case 19: + return $this->getVersion(); + break; + case 20: + return $this->getVersionCreatedAt(); + break; + case 21: + return $this->getVersionCreatedBy(); + break; default: return null; break; @@ -1935,6 +2169,9 @@ abstract class Order implements ActiveRecordInterface $keys[16] => $this->getLangId(), $keys[17] => $this->getCreatedAt(), $keys[18] => $this->getUpdatedAt(), + $keys[19] => $this->getVersion(), + $keys[20] => $this->getVersionCreatedAt(), + $keys[21] => $this->getVersionCreatedBy(), ); $virtualColumns = $this->virtualColumns; foreach ($virtualColumns as $key => $virtualColumn) { @@ -1972,6 +2209,9 @@ abstract class Order implements ActiveRecordInterface if (null !== $this->collOrderCoupons) { $result['OrderCoupons'] = $this->collOrderCoupons->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); } + if (null !== $this->collOrderVersions) { + $result['OrderVersions'] = $this->collOrderVersions->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); + } } return $result; @@ -2063,6 +2303,15 @@ abstract class Order implements ActiveRecordInterface case 18: $this->setUpdatedAt($value); break; + case 19: + $this->setVersion($value); + break; + case 20: + $this->setVersionCreatedAt($value); + break; + case 21: + $this->setVersionCreatedBy($value); + break; } // switch() } @@ -2106,6 +2355,9 @@ abstract class Order implements ActiveRecordInterface if (array_key_exists($keys[16], $arr)) $this->setLangId($arr[$keys[16]]); if (array_key_exists($keys[17], $arr)) $this->setCreatedAt($arr[$keys[17]]); if (array_key_exists($keys[18], $arr)) $this->setUpdatedAt($arr[$keys[18]]); + if (array_key_exists($keys[19], $arr)) $this->setVersion($arr[$keys[19]]); + if (array_key_exists($keys[20], $arr)) $this->setVersionCreatedAt($arr[$keys[20]]); + if (array_key_exists($keys[21], $arr)) $this->setVersionCreatedBy($arr[$keys[21]]); } /** @@ -2136,6 +2388,9 @@ abstract class Order implements ActiveRecordInterface if ($this->isColumnModified(OrderTableMap::LANG_ID)) $criteria->add(OrderTableMap::LANG_ID, $this->lang_id); if ($this->isColumnModified(OrderTableMap::CREATED_AT)) $criteria->add(OrderTableMap::CREATED_AT, $this->created_at); if ($this->isColumnModified(OrderTableMap::UPDATED_AT)) $criteria->add(OrderTableMap::UPDATED_AT, $this->updated_at); + if ($this->isColumnModified(OrderTableMap::VERSION)) $criteria->add(OrderTableMap::VERSION, $this->version); + if ($this->isColumnModified(OrderTableMap::VERSION_CREATED_AT)) $criteria->add(OrderTableMap::VERSION_CREATED_AT, $this->version_created_at); + if ($this->isColumnModified(OrderTableMap::VERSION_CREATED_BY)) $criteria->add(OrderTableMap::VERSION_CREATED_BY, $this->version_created_by); return $criteria; } @@ -2217,6 +2472,9 @@ abstract class Order implements ActiveRecordInterface $copyObj->setLangId($this->getLangId()); $copyObj->setCreatedAt($this->getCreatedAt()); $copyObj->setUpdatedAt($this->getUpdatedAt()); + $copyObj->setVersion($this->getVersion()); + $copyObj->setVersionCreatedAt($this->getVersionCreatedAt()); + $copyObj->setVersionCreatedBy($this->getVersionCreatedBy()); if ($deepCopy) { // important: temporarily setNew(false) because this affects the behavior of @@ -2235,6 +2493,12 @@ abstract class Order implements ActiveRecordInterface } } + foreach ($this->getOrderVersions() as $relObj) { + if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves + $copyObj->addOrderVersion($relObj->copy($deepCopy)); + } + } + } // if ($deepCopy) if ($makeNew) { @@ -2690,6 +2954,9 @@ abstract class Order implements ActiveRecordInterface if ('OrderCoupon' == $relationName) { return $this->initOrderCoupons(); } + if ('OrderVersion' == $relationName) { + return $this->initOrderVersions(); + } } /** @@ -3128,6 +3395,227 @@ abstract class Order implements ActiveRecordInterface return $this; } + /** + * Clears out the collOrderVersions collection + * + * This does not modify the database; however, it will remove any associated objects, causing + * them to be refetched by subsequent calls to accessor method. + * + * @return void + * @see addOrderVersions() + */ + public function clearOrderVersions() + { + $this->collOrderVersions = null; // important to set this to NULL since that means it is uninitialized + } + + /** + * Reset is the collOrderVersions collection loaded partially. + */ + public function resetPartialOrderVersions($v = true) + { + $this->collOrderVersionsPartial = $v; + } + + /** + * Initializes the collOrderVersions collection. + * + * By default this just sets the collOrderVersions collection to an empty array (like clearcollOrderVersions()); + * however, you may wish to override this method in your stub class to provide setting appropriate + * to your application -- for example, setting the initial array to the values stored in database. + * + * @param boolean $overrideExisting If set to true, the method call initializes + * the collection even if it is not empty + * + * @return void + */ + public function initOrderVersions($overrideExisting = true) + { + if (null !== $this->collOrderVersions && !$overrideExisting) { + return; + } + $this->collOrderVersions = new ObjectCollection(); + $this->collOrderVersions->setModel('\Thelia\Model\OrderVersion'); + } + + /** + * Gets an array of ChildOrderVersion objects which contain a foreign key that references this object. + * + * If the $criteria is not null, it is used to always fetch the results from the database. + * Otherwise the results are fetched from the database the first time, then cached. + * Next time the same method is called without $criteria, the cached collection is returned. + * If this ChildOrder is new, it will return + * an empty collection or the current collection; the criteria is ignored on a new object. + * + * @param Criteria $criteria optional Criteria object to narrow the query + * @param ConnectionInterface $con optional connection object + * @return Collection|ChildOrderVersion[] List of ChildOrderVersion objects + * @throws PropelException + */ + public function getOrderVersions($criteria = null, ConnectionInterface $con = null) + { + $partial = $this->collOrderVersionsPartial && !$this->isNew(); + if (null === $this->collOrderVersions || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collOrderVersions) { + // return empty collection + $this->initOrderVersions(); + } else { + $collOrderVersions = ChildOrderVersionQuery::create(null, $criteria) + ->filterByOrder($this) + ->find($con); + + if (null !== $criteria) { + if (false !== $this->collOrderVersionsPartial && count($collOrderVersions)) { + $this->initOrderVersions(false); + + foreach ($collOrderVersions as $obj) { + if (false == $this->collOrderVersions->contains($obj)) { + $this->collOrderVersions->append($obj); + } + } + + $this->collOrderVersionsPartial = true; + } + + reset($collOrderVersions); + + return $collOrderVersions; + } + + if ($partial && $this->collOrderVersions) { + foreach ($this->collOrderVersions as $obj) { + if ($obj->isNew()) { + $collOrderVersions[] = $obj; + } + } + } + + $this->collOrderVersions = $collOrderVersions; + $this->collOrderVersionsPartial = false; + } + } + + return $this->collOrderVersions; + } + + /** + * Sets a collection of OrderVersion objects related by a one-to-many relationship + * to the current object. + * It will also schedule objects for deletion based on a diff between old objects (aka persisted) + * and new objects from the given Propel collection. + * + * @param Collection $orderVersions A Propel collection. + * @param ConnectionInterface $con Optional connection object + * @return ChildOrder The current object (for fluent API support) + */ + public function setOrderVersions(Collection $orderVersions, ConnectionInterface $con = null) + { + $orderVersionsToDelete = $this->getOrderVersions(new Criteria(), $con)->diff($orderVersions); + + + //since at least one column in the foreign key is at the same time a PK + //we can not just set a PK to NULL in the lines below. We have to store + //a backup of all values, so we are able to manipulate these items based on the onDelete value later. + $this->orderVersionsScheduledForDeletion = clone $orderVersionsToDelete; + + foreach ($orderVersionsToDelete as $orderVersionRemoved) { + $orderVersionRemoved->setOrder(null); + } + + $this->collOrderVersions = null; + foreach ($orderVersions as $orderVersion) { + $this->addOrderVersion($orderVersion); + } + + $this->collOrderVersions = $orderVersions; + $this->collOrderVersionsPartial = false; + + return $this; + } + + /** + * Returns the number of related OrderVersion objects. + * + * @param Criteria $criteria + * @param boolean $distinct + * @param ConnectionInterface $con + * @return int Count of related OrderVersion objects. + * @throws PropelException + */ + public function countOrderVersions(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) + { + $partial = $this->collOrderVersionsPartial && !$this->isNew(); + if (null === $this->collOrderVersions || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collOrderVersions) { + return 0; + } + + if ($partial && !$criteria) { + return count($this->getOrderVersions()); + } + + $query = ChildOrderVersionQuery::create(null, $criteria); + if ($distinct) { + $query->distinct(); + } + + return $query + ->filterByOrder($this) + ->count($con); + } + + return count($this->collOrderVersions); + } + + /** + * Method called to associate a ChildOrderVersion object to this object + * through the ChildOrderVersion foreign key attribute. + * + * @param ChildOrderVersion $l ChildOrderVersion + * @return \Thelia\Model\Order The current object (for fluent API support) + */ + public function addOrderVersion(ChildOrderVersion $l) + { + if ($this->collOrderVersions === null) { + $this->initOrderVersions(); + $this->collOrderVersionsPartial = true; + } + + if (!in_array($l, $this->collOrderVersions->getArrayCopy(), true)) { // only add it if the **same** object is not already associated + $this->doAddOrderVersion($l); + } + + return $this; + } + + /** + * @param OrderVersion $orderVersion The orderVersion object to add. + */ + protected function doAddOrderVersion($orderVersion) + { + $this->collOrderVersions[]= $orderVersion; + $orderVersion->setOrder($this); + } + + /** + * @param OrderVersion $orderVersion The orderVersion object to remove. + * @return ChildOrder The current object (for fluent API support) + */ + public function removeOrderVersion($orderVersion) + { + if ($this->getOrderVersions()->contains($orderVersion)) { + $this->collOrderVersions->remove($this->collOrderVersions->search($orderVersion)); + if (null === $this->orderVersionsScheduledForDeletion) { + $this->orderVersionsScheduledForDeletion = clone $this->collOrderVersions; + $this->orderVersionsScheduledForDeletion->clear(); + } + $this->orderVersionsScheduledForDeletion[]= clone $orderVersion; + $orderVersion->setOrder(null); + } + + return $this; + } + /** * Clears the current object and sets all attributes to their default values */ @@ -3152,8 +3640,12 @@ abstract class Order implements ActiveRecordInterface $this->lang_id = null; $this->created_at = null; $this->updated_at = null; + $this->version = null; + $this->version_created_at = null; + $this->version_created_by = null; $this->alreadyInSave = false; $this->clearAllReferences(); + $this->applyDefaultValues(); $this->resetModified(); $this->setNew(true); $this->setDeleted(false); @@ -3181,10 +3673,16 @@ abstract class Order implements ActiveRecordInterface $o->clearAllReferences($deep); } } + if ($this->collOrderVersions) { + foreach ($this->collOrderVersions as $o) { + $o->clearAllReferences($deep); + } + } } // if ($deep) $this->collOrderProducts = null; $this->collOrderCoupons = null; + $this->collOrderVersions = null; $this->aCurrency = null; $this->aCustomer = null; $this->aOrderAddressRelatedByInvoiceOrderAddressId = null; @@ -3219,6 +3717,316 @@ abstract class Order implements ActiveRecordInterface return $this; } + // versionable behavior + + /** + * Enforce a new Version of this object upon next save. + * + * @return \Thelia\Model\Order + */ + public function enforceVersioning() + { + $this->enforceVersion = true; + + return $this; + } + + /** + * Checks whether the current state must be recorded as a version + * + * @return boolean + */ + public function isVersioningNecessary($con = null) + { + if ($this->alreadyInSave) { + return false; + } + + if ($this->enforceVersion) { + return true; + } + + if (ChildOrderQuery::isVersioningEnabled() && ($this->isNew() || $this->isModified()) || $this->isDeleted()) { + return true; + } + + return false; + } + + /** + * Creates a version of the current object and saves it. + * + * @param ConnectionInterface $con the connection to use + * + * @return ChildOrderVersion A version object + */ + public function addVersion($con = null) + { + $this->enforceVersion = false; + + $version = new ChildOrderVersion(); + $version->setId($this->getId()); + $version->setRef($this->getRef()); + $version->setCustomerId($this->getCustomerId()); + $version->setInvoiceOrderAddressId($this->getInvoiceOrderAddressId()); + $version->setDeliveryOrderAddressId($this->getDeliveryOrderAddressId()); + $version->setInvoiceDate($this->getInvoiceDate()); + $version->setCurrencyId($this->getCurrencyId()); + $version->setCurrencyRate($this->getCurrencyRate()); + $version->setTransactionRef($this->getTransactionRef()); + $version->setDeliveryRef($this->getDeliveryRef()); + $version->setInvoiceRef($this->getInvoiceRef()); + $version->setDiscount($this->getDiscount()); + $version->setPostage($this->getPostage()); + $version->setPaymentModuleId($this->getPaymentModuleId()); + $version->setDeliveryModuleId($this->getDeliveryModuleId()); + $version->setStatusId($this->getStatusId()); + $version->setLangId($this->getLangId()); + $version->setCreatedAt($this->getCreatedAt()); + $version->setUpdatedAt($this->getUpdatedAt()); + $version->setVersion($this->getVersion()); + $version->setVersionCreatedAt($this->getVersionCreatedAt()); + $version->setVersionCreatedBy($this->getVersionCreatedBy()); + $version->setOrder($this); + $version->save($con); + + return $version; + } + + /** + * Sets the properties of the current object to the value they had at a specific version + * + * @param integer $versionNumber The version number to read + * @param ConnectionInterface $con The connection to use + * + * @return ChildOrder The current object (for fluent API support) + */ + public function toVersion($versionNumber, $con = null) + { + $version = $this->getOneVersion($versionNumber, $con); + if (!$version) { + throw new PropelException(sprintf('No ChildOrder object found with version %d', $version)); + } + $this->populateFromVersion($version, $con); + + return $this; + } + + /** + * Sets the properties of the current object to the value they had at a specific version + * + * @param ChildOrderVersion $version The version object to use + * @param ConnectionInterface $con the connection to use + * @param array $loadedObjects objects that been loaded in a chain of populateFromVersion calls on referrer or fk objects. + * + * @return ChildOrder The current object (for fluent API support) + */ + public function populateFromVersion($version, $con = null, &$loadedObjects = array()) + { + $loadedObjects['ChildOrder'][$version->getId()][$version->getVersion()] = $this; + $this->setId($version->getId()); + $this->setRef($version->getRef()); + $this->setCustomerId($version->getCustomerId()); + $this->setInvoiceOrderAddressId($version->getInvoiceOrderAddressId()); + $this->setDeliveryOrderAddressId($version->getDeliveryOrderAddressId()); + $this->setInvoiceDate($version->getInvoiceDate()); + $this->setCurrencyId($version->getCurrencyId()); + $this->setCurrencyRate($version->getCurrencyRate()); + $this->setTransactionRef($version->getTransactionRef()); + $this->setDeliveryRef($version->getDeliveryRef()); + $this->setInvoiceRef($version->getInvoiceRef()); + $this->setDiscount($version->getDiscount()); + $this->setPostage($version->getPostage()); + $this->setPaymentModuleId($version->getPaymentModuleId()); + $this->setDeliveryModuleId($version->getDeliveryModuleId()); + $this->setStatusId($version->getStatusId()); + $this->setLangId($version->getLangId()); + $this->setCreatedAt($version->getCreatedAt()); + $this->setUpdatedAt($version->getUpdatedAt()); + $this->setVersion($version->getVersion()); + $this->setVersionCreatedAt($version->getVersionCreatedAt()); + $this->setVersionCreatedBy($version->getVersionCreatedBy()); + + return $this; + } + + /** + * Gets the latest persisted version number for the current object + * + * @param ConnectionInterface $con the connection to use + * + * @return integer + */ + public function getLastVersionNumber($con = null) + { + $v = ChildOrderVersionQuery::create() + ->filterByOrder($this) + ->orderByVersion('desc') + ->findOne($con); + if (!$v) { + return 0; + } + + return $v->getVersion(); + } + + /** + * Checks whether the current object is the latest one + * + * @param ConnectionInterface $con the connection to use + * + * @return Boolean + */ + public function isLastVersion($con = null) + { + return $this->getLastVersionNumber($con) == $this->getVersion(); + } + + /** + * Retrieves a version object for this entity and a version number + * + * @param integer $versionNumber The version number to read + * @param ConnectionInterface $con the connection to use + * + * @return ChildOrderVersion A version object + */ + public function getOneVersion($versionNumber, $con = null) + { + return ChildOrderVersionQuery::create() + ->filterByOrder($this) + ->filterByVersion($versionNumber) + ->findOne($con); + } + + /** + * Gets all the versions of this object, in incremental order + * + * @param ConnectionInterface $con the connection to use + * + * @return ObjectCollection A list of ChildOrderVersion objects + */ + public function getAllVersions($con = null) + { + $criteria = new Criteria(); + $criteria->addAscendingOrderByColumn(OrderVersionTableMap::VERSION); + + return $this->getOrderVersions($criteria, $con); + } + + /** + * Compares the current object with another of its version. + * + * print_r($book->compareVersion(1)); + * => array( + * '1' => array('Title' => 'Book title at version 1'), + * '2' => array('Title' => 'Book title at version 2') + * ); + * + * + * @param integer $versionNumber + * @param string $keys Main key used for the result diff (versions|columns) + * @param ConnectionInterface $con the connection to use + * @param array $ignoredColumns The columns to exclude from the diff. + * + * @return array A list of differences + */ + public function compareVersion($versionNumber, $keys = 'columns', $con = null, $ignoredColumns = array()) + { + $fromVersion = $this->toArray(); + $toVersion = $this->getOneVersion($versionNumber, $con)->toArray(); + + return $this->computeDiff($fromVersion, $toVersion, $keys, $ignoredColumns); + } + + /** + * Compares two versions of the current object. + * + * print_r($book->compareVersions(1, 2)); + * => array( + * '1' => array('Title' => 'Book title at version 1'), + * '2' => array('Title' => 'Book title at version 2') + * ); + * + * + * @param integer $fromVersionNumber + * @param integer $toVersionNumber + * @param string $keys Main key used for the result diff (versions|columns) + * @param ConnectionInterface $con the connection to use + * @param array $ignoredColumns The columns to exclude from the diff. + * + * @return array A list of differences + */ + public function compareVersions($fromVersionNumber, $toVersionNumber, $keys = 'columns', $con = null, $ignoredColumns = array()) + { + $fromVersion = $this->getOneVersion($fromVersionNumber, $con)->toArray(); + $toVersion = $this->getOneVersion($toVersionNumber, $con)->toArray(); + + return $this->computeDiff($fromVersion, $toVersion, $keys, $ignoredColumns); + } + + /** + * Computes the diff between two versions. + * + * print_r($book->computeDiff(1, 2)); + * => array( + * '1' => array('Title' => 'Book title at version 1'), + * '2' => array('Title' => 'Book title at version 2') + * ); + * + * + * @param array $fromVersion An array representing the original version. + * @param array $toVersion An array representing the destination version. + * @param string $keys Main key used for the result diff (versions|columns). + * @param array $ignoredColumns The columns to exclude from the diff. + * + * @return array A list of differences + */ + protected function computeDiff($fromVersion, $toVersion, $keys = 'columns', $ignoredColumns = array()) + { + $fromVersionNumber = $fromVersion['Version']; + $toVersionNumber = $toVersion['Version']; + $ignoredColumns = array_merge(array( + 'Version', + 'VersionCreatedAt', + 'VersionCreatedBy', + ), $ignoredColumns); + $diff = array(); + foreach ($fromVersion as $key => $value) { + if (in_array($key, $ignoredColumns)) { + continue; + } + if ($toVersion[$key] != $value) { + switch ($keys) { + case 'versions': + $diff[$fromVersionNumber][$key] = $value; + $diff[$toVersionNumber][$key] = $toVersion[$key]; + break; + default: + $diff[$key] = array( + $fromVersionNumber => $value, + $toVersionNumber => $toVersion[$key], + ); + break; + } + } + } + + return $diff; + } + /** + * retrieve the last $number versions. + * + * @param Integer $number the number of record to return. + * @return PropelCollection|array \Thelia\Model\OrderVersion[] List of \Thelia\Model\OrderVersion objects + */ + public function getLastVersions($number = 10, $criteria = null, $con = null) + { + $criteria = ChildOrderVersionQuery::create(null, $criteria); + $criteria->addDescendingOrderByColumn(OrderVersionTableMap::VERSION); + $criteria->limit($number); + + return $this->getOrderVersions($criteria, $con); + } /** * Code to be run before persisting the object * @param ConnectionInterface $con diff --git a/core/lib/Thelia/Model/Base/OrderQuery.php b/core/lib/Thelia/Model/Base/OrderQuery.php index 96aa3d30b..2db0f37e7 100644 --- a/core/lib/Thelia/Model/Base/OrderQuery.php +++ b/core/lib/Thelia/Model/Base/OrderQuery.php @@ -40,6 +40,9 @@ use Thelia\Model\Map\OrderTableMap; * @method ChildOrderQuery orderByLangId($order = Criteria::ASC) Order by the lang_id column * @method ChildOrderQuery orderByCreatedAt($order = Criteria::ASC) Order by the created_at column * @method ChildOrderQuery orderByUpdatedAt($order = Criteria::ASC) Order by the updated_at column + * @method ChildOrderQuery orderByVersion($order = Criteria::ASC) Order by the version column + * @method ChildOrderQuery orderByVersionCreatedAt($order = Criteria::ASC) Order by the version_created_at column + * @method ChildOrderQuery orderByVersionCreatedBy($order = Criteria::ASC) Order by the version_created_by column * * @method ChildOrderQuery groupById() Group by the id column * @method ChildOrderQuery groupByRef() Group by the ref column @@ -60,6 +63,9 @@ use Thelia\Model\Map\OrderTableMap; * @method ChildOrderQuery groupByLangId() Group by the lang_id column * @method ChildOrderQuery groupByCreatedAt() Group by the created_at column * @method ChildOrderQuery groupByUpdatedAt() Group by the updated_at column + * @method ChildOrderQuery groupByVersion() Group by the version column + * @method ChildOrderQuery groupByVersionCreatedAt() Group by the version_created_at column + * @method ChildOrderQuery groupByVersionCreatedBy() Group by the version_created_by column * * @method ChildOrderQuery leftJoin($relation) Adds a LEFT JOIN clause to the query * @method ChildOrderQuery rightJoin($relation) Adds a RIGHT JOIN clause to the query @@ -105,6 +111,10 @@ use Thelia\Model\Map\OrderTableMap; * @method ChildOrderQuery rightJoinOrderCoupon($relationAlias = null) Adds a RIGHT JOIN clause to the query using the OrderCoupon relation * @method ChildOrderQuery innerJoinOrderCoupon($relationAlias = null) Adds a INNER JOIN clause to the query using the OrderCoupon relation * + * @method ChildOrderQuery leftJoinOrderVersion($relationAlias = null) Adds a LEFT JOIN clause to the query using the OrderVersion relation + * @method ChildOrderQuery rightJoinOrderVersion($relationAlias = null) Adds a RIGHT JOIN clause to the query using the OrderVersion relation + * @method ChildOrderQuery innerJoinOrderVersion($relationAlias = null) Adds a INNER JOIN clause to the query using the OrderVersion relation + * * @method ChildOrder findOne(ConnectionInterface $con = null) Return the first ChildOrder matching the query * @method ChildOrder findOneOrCreate(ConnectionInterface $con = null) Return the first ChildOrder matching the query, or a new ChildOrder object populated from the query conditions when no match is found * @@ -127,6 +137,9 @@ use Thelia\Model\Map\OrderTableMap; * @method ChildOrder findOneByLangId(int $lang_id) Return the first ChildOrder filtered by the lang_id column * @method ChildOrder findOneByCreatedAt(string $created_at) Return the first ChildOrder filtered by the created_at column * @method ChildOrder findOneByUpdatedAt(string $updated_at) Return the first ChildOrder filtered by the updated_at column + * @method ChildOrder findOneByVersion(int $version) Return the first ChildOrder filtered by the version column + * @method ChildOrder findOneByVersionCreatedAt(string $version_created_at) Return the first ChildOrder filtered by the version_created_at column + * @method ChildOrder findOneByVersionCreatedBy(string $version_created_by) Return the first ChildOrder filtered by the version_created_by column * * @method array findById(int $id) Return ChildOrder objects filtered by the id column * @method array findByRef(string $ref) Return ChildOrder objects filtered by the ref column @@ -147,11 +160,21 @@ use Thelia\Model\Map\OrderTableMap; * @method array findByLangId(int $lang_id) Return ChildOrder objects filtered by the lang_id column * @method array findByCreatedAt(string $created_at) Return ChildOrder objects filtered by the created_at column * @method array findByUpdatedAt(string $updated_at) Return ChildOrder objects filtered by the updated_at column + * @method array findByVersion(int $version) Return ChildOrder objects filtered by the version column + * @method array findByVersionCreatedAt(string $version_created_at) Return ChildOrder objects filtered by the version_created_at column + * @method array findByVersionCreatedBy(string $version_created_by) Return ChildOrder objects filtered by the version_created_by column * */ abstract class OrderQuery extends ModelCriteria { + // versionable behavior + + /** + * Whether the versioning is enabled + */ + static $isVersioningEnabled = true; + /** * Initializes internal state of \Thelia\Model\Base\OrderQuery object. * @@ -235,7 +258,7 @@ abstract class OrderQuery extends ModelCriteria */ protected function findPkSimple($key, $con) { - $sql = 'SELECT `ID`, `REF`, `CUSTOMER_ID`, `INVOICE_ORDER_ADDRESS_ID`, `DELIVERY_ORDER_ADDRESS_ID`, `INVOICE_DATE`, `CURRENCY_ID`, `CURRENCY_RATE`, `TRANSACTION_REF`, `DELIVERY_REF`, `INVOICE_REF`, `DISCOUNT`, `POSTAGE`, `PAYMENT_MODULE_ID`, `DELIVERY_MODULE_ID`, `STATUS_ID`, `LANG_ID`, `CREATED_AT`, `UPDATED_AT` FROM `order` WHERE `ID` = :p0'; + $sql = 'SELECT `ID`, `REF`, `CUSTOMER_ID`, `INVOICE_ORDER_ADDRESS_ID`, `DELIVERY_ORDER_ADDRESS_ID`, `INVOICE_DATE`, `CURRENCY_ID`, `CURRENCY_RATE`, `TRANSACTION_REF`, `DELIVERY_REF`, `INVOICE_REF`, `DISCOUNT`, `POSTAGE`, `PAYMENT_MODULE_ID`, `DELIVERY_MODULE_ID`, `STATUS_ID`, `LANG_ID`, `CREATED_AT`, `UPDATED_AT`, `VERSION`, `VERSION_CREATED_AT`, `VERSION_CREATED_BY` FROM `order` WHERE `ID` = :p0'; try { $stmt = $con->prepare($sql); $stmt->bindValue(':p0', $key, PDO::PARAM_INT); @@ -1077,6 +1100,119 @@ abstract class OrderQuery extends ModelCriteria return $this->addUsingAlias(OrderTableMap::UPDATED_AT, $updatedAt, $comparison); } + /** + * Filter the query on the version column + * + * Example usage: + * + * $query->filterByVersion(1234); // WHERE version = 1234 + * $query->filterByVersion(array(12, 34)); // WHERE version IN (12, 34) + * $query->filterByVersion(array('min' => 12)); // WHERE version > 12 + * + * + * @param mixed $version 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 ChildOrderQuery The current query, for fluid interface + */ + public function filterByVersion($version = null, $comparison = null) + { + if (is_array($version)) { + $useMinMax = false; + if (isset($version['min'])) { + $this->addUsingAlias(OrderTableMap::VERSION, $version['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($version['max'])) { + $this->addUsingAlias(OrderTableMap::VERSION, $version['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(OrderTableMap::VERSION, $version, $comparison); + } + + /** + * Filter the query on the version_created_at column + * + * Example usage: + * + * $query->filterByVersionCreatedAt('2011-03-14'); // WHERE version_created_at = '2011-03-14' + * $query->filterByVersionCreatedAt('now'); // WHERE version_created_at = '2011-03-14' + * $query->filterByVersionCreatedAt(array('max' => 'yesterday')); // WHERE version_created_at > '2011-03-13' + * + * + * @param mixed $versionCreatedAt The value to use as filter. + * Values can be integers (unix timestamps), DateTime objects, or strings. + * Empty strings are treated as NULL. + * 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 ChildOrderQuery The current query, for fluid interface + */ + public function filterByVersionCreatedAt($versionCreatedAt = null, $comparison = null) + { + if (is_array($versionCreatedAt)) { + $useMinMax = false; + if (isset($versionCreatedAt['min'])) { + $this->addUsingAlias(OrderTableMap::VERSION_CREATED_AT, $versionCreatedAt['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($versionCreatedAt['max'])) { + $this->addUsingAlias(OrderTableMap::VERSION_CREATED_AT, $versionCreatedAt['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(OrderTableMap::VERSION_CREATED_AT, $versionCreatedAt, $comparison); + } + + /** + * Filter the query on the version_created_by column + * + * Example usage: + * + * $query->filterByVersionCreatedBy('fooValue'); // WHERE version_created_by = 'fooValue' + * $query->filterByVersionCreatedBy('%fooValue%'); // WHERE version_created_by LIKE '%fooValue%' + * + * + * @param string $versionCreatedBy 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 ChildOrderQuery The current query, for fluid interface + */ + public function filterByVersionCreatedBy($versionCreatedBy = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($versionCreatedBy)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $versionCreatedBy)) { + $versionCreatedBy = str_replace('*', '%', $versionCreatedBy); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(OrderTableMap::VERSION_CREATED_BY, $versionCreatedBy, $comparison); + } + /** * Filter the query by a related \Thelia\Model\Currency object * @@ -1823,6 +1959,79 @@ abstract class OrderQuery extends ModelCriteria ->useQuery($relationAlias ? $relationAlias : 'OrderCoupon', '\Thelia\Model\OrderCouponQuery'); } + /** + * Filter the query by a related \Thelia\Model\OrderVersion object + * + * @param \Thelia\Model\OrderVersion|ObjectCollection $orderVersion the related object to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildOrderQuery The current query, for fluid interface + */ + public function filterByOrderVersion($orderVersion, $comparison = null) + { + if ($orderVersion instanceof \Thelia\Model\OrderVersion) { + return $this + ->addUsingAlias(OrderTableMap::ID, $orderVersion->getId(), $comparison); + } elseif ($orderVersion instanceof ObjectCollection) { + return $this + ->useOrderVersionQuery() + ->filterByPrimaryKeys($orderVersion->getPrimaryKeys()) + ->endUse(); + } else { + throw new PropelException('filterByOrderVersion() only accepts arguments of type \Thelia\Model\OrderVersion or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the OrderVersion relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildOrderQuery The current query, for fluid interface + */ + public function joinOrderVersion($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('OrderVersion'); + + // create a ModelJoin object for this join + $join = new ModelJoin(); + $join->setJoinType($joinType); + $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); + if ($previousJoin = $this->getPreviousJoin()) { + $join->setPreviousJoin($previousJoin); + } + + // add the ModelJoin to the current object + if ($relationAlias) { + $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); + $this->addJoinObject($join, $relationAlias); + } else { + $this->addJoinObject($join, 'OrderVersion'); + } + + return $this; + } + + /** + * Use the OrderVersion relation OrderVersion object + * + * @see useQuery() + * + * @param string $relationAlias optional alias for the relation, + * to be used as main alias in the secondary query + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return \Thelia\Model\OrderVersionQuery A secondary query class using the current class as primary query + */ + public function useOrderVersionQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + return $this + ->joinOrderVersion($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'OrderVersion', '\Thelia\Model\OrderVersionQuery'); + } + /** * Exclude object from result * @@ -1980,4 +2189,32 @@ abstract class OrderQuery extends ModelCriteria return $this->addAscendingOrderByColumn(OrderTableMap::CREATED_AT); } + // versionable behavior + + /** + * Checks whether versioning is enabled + * + * @return boolean + */ + static public function isVersioningEnabled() + { + return self::$isVersioningEnabled; + } + + /** + * Enables versioning + */ + static public function enableVersioning() + { + self::$isVersioningEnabled = true; + } + + /** + * Disables versioning + */ + static public function disableVersioning() + { + self::$isVersioningEnabled = false; + } + } // OrderQuery diff --git a/core/lib/Thelia/Model/Base/OrderVersion.php b/core/lib/Thelia/Model/Base/OrderVersion.php new file mode 100644 index 000000000..2baed9528 --- /dev/null +++ b/core/lib/Thelia/Model/Base/OrderVersion.php @@ -0,0 +1,2420 @@ +version = 0; + } + + /** + * Initializes internal state of Thelia\Model\Base\OrderVersion object. + * @see applyDefaults() + */ + public function __construct() + { + $this->applyDefaultValues(); + } + + /** + * Returns whether the object has been modified. + * + * @return boolean True if the object has been modified. + */ + public function isModified() + { + return !!$this->modifiedColumns; + } + + /** + * Has specified column been modified? + * + * @param string $col column fully qualified name (TableMap::TYPE_COLNAME), e.g. Book::AUTHOR_ID + * @return boolean True if $col has been modified. + */ + public function isColumnModified($col) + { + return $this->modifiedColumns && isset($this->modifiedColumns[$col]); + } + + /** + * Get the columns that have been modified in this object. + * @return array A unique list of the modified column names for this object. + */ + public function getModifiedColumns() + { + return $this->modifiedColumns ? array_keys($this->modifiedColumns) : []; + } + + /** + * Returns whether the object has ever been saved. This will + * be false, if the object was retrieved from storage or was created + * and then saved. + * + * @return boolean true, if the object has never been persisted. + */ + public function isNew() + { + return $this->new; + } + + /** + * Setter for the isNew attribute. This method will be called + * by Propel-generated children and objects. + * + * @param boolean $b the state of the object. + */ + public function setNew($b) + { + $this->new = (Boolean) $b; + } + + /** + * Whether this object has been deleted. + * @return boolean The deleted state of this object. + */ + public function isDeleted() + { + return $this->deleted; + } + + /** + * Specify whether this object has been deleted. + * @param boolean $b The deleted state of this object. + * @return void + */ + public function setDeleted($b) + { + $this->deleted = (Boolean) $b; + } + + /** + * Sets the modified state for the object to be false. + * @param string $col If supplied, only the specified column is reset. + * @return void + */ + public function resetModified($col = null) + { + if (null !== $col) { + if (isset($this->modifiedColumns[$col])) { + unset($this->modifiedColumns[$col]); + } + } else { + $this->modifiedColumns = array(); + } + } + + /** + * Compares this with another OrderVersion instance. If + * obj is an instance of OrderVersion, delegates to + * equals(OrderVersion). Otherwise, returns false. + * + * @param mixed $obj The object to compare to. + * @return boolean Whether equal to the object specified. + */ + public function equals($obj) + { + $thisclazz = get_class($this); + if (!is_object($obj) || !($obj instanceof $thisclazz)) { + return false; + } + + if ($this === $obj) { + return true; + } + + if (null === $this->getPrimaryKey() + || null === $obj->getPrimaryKey()) { + return false; + } + + return $this->getPrimaryKey() === $obj->getPrimaryKey(); + } + + /** + * If the primary key is not null, return the hashcode of the + * primary key. Otherwise, return the hash code of the object. + * + * @return int Hashcode + */ + public function hashCode() + { + if (null !== $this->getPrimaryKey()) { + return crc32(serialize($this->getPrimaryKey())); + } + + return crc32(serialize(clone $this)); + } + + /** + * Get the associative array of the virtual columns in this object + * + * @return array + */ + public function getVirtualColumns() + { + return $this->virtualColumns; + } + + /** + * Checks the existence of a virtual column in this object + * + * @param string $name The virtual column name + * @return boolean + */ + public function hasVirtualColumn($name) + { + return array_key_exists($name, $this->virtualColumns); + } + + /** + * Get the value of a virtual column in this object + * + * @param string $name The virtual column name + * @return mixed + * + * @throws PropelException + */ + public function getVirtualColumn($name) + { + if (!$this->hasVirtualColumn($name)) { + throw new PropelException(sprintf('Cannot get value of inexistent virtual column %s.', $name)); + } + + return $this->virtualColumns[$name]; + } + + /** + * Set the value of a virtual column in this object + * + * @param string $name The virtual column name + * @param mixed $value The value to give to the virtual column + * + * @return OrderVersion The current object, for fluid interface + */ + public function setVirtualColumn($name, $value) + { + $this->virtualColumns[$name] = $value; + + return $this; + } + + /** + * Logs a message using Propel::log(). + * + * @param string $msg + * @param int $priority One of the Propel::LOG_* logging levels + * @return boolean + */ + protected function log($msg, $priority = Propel::LOG_INFO) + { + return Propel::log(get_class($this) . ': ' . $msg, $priority); + } + + /** + * Populate the current object from a string, using a given parser format + * + * $book = new Book(); + * $book->importFrom('JSON', '{"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); + * + * + * @param mixed $parser A AbstractParser instance, + * or a format name ('XML', 'YAML', 'JSON', 'CSV') + * @param string $data The source data to import from + * + * @return OrderVersion The current object, for fluid interface + */ + public function importFrom($parser, $data) + { + if (!$parser instanceof AbstractParser) { + $parser = AbstractParser::getParser($parser); + } + + $this->fromArray($parser->toArray($data), TableMap::TYPE_PHPNAME); + + return $this; + } + + /** + * Export the current object properties to a string, using a given parser format + * + * $book = BookQuery::create()->findPk(9012); + * echo $book->exportTo('JSON'); + * => {"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); + * + * + * @param mixed $parser A AbstractParser instance, or a format name ('XML', 'YAML', 'JSON', 'CSV') + * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy load(ed) columns. Defaults to TRUE. + * @return string The exported data + */ + public function exportTo($parser, $includeLazyLoadColumns = true) + { + if (!$parser instanceof AbstractParser) { + $parser = AbstractParser::getParser($parser); + } + + return $parser->fromArray($this->toArray(TableMap::TYPE_PHPNAME, $includeLazyLoadColumns, array(), true)); + } + + /** + * Clean up internal collections prior to serializing + * Avoids recursive loops that turn into segmentation faults when serializing + */ + public function __sleep() + { + $this->clearAllReferences(); + + return array_keys(get_object_vars($this)); + } + + /** + * Get the [id] column value. + * + * @return int + */ + public function getId() + { + + return $this->id; + } + + /** + * Get the [ref] column value. + * + * @return string + */ + public function getRef() + { + + return $this->ref; + } + + /** + * Get the [customer_id] column value. + * + * @return int + */ + public function getCustomerId() + { + + return $this->customer_id; + } + + /** + * Get the [invoice_order_address_id] column value. + * + * @return int + */ + public function getInvoiceOrderAddressId() + { + + return $this->invoice_order_address_id; + } + + /** + * Get the [delivery_order_address_id] column value. + * + * @return int + */ + public function getDeliveryOrderAddressId() + { + + return $this->delivery_order_address_id; + } + + /** + * Get the [optionally formatted] temporal [invoice_date] column value. + * + * + * @param string $format The date/time format string (either date()-style or strftime()-style). + * If format is NULL, then the raw \DateTime object will be returned. + * + * @return mixed Formatted date/time value as string or \DateTime object (if format is NULL), NULL if column is NULL, and 0 if column value is 0000-00-00 + * + * @throws PropelException - if unable to parse/validate the date/time value. + */ + public function getInvoiceDate($format = NULL) + { + if ($format === null) { + return $this->invoice_date; + } else { + return $this->invoice_date instanceof \DateTime ? $this->invoice_date->format($format) : null; + } + } + + /** + * Get the [currency_id] column value. + * + * @return int + */ + public function getCurrencyId() + { + + return $this->currency_id; + } + + /** + * Get the [currency_rate] column value. + * + * @return double + */ + public function getCurrencyRate() + { + + return $this->currency_rate; + } + + /** + * Get the [transaction_ref] column value. + * transaction reference - usually use to identify a transaction with banking modules + * @return string + */ + public function getTransactionRef() + { + + return $this->transaction_ref; + } + + /** + * Get the [delivery_ref] column value. + * delivery reference - usually use to identify a delivery progress on a distant delivery tracker website + * @return string + */ + public function getDeliveryRef() + { + + return $this->delivery_ref; + } + + /** + * Get the [invoice_ref] column value. + * the invoice reference + * @return string + */ + public function getInvoiceRef() + { + + return $this->invoice_ref; + } + + /** + * Get the [discount] column value. + * + * @return double + */ + public function getDiscount() + { + + return $this->discount; + } + + /** + * Get the [postage] column value. + * + * @return double + */ + public function getPostage() + { + + return $this->postage; + } + + /** + * Get the [payment_module_id] column value. + * + * @return int + */ + public function getPaymentModuleId() + { + + return $this->payment_module_id; + } + + /** + * Get the [delivery_module_id] column value. + * + * @return int + */ + public function getDeliveryModuleId() + { + + return $this->delivery_module_id; + } + + /** + * Get the [status_id] column value. + * + * @return int + */ + public function getStatusId() + { + + return $this->status_id; + } + + /** + * Get the [lang_id] column value. + * + * @return int + */ + public function getLangId() + { + + return $this->lang_id; + } + + /** + * Get the [optionally formatted] temporal [created_at] column value. + * + * + * @param string $format The date/time format string (either date()-style or strftime()-style). + * If format is NULL, then the raw \DateTime object will be returned. + * + * @return mixed Formatted date/time value as string or \DateTime object (if format is NULL), NULL if column is NULL, and 0 if column value is 0000-00-00 00:00:00 + * + * @throws PropelException - if unable to parse/validate the date/time value. + */ + public function getCreatedAt($format = NULL) + { + if ($format === null) { + return $this->created_at; + } else { + return $this->created_at instanceof \DateTime ? $this->created_at->format($format) : null; + } + } + + /** + * Get the [optionally formatted] temporal [updated_at] column value. + * + * + * @param string $format The date/time format string (either date()-style or strftime()-style). + * If format is NULL, then the raw \DateTime object will be returned. + * + * @return mixed Formatted date/time value as string or \DateTime object (if format is NULL), NULL if column is NULL, and 0 if column value is 0000-00-00 00:00:00 + * + * @throws PropelException - if unable to parse/validate the date/time value. + */ + public function getUpdatedAt($format = NULL) + { + if ($format === null) { + return $this->updated_at; + } else { + return $this->updated_at instanceof \DateTime ? $this->updated_at->format($format) : null; + } + } + + /** + * Get the [version] column value. + * + * @return int + */ + public function getVersion() + { + + return $this->version; + } + + /** + * Get the [optionally formatted] temporal [version_created_at] column value. + * + * + * @param string $format The date/time format string (either date()-style or strftime()-style). + * If format is NULL, then the raw \DateTime object will be returned. + * + * @return mixed Formatted date/time value as string or \DateTime object (if format is NULL), NULL if column is NULL, and 0 if column value is 0000-00-00 00:00:00 + * + * @throws PropelException - if unable to parse/validate the date/time value. + */ + public function getVersionCreatedAt($format = NULL) + { + if ($format === null) { + return $this->version_created_at; + } else { + return $this->version_created_at instanceof \DateTime ? $this->version_created_at->format($format) : null; + } + } + + /** + * Get the [version_created_by] column value. + * + * @return string + */ + public function getVersionCreatedBy() + { + + return $this->version_created_by; + } + + /** + * Set the value of [id] column. + * + * @param int $v new value + * @return \Thelia\Model\OrderVersion The current object (for fluent API support) + */ + public function setId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->id !== $v) { + $this->id = $v; + $this->modifiedColumns[OrderVersionTableMap::ID] = true; + } + + if ($this->aOrder !== null && $this->aOrder->getId() !== $v) { + $this->aOrder = null; + } + + + return $this; + } // setId() + + /** + * Set the value of [ref] column. + * + * @param string $v new value + * @return \Thelia\Model\OrderVersion The current object (for fluent API support) + */ + public function setRef($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->ref !== $v) { + $this->ref = $v; + $this->modifiedColumns[OrderVersionTableMap::REF] = true; + } + + + return $this; + } // setRef() + + /** + * Set the value of [customer_id] column. + * + * @param int $v new value + * @return \Thelia\Model\OrderVersion The current object (for fluent API support) + */ + public function setCustomerId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->customer_id !== $v) { + $this->customer_id = $v; + $this->modifiedColumns[OrderVersionTableMap::CUSTOMER_ID] = true; + } + + + return $this; + } // setCustomerId() + + /** + * Set the value of [invoice_order_address_id] column. + * + * @param int $v new value + * @return \Thelia\Model\OrderVersion The current object (for fluent API support) + */ + public function setInvoiceOrderAddressId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->invoice_order_address_id !== $v) { + $this->invoice_order_address_id = $v; + $this->modifiedColumns[OrderVersionTableMap::INVOICE_ORDER_ADDRESS_ID] = true; + } + + + return $this; + } // setInvoiceOrderAddressId() + + /** + * Set the value of [delivery_order_address_id] column. + * + * @param int $v new value + * @return \Thelia\Model\OrderVersion The current object (for fluent API support) + */ + public function setDeliveryOrderAddressId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->delivery_order_address_id !== $v) { + $this->delivery_order_address_id = $v; + $this->modifiedColumns[OrderVersionTableMap::DELIVERY_ORDER_ADDRESS_ID] = true; + } + + + return $this; + } // setDeliveryOrderAddressId() + + /** + * Sets the value of [invoice_date] column to a normalized version of the date/time value specified. + * + * @param mixed $v string, integer (timestamp), or \DateTime value. + * Empty strings are treated as NULL. + * @return \Thelia\Model\OrderVersion The current object (for fluent API support) + */ + public function setInvoiceDate($v) + { + $dt = PropelDateTime::newInstance($v, null, '\DateTime'); + if ($this->invoice_date !== null || $dt !== null) { + if ($dt !== $this->invoice_date) { + $this->invoice_date = $dt; + $this->modifiedColumns[OrderVersionTableMap::INVOICE_DATE] = true; + } + } // if either are not null + + + return $this; + } // setInvoiceDate() + + /** + * Set the value of [currency_id] column. + * + * @param int $v new value + * @return \Thelia\Model\OrderVersion The current object (for fluent API support) + */ + public function setCurrencyId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->currency_id !== $v) { + $this->currency_id = $v; + $this->modifiedColumns[OrderVersionTableMap::CURRENCY_ID] = true; + } + + + return $this; + } // setCurrencyId() + + /** + * Set the value of [currency_rate] column. + * + * @param double $v new value + * @return \Thelia\Model\OrderVersion The current object (for fluent API support) + */ + public function setCurrencyRate($v) + { + if ($v !== null) { + $v = (double) $v; + } + + if ($this->currency_rate !== $v) { + $this->currency_rate = $v; + $this->modifiedColumns[OrderVersionTableMap::CURRENCY_RATE] = true; + } + + + return $this; + } // setCurrencyRate() + + /** + * Set the value of [transaction_ref] column. + * transaction reference - usually use to identify a transaction with banking modules + * @param string $v new value + * @return \Thelia\Model\OrderVersion The current object (for fluent API support) + */ + public function setTransactionRef($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->transaction_ref !== $v) { + $this->transaction_ref = $v; + $this->modifiedColumns[OrderVersionTableMap::TRANSACTION_REF] = true; + } + + + return $this; + } // setTransactionRef() + + /** + * Set the value of [delivery_ref] column. + * delivery reference - usually use to identify a delivery progress on a distant delivery tracker website + * @param string $v new value + * @return \Thelia\Model\OrderVersion The current object (for fluent API support) + */ + public function setDeliveryRef($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->delivery_ref !== $v) { + $this->delivery_ref = $v; + $this->modifiedColumns[OrderVersionTableMap::DELIVERY_REF] = true; + } + + + return $this; + } // setDeliveryRef() + + /** + * Set the value of [invoice_ref] column. + * the invoice reference + * @param string $v new value + * @return \Thelia\Model\OrderVersion The current object (for fluent API support) + */ + public function setInvoiceRef($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->invoice_ref !== $v) { + $this->invoice_ref = $v; + $this->modifiedColumns[OrderVersionTableMap::INVOICE_REF] = true; + } + + + return $this; + } // setInvoiceRef() + + /** + * Set the value of [discount] column. + * + * @param double $v new value + * @return \Thelia\Model\OrderVersion The current object (for fluent API support) + */ + public function setDiscount($v) + { + if ($v !== null) { + $v = (double) $v; + } + + if ($this->discount !== $v) { + $this->discount = $v; + $this->modifiedColumns[OrderVersionTableMap::DISCOUNT] = true; + } + + + return $this; + } // setDiscount() + + /** + * Set the value of [postage] column. + * + * @param double $v new value + * @return \Thelia\Model\OrderVersion The current object (for fluent API support) + */ + public function setPostage($v) + { + if ($v !== null) { + $v = (double) $v; + } + + if ($this->postage !== $v) { + $this->postage = $v; + $this->modifiedColumns[OrderVersionTableMap::POSTAGE] = true; + } + + + return $this; + } // setPostage() + + /** + * Set the value of [payment_module_id] column. + * + * @param int $v new value + * @return \Thelia\Model\OrderVersion The current object (for fluent API support) + */ + public function setPaymentModuleId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->payment_module_id !== $v) { + $this->payment_module_id = $v; + $this->modifiedColumns[OrderVersionTableMap::PAYMENT_MODULE_ID] = true; + } + + + return $this; + } // setPaymentModuleId() + + /** + * Set the value of [delivery_module_id] column. + * + * @param int $v new value + * @return \Thelia\Model\OrderVersion The current object (for fluent API support) + */ + public function setDeliveryModuleId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->delivery_module_id !== $v) { + $this->delivery_module_id = $v; + $this->modifiedColumns[OrderVersionTableMap::DELIVERY_MODULE_ID] = true; + } + + + return $this; + } // setDeliveryModuleId() + + /** + * Set the value of [status_id] column. + * + * @param int $v new value + * @return \Thelia\Model\OrderVersion The current object (for fluent API support) + */ + public function setStatusId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->status_id !== $v) { + $this->status_id = $v; + $this->modifiedColumns[OrderVersionTableMap::STATUS_ID] = true; + } + + + return $this; + } // setStatusId() + + /** + * Set the value of [lang_id] column. + * + * @param int $v new value + * @return \Thelia\Model\OrderVersion The current object (for fluent API support) + */ + public function setLangId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->lang_id !== $v) { + $this->lang_id = $v; + $this->modifiedColumns[OrderVersionTableMap::LANG_ID] = true; + } + + + return $this; + } // setLangId() + + /** + * Sets the value of [created_at] column to a normalized version of the date/time value specified. + * + * @param mixed $v string, integer (timestamp), or \DateTime value. + * Empty strings are treated as NULL. + * @return \Thelia\Model\OrderVersion The current object (for fluent API support) + */ + public function setCreatedAt($v) + { + $dt = PropelDateTime::newInstance($v, null, '\DateTime'); + if ($this->created_at !== null || $dt !== null) { + if ($dt !== $this->created_at) { + $this->created_at = $dt; + $this->modifiedColumns[OrderVersionTableMap::CREATED_AT] = true; + } + } // if either are not null + + + return $this; + } // setCreatedAt() + + /** + * Sets the value of [updated_at] column to a normalized version of the date/time value specified. + * + * @param mixed $v string, integer (timestamp), or \DateTime value. + * Empty strings are treated as NULL. + * @return \Thelia\Model\OrderVersion The current object (for fluent API support) + */ + public function setUpdatedAt($v) + { + $dt = PropelDateTime::newInstance($v, null, '\DateTime'); + if ($this->updated_at !== null || $dt !== null) { + if ($dt !== $this->updated_at) { + $this->updated_at = $dt; + $this->modifiedColumns[OrderVersionTableMap::UPDATED_AT] = true; + } + } // if either are not null + + + return $this; + } // setUpdatedAt() + + /** + * Set the value of [version] column. + * + * @param int $v new value + * @return \Thelia\Model\OrderVersion The current object (for fluent API support) + */ + public function setVersion($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->version !== $v) { + $this->version = $v; + $this->modifiedColumns[OrderVersionTableMap::VERSION] = true; + } + + + return $this; + } // setVersion() + + /** + * Sets the value of [version_created_at] column to a normalized version of the date/time value specified. + * + * @param mixed $v string, integer (timestamp), or \DateTime value. + * Empty strings are treated as NULL. + * @return \Thelia\Model\OrderVersion The current object (for fluent API support) + */ + public function setVersionCreatedAt($v) + { + $dt = PropelDateTime::newInstance($v, null, '\DateTime'); + if ($this->version_created_at !== null || $dt !== null) { + if ($dt !== $this->version_created_at) { + $this->version_created_at = $dt; + $this->modifiedColumns[OrderVersionTableMap::VERSION_CREATED_AT] = true; + } + } // if either are not null + + + return $this; + } // setVersionCreatedAt() + + /** + * Set the value of [version_created_by] column. + * + * @param string $v new value + * @return \Thelia\Model\OrderVersion The current object (for fluent API support) + */ + public function setVersionCreatedBy($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->version_created_by !== $v) { + $this->version_created_by = $v; + $this->modifiedColumns[OrderVersionTableMap::VERSION_CREATED_BY] = true; + } + + + return $this; + } // setVersionCreatedBy() + + /** + * Indicates whether the columns in this object are only set to default values. + * + * This method can be used in conjunction with isModified() to indicate whether an object is both + * modified _and_ has some values set which are non-default. + * + * @return boolean Whether the columns in this object are only been set with default values. + */ + public function hasOnlyDefaultValues() + { + if ($this->version !== 0) { + return false; + } + + // otherwise, everything was equal, so return TRUE + return true; + } // hasOnlyDefaultValues() + + /** + * Hydrates (populates) the object variables with values from the database resultset. + * + * An offset (0-based "start column") is specified so that objects can be hydrated + * with a subset of the columns in the resultset rows. This is needed, for example, + * for results of JOIN queries where the resultset row includes columns from two or + * more tables. + * + * @param array $row The row returned by DataFetcher->fetch(). + * @param int $startcol 0-based offset column which indicates which restultset column to start with. + * @param boolean $rehydrate Whether this object is being re-hydrated from the database. + * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). + One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * + * @return int next starting column + * @throws PropelException - Any caught Exception will be rewrapped as a PropelException. + */ + public function hydrate($row, $startcol = 0, $rehydrate = false, $indexType = TableMap::TYPE_NUM) + { + try { + + + $col = $row[TableMap::TYPE_NUM == $indexType ? 0 + $startcol : OrderVersionTableMap::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; + $this->id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : OrderVersionTableMap::translateFieldName('Ref', TableMap::TYPE_PHPNAME, $indexType)]; + $this->ref = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : OrderVersionTableMap::translateFieldName('CustomerId', TableMap::TYPE_PHPNAME, $indexType)]; + $this->customer_id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : OrderVersionTableMap::translateFieldName('InvoiceOrderAddressId', TableMap::TYPE_PHPNAME, $indexType)]; + $this->invoice_order_address_id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : OrderVersionTableMap::translateFieldName('DeliveryOrderAddressId', TableMap::TYPE_PHPNAME, $indexType)]; + $this->delivery_order_address_id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : OrderVersionTableMap::translateFieldName('InvoiceDate', TableMap::TYPE_PHPNAME, $indexType)]; + if ($col === '0000-00-00') { + $col = null; + } + $this->invoice_date = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 6 + $startcol : OrderVersionTableMap::translateFieldName('CurrencyId', TableMap::TYPE_PHPNAME, $indexType)]; + $this->currency_id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 7 + $startcol : OrderVersionTableMap::translateFieldName('CurrencyRate', TableMap::TYPE_PHPNAME, $indexType)]; + $this->currency_rate = (null !== $col) ? (double) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 8 + $startcol : OrderVersionTableMap::translateFieldName('TransactionRef', TableMap::TYPE_PHPNAME, $indexType)]; + $this->transaction_ref = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 9 + $startcol : OrderVersionTableMap::translateFieldName('DeliveryRef', TableMap::TYPE_PHPNAME, $indexType)]; + $this->delivery_ref = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 10 + $startcol : OrderVersionTableMap::translateFieldName('InvoiceRef', TableMap::TYPE_PHPNAME, $indexType)]; + $this->invoice_ref = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 11 + $startcol : OrderVersionTableMap::translateFieldName('Discount', TableMap::TYPE_PHPNAME, $indexType)]; + $this->discount = (null !== $col) ? (double) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 12 + $startcol : OrderVersionTableMap::translateFieldName('Postage', TableMap::TYPE_PHPNAME, $indexType)]; + $this->postage = (null !== $col) ? (double) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 13 + $startcol : OrderVersionTableMap::translateFieldName('PaymentModuleId', TableMap::TYPE_PHPNAME, $indexType)]; + $this->payment_module_id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 14 + $startcol : OrderVersionTableMap::translateFieldName('DeliveryModuleId', TableMap::TYPE_PHPNAME, $indexType)]; + $this->delivery_module_id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 15 + $startcol : OrderVersionTableMap::translateFieldName('StatusId', TableMap::TYPE_PHPNAME, $indexType)]; + $this->status_id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 16 + $startcol : OrderVersionTableMap::translateFieldName('LangId', TableMap::TYPE_PHPNAME, $indexType)]; + $this->lang_id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 17 + $startcol : OrderVersionTableMap::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 ? 18 + $startcol : OrderVersionTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + if ($col === '0000-00-00 00:00:00') { + $col = null; + } + $this->updated_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 19 + $startcol : OrderVersionTableMap::translateFieldName('Version', TableMap::TYPE_PHPNAME, $indexType)]; + $this->version = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 20 + $startcol : OrderVersionTableMap::translateFieldName('VersionCreatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + if ($col === '0000-00-00 00:00:00') { + $col = null; + } + $this->version_created_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 21 + $startcol : OrderVersionTableMap::translateFieldName('VersionCreatedBy', TableMap::TYPE_PHPNAME, $indexType)]; + $this->version_created_by = (null !== $col) ? (string) $col : null; + $this->resetModified(); + + $this->setNew(false); + + if ($rehydrate) { + $this->ensureConsistency(); + } + + return $startcol + 22; // 22 = OrderVersionTableMap::NUM_HYDRATE_COLUMNS. + + } catch (Exception $e) { + throw new PropelException("Error populating \Thelia\Model\OrderVersion object", 0, $e); + } + } + + /** + * Checks and repairs the internal consistency of the object. + * + * This method is executed after an already-instantiated object is re-hydrated + * from the database. It exists to check any foreign keys to make sure that + * the objects related to the current object are correct based on foreign key. + * + * You can override this method in the stub class, but you should always invoke + * the base method from the overridden method (i.e. parent::ensureConsistency()), + * in case your model changes. + * + * @throws PropelException + */ + public function ensureConsistency() + { + if ($this->aOrder !== null && $this->id !== $this->aOrder->getId()) { + $this->aOrder = null; + } + } // ensureConsistency + + /** + * Reloads this object from datastore based on primary key and (optionally) resets all associated objects. + * + * This will only work if the object has been saved and has a valid primary key set. + * + * @param boolean $deep (optional) Whether to also de-associated any related objects. + * @param ConnectionInterface $con (optional) The ConnectionInterface connection to use. + * @return void + * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db + */ + public function reload($deep = false, ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("Cannot reload a deleted object."); + } + + if ($this->isNew()) { + throw new PropelException("Cannot reload an unsaved object."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(OrderVersionTableMap::DATABASE_NAME); + } + + // We don't need to alter the object instance pool; we're just modifying this instance + // already in the pool. + + $dataFetcher = ChildOrderVersionQuery::create(null, $this->buildPkeyCriteria())->setFormatter(ModelCriteria::FORMAT_STATEMENT)->find($con); + $row = $dataFetcher->fetch(); + $dataFetcher->close(); + if (!$row) { + throw new PropelException('Cannot find matching row in the database to reload object values.'); + } + $this->hydrate($row, 0, true, $dataFetcher->getIndexType()); // rehydrate + + if ($deep) { // also de-associate any related objects? + + $this->aOrder = null; + } // if (deep) + } + + /** + * Removes this object from datastore and sets delete attribute. + * + * @param ConnectionInterface $con + * @return void + * @throws PropelException + * @see OrderVersion::setDeleted() + * @see OrderVersion::isDeleted() + */ + public function delete(ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("This object has already been deleted."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getWriteConnection(OrderVersionTableMap::DATABASE_NAME); + } + + $con->beginTransaction(); + try { + $deleteQuery = ChildOrderVersionQuery::create() + ->filterByPrimaryKey($this->getPrimaryKey()); + $ret = $this->preDelete($con); + if ($ret) { + $deleteQuery->delete($con); + $this->postDelete($con); + $con->commit(); + $this->setDeleted(true); + } else { + $con->commit(); + } + } catch (Exception $e) { + $con->rollBack(); + throw $e; + } + } + + /** + * Persists this object to the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All modified related objects will also be persisted in the doSave() + * method. This method wraps all precipitate database operations in a + * single transaction. + * + * @param ConnectionInterface $con + * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. + * @throws PropelException + * @see doSave() + */ + public function save(ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("You cannot save an object that has been deleted."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getWriteConnection(OrderVersionTableMap::DATABASE_NAME); + } + + $con->beginTransaction(); + $isInsert = $this->isNew(); + try { + $ret = $this->preSave($con); + if ($isInsert) { + $ret = $ret && $this->preInsert($con); + } else { + $ret = $ret && $this->preUpdate($con); + } + if ($ret) { + $affectedRows = $this->doSave($con); + if ($isInsert) { + $this->postInsert($con); + } else { + $this->postUpdate($con); + } + $this->postSave($con); + OrderVersionTableMap::addInstanceToPool($this); + } else { + $affectedRows = 0; + } + $con->commit(); + + return $affectedRows; + } catch (Exception $e) { + $con->rollBack(); + throw $e; + } + } + + /** + * Performs the work of inserting or updating the row in the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All related objects are also updated in this method. + * + * @param ConnectionInterface $con + * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. + * @throws PropelException + * @see save() + */ + protected function doSave(ConnectionInterface $con) + { + $affectedRows = 0; // initialize var to track total num of affected rows + if (!$this->alreadyInSave) { + $this->alreadyInSave = true; + + // We call the save method on the following object(s) if they + // were passed to this object by their corresponding set + // method. This object relates to these object(s) by a + // foreign key reference. + + if ($this->aOrder !== null) { + if ($this->aOrder->isModified() || $this->aOrder->isNew()) { + $affectedRows += $this->aOrder->save($con); + } + $this->setOrder($this->aOrder); + } + + if ($this->isNew() || $this->isModified()) { + // persist changes + if ($this->isNew()) { + $this->doInsert($con); + } else { + $this->doUpdate($con); + } + $affectedRows += 1; + $this->resetModified(); + } + + $this->alreadyInSave = false; + + } + + return $affectedRows; + } // doSave() + + /** + * Insert the row in the database. + * + * @param ConnectionInterface $con + * + * @throws PropelException + * @see doSave() + */ + protected function doInsert(ConnectionInterface $con) + { + $modifiedColumns = array(); + $index = 0; + + + // check the columns in natural order for more readable SQL queries + if ($this->isColumnModified(OrderVersionTableMap::ID)) { + $modifiedColumns[':p' . $index++] = '`ID`'; + } + if ($this->isColumnModified(OrderVersionTableMap::REF)) { + $modifiedColumns[':p' . $index++] = '`REF`'; + } + if ($this->isColumnModified(OrderVersionTableMap::CUSTOMER_ID)) { + $modifiedColumns[':p' . $index++] = '`CUSTOMER_ID`'; + } + if ($this->isColumnModified(OrderVersionTableMap::INVOICE_ORDER_ADDRESS_ID)) { + $modifiedColumns[':p' . $index++] = '`INVOICE_ORDER_ADDRESS_ID`'; + } + if ($this->isColumnModified(OrderVersionTableMap::DELIVERY_ORDER_ADDRESS_ID)) { + $modifiedColumns[':p' . $index++] = '`DELIVERY_ORDER_ADDRESS_ID`'; + } + if ($this->isColumnModified(OrderVersionTableMap::INVOICE_DATE)) { + $modifiedColumns[':p' . $index++] = '`INVOICE_DATE`'; + } + if ($this->isColumnModified(OrderVersionTableMap::CURRENCY_ID)) { + $modifiedColumns[':p' . $index++] = '`CURRENCY_ID`'; + } + if ($this->isColumnModified(OrderVersionTableMap::CURRENCY_RATE)) { + $modifiedColumns[':p' . $index++] = '`CURRENCY_RATE`'; + } + if ($this->isColumnModified(OrderVersionTableMap::TRANSACTION_REF)) { + $modifiedColumns[':p' . $index++] = '`TRANSACTION_REF`'; + } + if ($this->isColumnModified(OrderVersionTableMap::DELIVERY_REF)) { + $modifiedColumns[':p' . $index++] = '`DELIVERY_REF`'; + } + if ($this->isColumnModified(OrderVersionTableMap::INVOICE_REF)) { + $modifiedColumns[':p' . $index++] = '`INVOICE_REF`'; + } + if ($this->isColumnModified(OrderVersionTableMap::DISCOUNT)) { + $modifiedColumns[':p' . $index++] = '`DISCOUNT`'; + } + if ($this->isColumnModified(OrderVersionTableMap::POSTAGE)) { + $modifiedColumns[':p' . $index++] = '`POSTAGE`'; + } + if ($this->isColumnModified(OrderVersionTableMap::PAYMENT_MODULE_ID)) { + $modifiedColumns[':p' . $index++] = '`PAYMENT_MODULE_ID`'; + } + if ($this->isColumnModified(OrderVersionTableMap::DELIVERY_MODULE_ID)) { + $modifiedColumns[':p' . $index++] = '`DELIVERY_MODULE_ID`'; + } + if ($this->isColumnModified(OrderVersionTableMap::STATUS_ID)) { + $modifiedColumns[':p' . $index++] = '`STATUS_ID`'; + } + if ($this->isColumnModified(OrderVersionTableMap::LANG_ID)) { + $modifiedColumns[':p' . $index++] = '`LANG_ID`'; + } + if ($this->isColumnModified(OrderVersionTableMap::CREATED_AT)) { + $modifiedColumns[':p' . $index++] = '`CREATED_AT`'; + } + if ($this->isColumnModified(OrderVersionTableMap::UPDATED_AT)) { + $modifiedColumns[':p' . $index++] = '`UPDATED_AT`'; + } + if ($this->isColumnModified(OrderVersionTableMap::VERSION)) { + $modifiedColumns[':p' . $index++] = '`VERSION`'; + } + if ($this->isColumnModified(OrderVersionTableMap::VERSION_CREATED_AT)) { + $modifiedColumns[':p' . $index++] = '`VERSION_CREATED_AT`'; + } + if ($this->isColumnModified(OrderVersionTableMap::VERSION_CREATED_BY)) { + $modifiedColumns[':p' . $index++] = '`VERSION_CREATED_BY`'; + } + + $sql = sprintf( + 'INSERT INTO `order_version` (%s) VALUES (%s)', + implode(', ', $modifiedColumns), + implode(', ', array_keys($modifiedColumns)) + ); + + try { + $stmt = $con->prepare($sql); + foreach ($modifiedColumns as $identifier => $columnName) { + switch ($columnName) { + case '`ID`': + $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT); + break; + case '`REF`': + $stmt->bindValue($identifier, $this->ref, PDO::PARAM_STR); + break; + case '`CUSTOMER_ID`': + $stmt->bindValue($identifier, $this->customer_id, PDO::PARAM_INT); + break; + case '`INVOICE_ORDER_ADDRESS_ID`': + $stmt->bindValue($identifier, $this->invoice_order_address_id, PDO::PARAM_INT); + break; + case '`DELIVERY_ORDER_ADDRESS_ID`': + $stmt->bindValue($identifier, $this->delivery_order_address_id, PDO::PARAM_INT); + break; + case '`INVOICE_DATE`': + $stmt->bindValue($identifier, $this->invoice_date ? $this->invoice_date->format("Y-m-d H:i:s") : null, PDO::PARAM_STR); + break; + case '`CURRENCY_ID`': + $stmt->bindValue($identifier, $this->currency_id, PDO::PARAM_INT); + break; + case '`CURRENCY_RATE`': + $stmt->bindValue($identifier, $this->currency_rate, PDO::PARAM_STR); + break; + case '`TRANSACTION_REF`': + $stmt->bindValue($identifier, $this->transaction_ref, PDO::PARAM_STR); + break; + case '`DELIVERY_REF`': + $stmt->bindValue($identifier, $this->delivery_ref, PDO::PARAM_STR); + break; + case '`INVOICE_REF`': + $stmt->bindValue($identifier, $this->invoice_ref, PDO::PARAM_STR); + break; + case '`DISCOUNT`': + $stmt->bindValue($identifier, $this->discount, PDO::PARAM_STR); + break; + case '`POSTAGE`': + $stmt->bindValue($identifier, $this->postage, PDO::PARAM_STR); + break; + case '`PAYMENT_MODULE_ID`': + $stmt->bindValue($identifier, $this->payment_module_id, PDO::PARAM_INT); + break; + case '`DELIVERY_MODULE_ID`': + $stmt->bindValue($identifier, $this->delivery_module_id, PDO::PARAM_INT); + break; + case '`STATUS_ID`': + $stmt->bindValue($identifier, $this->status_id, PDO::PARAM_INT); + break; + case '`LANG_ID`': + $stmt->bindValue($identifier, $this->lang_id, 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; + case '`UPDATED_AT`': + $stmt->bindValue($identifier, $this->updated_at ? $this->updated_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR); + break; + case '`VERSION`': + $stmt->bindValue($identifier, $this->version, PDO::PARAM_INT); + break; + case '`VERSION_CREATED_AT`': + $stmt->bindValue($identifier, $this->version_created_at ? $this->version_created_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR); + break; + case '`VERSION_CREATED_BY`': + $stmt->bindValue($identifier, $this->version_created_by, PDO::PARAM_STR); + break; + } + } + $stmt->execute(); + } catch (Exception $e) { + Propel::log($e->getMessage(), Propel::LOG_ERR); + throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), 0, $e); + } + + $this->setNew(false); + } + + /** + * Update the row in the database. + * + * @param ConnectionInterface $con + * + * @return Integer Number of updated rows + * @see doSave() + */ + protected function doUpdate(ConnectionInterface $con) + { + $selectCriteria = $this->buildPkeyCriteria(); + $valuesCriteria = $this->buildCriteria(); + + return $selectCriteria->doUpdate($valuesCriteria, $con); + } + + /** + * Retrieves a field from the object by name passed in as a string. + * + * @param string $name name + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @return mixed Value of field. + */ + public function getByName($name, $type = TableMap::TYPE_PHPNAME) + { + $pos = OrderVersionTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + $field = $this->getByPosition($pos); + + return $field; + } + + /** + * Retrieves a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @return mixed Value of field at $pos + */ + public function getByPosition($pos) + { + switch ($pos) { + case 0: + return $this->getId(); + break; + case 1: + return $this->getRef(); + break; + case 2: + return $this->getCustomerId(); + break; + case 3: + return $this->getInvoiceOrderAddressId(); + break; + case 4: + return $this->getDeliveryOrderAddressId(); + break; + case 5: + return $this->getInvoiceDate(); + break; + case 6: + return $this->getCurrencyId(); + break; + case 7: + return $this->getCurrencyRate(); + break; + case 8: + return $this->getTransactionRef(); + break; + case 9: + return $this->getDeliveryRef(); + break; + case 10: + return $this->getInvoiceRef(); + break; + case 11: + return $this->getDiscount(); + break; + case 12: + return $this->getPostage(); + break; + case 13: + return $this->getPaymentModuleId(); + break; + case 14: + return $this->getDeliveryModuleId(); + break; + case 15: + return $this->getStatusId(); + break; + case 16: + return $this->getLangId(); + break; + case 17: + return $this->getCreatedAt(); + break; + case 18: + return $this->getUpdatedAt(); + break; + case 19: + return $this->getVersion(); + break; + case 20: + return $this->getVersionCreatedAt(); + break; + case 21: + return $this->getVersionCreatedBy(); + break; + default: + return null; + break; + } // switch() + } + + /** + * Exports the object as an array. + * + * You can specify the key type of the array by passing one of the class + * type constants. + * + * @param string $keyType (optional) One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE. + * @param array $alreadyDumpedObjects List of objects to skip to avoid recursion + * @param boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE. + * + * @return array an associative array containing the field names (as keys) and field values + */ + public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false) + { + if (isset($alreadyDumpedObjects['OrderVersion'][serialize($this->getPrimaryKey())])) { + return '*RECURSION*'; + } + $alreadyDumpedObjects['OrderVersion'][serialize($this->getPrimaryKey())] = true; + $keys = OrderVersionTableMap::getFieldNames($keyType); + $result = array( + $keys[0] => $this->getId(), + $keys[1] => $this->getRef(), + $keys[2] => $this->getCustomerId(), + $keys[3] => $this->getInvoiceOrderAddressId(), + $keys[4] => $this->getDeliveryOrderAddressId(), + $keys[5] => $this->getInvoiceDate(), + $keys[6] => $this->getCurrencyId(), + $keys[7] => $this->getCurrencyRate(), + $keys[8] => $this->getTransactionRef(), + $keys[9] => $this->getDeliveryRef(), + $keys[10] => $this->getInvoiceRef(), + $keys[11] => $this->getDiscount(), + $keys[12] => $this->getPostage(), + $keys[13] => $this->getPaymentModuleId(), + $keys[14] => $this->getDeliveryModuleId(), + $keys[15] => $this->getStatusId(), + $keys[16] => $this->getLangId(), + $keys[17] => $this->getCreatedAt(), + $keys[18] => $this->getUpdatedAt(), + $keys[19] => $this->getVersion(), + $keys[20] => $this->getVersionCreatedAt(), + $keys[21] => $this->getVersionCreatedBy(), + ); + $virtualColumns = $this->virtualColumns; + foreach ($virtualColumns as $key => $virtualColumn) { + $result[$key] = $virtualColumn; + } + + if ($includeForeignObjects) { + if (null !== $this->aOrder) { + $result['Order'] = $this->aOrder->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); + } + } + + return $result; + } + + /** + * Sets a field from the object by name passed in as a string. + * + * @param string $name + * @param mixed $value field value + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @return void + */ + public function setByName($name, $value, $type = TableMap::TYPE_PHPNAME) + { + $pos = OrderVersionTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + + return $this->setByPosition($pos, $value); + } + + /** + * Sets a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @param mixed $value field value + * @return void + */ + public function setByPosition($pos, $value) + { + switch ($pos) { + case 0: + $this->setId($value); + break; + case 1: + $this->setRef($value); + break; + case 2: + $this->setCustomerId($value); + break; + case 3: + $this->setInvoiceOrderAddressId($value); + break; + case 4: + $this->setDeliveryOrderAddressId($value); + break; + case 5: + $this->setInvoiceDate($value); + break; + case 6: + $this->setCurrencyId($value); + break; + case 7: + $this->setCurrencyRate($value); + break; + case 8: + $this->setTransactionRef($value); + break; + case 9: + $this->setDeliveryRef($value); + break; + case 10: + $this->setInvoiceRef($value); + break; + case 11: + $this->setDiscount($value); + break; + case 12: + $this->setPostage($value); + break; + case 13: + $this->setPaymentModuleId($value); + break; + case 14: + $this->setDeliveryModuleId($value); + break; + case 15: + $this->setStatusId($value); + break; + case 16: + $this->setLangId($value); + break; + case 17: + $this->setCreatedAt($value); + break; + case 18: + $this->setUpdatedAt($value); + break; + case 19: + $this->setVersion($value); + break; + case 20: + $this->setVersionCreatedAt($value); + break; + case 21: + $this->setVersionCreatedBy($value); + break; + } // switch() + } + + /** + * Populates the object using an array. + * + * This is particularly useful when populating an object from one of the + * request arrays (e.g. $_POST). This method goes through the column + * names, checking to see whether a matching key exists in populated + * array. If so the setByName() method is called for that column. + * + * You can specify the key type of the array by additionally passing one + * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * The default key type is the column's TableMap::TYPE_PHPNAME. + * + * @param array $arr An array to populate the object from. + * @param string $keyType The type of keys the array uses. + * @return void + */ + public function fromArray($arr, $keyType = TableMap::TYPE_PHPNAME) + { + $keys = OrderVersionTableMap::getFieldNames($keyType); + + if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]); + if (array_key_exists($keys[1], $arr)) $this->setRef($arr[$keys[1]]); + if (array_key_exists($keys[2], $arr)) $this->setCustomerId($arr[$keys[2]]); + if (array_key_exists($keys[3], $arr)) $this->setInvoiceOrderAddressId($arr[$keys[3]]); + if (array_key_exists($keys[4], $arr)) $this->setDeliveryOrderAddressId($arr[$keys[4]]); + if (array_key_exists($keys[5], $arr)) $this->setInvoiceDate($arr[$keys[5]]); + if (array_key_exists($keys[6], $arr)) $this->setCurrencyId($arr[$keys[6]]); + if (array_key_exists($keys[7], $arr)) $this->setCurrencyRate($arr[$keys[7]]); + if (array_key_exists($keys[8], $arr)) $this->setTransactionRef($arr[$keys[8]]); + if (array_key_exists($keys[9], $arr)) $this->setDeliveryRef($arr[$keys[9]]); + if (array_key_exists($keys[10], $arr)) $this->setInvoiceRef($arr[$keys[10]]); + if (array_key_exists($keys[11], $arr)) $this->setDiscount($arr[$keys[11]]); + if (array_key_exists($keys[12], $arr)) $this->setPostage($arr[$keys[12]]); + if (array_key_exists($keys[13], $arr)) $this->setPaymentModuleId($arr[$keys[13]]); + if (array_key_exists($keys[14], $arr)) $this->setDeliveryModuleId($arr[$keys[14]]); + if (array_key_exists($keys[15], $arr)) $this->setStatusId($arr[$keys[15]]); + if (array_key_exists($keys[16], $arr)) $this->setLangId($arr[$keys[16]]); + if (array_key_exists($keys[17], $arr)) $this->setCreatedAt($arr[$keys[17]]); + if (array_key_exists($keys[18], $arr)) $this->setUpdatedAt($arr[$keys[18]]); + if (array_key_exists($keys[19], $arr)) $this->setVersion($arr[$keys[19]]); + if (array_key_exists($keys[20], $arr)) $this->setVersionCreatedAt($arr[$keys[20]]); + if (array_key_exists($keys[21], $arr)) $this->setVersionCreatedBy($arr[$keys[21]]); + } + + /** + * Build a Criteria object containing the values of all modified columns in this object. + * + * @return Criteria The Criteria object containing all modified values. + */ + public function buildCriteria() + { + $criteria = new Criteria(OrderVersionTableMap::DATABASE_NAME); + + if ($this->isColumnModified(OrderVersionTableMap::ID)) $criteria->add(OrderVersionTableMap::ID, $this->id); + if ($this->isColumnModified(OrderVersionTableMap::REF)) $criteria->add(OrderVersionTableMap::REF, $this->ref); + if ($this->isColumnModified(OrderVersionTableMap::CUSTOMER_ID)) $criteria->add(OrderVersionTableMap::CUSTOMER_ID, $this->customer_id); + if ($this->isColumnModified(OrderVersionTableMap::INVOICE_ORDER_ADDRESS_ID)) $criteria->add(OrderVersionTableMap::INVOICE_ORDER_ADDRESS_ID, $this->invoice_order_address_id); + if ($this->isColumnModified(OrderVersionTableMap::DELIVERY_ORDER_ADDRESS_ID)) $criteria->add(OrderVersionTableMap::DELIVERY_ORDER_ADDRESS_ID, $this->delivery_order_address_id); + if ($this->isColumnModified(OrderVersionTableMap::INVOICE_DATE)) $criteria->add(OrderVersionTableMap::INVOICE_DATE, $this->invoice_date); + if ($this->isColumnModified(OrderVersionTableMap::CURRENCY_ID)) $criteria->add(OrderVersionTableMap::CURRENCY_ID, $this->currency_id); + if ($this->isColumnModified(OrderVersionTableMap::CURRENCY_RATE)) $criteria->add(OrderVersionTableMap::CURRENCY_RATE, $this->currency_rate); + if ($this->isColumnModified(OrderVersionTableMap::TRANSACTION_REF)) $criteria->add(OrderVersionTableMap::TRANSACTION_REF, $this->transaction_ref); + if ($this->isColumnModified(OrderVersionTableMap::DELIVERY_REF)) $criteria->add(OrderVersionTableMap::DELIVERY_REF, $this->delivery_ref); + if ($this->isColumnModified(OrderVersionTableMap::INVOICE_REF)) $criteria->add(OrderVersionTableMap::INVOICE_REF, $this->invoice_ref); + if ($this->isColumnModified(OrderVersionTableMap::DISCOUNT)) $criteria->add(OrderVersionTableMap::DISCOUNT, $this->discount); + if ($this->isColumnModified(OrderVersionTableMap::POSTAGE)) $criteria->add(OrderVersionTableMap::POSTAGE, $this->postage); + if ($this->isColumnModified(OrderVersionTableMap::PAYMENT_MODULE_ID)) $criteria->add(OrderVersionTableMap::PAYMENT_MODULE_ID, $this->payment_module_id); + if ($this->isColumnModified(OrderVersionTableMap::DELIVERY_MODULE_ID)) $criteria->add(OrderVersionTableMap::DELIVERY_MODULE_ID, $this->delivery_module_id); + if ($this->isColumnModified(OrderVersionTableMap::STATUS_ID)) $criteria->add(OrderVersionTableMap::STATUS_ID, $this->status_id); + if ($this->isColumnModified(OrderVersionTableMap::LANG_ID)) $criteria->add(OrderVersionTableMap::LANG_ID, $this->lang_id); + if ($this->isColumnModified(OrderVersionTableMap::CREATED_AT)) $criteria->add(OrderVersionTableMap::CREATED_AT, $this->created_at); + if ($this->isColumnModified(OrderVersionTableMap::UPDATED_AT)) $criteria->add(OrderVersionTableMap::UPDATED_AT, $this->updated_at); + if ($this->isColumnModified(OrderVersionTableMap::VERSION)) $criteria->add(OrderVersionTableMap::VERSION, $this->version); + if ($this->isColumnModified(OrderVersionTableMap::VERSION_CREATED_AT)) $criteria->add(OrderVersionTableMap::VERSION_CREATED_AT, $this->version_created_at); + if ($this->isColumnModified(OrderVersionTableMap::VERSION_CREATED_BY)) $criteria->add(OrderVersionTableMap::VERSION_CREATED_BY, $this->version_created_by); + + return $criteria; + } + + /** + * Builds a Criteria object containing the primary key for this object. + * + * Unlike buildCriteria() this method includes the primary key values regardless + * of whether or not they have been modified. + * + * @return Criteria The Criteria object containing value(s) for primary key(s). + */ + public function buildPkeyCriteria() + { + $criteria = new Criteria(OrderVersionTableMap::DATABASE_NAME); + $criteria->add(OrderVersionTableMap::ID, $this->id); + $criteria->add(OrderVersionTableMap::VERSION, $this->version); + + return $criteria; + } + + /** + * Returns the composite primary key for this object. + * The array elements will be in same order as specified in XML. + * @return array + */ + public function getPrimaryKey() + { + $pks = array(); + $pks[0] = $this->getId(); + $pks[1] = $this->getVersion(); + + return $pks; + } + + /** + * Set the [composite] primary key. + * + * @param array $keys The elements of the composite key (order must match the order in XML file). + * @return void + */ + public function setPrimaryKey($keys) + { + $this->setId($keys[0]); + $this->setVersion($keys[1]); + } + + /** + * Returns true if the primary key for this object is null. + * @return boolean + */ + public function isPrimaryKeyNull() + { + + return (null === $this->getId()) && (null === $this->getVersion()); + } + + /** + * Sets contents of passed object to values from current object. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param object $copyObj An object of \Thelia\Model\OrderVersion (or compatible) type. + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new. + * @throws PropelException + */ + public function copyInto($copyObj, $deepCopy = false, $makeNew = true) + { + $copyObj->setId($this->getId()); + $copyObj->setRef($this->getRef()); + $copyObj->setCustomerId($this->getCustomerId()); + $copyObj->setInvoiceOrderAddressId($this->getInvoiceOrderAddressId()); + $copyObj->setDeliveryOrderAddressId($this->getDeliveryOrderAddressId()); + $copyObj->setInvoiceDate($this->getInvoiceDate()); + $copyObj->setCurrencyId($this->getCurrencyId()); + $copyObj->setCurrencyRate($this->getCurrencyRate()); + $copyObj->setTransactionRef($this->getTransactionRef()); + $copyObj->setDeliveryRef($this->getDeliveryRef()); + $copyObj->setInvoiceRef($this->getInvoiceRef()); + $copyObj->setDiscount($this->getDiscount()); + $copyObj->setPostage($this->getPostage()); + $copyObj->setPaymentModuleId($this->getPaymentModuleId()); + $copyObj->setDeliveryModuleId($this->getDeliveryModuleId()); + $copyObj->setStatusId($this->getStatusId()); + $copyObj->setLangId($this->getLangId()); + $copyObj->setCreatedAt($this->getCreatedAt()); + $copyObj->setUpdatedAt($this->getUpdatedAt()); + $copyObj->setVersion($this->getVersion()); + $copyObj->setVersionCreatedAt($this->getVersionCreatedAt()); + $copyObj->setVersionCreatedBy($this->getVersionCreatedBy()); + if ($makeNew) { + $copyObj->setNew(true); + } + } + + /** + * Makes a copy of this object that will be inserted as a new row in table when saved. + * It creates a new object filling in the simple attributes, but skipping any primary + * keys that are defined for the table. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @return \Thelia\Model\OrderVersion Clone of current object. + * @throws PropelException + */ + public function copy($deepCopy = false) + { + // we use get_class(), because this might be a subclass + $clazz = get_class($this); + $copyObj = new $clazz(); + $this->copyInto($copyObj, $deepCopy); + + return $copyObj; + } + + /** + * Declares an association between this object and a ChildOrder object. + * + * @param ChildOrder $v + * @return \Thelia\Model\OrderVersion The current object (for fluent API support) + * @throws PropelException + */ + public function setOrder(ChildOrder $v = null) + { + if ($v === null) { + $this->setId(NULL); + } else { + $this->setId($v->getId()); + } + + $this->aOrder = $v; + + // Add binding for other direction of this n:n relationship. + // If this object has already been added to the ChildOrder object, it will not be re-added. + if ($v !== null) { + $v->addOrderVersion($this); + } + + + return $this; + } + + + /** + * Get the associated ChildOrder object + * + * @param ConnectionInterface $con Optional Connection object. + * @return ChildOrder The associated ChildOrder object. + * @throws PropelException + */ + public function getOrder(ConnectionInterface $con = null) + { + if ($this->aOrder === null && ($this->id !== null)) { + $this->aOrder = ChildOrderQuery::create()->findPk($this->id, $con); + /* The following can be used additionally to + guarantee the related object contains a reference + to this object. This level of coupling may, however, be + undesirable since it could result in an only partially populated collection + in the referenced object. + $this->aOrder->addOrderVersions($this); + */ + } + + return $this->aOrder; + } + + /** + * Clears the current object and sets all attributes to their default values + */ + public function clear() + { + $this->id = null; + $this->ref = null; + $this->customer_id = null; + $this->invoice_order_address_id = null; + $this->delivery_order_address_id = null; + $this->invoice_date = null; + $this->currency_id = null; + $this->currency_rate = null; + $this->transaction_ref = null; + $this->delivery_ref = null; + $this->invoice_ref = null; + $this->discount = null; + $this->postage = null; + $this->payment_module_id = null; + $this->delivery_module_id = null; + $this->status_id = null; + $this->lang_id = null; + $this->created_at = null; + $this->updated_at = null; + $this->version = null; + $this->version_created_at = null; + $this->version_created_by = null; + $this->alreadyInSave = false; + $this->clearAllReferences(); + $this->applyDefaultValues(); + $this->resetModified(); + $this->setNew(true); + $this->setDeleted(false); + } + + /** + * Resets all references to other model objects or collections of model objects. + * + * This method is a user-space workaround for PHP's inability to garbage collect + * objects with circular references (even in PHP 5.3). This is currently necessary + * when using Propel in certain daemon or large-volume/high-memory operations. + * + * @param boolean $deep Whether to also clear the references on all referrer objects. + */ + public function clearAllReferences($deep = false) + { + if ($deep) { + } // if ($deep) + + $this->aOrder = null; + } + + /** + * Return the string representation of this object + * + * @return string + */ + public function __toString() + { + return (string) $this->exportTo(OrderVersionTableMap::DEFAULT_STRING_FORMAT); + } + + /** + * Code to be run before persisting the object + * @param ConnectionInterface $con + * @return boolean + */ + public function preSave(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after persisting the object + * @param ConnectionInterface $con + */ + public function postSave(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before inserting to database + * @param ConnectionInterface $con + * @return boolean + */ + public function preInsert(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after inserting to database + * @param ConnectionInterface $con + */ + public function postInsert(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before updating the object in database + * @param ConnectionInterface $con + * @return boolean + */ + public function preUpdate(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after updating the object in database + * @param ConnectionInterface $con + */ + public function postUpdate(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before deleting the object in database + * @param ConnectionInterface $con + * @return boolean + */ + public function preDelete(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after deleting the object in database + * @param ConnectionInterface $con + */ + public function postDelete(ConnectionInterface $con = null) + { + + } + + + /** + * Derived method to catches calls to undefined methods. + * + * Provides magic import/export method support (fromXML()/toXML(), fromYAML()/toYAML(), etc.). + * Allows to define default __call() behavior if you overwrite __call() + * + * @param string $name + * @param mixed $params + * + * @return array|string + */ + public function __call($name, $params) + { + if (0 === strpos($name, 'get')) { + $virtualColumn = substr($name, 3); + if ($this->hasVirtualColumn($virtualColumn)) { + return $this->getVirtualColumn($virtualColumn); + } + + $virtualColumn = lcfirst($virtualColumn); + if ($this->hasVirtualColumn($virtualColumn)) { + return $this->getVirtualColumn($virtualColumn); + } + } + + if (0 === strpos($name, 'from')) { + $format = substr($name, 4); + + return $this->importFrom($format, reset($params)); + } + + if (0 === strpos($name, 'to')) { + $format = substr($name, 2); + $includeLazyLoadColumns = isset($params[0]) ? $params[0] : true; + + return $this->exportTo($format, $includeLazyLoadColumns); + } + + throw new BadMethodCallException(sprintf('Call to undefined method: %s.', $name)); + } + +} diff --git a/core/lib/Thelia/Model/Base/OrderVersionQuery.php b/core/lib/Thelia/Model/Base/OrderVersionQuery.php new file mode 100644 index 000000000..5d4dd6211 --- /dev/null +++ b/core/lib/Thelia/Model/Base/OrderVersionQuery.php @@ -0,0 +1,1335 @@ +setModelAlias($modelAlias); + } + if ($criteria instanceof Criteria) { + $query->mergeWith($criteria); + } + + return $query; + } + + /** + * Find object by primary key. + * Propel uses the instance pool to skip the database if the object exists. + * Go fast if the query is untouched. + * + * + * $obj = $c->findPk(array(12, 34), $con); + * + * + * @param array[$id, $version] $key Primary key to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ChildOrderVersion|array|mixed the result, formatted by the current formatter + */ + public function findPk($key, $con = null) + { + if ($key === null) { + return null; + } + if ((null !== ($obj = OrderVersionTableMap::getInstanceFromPool(serialize(array((string) $key[0], (string) $key[1]))))) && !$this->formatter) { + // the object is already in the instance pool + return $obj; + } + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(OrderVersionTableMap::DATABASE_NAME); + } + $this->basePreSelect($con); + if ($this->formatter || $this->modelAlias || $this->with || $this->select + || $this->selectColumns || $this->asColumns || $this->selectModifiers + || $this->map || $this->having || $this->joins) { + return $this->findPkComplex($key, $con); + } else { + return $this->findPkSimple($key, $con); + } + } + + /** + * Find object by primary key using raw SQL to go fast. + * Bypass doSelect() and the object formatter by using generated code. + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con A connection object + * + * @return ChildOrderVersion A model object, or null if the key is not found + */ + protected function findPkSimple($key, $con) + { + $sql = 'SELECT `ID`, `REF`, `CUSTOMER_ID`, `INVOICE_ORDER_ADDRESS_ID`, `DELIVERY_ORDER_ADDRESS_ID`, `INVOICE_DATE`, `CURRENCY_ID`, `CURRENCY_RATE`, `TRANSACTION_REF`, `DELIVERY_REF`, `INVOICE_REF`, `DISCOUNT`, `POSTAGE`, `PAYMENT_MODULE_ID`, `DELIVERY_MODULE_ID`, `STATUS_ID`, `LANG_ID`, `CREATED_AT`, `UPDATED_AT`, `VERSION`, `VERSION_CREATED_AT`, `VERSION_CREATED_BY` FROM `order_version` WHERE `ID` = :p0 AND `VERSION` = :p1'; + try { + $stmt = $con->prepare($sql); + $stmt->bindValue(':p0', $key[0], PDO::PARAM_INT); + $stmt->bindValue(':p1', $key[1], PDO::PARAM_INT); + $stmt->execute(); + } catch (Exception $e) { + Propel::log($e->getMessage(), Propel::LOG_ERR); + throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), 0, $e); + } + $obj = null; + if ($row = $stmt->fetch(\PDO::FETCH_NUM)) { + $obj = new ChildOrderVersion(); + $obj->hydrate($row); + OrderVersionTableMap::addInstanceToPool($obj, serialize(array((string) $key[0], (string) $key[1]))); + } + $stmt->closeCursor(); + + return $obj; + } + + /** + * Find object by primary key. + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con A connection object + * + * @return ChildOrderVersion|array|mixed the result, formatted by the current formatter + */ + protected function findPkComplex($key, $con) + { + // As the query uses a PK condition, no limit(1) is necessary. + $criteria = $this->isKeepQuery() ? clone $this : $this; + $dataFetcher = $criteria + ->filterByPrimaryKey($key) + ->doSelect($con); + + return $criteria->getFormatter()->init($criteria)->formatOne($dataFetcher); + } + + /** + * Find objects by primary key + * + * $objs = $c->findPks(array(array(12, 56), array(832, 123), array(123, 456)), $con); + * + * @param array $keys Primary keys to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ObjectCollection|array|mixed the list of results, formatted by the current formatter + */ + public function findPks($keys, $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getReadConnection($this->getDbName()); + } + $this->basePreSelect($con); + $criteria = $this->isKeepQuery() ? clone $this : $this; + $dataFetcher = $criteria + ->filterByPrimaryKeys($keys) + ->doSelect($con); + + return $criteria->getFormatter()->init($criteria)->format($dataFetcher); + } + + /** + * Filter the query by primary key + * + * @param mixed $key Primary key to use for the query + * + * @return ChildOrderVersionQuery The current query, for fluid interface + */ + public function filterByPrimaryKey($key) + { + $this->addUsingAlias(OrderVersionTableMap::ID, $key[0], Criteria::EQUAL); + $this->addUsingAlias(OrderVersionTableMap::VERSION, $key[1], Criteria::EQUAL); + + return $this; + } + + /** + * Filter the query by a list of primary keys + * + * @param array $keys The list of primary key to use for the query + * + * @return ChildOrderVersionQuery The current query, for fluid interface + */ + public function filterByPrimaryKeys($keys) + { + if (empty($keys)) { + return $this->add(null, '1<>1', Criteria::CUSTOM); + } + foreach ($keys as $key) { + $cton0 = $this->getNewCriterion(OrderVersionTableMap::ID, $key[0], Criteria::EQUAL); + $cton1 = $this->getNewCriterion(OrderVersionTableMap::VERSION, $key[1], Criteria::EQUAL); + $cton0->addAnd($cton1); + $this->addOr($cton0); + } + + return $this; + } + + /** + * Filter the query on the id column + * + * Example usage: + * + * $query->filterById(1234); // WHERE id = 1234 + * $query->filterById(array(12, 34)); // WHERE id IN (12, 34) + * $query->filterById(array('min' => 12)); // WHERE id > 12 + * + * + * @see filterByOrder() + * + * @param mixed $id 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 ChildOrderVersionQuery The current query, for fluid interface + */ + public function filterById($id = null, $comparison = null) + { + if (is_array($id)) { + $useMinMax = false; + if (isset($id['min'])) { + $this->addUsingAlias(OrderVersionTableMap::ID, $id['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($id['max'])) { + $this->addUsingAlias(OrderVersionTableMap::ID, $id['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(OrderVersionTableMap::ID, $id, $comparison); + } + + /** + * Filter the query on the ref column + * + * Example usage: + * + * $query->filterByRef('fooValue'); // WHERE ref = 'fooValue' + * $query->filterByRef('%fooValue%'); // WHERE ref LIKE '%fooValue%' + * + * + * @param string $ref 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 ChildOrderVersionQuery The current query, for fluid interface + */ + public function filterByRef($ref = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($ref)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $ref)) { + $ref = str_replace('*', '%', $ref); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(OrderVersionTableMap::REF, $ref, $comparison); + } + + /** + * Filter the query on the customer_id column + * + * Example usage: + * + * $query->filterByCustomerId(1234); // WHERE customer_id = 1234 + * $query->filterByCustomerId(array(12, 34)); // WHERE customer_id IN (12, 34) + * $query->filterByCustomerId(array('min' => 12)); // WHERE customer_id > 12 + * + * + * @param mixed $customerId 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 ChildOrderVersionQuery The current query, for fluid interface + */ + public function filterByCustomerId($customerId = null, $comparison = null) + { + if (is_array($customerId)) { + $useMinMax = false; + if (isset($customerId['min'])) { + $this->addUsingAlias(OrderVersionTableMap::CUSTOMER_ID, $customerId['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($customerId['max'])) { + $this->addUsingAlias(OrderVersionTableMap::CUSTOMER_ID, $customerId['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(OrderVersionTableMap::CUSTOMER_ID, $customerId, $comparison); + } + + /** + * Filter the query on the invoice_order_address_id column + * + * Example usage: + * + * $query->filterByInvoiceOrderAddressId(1234); // WHERE invoice_order_address_id = 1234 + * $query->filterByInvoiceOrderAddressId(array(12, 34)); // WHERE invoice_order_address_id IN (12, 34) + * $query->filterByInvoiceOrderAddressId(array('min' => 12)); // WHERE invoice_order_address_id > 12 + * + * + * @param mixed $invoiceOrderAddressId 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 ChildOrderVersionQuery The current query, for fluid interface + */ + public function filterByInvoiceOrderAddressId($invoiceOrderAddressId = null, $comparison = null) + { + if (is_array($invoiceOrderAddressId)) { + $useMinMax = false; + if (isset($invoiceOrderAddressId['min'])) { + $this->addUsingAlias(OrderVersionTableMap::INVOICE_ORDER_ADDRESS_ID, $invoiceOrderAddressId['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($invoiceOrderAddressId['max'])) { + $this->addUsingAlias(OrderVersionTableMap::INVOICE_ORDER_ADDRESS_ID, $invoiceOrderAddressId['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(OrderVersionTableMap::INVOICE_ORDER_ADDRESS_ID, $invoiceOrderAddressId, $comparison); + } + + /** + * Filter the query on the delivery_order_address_id column + * + * Example usage: + * + * $query->filterByDeliveryOrderAddressId(1234); // WHERE delivery_order_address_id = 1234 + * $query->filterByDeliveryOrderAddressId(array(12, 34)); // WHERE delivery_order_address_id IN (12, 34) + * $query->filterByDeliveryOrderAddressId(array('min' => 12)); // WHERE delivery_order_address_id > 12 + * + * + * @param mixed $deliveryOrderAddressId 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 ChildOrderVersionQuery The current query, for fluid interface + */ + public function filterByDeliveryOrderAddressId($deliveryOrderAddressId = null, $comparison = null) + { + if (is_array($deliveryOrderAddressId)) { + $useMinMax = false; + if (isset($deliveryOrderAddressId['min'])) { + $this->addUsingAlias(OrderVersionTableMap::DELIVERY_ORDER_ADDRESS_ID, $deliveryOrderAddressId['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($deliveryOrderAddressId['max'])) { + $this->addUsingAlias(OrderVersionTableMap::DELIVERY_ORDER_ADDRESS_ID, $deliveryOrderAddressId['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(OrderVersionTableMap::DELIVERY_ORDER_ADDRESS_ID, $deliveryOrderAddressId, $comparison); + } + + /** + * Filter the query on the invoice_date column + * + * Example usage: + * + * $query->filterByInvoiceDate('2011-03-14'); // WHERE invoice_date = '2011-03-14' + * $query->filterByInvoiceDate('now'); // WHERE invoice_date = '2011-03-14' + * $query->filterByInvoiceDate(array('max' => 'yesterday')); // WHERE invoice_date > '2011-03-13' + * + * + * @param mixed $invoiceDate The value to use as filter. + * Values can be integers (unix timestamps), DateTime objects, or strings. + * Empty strings are treated as NULL. + * 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 ChildOrderVersionQuery The current query, for fluid interface + */ + public function filterByInvoiceDate($invoiceDate = null, $comparison = null) + { + if (is_array($invoiceDate)) { + $useMinMax = false; + if (isset($invoiceDate['min'])) { + $this->addUsingAlias(OrderVersionTableMap::INVOICE_DATE, $invoiceDate['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($invoiceDate['max'])) { + $this->addUsingAlias(OrderVersionTableMap::INVOICE_DATE, $invoiceDate['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(OrderVersionTableMap::INVOICE_DATE, $invoiceDate, $comparison); + } + + /** + * Filter the query on the currency_id column + * + * Example usage: + * + * $query->filterByCurrencyId(1234); // WHERE currency_id = 1234 + * $query->filterByCurrencyId(array(12, 34)); // WHERE currency_id IN (12, 34) + * $query->filterByCurrencyId(array('min' => 12)); // WHERE currency_id > 12 + * + * + * @param mixed $currencyId 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 ChildOrderVersionQuery The current query, for fluid interface + */ + public function filterByCurrencyId($currencyId = null, $comparison = null) + { + if (is_array($currencyId)) { + $useMinMax = false; + if (isset($currencyId['min'])) { + $this->addUsingAlias(OrderVersionTableMap::CURRENCY_ID, $currencyId['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($currencyId['max'])) { + $this->addUsingAlias(OrderVersionTableMap::CURRENCY_ID, $currencyId['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(OrderVersionTableMap::CURRENCY_ID, $currencyId, $comparison); + } + + /** + * Filter the query on the currency_rate column + * + * Example usage: + * + * $query->filterByCurrencyRate(1234); // WHERE currency_rate = 1234 + * $query->filterByCurrencyRate(array(12, 34)); // WHERE currency_rate IN (12, 34) + * $query->filterByCurrencyRate(array('min' => 12)); // WHERE currency_rate > 12 + * + * + * @param mixed $currencyRate 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 ChildOrderVersionQuery The current query, for fluid interface + */ + public function filterByCurrencyRate($currencyRate = null, $comparison = null) + { + if (is_array($currencyRate)) { + $useMinMax = false; + if (isset($currencyRate['min'])) { + $this->addUsingAlias(OrderVersionTableMap::CURRENCY_RATE, $currencyRate['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($currencyRate['max'])) { + $this->addUsingAlias(OrderVersionTableMap::CURRENCY_RATE, $currencyRate['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(OrderVersionTableMap::CURRENCY_RATE, $currencyRate, $comparison); + } + + /** + * Filter the query on the transaction_ref column + * + * Example usage: + * + * $query->filterByTransactionRef('fooValue'); // WHERE transaction_ref = 'fooValue' + * $query->filterByTransactionRef('%fooValue%'); // WHERE transaction_ref LIKE '%fooValue%' + * + * + * @param string $transactionRef 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 ChildOrderVersionQuery The current query, for fluid interface + */ + public function filterByTransactionRef($transactionRef = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($transactionRef)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $transactionRef)) { + $transactionRef = str_replace('*', '%', $transactionRef); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(OrderVersionTableMap::TRANSACTION_REF, $transactionRef, $comparison); + } + + /** + * Filter the query on the delivery_ref column + * + * Example usage: + * + * $query->filterByDeliveryRef('fooValue'); // WHERE delivery_ref = 'fooValue' + * $query->filterByDeliveryRef('%fooValue%'); // WHERE delivery_ref LIKE '%fooValue%' + * + * + * @param string $deliveryRef 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 ChildOrderVersionQuery The current query, for fluid interface + */ + public function filterByDeliveryRef($deliveryRef = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($deliveryRef)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $deliveryRef)) { + $deliveryRef = str_replace('*', '%', $deliveryRef); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(OrderVersionTableMap::DELIVERY_REF, $deliveryRef, $comparison); + } + + /** + * Filter the query on the invoice_ref column + * + * Example usage: + * + * $query->filterByInvoiceRef('fooValue'); // WHERE invoice_ref = 'fooValue' + * $query->filterByInvoiceRef('%fooValue%'); // WHERE invoice_ref LIKE '%fooValue%' + * + * + * @param string $invoiceRef 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 ChildOrderVersionQuery The current query, for fluid interface + */ + public function filterByInvoiceRef($invoiceRef = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($invoiceRef)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $invoiceRef)) { + $invoiceRef = str_replace('*', '%', $invoiceRef); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(OrderVersionTableMap::INVOICE_REF, $invoiceRef, $comparison); + } + + /** + * Filter the query on the discount column + * + * Example usage: + * + * $query->filterByDiscount(1234); // WHERE discount = 1234 + * $query->filterByDiscount(array(12, 34)); // WHERE discount IN (12, 34) + * $query->filterByDiscount(array('min' => 12)); // WHERE discount > 12 + * + * + * @param mixed $discount 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 ChildOrderVersionQuery The current query, for fluid interface + */ + public function filterByDiscount($discount = null, $comparison = null) + { + if (is_array($discount)) { + $useMinMax = false; + if (isset($discount['min'])) { + $this->addUsingAlias(OrderVersionTableMap::DISCOUNT, $discount['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($discount['max'])) { + $this->addUsingAlias(OrderVersionTableMap::DISCOUNT, $discount['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(OrderVersionTableMap::DISCOUNT, $discount, $comparison); + } + + /** + * Filter the query on the postage column + * + * Example usage: + * + * $query->filterByPostage(1234); // WHERE postage = 1234 + * $query->filterByPostage(array(12, 34)); // WHERE postage IN (12, 34) + * $query->filterByPostage(array('min' => 12)); // WHERE postage > 12 + * + * + * @param mixed $postage 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 ChildOrderVersionQuery The current query, for fluid interface + */ + public function filterByPostage($postage = null, $comparison = null) + { + if (is_array($postage)) { + $useMinMax = false; + if (isset($postage['min'])) { + $this->addUsingAlias(OrderVersionTableMap::POSTAGE, $postage['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($postage['max'])) { + $this->addUsingAlias(OrderVersionTableMap::POSTAGE, $postage['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(OrderVersionTableMap::POSTAGE, $postage, $comparison); + } + + /** + * Filter the query on the payment_module_id column + * + * Example usage: + * + * $query->filterByPaymentModuleId(1234); // WHERE payment_module_id = 1234 + * $query->filterByPaymentModuleId(array(12, 34)); // WHERE payment_module_id IN (12, 34) + * $query->filterByPaymentModuleId(array('min' => 12)); // WHERE payment_module_id > 12 + * + * + * @param mixed $paymentModuleId 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 ChildOrderVersionQuery The current query, for fluid interface + */ + public function filterByPaymentModuleId($paymentModuleId = null, $comparison = null) + { + if (is_array($paymentModuleId)) { + $useMinMax = false; + if (isset($paymentModuleId['min'])) { + $this->addUsingAlias(OrderVersionTableMap::PAYMENT_MODULE_ID, $paymentModuleId['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($paymentModuleId['max'])) { + $this->addUsingAlias(OrderVersionTableMap::PAYMENT_MODULE_ID, $paymentModuleId['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(OrderVersionTableMap::PAYMENT_MODULE_ID, $paymentModuleId, $comparison); + } + + /** + * Filter the query on the delivery_module_id column + * + * Example usage: + * + * $query->filterByDeliveryModuleId(1234); // WHERE delivery_module_id = 1234 + * $query->filterByDeliveryModuleId(array(12, 34)); // WHERE delivery_module_id IN (12, 34) + * $query->filterByDeliveryModuleId(array('min' => 12)); // WHERE delivery_module_id > 12 + * + * + * @param mixed $deliveryModuleId 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 ChildOrderVersionQuery The current query, for fluid interface + */ + public function filterByDeliveryModuleId($deliveryModuleId = null, $comparison = null) + { + if (is_array($deliveryModuleId)) { + $useMinMax = false; + if (isset($deliveryModuleId['min'])) { + $this->addUsingAlias(OrderVersionTableMap::DELIVERY_MODULE_ID, $deliveryModuleId['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($deliveryModuleId['max'])) { + $this->addUsingAlias(OrderVersionTableMap::DELIVERY_MODULE_ID, $deliveryModuleId['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(OrderVersionTableMap::DELIVERY_MODULE_ID, $deliveryModuleId, $comparison); + } + + /** + * Filter the query on the status_id column + * + * Example usage: + * + * $query->filterByStatusId(1234); // WHERE status_id = 1234 + * $query->filterByStatusId(array(12, 34)); // WHERE status_id IN (12, 34) + * $query->filterByStatusId(array('min' => 12)); // WHERE status_id > 12 + * + * + * @param mixed $statusId 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 ChildOrderVersionQuery The current query, for fluid interface + */ + public function filterByStatusId($statusId = null, $comparison = null) + { + if (is_array($statusId)) { + $useMinMax = false; + if (isset($statusId['min'])) { + $this->addUsingAlias(OrderVersionTableMap::STATUS_ID, $statusId['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($statusId['max'])) { + $this->addUsingAlias(OrderVersionTableMap::STATUS_ID, $statusId['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(OrderVersionTableMap::STATUS_ID, $statusId, $comparison); + } + + /** + * Filter the query on the lang_id column + * + * Example usage: + * + * $query->filterByLangId(1234); // WHERE lang_id = 1234 + * $query->filterByLangId(array(12, 34)); // WHERE lang_id IN (12, 34) + * $query->filterByLangId(array('min' => 12)); // WHERE lang_id > 12 + * + * + * @param mixed $langId 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 ChildOrderVersionQuery The current query, for fluid interface + */ + public function filterByLangId($langId = null, $comparison = null) + { + if (is_array($langId)) { + $useMinMax = false; + if (isset($langId['min'])) { + $this->addUsingAlias(OrderVersionTableMap::LANG_ID, $langId['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($langId['max'])) { + $this->addUsingAlias(OrderVersionTableMap::LANG_ID, $langId['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(OrderVersionTableMap::LANG_ID, $langId, $comparison); + } + + /** + * Filter the query on the created_at column + * + * Example usage: + * + * $query->filterByCreatedAt('2011-03-14'); // WHERE created_at = '2011-03-14' + * $query->filterByCreatedAt('now'); // WHERE created_at = '2011-03-14' + * $query->filterByCreatedAt(array('max' => 'yesterday')); // WHERE created_at > '2011-03-13' + * + * + * @param mixed $createdAt The value to use as filter. + * Values can be integers (unix timestamps), DateTime objects, or strings. + * Empty strings are treated as NULL. + * 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 ChildOrderVersionQuery The current query, for fluid interface + */ + public function filterByCreatedAt($createdAt = null, $comparison = null) + { + if (is_array($createdAt)) { + $useMinMax = false; + if (isset($createdAt['min'])) { + $this->addUsingAlias(OrderVersionTableMap::CREATED_AT, $createdAt['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($createdAt['max'])) { + $this->addUsingAlias(OrderVersionTableMap::CREATED_AT, $createdAt['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(OrderVersionTableMap::CREATED_AT, $createdAt, $comparison); + } + + /** + * Filter the query on the updated_at column + * + * Example usage: + * + * $query->filterByUpdatedAt('2011-03-14'); // WHERE updated_at = '2011-03-14' + * $query->filterByUpdatedAt('now'); // WHERE updated_at = '2011-03-14' + * $query->filterByUpdatedAt(array('max' => 'yesterday')); // WHERE updated_at > '2011-03-13' + * + * + * @param mixed $updatedAt The value to use as filter. + * Values can be integers (unix timestamps), DateTime objects, or strings. + * Empty strings are treated as NULL. + * 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 ChildOrderVersionQuery The current query, for fluid interface + */ + public function filterByUpdatedAt($updatedAt = null, $comparison = null) + { + if (is_array($updatedAt)) { + $useMinMax = false; + if (isset($updatedAt['min'])) { + $this->addUsingAlias(OrderVersionTableMap::UPDATED_AT, $updatedAt['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($updatedAt['max'])) { + $this->addUsingAlias(OrderVersionTableMap::UPDATED_AT, $updatedAt['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(OrderVersionTableMap::UPDATED_AT, $updatedAt, $comparison); + } + + /** + * Filter the query on the version column + * + * Example usage: + * + * $query->filterByVersion(1234); // WHERE version = 1234 + * $query->filterByVersion(array(12, 34)); // WHERE version IN (12, 34) + * $query->filterByVersion(array('min' => 12)); // WHERE version > 12 + * + * + * @param mixed $version 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 ChildOrderVersionQuery The current query, for fluid interface + */ + public function filterByVersion($version = null, $comparison = null) + { + if (is_array($version)) { + $useMinMax = false; + if (isset($version['min'])) { + $this->addUsingAlias(OrderVersionTableMap::VERSION, $version['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($version['max'])) { + $this->addUsingAlias(OrderVersionTableMap::VERSION, $version['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(OrderVersionTableMap::VERSION, $version, $comparison); + } + + /** + * Filter the query on the version_created_at column + * + * Example usage: + * + * $query->filterByVersionCreatedAt('2011-03-14'); // WHERE version_created_at = '2011-03-14' + * $query->filterByVersionCreatedAt('now'); // WHERE version_created_at = '2011-03-14' + * $query->filterByVersionCreatedAt(array('max' => 'yesterday')); // WHERE version_created_at > '2011-03-13' + * + * + * @param mixed $versionCreatedAt The value to use as filter. + * Values can be integers (unix timestamps), DateTime objects, or strings. + * Empty strings are treated as NULL. + * 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 ChildOrderVersionQuery The current query, for fluid interface + */ + public function filterByVersionCreatedAt($versionCreatedAt = null, $comparison = null) + { + if (is_array($versionCreatedAt)) { + $useMinMax = false; + if (isset($versionCreatedAt['min'])) { + $this->addUsingAlias(OrderVersionTableMap::VERSION_CREATED_AT, $versionCreatedAt['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($versionCreatedAt['max'])) { + $this->addUsingAlias(OrderVersionTableMap::VERSION_CREATED_AT, $versionCreatedAt['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(OrderVersionTableMap::VERSION_CREATED_AT, $versionCreatedAt, $comparison); + } + + /** + * Filter the query on the version_created_by column + * + * Example usage: + * + * $query->filterByVersionCreatedBy('fooValue'); // WHERE version_created_by = 'fooValue' + * $query->filterByVersionCreatedBy('%fooValue%'); // WHERE version_created_by LIKE '%fooValue%' + * + * + * @param string $versionCreatedBy 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 ChildOrderVersionQuery The current query, for fluid interface + */ + public function filterByVersionCreatedBy($versionCreatedBy = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($versionCreatedBy)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $versionCreatedBy)) { + $versionCreatedBy = str_replace('*', '%', $versionCreatedBy); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(OrderVersionTableMap::VERSION_CREATED_BY, $versionCreatedBy, $comparison); + } + + /** + * Filter the query by a related \Thelia\Model\Order object + * + * @param \Thelia\Model\Order|ObjectCollection $order The related object(s) to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildOrderVersionQuery The current query, for fluid interface + */ + public function filterByOrder($order, $comparison = null) + { + if ($order instanceof \Thelia\Model\Order) { + return $this + ->addUsingAlias(OrderVersionTableMap::ID, $order->getId(), $comparison); + } elseif ($order instanceof ObjectCollection) { + if (null === $comparison) { + $comparison = Criteria::IN; + } + + return $this + ->addUsingAlias(OrderVersionTableMap::ID, $order->toKeyValue('PrimaryKey', 'Id'), $comparison); + } else { + throw new PropelException('filterByOrder() only accepts arguments of type \Thelia\Model\Order or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the Order relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildOrderVersionQuery The current query, for fluid interface + */ + public function joinOrder($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('Order'); + + // create a ModelJoin object for this join + $join = new ModelJoin(); + $join->setJoinType($joinType); + $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); + if ($previousJoin = $this->getPreviousJoin()) { + $join->setPreviousJoin($previousJoin); + } + + // add the ModelJoin to the current object + if ($relationAlias) { + $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); + $this->addJoinObject($join, $relationAlias); + } else { + $this->addJoinObject($join, 'Order'); + } + + return $this; + } + + /** + * Use the Order relation Order object + * + * @see useQuery() + * + * @param string $relationAlias optional alias for the relation, + * to be used as main alias in the secondary query + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return \Thelia\Model\OrderQuery A secondary query class using the current class as primary query + */ + public function useOrderQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + return $this + ->joinOrder($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'Order', '\Thelia\Model\OrderQuery'); + } + + /** + * Exclude object from result + * + * @param ChildOrderVersion $orderVersion Object to remove from the list of results + * + * @return ChildOrderVersionQuery The current query, for fluid interface + */ + public function prune($orderVersion = null) + { + if ($orderVersion) { + $this->addCond('pruneCond0', $this->getAliasedColName(OrderVersionTableMap::ID), $orderVersion->getId(), Criteria::NOT_EQUAL); + $this->addCond('pruneCond1', $this->getAliasedColName(OrderVersionTableMap::VERSION), $orderVersion->getVersion(), Criteria::NOT_EQUAL); + $this->combine(array('pruneCond0', 'pruneCond1'), Criteria::LOGICAL_OR); + } + + return $this; + } + + /** + * Deletes all rows from the order_version table. + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + */ + public function doDeleteAll(ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(OrderVersionTableMap::DATABASE_NAME); + } + $affectedRows = 0; // initialize var to track total num of affected rows + try { + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + $con->beginTransaction(); + $affectedRows += parent::doDeleteAll($con); + // Because this db requires some delete cascade/set null emulation, we have to + // clear the cached instance *after* the emulation has happened (since + // instances get re-added by the select statement contained therein). + OrderVersionTableMap::clearInstancePool(); + OrderVersionTableMap::clearRelatedInstancePool(); + + $con->commit(); + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + + return $affectedRows; + } + + /** + * Performs a DELETE on the database, given a ChildOrderVersion or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or ChildOrderVersion object or primary key or array of primary keys + * which is used to create the DELETE statement + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public function delete(ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(OrderVersionTableMap::DATABASE_NAME); + } + + $criteria = $this; + + // Set the correct dbName + $criteria->setDbName(OrderVersionTableMap::DATABASE_NAME); + + $affectedRows = 0; // initialize var to track total num of affected rows + + try { + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + $con->beginTransaction(); + + + OrderVersionTableMap::removeInstanceFromPool($criteria); + + $affectedRows += ModelCriteria::delete($con); + OrderVersionTableMap::clearRelatedInstancePool(); + $con->commit(); + + return $affectedRows; + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + } + +} // OrderVersionQuery diff --git a/core/lib/Thelia/Model/Map/OrderTableMap.php b/core/lib/Thelia/Model/Map/OrderTableMap.php index 2246af89c..a7324e414 100644 --- a/core/lib/Thelia/Model/Map/OrderTableMap.php +++ b/core/lib/Thelia/Model/Map/OrderTableMap.php @@ -58,7 +58,7 @@ class OrderTableMap extends TableMap /** * The total number of columns */ - const NUM_COLUMNS = 19; + const NUM_COLUMNS = 22; /** * The number of lazy-loaded columns @@ -68,7 +68,7 @@ class OrderTableMap extends TableMap /** * The number of columns to hydrate (NUM_COLUMNS - NUM_LAZY_LOAD_COLUMNS) */ - const NUM_HYDRATE_COLUMNS = 19; + const NUM_HYDRATE_COLUMNS = 22; /** * the column name for the ID field @@ -165,6 +165,21 @@ class OrderTableMap extends TableMap */ const UPDATED_AT = 'order.UPDATED_AT'; + /** + * the column name for the VERSION field + */ + const VERSION = 'order.VERSION'; + + /** + * the column name for the VERSION_CREATED_AT field + */ + const VERSION_CREATED_AT = 'order.VERSION_CREATED_AT'; + + /** + * the column name for the VERSION_CREATED_BY field + */ + const VERSION_CREATED_BY = 'order.VERSION_CREATED_BY'; + /** * The default string format for model objects of the related table */ @@ -177,12 +192,12 @@ class OrderTableMap extends TableMap * e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id' */ protected static $fieldNames = array ( - self::TYPE_PHPNAME => array('Id', 'Ref', 'CustomerId', 'InvoiceOrderAddressId', 'DeliveryOrderAddressId', 'InvoiceDate', 'CurrencyId', 'CurrencyRate', 'TransactionRef', 'DeliveryRef', 'InvoiceRef', 'Discount', 'Postage', 'PaymentModuleId', 'DeliveryModuleId', 'StatusId', 'LangId', 'CreatedAt', 'UpdatedAt', ), - self::TYPE_STUDLYPHPNAME => array('id', 'ref', 'customerId', 'invoiceOrderAddressId', 'deliveryOrderAddressId', 'invoiceDate', 'currencyId', 'currencyRate', 'transactionRef', 'deliveryRef', 'invoiceRef', 'discount', 'postage', 'paymentModuleId', 'deliveryModuleId', 'statusId', 'langId', 'createdAt', 'updatedAt', ), - self::TYPE_COLNAME => array(OrderTableMap::ID, OrderTableMap::REF, OrderTableMap::CUSTOMER_ID, OrderTableMap::INVOICE_ORDER_ADDRESS_ID, OrderTableMap::DELIVERY_ORDER_ADDRESS_ID, OrderTableMap::INVOICE_DATE, OrderTableMap::CURRENCY_ID, OrderTableMap::CURRENCY_RATE, OrderTableMap::TRANSACTION_REF, OrderTableMap::DELIVERY_REF, OrderTableMap::INVOICE_REF, OrderTableMap::DISCOUNT, OrderTableMap::POSTAGE, OrderTableMap::PAYMENT_MODULE_ID, OrderTableMap::DELIVERY_MODULE_ID, OrderTableMap::STATUS_ID, OrderTableMap::LANG_ID, OrderTableMap::CREATED_AT, OrderTableMap::UPDATED_AT, ), - self::TYPE_RAW_COLNAME => array('ID', 'REF', 'CUSTOMER_ID', 'INVOICE_ORDER_ADDRESS_ID', 'DELIVERY_ORDER_ADDRESS_ID', 'INVOICE_DATE', 'CURRENCY_ID', 'CURRENCY_RATE', 'TRANSACTION_REF', 'DELIVERY_REF', 'INVOICE_REF', 'DISCOUNT', 'POSTAGE', 'PAYMENT_MODULE_ID', 'DELIVERY_MODULE_ID', 'STATUS_ID', 'LANG_ID', 'CREATED_AT', 'UPDATED_AT', ), - self::TYPE_FIELDNAME => array('id', 'ref', 'customer_id', 'invoice_order_address_id', 'delivery_order_address_id', 'invoice_date', 'currency_id', 'currency_rate', 'transaction_ref', 'delivery_ref', 'invoice_ref', 'discount', 'postage', 'payment_module_id', 'delivery_module_id', 'status_id', 'lang_id', 'created_at', 'updated_at', ), - self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, ) + self::TYPE_PHPNAME => array('Id', 'Ref', 'CustomerId', 'InvoiceOrderAddressId', 'DeliveryOrderAddressId', 'InvoiceDate', 'CurrencyId', 'CurrencyRate', 'TransactionRef', 'DeliveryRef', 'InvoiceRef', 'Discount', 'Postage', 'PaymentModuleId', 'DeliveryModuleId', 'StatusId', 'LangId', 'CreatedAt', 'UpdatedAt', 'Version', 'VersionCreatedAt', 'VersionCreatedBy', ), + self::TYPE_STUDLYPHPNAME => array('id', 'ref', 'customerId', 'invoiceOrderAddressId', 'deliveryOrderAddressId', 'invoiceDate', 'currencyId', 'currencyRate', 'transactionRef', 'deliveryRef', 'invoiceRef', 'discount', 'postage', 'paymentModuleId', 'deliveryModuleId', 'statusId', 'langId', 'createdAt', 'updatedAt', 'version', 'versionCreatedAt', 'versionCreatedBy', ), + self::TYPE_COLNAME => array(OrderTableMap::ID, OrderTableMap::REF, OrderTableMap::CUSTOMER_ID, OrderTableMap::INVOICE_ORDER_ADDRESS_ID, OrderTableMap::DELIVERY_ORDER_ADDRESS_ID, OrderTableMap::INVOICE_DATE, OrderTableMap::CURRENCY_ID, OrderTableMap::CURRENCY_RATE, OrderTableMap::TRANSACTION_REF, OrderTableMap::DELIVERY_REF, OrderTableMap::INVOICE_REF, OrderTableMap::DISCOUNT, OrderTableMap::POSTAGE, OrderTableMap::PAYMENT_MODULE_ID, OrderTableMap::DELIVERY_MODULE_ID, OrderTableMap::STATUS_ID, OrderTableMap::LANG_ID, OrderTableMap::CREATED_AT, OrderTableMap::UPDATED_AT, OrderTableMap::VERSION, OrderTableMap::VERSION_CREATED_AT, OrderTableMap::VERSION_CREATED_BY, ), + self::TYPE_RAW_COLNAME => array('ID', 'REF', 'CUSTOMER_ID', 'INVOICE_ORDER_ADDRESS_ID', 'DELIVERY_ORDER_ADDRESS_ID', 'INVOICE_DATE', 'CURRENCY_ID', 'CURRENCY_RATE', 'TRANSACTION_REF', 'DELIVERY_REF', 'INVOICE_REF', 'DISCOUNT', 'POSTAGE', 'PAYMENT_MODULE_ID', 'DELIVERY_MODULE_ID', 'STATUS_ID', 'LANG_ID', 'CREATED_AT', 'UPDATED_AT', 'VERSION', 'VERSION_CREATED_AT', 'VERSION_CREATED_BY', ), + self::TYPE_FIELDNAME => array('id', 'ref', 'customer_id', 'invoice_order_address_id', 'delivery_order_address_id', 'invoice_date', 'currency_id', 'currency_rate', 'transaction_ref', 'delivery_ref', 'invoice_ref', 'discount', 'postage', 'payment_module_id', 'delivery_module_id', 'status_id', 'lang_id', 'created_at', 'updated_at', 'version', 'version_created_at', 'version_created_by', ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, ) ); /** @@ -192,12 +207,12 @@ class OrderTableMap extends TableMap * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 */ protected static $fieldKeys = array ( - self::TYPE_PHPNAME => array('Id' => 0, 'Ref' => 1, 'CustomerId' => 2, 'InvoiceOrderAddressId' => 3, 'DeliveryOrderAddressId' => 4, 'InvoiceDate' => 5, 'CurrencyId' => 6, 'CurrencyRate' => 7, 'TransactionRef' => 8, 'DeliveryRef' => 9, 'InvoiceRef' => 10, 'Discount' => 11, 'Postage' => 12, 'PaymentModuleId' => 13, 'DeliveryModuleId' => 14, 'StatusId' => 15, 'LangId' => 16, 'CreatedAt' => 17, 'UpdatedAt' => 18, ), - self::TYPE_STUDLYPHPNAME => array('id' => 0, 'ref' => 1, 'customerId' => 2, 'invoiceOrderAddressId' => 3, 'deliveryOrderAddressId' => 4, 'invoiceDate' => 5, 'currencyId' => 6, 'currencyRate' => 7, 'transactionRef' => 8, 'deliveryRef' => 9, 'invoiceRef' => 10, 'discount' => 11, 'postage' => 12, 'paymentModuleId' => 13, 'deliveryModuleId' => 14, 'statusId' => 15, 'langId' => 16, 'createdAt' => 17, 'updatedAt' => 18, ), - self::TYPE_COLNAME => array(OrderTableMap::ID => 0, OrderTableMap::REF => 1, OrderTableMap::CUSTOMER_ID => 2, OrderTableMap::INVOICE_ORDER_ADDRESS_ID => 3, OrderTableMap::DELIVERY_ORDER_ADDRESS_ID => 4, OrderTableMap::INVOICE_DATE => 5, OrderTableMap::CURRENCY_ID => 6, OrderTableMap::CURRENCY_RATE => 7, OrderTableMap::TRANSACTION_REF => 8, OrderTableMap::DELIVERY_REF => 9, OrderTableMap::INVOICE_REF => 10, OrderTableMap::DISCOUNT => 11, OrderTableMap::POSTAGE => 12, OrderTableMap::PAYMENT_MODULE_ID => 13, OrderTableMap::DELIVERY_MODULE_ID => 14, OrderTableMap::STATUS_ID => 15, OrderTableMap::LANG_ID => 16, OrderTableMap::CREATED_AT => 17, OrderTableMap::UPDATED_AT => 18, ), - self::TYPE_RAW_COLNAME => array('ID' => 0, 'REF' => 1, 'CUSTOMER_ID' => 2, 'INVOICE_ORDER_ADDRESS_ID' => 3, 'DELIVERY_ORDER_ADDRESS_ID' => 4, 'INVOICE_DATE' => 5, 'CURRENCY_ID' => 6, 'CURRENCY_RATE' => 7, 'TRANSACTION_REF' => 8, 'DELIVERY_REF' => 9, 'INVOICE_REF' => 10, 'DISCOUNT' => 11, 'POSTAGE' => 12, 'PAYMENT_MODULE_ID' => 13, 'DELIVERY_MODULE_ID' => 14, 'STATUS_ID' => 15, 'LANG_ID' => 16, 'CREATED_AT' => 17, 'UPDATED_AT' => 18, ), - self::TYPE_FIELDNAME => array('id' => 0, 'ref' => 1, 'customer_id' => 2, 'invoice_order_address_id' => 3, 'delivery_order_address_id' => 4, 'invoice_date' => 5, 'currency_id' => 6, 'currency_rate' => 7, 'transaction_ref' => 8, 'delivery_ref' => 9, 'invoice_ref' => 10, 'discount' => 11, 'postage' => 12, 'payment_module_id' => 13, 'delivery_module_id' => 14, 'status_id' => 15, 'lang_id' => 16, 'created_at' => 17, 'updated_at' => 18, ), - self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, ) + self::TYPE_PHPNAME => array('Id' => 0, 'Ref' => 1, 'CustomerId' => 2, 'InvoiceOrderAddressId' => 3, 'DeliveryOrderAddressId' => 4, 'InvoiceDate' => 5, 'CurrencyId' => 6, 'CurrencyRate' => 7, 'TransactionRef' => 8, 'DeliveryRef' => 9, 'InvoiceRef' => 10, 'Discount' => 11, 'Postage' => 12, 'PaymentModuleId' => 13, 'DeliveryModuleId' => 14, 'StatusId' => 15, 'LangId' => 16, 'CreatedAt' => 17, 'UpdatedAt' => 18, 'Version' => 19, 'VersionCreatedAt' => 20, 'VersionCreatedBy' => 21, ), + self::TYPE_STUDLYPHPNAME => array('id' => 0, 'ref' => 1, 'customerId' => 2, 'invoiceOrderAddressId' => 3, 'deliveryOrderAddressId' => 4, 'invoiceDate' => 5, 'currencyId' => 6, 'currencyRate' => 7, 'transactionRef' => 8, 'deliveryRef' => 9, 'invoiceRef' => 10, 'discount' => 11, 'postage' => 12, 'paymentModuleId' => 13, 'deliveryModuleId' => 14, 'statusId' => 15, 'langId' => 16, 'createdAt' => 17, 'updatedAt' => 18, 'version' => 19, 'versionCreatedAt' => 20, 'versionCreatedBy' => 21, ), + self::TYPE_COLNAME => array(OrderTableMap::ID => 0, OrderTableMap::REF => 1, OrderTableMap::CUSTOMER_ID => 2, OrderTableMap::INVOICE_ORDER_ADDRESS_ID => 3, OrderTableMap::DELIVERY_ORDER_ADDRESS_ID => 4, OrderTableMap::INVOICE_DATE => 5, OrderTableMap::CURRENCY_ID => 6, OrderTableMap::CURRENCY_RATE => 7, OrderTableMap::TRANSACTION_REF => 8, OrderTableMap::DELIVERY_REF => 9, OrderTableMap::INVOICE_REF => 10, OrderTableMap::DISCOUNT => 11, OrderTableMap::POSTAGE => 12, OrderTableMap::PAYMENT_MODULE_ID => 13, OrderTableMap::DELIVERY_MODULE_ID => 14, OrderTableMap::STATUS_ID => 15, OrderTableMap::LANG_ID => 16, OrderTableMap::CREATED_AT => 17, OrderTableMap::UPDATED_AT => 18, OrderTableMap::VERSION => 19, OrderTableMap::VERSION_CREATED_AT => 20, OrderTableMap::VERSION_CREATED_BY => 21, ), + self::TYPE_RAW_COLNAME => array('ID' => 0, 'REF' => 1, 'CUSTOMER_ID' => 2, 'INVOICE_ORDER_ADDRESS_ID' => 3, 'DELIVERY_ORDER_ADDRESS_ID' => 4, 'INVOICE_DATE' => 5, 'CURRENCY_ID' => 6, 'CURRENCY_RATE' => 7, 'TRANSACTION_REF' => 8, 'DELIVERY_REF' => 9, 'INVOICE_REF' => 10, 'DISCOUNT' => 11, 'POSTAGE' => 12, 'PAYMENT_MODULE_ID' => 13, 'DELIVERY_MODULE_ID' => 14, 'STATUS_ID' => 15, 'LANG_ID' => 16, 'CREATED_AT' => 17, 'UPDATED_AT' => 18, 'VERSION' => 19, 'VERSION_CREATED_AT' => 20, 'VERSION_CREATED_BY' => 21, ), + self::TYPE_FIELDNAME => array('id' => 0, 'ref' => 1, 'customer_id' => 2, 'invoice_order_address_id' => 3, 'delivery_order_address_id' => 4, 'invoice_date' => 5, 'currency_id' => 6, 'currency_rate' => 7, 'transaction_ref' => 8, 'delivery_ref' => 9, 'invoice_ref' => 10, 'discount' => 11, 'postage' => 12, 'payment_module_id' => 13, 'delivery_module_id' => 14, 'status_id' => 15, 'lang_id' => 16, 'created_at' => 17, 'updated_at' => 18, 'version' => 19, 'version_created_at' => 20, 'version_created_by' => 21, ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, ) ); /** @@ -235,6 +250,9 @@ class OrderTableMap extends TableMap $this->addForeignKey('LANG_ID', 'LangId', 'INTEGER', 'lang', 'ID', true, null, null); $this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null); $this->addColumn('UPDATED_AT', 'UpdatedAt', 'TIMESTAMP', false, null, null); + $this->addColumn('VERSION', 'Version', 'INTEGER', false, null, 0); + $this->addColumn('VERSION_CREATED_AT', 'VersionCreatedAt', 'TIMESTAMP', false, null, null); + $this->addColumn('VERSION_CREATED_BY', 'VersionCreatedBy', 'VARCHAR', false, 100, null); } // initialize() /** @@ -252,6 +270,7 @@ class OrderTableMap extends TableMap $this->addRelation('Lang', '\\Thelia\\Model\\Lang', RelationMap::MANY_TO_ONE, array('lang_id' => 'id', ), 'RESTRICT', 'RESTRICT'); $this->addRelation('OrderProduct', '\\Thelia\\Model\\OrderProduct', RelationMap::ONE_TO_MANY, array('id' => 'order_id', ), 'CASCADE', 'RESTRICT', 'OrderProducts'); $this->addRelation('OrderCoupon', '\\Thelia\\Model\\OrderCoupon', RelationMap::ONE_TO_MANY, array('id' => 'order_id', ), 'CASCADE', 'RESTRICT', 'OrderCoupons'); + $this->addRelation('OrderVersion', '\\Thelia\\Model\\OrderVersion', RelationMap::ONE_TO_MANY, array('id' => 'id', ), 'CASCADE', null, 'OrderVersions'); } // buildRelations() /** @@ -264,6 +283,7 @@ class OrderTableMap extends TableMap { return array( 'timestampable' => array('create_column' => 'created_at', 'update_column' => 'updated_at', ), + 'versionable' => array('version_column' => 'version', 'version_table' => '', 'log_created_at' => 'true', 'log_created_by' => 'true', 'log_comment' => 'false', 'version_created_at_column' => 'version_created_at', 'version_created_by_column' => 'version_created_by', 'version_comment_column' => 'version_comment', ), ); } // getBehaviors() /** @@ -275,6 +295,7 @@ class OrderTableMap extends TableMap // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule. OrderProductTableMap::clearInstancePool(); OrderCouponTableMap::clearInstancePool(); + OrderVersionTableMap::clearInstancePool(); } /** @@ -434,6 +455,9 @@ class OrderTableMap extends TableMap $criteria->addSelectColumn(OrderTableMap::LANG_ID); $criteria->addSelectColumn(OrderTableMap::CREATED_AT); $criteria->addSelectColumn(OrderTableMap::UPDATED_AT); + $criteria->addSelectColumn(OrderTableMap::VERSION); + $criteria->addSelectColumn(OrderTableMap::VERSION_CREATED_AT); + $criteria->addSelectColumn(OrderTableMap::VERSION_CREATED_BY); } else { $criteria->addSelectColumn($alias . '.ID'); $criteria->addSelectColumn($alias . '.REF'); @@ -454,6 +478,9 @@ class OrderTableMap extends TableMap $criteria->addSelectColumn($alias . '.LANG_ID'); $criteria->addSelectColumn($alias . '.CREATED_AT'); $criteria->addSelectColumn($alias . '.UPDATED_AT'); + $criteria->addSelectColumn($alias . '.VERSION'); + $criteria->addSelectColumn($alias . '.VERSION_CREATED_AT'); + $criteria->addSelectColumn($alias . '.VERSION_CREATED_BY'); } } diff --git a/core/lib/Thelia/Model/Map/OrderVersionTableMap.php b/core/lib/Thelia/Model/Map/OrderVersionTableMap.php new file mode 100644 index 000000000..1c92b9ea1 --- /dev/null +++ b/core/lib/Thelia/Model/Map/OrderVersionTableMap.php @@ -0,0 +1,626 @@ + array('Id', 'Ref', 'CustomerId', 'InvoiceOrderAddressId', 'DeliveryOrderAddressId', 'InvoiceDate', 'CurrencyId', 'CurrencyRate', 'TransactionRef', 'DeliveryRef', 'InvoiceRef', 'Discount', 'Postage', 'PaymentModuleId', 'DeliveryModuleId', 'StatusId', 'LangId', 'CreatedAt', 'UpdatedAt', 'Version', 'VersionCreatedAt', 'VersionCreatedBy', ), + self::TYPE_STUDLYPHPNAME => array('id', 'ref', 'customerId', 'invoiceOrderAddressId', 'deliveryOrderAddressId', 'invoiceDate', 'currencyId', 'currencyRate', 'transactionRef', 'deliveryRef', 'invoiceRef', 'discount', 'postage', 'paymentModuleId', 'deliveryModuleId', 'statusId', 'langId', 'createdAt', 'updatedAt', 'version', 'versionCreatedAt', 'versionCreatedBy', ), + self::TYPE_COLNAME => array(OrderVersionTableMap::ID, OrderVersionTableMap::REF, OrderVersionTableMap::CUSTOMER_ID, OrderVersionTableMap::INVOICE_ORDER_ADDRESS_ID, OrderVersionTableMap::DELIVERY_ORDER_ADDRESS_ID, OrderVersionTableMap::INVOICE_DATE, OrderVersionTableMap::CURRENCY_ID, OrderVersionTableMap::CURRENCY_RATE, OrderVersionTableMap::TRANSACTION_REF, OrderVersionTableMap::DELIVERY_REF, OrderVersionTableMap::INVOICE_REF, OrderVersionTableMap::DISCOUNT, OrderVersionTableMap::POSTAGE, OrderVersionTableMap::PAYMENT_MODULE_ID, OrderVersionTableMap::DELIVERY_MODULE_ID, OrderVersionTableMap::STATUS_ID, OrderVersionTableMap::LANG_ID, OrderVersionTableMap::CREATED_AT, OrderVersionTableMap::UPDATED_AT, OrderVersionTableMap::VERSION, OrderVersionTableMap::VERSION_CREATED_AT, OrderVersionTableMap::VERSION_CREATED_BY, ), + self::TYPE_RAW_COLNAME => array('ID', 'REF', 'CUSTOMER_ID', 'INVOICE_ORDER_ADDRESS_ID', 'DELIVERY_ORDER_ADDRESS_ID', 'INVOICE_DATE', 'CURRENCY_ID', 'CURRENCY_RATE', 'TRANSACTION_REF', 'DELIVERY_REF', 'INVOICE_REF', 'DISCOUNT', 'POSTAGE', 'PAYMENT_MODULE_ID', 'DELIVERY_MODULE_ID', 'STATUS_ID', 'LANG_ID', 'CREATED_AT', 'UPDATED_AT', 'VERSION', 'VERSION_CREATED_AT', 'VERSION_CREATED_BY', ), + self::TYPE_FIELDNAME => array('id', 'ref', 'customer_id', 'invoice_order_address_id', 'delivery_order_address_id', 'invoice_date', 'currency_id', 'currency_rate', 'transaction_ref', 'delivery_ref', 'invoice_ref', 'discount', 'postage', 'payment_module_id', 'delivery_module_id', 'status_id', 'lang_id', 'created_at', 'updated_at', 'version', 'version_created_at', 'version_created_by', ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, ) + ); + + /** + * holds an array of keys for quick access to the fieldnames array + * + * first dimension keys are the type constants + * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 + */ + protected static $fieldKeys = array ( + self::TYPE_PHPNAME => array('Id' => 0, 'Ref' => 1, 'CustomerId' => 2, 'InvoiceOrderAddressId' => 3, 'DeliveryOrderAddressId' => 4, 'InvoiceDate' => 5, 'CurrencyId' => 6, 'CurrencyRate' => 7, 'TransactionRef' => 8, 'DeliveryRef' => 9, 'InvoiceRef' => 10, 'Discount' => 11, 'Postage' => 12, 'PaymentModuleId' => 13, 'DeliveryModuleId' => 14, 'StatusId' => 15, 'LangId' => 16, 'CreatedAt' => 17, 'UpdatedAt' => 18, 'Version' => 19, 'VersionCreatedAt' => 20, 'VersionCreatedBy' => 21, ), + self::TYPE_STUDLYPHPNAME => array('id' => 0, 'ref' => 1, 'customerId' => 2, 'invoiceOrderAddressId' => 3, 'deliveryOrderAddressId' => 4, 'invoiceDate' => 5, 'currencyId' => 6, 'currencyRate' => 7, 'transactionRef' => 8, 'deliveryRef' => 9, 'invoiceRef' => 10, 'discount' => 11, 'postage' => 12, 'paymentModuleId' => 13, 'deliveryModuleId' => 14, 'statusId' => 15, 'langId' => 16, 'createdAt' => 17, 'updatedAt' => 18, 'version' => 19, 'versionCreatedAt' => 20, 'versionCreatedBy' => 21, ), + self::TYPE_COLNAME => array(OrderVersionTableMap::ID => 0, OrderVersionTableMap::REF => 1, OrderVersionTableMap::CUSTOMER_ID => 2, OrderVersionTableMap::INVOICE_ORDER_ADDRESS_ID => 3, OrderVersionTableMap::DELIVERY_ORDER_ADDRESS_ID => 4, OrderVersionTableMap::INVOICE_DATE => 5, OrderVersionTableMap::CURRENCY_ID => 6, OrderVersionTableMap::CURRENCY_RATE => 7, OrderVersionTableMap::TRANSACTION_REF => 8, OrderVersionTableMap::DELIVERY_REF => 9, OrderVersionTableMap::INVOICE_REF => 10, OrderVersionTableMap::DISCOUNT => 11, OrderVersionTableMap::POSTAGE => 12, OrderVersionTableMap::PAYMENT_MODULE_ID => 13, OrderVersionTableMap::DELIVERY_MODULE_ID => 14, OrderVersionTableMap::STATUS_ID => 15, OrderVersionTableMap::LANG_ID => 16, OrderVersionTableMap::CREATED_AT => 17, OrderVersionTableMap::UPDATED_AT => 18, OrderVersionTableMap::VERSION => 19, OrderVersionTableMap::VERSION_CREATED_AT => 20, OrderVersionTableMap::VERSION_CREATED_BY => 21, ), + self::TYPE_RAW_COLNAME => array('ID' => 0, 'REF' => 1, 'CUSTOMER_ID' => 2, 'INVOICE_ORDER_ADDRESS_ID' => 3, 'DELIVERY_ORDER_ADDRESS_ID' => 4, 'INVOICE_DATE' => 5, 'CURRENCY_ID' => 6, 'CURRENCY_RATE' => 7, 'TRANSACTION_REF' => 8, 'DELIVERY_REF' => 9, 'INVOICE_REF' => 10, 'DISCOUNT' => 11, 'POSTAGE' => 12, 'PAYMENT_MODULE_ID' => 13, 'DELIVERY_MODULE_ID' => 14, 'STATUS_ID' => 15, 'LANG_ID' => 16, 'CREATED_AT' => 17, 'UPDATED_AT' => 18, 'VERSION' => 19, 'VERSION_CREATED_AT' => 20, 'VERSION_CREATED_BY' => 21, ), + self::TYPE_FIELDNAME => array('id' => 0, 'ref' => 1, 'customer_id' => 2, 'invoice_order_address_id' => 3, 'delivery_order_address_id' => 4, 'invoice_date' => 5, 'currency_id' => 6, 'currency_rate' => 7, 'transaction_ref' => 8, 'delivery_ref' => 9, 'invoice_ref' => 10, 'discount' => 11, 'postage' => 12, 'payment_module_id' => 13, 'delivery_module_id' => 14, 'status_id' => 15, 'lang_id' => 16, 'created_at' => 17, 'updated_at' => 18, 'version' => 19, 'version_created_at' => 20, 'version_created_by' => 21, ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, ) + ); + + /** + * Initialize the table attributes and columns + * Relations are not initialized by this method since they are lazy loaded + * + * @return void + * @throws PropelException + */ + public function initialize() + { + // attributes + $this->setName('order_version'); + $this->setPhpName('OrderVersion'); + $this->setClassName('\\Thelia\\Model\\OrderVersion'); + $this->setPackage('Thelia.Model'); + $this->setUseIdGenerator(false); + // columns + $this->addForeignPrimaryKey('ID', 'Id', 'INTEGER' , 'order', 'ID', true, null, null); + $this->addColumn('REF', 'Ref', 'VARCHAR', false, 45, null); + $this->addColumn('CUSTOMER_ID', 'CustomerId', 'INTEGER', true, null, null); + $this->addColumn('INVOICE_ORDER_ADDRESS_ID', 'InvoiceOrderAddressId', 'INTEGER', true, null, null); + $this->addColumn('DELIVERY_ORDER_ADDRESS_ID', 'DeliveryOrderAddressId', 'INTEGER', true, null, null); + $this->addColumn('INVOICE_DATE', 'InvoiceDate', 'DATE', false, null, null); + $this->addColumn('CURRENCY_ID', 'CurrencyId', 'INTEGER', true, null, null); + $this->addColumn('CURRENCY_RATE', 'CurrencyRate', 'FLOAT', true, null, null); + $this->addColumn('TRANSACTION_REF', 'TransactionRef', 'VARCHAR', false, 100, null); + $this->addColumn('DELIVERY_REF', 'DeliveryRef', 'VARCHAR', false, 100, null); + $this->addColumn('INVOICE_REF', 'InvoiceRef', 'VARCHAR', false, 100, null); + $this->addColumn('DISCOUNT', 'Discount', 'FLOAT', false, null, null); + $this->addColumn('POSTAGE', 'Postage', 'FLOAT', true, null, null); + $this->addColumn('PAYMENT_MODULE_ID', 'PaymentModuleId', 'INTEGER', true, null, null); + $this->addColumn('DELIVERY_MODULE_ID', 'DeliveryModuleId', 'INTEGER', true, null, null); + $this->addColumn('STATUS_ID', 'StatusId', 'INTEGER', true, null, null); + $this->addColumn('LANG_ID', 'LangId', 'INTEGER', true, null, null); + $this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null); + $this->addColumn('UPDATED_AT', 'UpdatedAt', 'TIMESTAMP', false, null, null); + $this->addPrimaryKey('VERSION', 'Version', 'INTEGER', true, null, 0); + $this->addColumn('VERSION_CREATED_AT', 'VersionCreatedAt', 'TIMESTAMP', false, null, null); + $this->addColumn('VERSION_CREATED_BY', 'VersionCreatedBy', 'VARCHAR', false, 100, null); + } // initialize() + + /** + * Build the RelationMap objects for this table relationships + */ + public function buildRelations() + { + $this->addRelation('Order', '\\Thelia\\Model\\Order', RelationMap::MANY_TO_ONE, array('id' => 'id', ), 'CASCADE', null); + } // buildRelations() + + /** + * Adds an object to the instance pool. + * + * Propel keeps cached copies of objects in an instance pool when they are retrieved + * from the database. In some cases you may need to explicitly add objects + * to the cache in order to ensure that the same objects are always returned by find*() + * and findPk*() calls. + * + * @param \Thelia\Model\OrderVersion $obj A \Thelia\Model\OrderVersion object. + * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). + */ + public static function addInstanceToPool($obj, $key = null) + { + if (Propel::isInstancePoolingEnabled()) { + if (null === $key) { + $key = serialize(array((string) $obj->getId(), (string) $obj->getVersion())); + } // if key === null + self::$instances[$key] = $obj; + } + } + + /** + * Removes an object from the instance pool. + * + * Propel keeps cached copies of objects in an instance pool when they are retrieved + * from the database. In some cases -- especially when you override doDelete + * methods in your stub classes -- you may need to explicitly remove objects + * from the cache in order to prevent returning objects that no longer exist. + * + * @param mixed $value A \Thelia\Model\OrderVersion object or a primary key value. + */ + public static function removeInstanceFromPool($value) + { + if (Propel::isInstancePoolingEnabled() && null !== $value) { + if (is_object($value) && $value instanceof \Thelia\Model\OrderVersion) { + $key = serialize(array((string) $value->getId(), (string) $value->getVersion())); + + } elseif (is_array($value) && count($value) === 2) { + // assume we've been passed a primary key"; + $key = serialize(array((string) $value[0], (string) $value[1])); + } elseif ($value instanceof Criteria) { + self::$instances = []; + + return; + } else { + $e = new PropelException("Invalid value passed to removeInstanceFromPool(). Expected primary key or \Thelia\Model\OrderVersion object; got " . (is_object($value) ? get_class($value) . ' object.' : var_export($value, true))); + throw $e; + } + + unset(self::$instances[$key]); + } + } + + /** + * Retrieves a string version of the primary key from the DB resultset row that can be used to uniquely identify a row in this table. + * + * For tables with a single-column primary key, that simple pkey value will be returned. For tables with + * a multi-column primary key, a serialize()d version of the primary key will be returned. + * + * @param array $row resultset row. + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM + */ + public static function getPrimaryKeyHashFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + // If the PK cannot be derived from the row, return NULL. + if ($row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)] === null && $row[TableMap::TYPE_NUM == $indexType ? 19 + $offset : static::translateFieldName('Version', TableMap::TYPE_PHPNAME, $indexType)] === null) { + return null; + } + + return serialize(array((string) $row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)], (string) $row[TableMap::TYPE_NUM == $indexType ? 19 + $offset : static::translateFieldName('Version', TableMap::TYPE_PHPNAME, $indexType)])); + } + + /** + * Retrieves the primary key from the DB resultset row + * For tables with a single-column primary key, that simple pkey value will be returned. For tables with + * a multi-column primary key, an array of the primary key columns will be returned. + * + * @param array $row resultset row. + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM + * + * @return mixed The primary key of the row + */ + public static function getPrimaryKeyFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + + return $pks; + } + + /** + * The class that the tableMap will make instances of. + * + * If $withPrefix is true, the returned path + * uses a dot-path notation which is translated into a path + * relative to a location on the PHP include_path. + * (e.g. path.to.MyClass -> 'path/to/MyClass.php') + * + * @param boolean $withPrefix Whether or not to return the path with the class name + * @return string path.to.ClassName + */ + public static function getOMClass($withPrefix = true) + { + return $withPrefix ? OrderVersionTableMap::CLASS_DEFAULT : OrderVersionTableMap::OM_CLASS; + } + + /** + * Populates an object of the default type or an object that inherit from the default. + * + * @param array $row row returned by DataFetcher->fetch(). + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). + One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + * @return array (OrderVersion object, last column rank) + */ + public static function populateObject($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + $key = OrderVersionTableMap::getPrimaryKeyHashFromRow($row, $offset, $indexType); + if (null !== ($obj = OrderVersionTableMap::getInstanceFromPool($key))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj->hydrate($row, $offset, true); // rehydrate + $col = $offset + OrderVersionTableMap::NUM_HYDRATE_COLUMNS; + } else { + $cls = OrderVersionTableMap::OM_CLASS; + $obj = new $cls(); + $col = $obj->hydrate($row, $offset, false, $indexType); + OrderVersionTableMap::addInstanceToPool($obj, $key); + } + + return array($obj, $col); + } + + /** + * The returned array will contain objects of the default type or + * objects that inherit from the default. + * + * @param DataFetcherInterface $dataFetcher + * @return array + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function populateObjects(DataFetcherInterface $dataFetcher) + { + $results = array(); + + // set the class once to avoid overhead in the loop + $cls = static::getOMClass(false); + // populate the object(s) + while ($row = $dataFetcher->fetch()) { + $key = OrderVersionTableMap::getPrimaryKeyHashFromRow($row, 0, $dataFetcher->getIndexType()); + if (null !== ($obj = OrderVersionTableMap::getInstanceFromPool($key))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj->hydrate($row, 0, true); // rehydrate + $results[] = $obj; + } else { + $obj = new $cls(); + $obj->hydrate($row); + $results[] = $obj; + OrderVersionTableMap::addInstanceToPool($obj, $key); + } // if key exists + } + + return $results; + } + /** + * Add all the columns needed to create a new object. + * + * Note: any columns that were marked with lazyLoad="true" in the + * XML schema will not be added to the select list and only loaded + * on demand. + * + * @param Criteria $criteria object containing the columns to add. + * @param string $alias optional table alias + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function addSelectColumns(Criteria $criteria, $alias = null) + { + if (null === $alias) { + $criteria->addSelectColumn(OrderVersionTableMap::ID); + $criteria->addSelectColumn(OrderVersionTableMap::REF); + $criteria->addSelectColumn(OrderVersionTableMap::CUSTOMER_ID); + $criteria->addSelectColumn(OrderVersionTableMap::INVOICE_ORDER_ADDRESS_ID); + $criteria->addSelectColumn(OrderVersionTableMap::DELIVERY_ORDER_ADDRESS_ID); + $criteria->addSelectColumn(OrderVersionTableMap::INVOICE_DATE); + $criteria->addSelectColumn(OrderVersionTableMap::CURRENCY_ID); + $criteria->addSelectColumn(OrderVersionTableMap::CURRENCY_RATE); + $criteria->addSelectColumn(OrderVersionTableMap::TRANSACTION_REF); + $criteria->addSelectColumn(OrderVersionTableMap::DELIVERY_REF); + $criteria->addSelectColumn(OrderVersionTableMap::INVOICE_REF); + $criteria->addSelectColumn(OrderVersionTableMap::DISCOUNT); + $criteria->addSelectColumn(OrderVersionTableMap::POSTAGE); + $criteria->addSelectColumn(OrderVersionTableMap::PAYMENT_MODULE_ID); + $criteria->addSelectColumn(OrderVersionTableMap::DELIVERY_MODULE_ID); + $criteria->addSelectColumn(OrderVersionTableMap::STATUS_ID); + $criteria->addSelectColumn(OrderVersionTableMap::LANG_ID); + $criteria->addSelectColumn(OrderVersionTableMap::CREATED_AT); + $criteria->addSelectColumn(OrderVersionTableMap::UPDATED_AT); + $criteria->addSelectColumn(OrderVersionTableMap::VERSION); + $criteria->addSelectColumn(OrderVersionTableMap::VERSION_CREATED_AT); + $criteria->addSelectColumn(OrderVersionTableMap::VERSION_CREATED_BY); + } else { + $criteria->addSelectColumn($alias . '.ID'); + $criteria->addSelectColumn($alias . '.REF'); + $criteria->addSelectColumn($alias . '.CUSTOMER_ID'); + $criteria->addSelectColumn($alias . '.INVOICE_ORDER_ADDRESS_ID'); + $criteria->addSelectColumn($alias . '.DELIVERY_ORDER_ADDRESS_ID'); + $criteria->addSelectColumn($alias . '.INVOICE_DATE'); + $criteria->addSelectColumn($alias . '.CURRENCY_ID'); + $criteria->addSelectColumn($alias . '.CURRENCY_RATE'); + $criteria->addSelectColumn($alias . '.TRANSACTION_REF'); + $criteria->addSelectColumn($alias . '.DELIVERY_REF'); + $criteria->addSelectColumn($alias . '.INVOICE_REF'); + $criteria->addSelectColumn($alias . '.DISCOUNT'); + $criteria->addSelectColumn($alias . '.POSTAGE'); + $criteria->addSelectColumn($alias . '.PAYMENT_MODULE_ID'); + $criteria->addSelectColumn($alias . '.DELIVERY_MODULE_ID'); + $criteria->addSelectColumn($alias . '.STATUS_ID'); + $criteria->addSelectColumn($alias . '.LANG_ID'); + $criteria->addSelectColumn($alias . '.CREATED_AT'); + $criteria->addSelectColumn($alias . '.UPDATED_AT'); + $criteria->addSelectColumn($alias . '.VERSION'); + $criteria->addSelectColumn($alias . '.VERSION_CREATED_AT'); + $criteria->addSelectColumn($alias . '.VERSION_CREATED_BY'); + } + } + + /** + * Returns the TableMap related to this object. + * This method is not needed for general use but a specific application could have a need. + * @return TableMap + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function getTableMap() + { + return Propel::getServiceContainer()->getDatabaseMap(OrderVersionTableMap::DATABASE_NAME)->getTable(OrderVersionTableMap::TABLE_NAME); + } + + /** + * Add a TableMap instance to the database for this tableMap class. + */ + public static function buildTableMap() + { + $dbMap = Propel::getServiceContainer()->getDatabaseMap(OrderVersionTableMap::DATABASE_NAME); + if (!$dbMap->hasTable(OrderVersionTableMap::TABLE_NAME)) { + $dbMap->addTableObject(new OrderVersionTableMap()); + } + } + + /** + * Performs a DELETE on the database, given a OrderVersion or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or OrderVersion object or primary key or array of primary keys + * which is used to create the DELETE statement + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doDelete($values, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(OrderVersionTableMap::DATABASE_NAME); + } + + if ($values instanceof Criteria) { + // rename for clarity + $criteria = $values; + } elseif ($values instanceof \Thelia\Model\OrderVersion) { // it's a model object + // create criteria based on pk values + $criteria = $values->buildPkeyCriteria(); + } else { // it's a primary key, or an array of pks + $criteria = new Criteria(OrderVersionTableMap::DATABASE_NAME); + // primary key is composite; we therefore, expect + // the primary key passed to be an array of pkey values + if (count($values) == count($values, COUNT_RECURSIVE)) { + // array is not multi-dimensional + $values = array($values); + } + foreach ($values as $value) { + $criterion = $criteria->getNewCriterion(OrderVersionTableMap::ID, $value[0]); + $criterion->addAnd($criteria->getNewCriterion(OrderVersionTableMap::VERSION, $value[1])); + $criteria->addOr($criterion); + } + } + + $query = OrderVersionQuery::create()->mergeWith($criteria); + + if ($values instanceof Criteria) { OrderVersionTableMap::clearInstancePool(); + } elseif (!is_object($values)) { // it's a primary key, or an array of pks + foreach ((array) $values as $singleval) { OrderVersionTableMap::removeInstanceFromPool($singleval); + } + } + + return $query->delete($con); + } + + /** + * Deletes all rows from the order_version table. + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + */ + public static function doDeleteAll(ConnectionInterface $con = null) + { + return OrderVersionQuery::create()->doDeleteAll($con); + } + + /** + * Performs an INSERT on the database, given a OrderVersion or Criteria object. + * + * @param mixed $criteria Criteria or OrderVersion object containing data that is used to create the INSERT statement. + * @param ConnectionInterface $con the ConnectionInterface connection to use + * @return mixed The new primary key. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doInsert($criteria, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(OrderVersionTableMap::DATABASE_NAME); + } + + if ($criteria instanceof Criteria) { + $criteria = clone $criteria; // rename for clarity + } else { + $criteria = $criteria->buildCriteria(); // build Criteria from OrderVersion object + } + + + // Set the correct dbName + $query = OrderVersionQuery::create()->mergeWith($criteria); + + try { + // use transaction because $criteria could contain info + // for more than one table (I guess, conceivably) + $con->beginTransaction(); + $pk = $query->doInsert($con); + $con->commit(); + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + + return $pk; + } + +} // OrderVersionTableMap +// This is the static code needed to register the TableMap for this table with the main Propel class. +// +OrderVersionTableMap::buildTableMap(); diff --git a/core/lib/Thelia/Model/OrderVersion.php b/core/lib/Thelia/Model/OrderVersion.php new file mode 100644 index 000000000..bda760833 --- /dev/null +++ b/core/lib/Thelia/Model/OrderVersion.php @@ -0,0 +1,10 @@ + + + + + diff --git a/setup/thelia.sql b/setup/thelia.sql index 988a88bd0..97c3b75c3 100644 --- a/setup/thelia.sql +++ b/setup/thelia.sql @@ -669,6 +669,9 @@ CREATE TABLE `order` `lang_id` INTEGER NOT NULL, `created_at` DATETIME, `updated_at` DATETIME, + `version` INTEGER DEFAULT 0, + `version_created_at` DATETIME, + `version_created_by` VARCHAR(100), PRIMARY KEY (`id`), UNIQUE INDEX `ref_UNIQUE` (`ref`), INDEX `idx_order_currency_id` (`currency_id`), @@ -2484,6 +2487,43 @@ CREATE TABLE `content_version` ON DELETE CASCADE ) ENGINE=InnoDB CHARACTER SET='utf8'; +-- --------------------------------------------------------------------- +-- order_version +-- --------------------------------------------------------------------- + +DROP TABLE IF EXISTS `order_version`; + +CREATE TABLE `order_version` +( + `id` INTEGER NOT NULL, + `ref` VARCHAR(45), + `customer_id` INTEGER NOT NULL, + `invoice_order_address_id` INTEGER NOT NULL, + `delivery_order_address_id` INTEGER NOT NULL, + `invoice_date` DATE, + `currency_id` INTEGER NOT NULL, + `currency_rate` FLOAT NOT NULL, + `transaction_ref` VARCHAR(100) COMMENT 'transaction reference - usually use to identify a transaction with banking modules', + `delivery_ref` VARCHAR(100) COMMENT 'delivery reference - usually use to identify a delivery progress on a distant delivery tracker website', + `invoice_ref` VARCHAR(100) COMMENT 'the invoice reference', + `discount` FLOAT, + `postage` FLOAT NOT NULL, + `payment_module_id` INTEGER NOT NULL, + `delivery_module_id` INTEGER NOT NULL, + `status_id` INTEGER NOT NULL, + `lang_id` INTEGER NOT NULL, + `created_at` DATETIME, + `updated_at` DATETIME, + `version` INTEGER DEFAULT 0 NOT NULL, + `version_created_at` DATETIME, + `version_created_by` VARCHAR(100), + PRIMARY KEY (`id`,`version`), + CONSTRAINT `order_version_FK_1` + FOREIGN KEY (`id`) + REFERENCES `order` (`id`) + ON DELETE CASCADE +) ENGINE=InnoDB CHARACTER SET='utf8'; + -- --------------------------------------------------------------------- -- message_version -- --------------------------------------------------------------------- diff --git a/setup/update/2.0.3.sql b/setup/update/2.0.3.sql new file mode 100644 index 000000000..1e9234d93 --- /dev/null +++ b/setup/update/2.0.3.sql @@ -0,0 +1,48 @@ +# This is a fix for InnoDB in MySQL >= 4.1.x +# It "suspends judgement" for fkey relationships until are tables are set. +SET FOREIGN_KEY_CHECKS = 0; + +UPDATE `config` SET `value`='2.0.3' WHERE `name`='thelia_version'; +UPDATE `config` SET `value`='2' WHERE `name`='thelia_release_version'; +UPDATE `config` SET `value`='' WHERE `name`='thelia_extra_version'; + +# Add new column to order (version, version_created_at, version_created_by) + +ALTER TABLE `order` ADD `version` INT DEFAULT 0 AFTER `updated_at`; +ALTER TABLE `order` ADD `version_created_at` DATE AFTER `version`; +ALTER TABLE `order` ADD `version_created_by` VARCHAR(100) AFTER `version_created_at`; + +DROP TABLE IF EXISTS `order_version`; + +CREATE TABLE `order_version` +( + `id` INTEGER NOT NULL, + `ref` VARCHAR(45), + `customer_id` INTEGER NOT NULL, + `invoice_order_address_id` INTEGER NOT NULL, + `delivery_order_address_id` INTEGER NOT NULL, + `invoice_date` DATE, + `currency_id` INTEGER NOT NULL, + `currency_rate` FLOAT NOT NULL, + `transaction_ref` VARCHAR(100) COMMENT 'transaction reference - usually use to identify a transaction with banking modules', + `delivery_ref` VARCHAR(100) COMMENT 'delivery reference - usually use to identify a delivery progress on a distant delivery tracker website', + `invoice_ref` VARCHAR(100) COMMENT 'the invoice reference', + `discount` FLOAT, + `postage` FLOAT NOT NULL, + `payment_module_id` INTEGER NOT NULL, + `delivery_module_id` INTEGER NOT NULL, + `status_id` INTEGER NOT NULL, + `lang_id` INTEGER NOT NULL, + `created_at` DATETIME, + `updated_at` DATETIME, + `version` INTEGER DEFAULT 0 NOT NULL, + `version_created_at` DATETIME, + `version_created_by` VARCHAR(100), + PRIMARY KEY (`id`,`version`), + CONSTRAINT `order_version_FK_1` + FOREIGN KEY (`id`) + REFERENCES `order` (`id`) + ON DELETE CASCADE +) ENGINE=InnoDB CHARACTER SET='utf8'; + +SET FOREIGN_KEY_CHECKS = 1; \ No newline at end of file