diff --git a/core/lib/Thelia/Model/Base/Country.php b/core/lib/Thelia/Model/Base/Country.php index aa2597ceb..15d56bd17 100644 --- a/core/lib/Thelia/Model/Base/Country.php +++ b/core/lib/Thelia/Model/Base/Country.php @@ -25,6 +25,10 @@ use Thelia\Model\Country as ChildCountry; use Thelia\Model\CountryI18n as ChildCountryI18n; use Thelia\Model\CountryI18nQuery as ChildCountryI18nQuery; use Thelia\Model\CountryQuery as ChildCountryQuery; +use Thelia\Model\Coupon as ChildCoupon; +use Thelia\Model\CouponCountry as ChildCouponCountry; +use Thelia\Model\CouponCountryQuery as ChildCouponCountryQuery; +use Thelia\Model\CouponQuery as ChildCouponQuery; use Thelia\Model\TaxRuleCountry as ChildTaxRuleCountry; use Thelia\Model\TaxRuleCountryQuery as ChildTaxRuleCountryQuery; use Thelia\Model\Map\CountryTableMap; @@ -136,12 +140,23 @@ abstract class Country implements ActiveRecordInterface protected $collAddresses; protected $collAddressesPartial; + /** + * @var ObjectCollection|ChildCouponCountry[] Collection to store aggregation of ChildCouponCountry objects. + */ + protected $collCouponCountries; + protected $collCouponCountriesPartial; + /** * @var ObjectCollection|ChildCountryI18n[] Collection to store aggregation of ChildCountryI18n objects. */ protected $collCountryI18ns; protected $collCountryI18nsPartial; + /** + * @var ChildCoupon[] Collection to store aggregation of ChildCoupon objects. + */ + protected $collCoupons; + /** * Flag to prevent endless save loop, if this object is referenced * by another object which falls in this transaction. @@ -164,6 +179,12 @@ abstract class Country implements ActiveRecordInterface */ protected $currentTranslations; + /** + * An array of objects scheduled for deletion. + * @var ObjectCollection + */ + protected $couponsScheduledForDeletion = null; + /** * An array of objects scheduled for deletion. * @var ObjectCollection @@ -176,6 +197,12 @@ abstract class Country implements ActiveRecordInterface */ protected $addressesScheduledForDeletion = null; + /** + * An array of objects scheduled for deletion. + * @var ObjectCollection + */ + protected $couponCountriesScheduledForDeletion = null; + /** * An array of objects scheduled for deletion. * @var ObjectCollection @@ -926,8 +953,11 @@ abstract class Country implements ActiveRecordInterface $this->collAddresses = null; + $this->collCouponCountries = null; + $this->collCountryI18ns = null; + $this->collCoupons = null; } // if (deep) } @@ -1073,6 +1103,33 @@ abstract class Country implements ActiveRecordInterface $this->resetModified(); } + if ($this->couponsScheduledForDeletion !== null) { + if (!$this->couponsScheduledForDeletion->isEmpty()) { + $pks = array(); + $pk = $this->getPrimaryKey(); + foreach ($this->couponsScheduledForDeletion->getPrimaryKeys(false) as $remotePk) { + $pks[] = array($pk, $remotePk); + } + + CouponCountryQuery::create() + ->filterByPrimaryKeys($pks) + ->delete($con); + $this->couponsScheduledForDeletion = null; + } + + foreach ($this->getCoupons() as $coupon) { + if ($coupon->isModified()) { + $coupon->save($con); + } + } + } elseif ($this->collCoupons) { + foreach ($this->collCoupons as $coupon) { + if ($coupon->isModified()) { + $coupon->save($con); + } + } + } + if ($this->taxRuleCountriesScheduledForDeletion !== null) { if (!$this->taxRuleCountriesScheduledForDeletion->isEmpty()) { \Thelia\Model\TaxRuleCountryQuery::create() @@ -1107,6 +1164,23 @@ abstract class Country implements ActiveRecordInterface } } + if ($this->couponCountriesScheduledForDeletion !== null) { + if (!$this->couponCountriesScheduledForDeletion->isEmpty()) { + \Thelia\Model\CouponCountryQuery::create() + ->filterByPrimaryKeys($this->couponCountriesScheduledForDeletion->getPrimaryKeys(false)) + ->delete($con); + $this->couponCountriesScheduledForDeletion = null; + } + } + + if ($this->collCouponCountries !== null) { + foreach ($this->collCouponCountries as $referrerFK) { + if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) { + $affectedRows += $referrerFK->save($con); + } + } + } + if ($this->countryI18nsScheduledForDeletion !== null) { if (!$this->countryI18nsScheduledForDeletion->isEmpty()) { \Thelia\Model\CountryI18nQuery::create() @@ -1358,6 +1432,9 @@ abstract class Country implements ActiveRecordInterface if (null !== $this->collAddresses) { $result['Addresses'] = $this->collAddresses->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); } + if (null !== $this->collCouponCountries) { + $result['CouponCountries'] = $this->collCouponCountries->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); + } if (null !== $this->collCountryI18ns) { $result['CountryI18ns'] = $this->collCountryI18ns->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); } @@ -1564,6 +1641,12 @@ abstract class Country implements ActiveRecordInterface } } + foreach ($this->getCouponCountries() as $relObj) { + if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves + $copyObj->addCouponCountry($relObj->copy($deepCopy)); + } + } + foreach ($this->getCountryI18ns() as $relObj) { if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves $copyObj->addCountryI18n($relObj->copy($deepCopy)); @@ -1668,6 +1751,9 @@ abstract class Country implements ActiveRecordInterface if ('Address' == $relationName) { return $this->initAddresses(); } + if ('CouponCountry' == $relationName) { + return $this->initCouponCountries(); + } if ('CountryI18n' == $relationName) { return $this->initCountryI18ns(); } @@ -2212,6 +2298,252 @@ abstract class Country implements ActiveRecordInterface return $this->getAddresses($query, $con); } + /** + * Clears out the collCouponCountries 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 addCouponCountries() + */ + public function clearCouponCountries() + { + $this->collCouponCountries = null; // important to set this to NULL since that means it is uninitialized + } + + /** + * Reset is the collCouponCountries collection loaded partially. + */ + public function resetPartialCouponCountries($v = true) + { + $this->collCouponCountriesPartial = $v; + } + + /** + * Initializes the collCouponCountries collection. + * + * By default this just sets the collCouponCountries collection to an empty array (like clearcollCouponCountries()); + * 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 initCouponCountries($overrideExisting = true) + { + if (null !== $this->collCouponCountries && !$overrideExisting) { + return; + } + $this->collCouponCountries = new ObjectCollection(); + $this->collCouponCountries->setModel('\Thelia\Model\CouponCountry'); + } + + /** + * Gets an array of ChildCouponCountry 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 ChildCountry 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|ChildCouponCountry[] List of ChildCouponCountry objects + * @throws PropelException + */ + public function getCouponCountries($criteria = null, ConnectionInterface $con = null) + { + $partial = $this->collCouponCountriesPartial && !$this->isNew(); + if (null === $this->collCouponCountries || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collCouponCountries) { + // return empty collection + $this->initCouponCountries(); + } else { + $collCouponCountries = ChildCouponCountryQuery::create(null, $criteria) + ->filterByCountry($this) + ->find($con); + + if (null !== $criteria) { + if (false !== $this->collCouponCountriesPartial && count($collCouponCountries)) { + $this->initCouponCountries(false); + + foreach ($collCouponCountries as $obj) { + if (false == $this->collCouponCountries->contains($obj)) { + $this->collCouponCountries->append($obj); + } + } + + $this->collCouponCountriesPartial = true; + } + + reset($collCouponCountries); + + return $collCouponCountries; + } + + if ($partial && $this->collCouponCountries) { + foreach ($this->collCouponCountries as $obj) { + if ($obj->isNew()) { + $collCouponCountries[] = $obj; + } + } + } + + $this->collCouponCountries = $collCouponCountries; + $this->collCouponCountriesPartial = false; + } + } + + return $this->collCouponCountries; + } + + /** + * Sets a collection of CouponCountry 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 $couponCountries A Propel collection. + * @param ConnectionInterface $con Optional connection object + * @return ChildCountry The current object (for fluent API support) + */ + public function setCouponCountries(Collection $couponCountries, ConnectionInterface $con = null) + { + $couponCountriesToDelete = $this->getCouponCountries(new Criteria(), $con)->diff($couponCountries); + + + //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->couponCountriesScheduledForDeletion = clone $couponCountriesToDelete; + + foreach ($couponCountriesToDelete as $couponCountryRemoved) { + $couponCountryRemoved->setCountry(null); + } + + $this->collCouponCountries = null; + foreach ($couponCountries as $couponCountry) { + $this->addCouponCountry($couponCountry); + } + + $this->collCouponCountries = $couponCountries; + $this->collCouponCountriesPartial = false; + + return $this; + } + + /** + * Returns the number of related CouponCountry objects. + * + * @param Criteria $criteria + * @param boolean $distinct + * @param ConnectionInterface $con + * @return int Count of related CouponCountry objects. + * @throws PropelException + */ + public function countCouponCountries(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) + { + $partial = $this->collCouponCountriesPartial && !$this->isNew(); + if (null === $this->collCouponCountries || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collCouponCountries) { + return 0; + } + + if ($partial && !$criteria) { + return count($this->getCouponCountries()); + } + + $query = ChildCouponCountryQuery::create(null, $criteria); + if ($distinct) { + $query->distinct(); + } + + return $query + ->filterByCountry($this) + ->count($con); + } + + return count($this->collCouponCountries); + } + + /** + * Method called to associate a ChildCouponCountry object to this object + * through the ChildCouponCountry foreign key attribute. + * + * @param ChildCouponCountry $l ChildCouponCountry + * @return \Thelia\Model\Country The current object (for fluent API support) + */ + public function addCouponCountry(ChildCouponCountry $l) + { + if ($this->collCouponCountries === null) { + $this->initCouponCountries(); + $this->collCouponCountriesPartial = true; + } + + if (!in_array($l, $this->collCouponCountries->getArrayCopy(), true)) { // only add it if the **same** object is not already associated + $this->doAddCouponCountry($l); + } + + return $this; + } + + /** + * @param CouponCountry $couponCountry The couponCountry object to add. + */ + protected function doAddCouponCountry($couponCountry) + { + $this->collCouponCountries[]= $couponCountry; + $couponCountry->setCountry($this); + } + + /** + * @param CouponCountry $couponCountry The couponCountry object to remove. + * @return ChildCountry The current object (for fluent API support) + */ + public function removeCouponCountry($couponCountry) + { + if ($this->getCouponCountries()->contains($couponCountry)) { + $this->collCouponCountries->remove($this->collCouponCountries->search($couponCountry)); + if (null === $this->couponCountriesScheduledForDeletion) { + $this->couponCountriesScheduledForDeletion = clone $this->collCouponCountries; + $this->couponCountriesScheduledForDeletion->clear(); + } + $this->couponCountriesScheduledForDeletion[]= clone $couponCountry; + $couponCountry->setCountry(null); + } + + return $this; + } + + + /** + * If this collection has already been initialized with + * an identical criteria, it returns the collection. + * Otherwise if this Country is new, it will return + * an empty collection; or if this Country has previously + * been saved, it will retrieve related CouponCountries from storage. + * + * This method is protected by default in order to keep the public + * api reasonable. You can provide public methods for those you + * actually need in Country. + * + * @param Criteria $criteria optional Criteria object to narrow the query + * @param ConnectionInterface $con optional connection object + * @param string $joinBehavior optional join type to use (defaults to Criteria::LEFT_JOIN) + * @return Collection|ChildCouponCountry[] List of ChildCouponCountry objects + */ + public function getCouponCountriesJoinCoupon($criteria = null, $con = null, $joinBehavior = Criteria::LEFT_JOIN) + { + $query = ChildCouponCountryQuery::create(null, $criteria); + $query->joinWith('Coupon', $joinBehavior); + + return $this->getCouponCountries($query, $con); + } + /** * Clears out the collCountryI18ns collection * @@ -2437,6 +2769,189 @@ abstract class Country implements ActiveRecordInterface return $this; } + /** + * Clears out the collCoupons 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 addCoupons() + */ + public function clearCoupons() + { + $this->collCoupons = null; // important to set this to NULL since that means it is uninitialized + $this->collCouponsPartial = null; + } + + /** + * Initializes the collCoupons collection. + * + * By default this just sets the collCoupons collection to an empty collection (like clearCoupons()); + * 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. + * + * @return void + */ + public function initCoupons() + { + $this->collCoupons = new ObjectCollection(); + $this->collCoupons->setModel('\Thelia\Model\Coupon'); + } + + /** + * Gets a collection of ChildCoupon objects related by a many-to-many relationship + * to the current object by way of the coupon_country cross-reference table. + * + * 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 ChildCountry is new, it will return + * an empty collection or the current collection; the criteria is ignored on a new object. + * + * @param Criteria $criteria Optional query object to filter the query + * @param ConnectionInterface $con Optional connection object + * + * @return ObjectCollection|ChildCoupon[] List of ChildCoupon objects + */ + public function getCoupons($criteria = null, ConnectionInterface $con = null) + { + if (null === $this->collCoupons || null !== $criteria) { + if ($this->isNew() && null === $this->collCoupons) { + // return empty collection + $this->initCoupons(); + } else { + $collCoupons = ChildCouponQuery::create(null, $criteria) + ->filterByCountry($this) + ->find($con); + if (null !== $criteria) { + return $collCoupons; + } + $this->collCoupons = $collCoupons; + } + } + + return $this->collCoupons; + } + + /** + * Sets a collection of Coupon objects related by a many-to-many relationship + * to the current object by way of the coupon_country cross-reference table. + * 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 $coupons A Propel collection. + * @param ConnectionInterface $con Optional connection object + * @return ChildCountry The current object (for fluent API support) + */ + public function setCoupons(Collection $coupons, ConnectionInterface $con = null) + { + $this->clearCoupons(); + $currentCoupons = $this->getCoupons(); + + $this->couponsScheduledForDeletion = $currentCoupons->diff($coupons); + + foreach ($coupons as $coupon) { + if (!$currentCoupons->contains($coupon)) { + $this->doAddCoupon($coupon); + } + } + + $this->collCoupons = $coupons; + + return $this; + } + + /** + * Gets the number of ChildCoupon objects related by a many-to-many relationship + * to the current object by way of the coupon_country cross-reference table. + * + * @param Criteria $criteria Optional query object to filter the query + * @param boolean $distinct Set to true to force count distinct + * @param ConnectionInterface $con Optional connection object + * + * @return int the number of related ChildCoupon objects + */ + public function countCoupons($criteria = null, $distinct = false, ConnectionInterface $con = null) + { + if (null === $this->collCoupons || null !== $criteria) { + if ($this->isNew() && null === $this->collCoupons) { + return 0; + } else { + $query = ChildCouponQuery::create(null, $criteria); + if ($distinct) { + $query->distinct(); + } + + return $query + ->filterByCountry($this) + ->count($con); + } + } else { + return count($this->collCoupons); + } + } + + /** + * Associate a ChildCoupon object to this object + * through the coupon_country cross reference table. + * + * @param ChildCoupon $coupon The ChildCouponCountry object to relate + * @return ChildCountry The current object (for fluent API support) + */ + public function addCoupon(ChildCoupon $coupon) + { + if ($this->collCoupons === null) { + $this->initCoupons(); + } + + if (!$this->collCoupons->contains($coupon)) { // only add it if the **same** object is not already associated + $this->doAddCoupon($coupon); + $this->collCoupons[] = $coupon; + } + + return $this; + } + + /** + * @param Coupon $coupon The coupon object to add. + */ + protected function doAddCoupon($coupon) + { + $couponCountry = new ChildCouponCountry(); + $couponCountry->setCoupon($coupon); + $this->addCouponCountry($couponCountry); + // set the back reference to this object directly as using provided method either results + // in endless loop or in multiple relations + if (!$coupon->getCountries()->contains($this)) { + $foreignCollection = $coupon->getCountries(); + $foreignCollection[] = $this; + } + } + + /** + * Remove a ChildCoupon object to this object + * through the coupon_country cross reference table. + * + * @param ChildCoupon $coupon The ChildCouponCountry object to relate + * @return ChildCountry The current object (for fluent API support) + */ + public function removeCoupon(ChildCoupon $coupon) + { + if ($this->getCoupons()->contains($coupon)) { + $this->collCoupons->remove($this->collCoupons->search($coupon)); + + if (null === $this->couponsScheduledForDeletion) { + $this->couponsScheduledForDeletion = clone $this->collCoupons; + $this->couponsScheduledForDeletion->clear(); + } + + $this->couponsScheduledForDeletion[] = $coupon; + } + + return $this; + } + /** * Clears the current object and sets all attributes to their default values */ @@ -2481,11 +2996,21 @@ abstract class Country implements ActiveRecordInterface $o->clearAllReferences($deep); } } + if ($this->collCouponCountries) { + foreach ($this->collCouponCountries as $o) { + $o->clearAllReferences($deep); + } + } if ($this->collCountryI18ns) { foreach ($this->collCountryI18ns as $o) { $o->clearAllReferences($deep); } } + if ($this->collCoupons) { + foreach ($this->collCoupons as $o) { + $o->clearAllReferences($deep); + } + } } // if ($deep) // i18n behavior @@ -2494,7 +3019,9 @@ abstract class Country implements ActiveRecordInterface $this->collTaxRuleCountries = null; $this->collAddresses = null; + $this->collCouponCountries = null; $this->collCountryI18ns = null; + $this->collCoupons = null; $this->aArea = null; } diff --git a/core/lib/Thelia/Model/Base/CountryQuery.php b/core/lib/Thelia/Model/Base/CountryQuery.php index 270802f07..6373c4912 100644 --- a/core/lib/Thelia/Model/Base/CountryQuery.php +++ b/core/lib/Thelia/Model/Base/CountryQuery.php @@ -58,6 +58,10 @@ use Thelia\Model\Map\CountryTableMap; * @method ChildCountryQuery rightJoinAddress($relationAlias = null) Adds a RIGHT JOIN clause to the query using the Address relation * @method ChildCountryQuery innerJoinAddress($relationAlias = null) Adds a INNER JOIN clause to the query using the Address relation * + * @method ChildCountryQuery leftJoinCouponCountry($relationAlias = null) Adds a LEFT JOIN clause to the query using the CouponCountry relation + * @method ChildCountryQuery rightJoinCouponCountry($relationAlias = null) Adds a RIGHT JOIN clause to the query using the CouponCountry relation + * @method ChildCountryQuery innerJoinCouponCountry($relationAlias = null) Adds a INNER JOIN clause to the query using the CouponCountry relation + * * @method ChildCountryQuery leftJoinCountryI18n($relationAlias = null) Adds a LEFT JOIN clause to the query using the CountryI18n relation * @method ChildCountryQuery rightJoinCountryI18n($relationAlias = null) Adds a RIGHT JOIN clause to the query using the CountryI18n relation * @method ChildCountryQuery innerJoinCountryI18n($relationAlias = null) Adds a INNER JOIN clause to the query using the CountryI18n relation @@ -807,6 +811,79 @@ abstract class CountryQuery extends ModelCriteria ->useQuery($relationAlias ? $relationAlias : 'Address', '\Thelia\Model\AddressQuery'); } + /** + * Filter the query by a related \Thelia\Model\CouponCountry object + * + * @param \Thelia\Model\CouponCountry|ObjectCollection $couponCountry the related object to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildCountryQuery The current query, for fluid interface + */ + public function filterByCouponCountry($couponCountry, $comparison = null) + { + if ($couponCountry instanceof \Thelia\Model\CouponCountry) { + return $this + ->addUsingAlias(CountryTableMap::ID, $couponCountry->getCountryId(), $comparison); + } elseif ($couponCountry instanceof ObjectCollection) { + return $this + ->useCouponCountryQuery() + ->filterByPrimaryKeys($couponCountry->getPrimaryKeys()) + ->endUse(); + } else { + throw new PropelException('filterByCouponCountry() only accepts arguments of type \Thelia\Model\CouponCountry or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the CouponCountry relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildCountryQuery The current query, for fluid interface + */ + public function joinCouponCountry($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('CouponCountry'); + + // 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, 'CouponCountry'); + } + + return $this; + } + + /** + * Use the CouponCountry relation CouponCountry 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\CouponCountryQuery A secondary query class using the current class as primary query + */ + public function useCouponCountryQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + return $this + ->joinCouponCountry($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'CouponCountry', '\Thelia\Model\CouponCountryQuery'); + } + /** * Filter the query by a related \Thelia\Model\CountryI18n object * @@ -880,6 +957,23 @@ abstract class CountryQuery extends ModelCriteria ->useQuery($relationAlias ? $relationAlias : 'CountryI18n', '\Thelia\Model\CountryI18nQuery'); } + /** + * Filter the query by a related Coupon object + * using the coupon_country table as cross reference + * + * @param Coupon $coupon the related object to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildCountryQuery The current query, for fluid interface + */ + public function filterByCoupon($coupon, $comparison = Criteria::EQUAL) + { + return $this + ->useCouponCountryQuery() + ->filterByCoupon($coupon, $comparison) + ->endUse(); + } + /** * Exclude object from result * diff --git a/core/lib/Thelia/Model/Base/Coupon.php b/core/lib/Thelia/Model/Base/Coupon.php index 56d271683..8d47b580c 100644 --- a/core/lib/Thelia/Model/Base/Coupon.php +++ b/core/lib/Thelia/Model/Base/Coupon.php @@ -17,12 +17,20 @@ use Propel\Runtime\Exception\PropelException; use Propel\Runtime\Map\TableMap; use Propel\Runtime\Parser\AbstractParser; use Propel\Runtime\Util\PropelDateTime; +use Thelia\Model\Country as ChildCountry; +use Thelia\Model\CountryQuery as ChildCountryQuery; use Thelia\Model\Coupon as ChildCoupon; +use Thelia\Model\CouponCountry as ChildCouponCountry; +use Thelia\Model\CouponCountryQuery as ChildCouponCountryQuery; use Thelia\Model\CouponI18n as ChildCouponI18n; use Thelia\Model\CouponI18nQuery as ChildCouponI18nQuery; +use Thelia\Model\CouponModule as ChildCouponModule; +use Thelia\Model\CouponModuleQuery as ChildCouponModuleQuery; use Thelia\Model\CouponQuery as ChildCouponQuery; use Thelia\Model\CouponVersion as ChildCouponVersion; use Thelia\Model\CouponVersionQuery as ChildCouponVersionQuery; +use Thelia\Model\Module as ChildModule; +use Thelia\Model\ModuleQuery as ChildModuleQuery; use Thelia\Model\Map\CouponTableMap; use Thelia\Model\Map\CouponVersionTableMap; @@ -151,6 +159,18 @@ abstract class Coupon implements ActiveRecordInterface */ protected $version; + /** + * @var ObjectCollection|ChildCouponCountry[] Collection to store aggregation of ChildCouponCountry objects. + */ + protected $collCouponCountries; + protected $collCouponCountriesPartial; + + /** + * @var ObjectCollection|ChildCouponModule[] Collection to store aggregation of ChildCouponModule objects. + */ + protected $collCouponModules; + protected $collCouponModulesPartial; + /** * @var ObjectCollection|ChildCouponI18n[] Collection to store aggregation of ChildCouponI18n objects. */ @@ -163,6 +183,16 @@ abstract class Coupon implements ActiveRecordInterface protected $collCouponVersions; protected $collCouponVersionsPartial; + /** + * @var ChildCountry[] Collection to store aggregation of ChildCountry objects. + */ + protected $collCountries; + + /** + * @var ChildModule[] Collection to store aggregation of ChildModule objects. + */ + protected $collModules; + /** * Flag to prevent endless save loop, if this object is referenced * by another object which falls in this transaction. @@ -193,6 +223,30 @@ abstract class Coupon implements ActiveRecordInterface */ protected $enforceVersion = false; + /** + * An array of objects scheduled for deletion. + * @var ObjectCollection + */ + protected $countriesScheduledForDeletion = null; + + /** + * An array of objects scheduled for deletion. + * @var ObjectCollection + */ + protected $modulesScheduledForDeletion = null; + + /** + * An array of objects scheduled for deletion. + * @var ObjectCollection + */ + protected $couponCountriesScheduledForDeletion = null; + + /** + * An array of objects scheduled for deletion. + * @var ObjectCollection + */ + protected $couponModulesScheduledForDeletion = null; + /** * An array of objects scheduled for deletion. * @var ObjectCollection @@ -1186,10 +1240,16 @@ abstract class Coupon implements ActiveRecordInterface if ($deep) { // also de-associate any related objects? + $this->collCouponCountries = null; + + $this->collCouponModules = null; + $this->collCouponI18ns = null; $this->collCouponVersions = null; + $this->collCountries = null; + $this->collModules = null; } // if (deep) } @@ -1332,6 +1392,94 @@ abstract class Coupon implements ActiveRecordInterface $this->resetModified(); } + if ($this->countriesScheduledForDeletion !== null) { + if (!$this->countriesScheduledForDeletion->isEmpty()) { + $pks = array(); + $pk = $this->getPrimaryKey(); + foreach ($this->countriesScheduledForDeletion->getPrimaryKeys(false) as $remotePk) { + $pks[] = array($remotePk, $pk); + } + + CouponCountryQuery::create() + ->filterByPrimaryKeys($pks) + ->delete($con); + $this->countriesScheduledForDeletion = null; + } + + foreach ($this->getCountries() as $country) { + if ($country->isModified()) { + $country->save($con); + } + } + } elseif ($this->collCountries) { + foreach ($this->collCountries as $country) { + if ($country->isModified()) { + $country->save($con); + } + } + } + + if ($this->modulesScheduledForDeletion !== null) { + if (!$this->modulesScheduledForDeletion->isEmpty()) { + $pks = array(); + $pk = $this->getPrimaryKey(); + foreach ($this->modulesScheduledForDeletion->getPrimaryKeys(false) as $remotePk) { + $pks[] = array($pk, $remotePk); + } + + CouponModuleQuery::create() + ->filterByPrimaryKeys($pks) + ->delete($con); + $this->modulesScheduledForDeletion = null; + } + + foreach ($this->getModules() as $module) { + if ($module->isModified()) { + $module->save($con); + } + } + } elseif ($this->collModules) { + foreach ($this->collModules as $module) { + if ($module->isModified()) { + $module->save($con); + } + } + } + + if ($this->couponCountriesScheduledForDeletion !== null) { + if (!$this->couponCountriesScheduledForDeletion->isEmpty()) { + \Thelia\Model\CouponCountryQuery::create() + ->filterByPrimaryKeys($this->couponCountriesScheduledForDeletion->getPrimaryKeys(false)) + ->delete($con); + $this->couponCountriesScheduledForDeletion = null; + } + } + + if ($this->collCouponCountries !== null) { + foreach ($this->collCouponCountries as $referrerFK) { + if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) { + $affectedRows += $referrerFK->save($con); + } + } + } + + if ($this->couponModulesScheduledForDeletion !== null) { + if (!$this->couponModulesScheduledForDeletion->isEmpty()) { + \Thelia\Model\CouponModuleQuery::create() + ->filterByPrimaryKeys($this->couponModulesScheduledForDeletion->getPrimaryKeys(false)) + ->delete($con); + $this->couponModulesScheduledForDeletion = null; + } + } + + if ($this->collCouponModules !== null) { + foreach ($this->collCouponModules as $referrerFK) { + if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) { + $affectedRows += $referrerFK->save($con); + } + } + } + if ($this->couponI18nsScheduledForDeletion !== null) { if (!$this->couponI18nsScheduledForDeletion->isEmpty()) { \Thelia\Model\CouponI18nQuery::create() @@ -1651,6 +1799,12 @@ abstract class Coupon implements ActiveRecordInterface } if ($includeForeignObjects) { + if (null !== $this->collCouponCountries) { + $result['CouponCountries'] = $this->collCouponCountries->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); + } + if (null !== $this->collCouponModules) { + $result['CouponModules'] = $this->collCouponModules->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); + } if (null !== $this->collCouponI18ns) { $result['CouponI18ns'] = $this->collCouponI18ns->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); } @@ -1884,6 +2038,18 @@ abstract class Coupon implements ActiveRecordInterface // the getter/setter methods for fkey referrer objects. $copyObj->setNew(false); + foreach ($this->getCouponCountries() as $relObj) { + if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves + $copyObj->addCouponCountry($relObj->copy($deepCopy)); + } + } + + foreach ($this->getCouponModules() as $relObj) { + if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves + $copyObj->addCouponModule($relObj->copy($deepCopy)); + } + } + foreach ($this->getCouponI18ns() as $relObj) { if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves $copyObj->addCouponI18n($relObj->copy($deepCopy)); @@ -1937,6 +2103,12 @@ abstract class Coupon implements ActiveRecordInterface */ public function initRelation($relationName) { + if ('CouponCountry' == $relationName) { + return $this->initCouponCountries(); + } + if ('CouponModule' == $relationName) { + return $this->initCouponModules(); + } if ('CouponI18n' == $relationName) { return $this->initCouponI18ns(); } @@ -1945,6 +2117,498 @@ abstract class Coupon implements ActiveRecordInterface } } + /** + * Clears out the collCouponCountries 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 addCouponCountries() + */ + public function clearCouponCountries() + { + $this->collCouponCountries = null; // important to set this to NULL since that means it is uninitialized + } + + /** + * Reset is the collCouponCountries collection loaded partially. + */ + public function resetPartialCouponCountries($v = true) + { + $this->collCouponCountriesPartial = $v; + } + + /** + * Initializes the collCouponCountries collection. + * + * By default this just sets the collCouponCountries collection to an empty array (like clearcollCouponCountries()); + * 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 initCouponCountries($overrideExisting = true) + { + if (null !== $this->collCouponCountries && !$overrideExisting) { + return; + } + $this->collCouponCountries = new ObjectCollection(); + $this->collCouponCountries->setModel('\Thelia\Model\CouponCountry'); + } + + /** + * Gets an array of ChildCouponCountry 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 ChildCoupon 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|ChildCouponCountry[] List of ChildCouponCountry objects + * @throws PropelException + */ + public function getCouponCountries($criteria = null, ConnectionInterface $con = null) + { + $partial = $this->collCouponCountriesPartial && !$this->isNew(); + if (null === $this->collCouponCountries || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collCouponCountries) { + // return empty collection + $this->initCouponCountries(); + } else { + $collCouponCountries = ChildCouponCountryQuery::create(null, $criteria) + ->filterByCoupon($this) + ->find($con); + + if (null !== $criteria) { + if (false !== $this->collCouponCountriesPartial && count($collCouponCountries)) { + $this->initCouponCountries(false); + + foreach ($collCouponCountries as $obj) { + if (false == $this->collCouponCountries->contains($obj)) { + $this->collCouponCountries->append($obj); + } + } + + $this->collCouponCountriesPartial = true; + } + + reset($collCouponCountries); + + return $collCouponCountries; + } + + if ($partial && $this->collCouponCountries) { + foreach ($this->collCouponCountries as $obj) { + if ($obj->isNew()) { + $collCouponCountries[] = $obj; + } + } + } + + $this->collCouponCountries = $collCouponCountries; + $this->collCouponCountriesPartial = false; + } + } + + return $this->collCouponCountries; + } + + /** + * Sets a collection of CouponCountry 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 $couponCountries A Propel collection. + * @param ConnectionInterface $con Optional connection object + * @return ChildCoupon The current object (for fluent API support) + */ + public function setCouponCountries(Collection $couponCountries, ConnectionInterface $con = null) + { + $couponCountriesToDelete = $this->getCouponCountries(new Criteria(), $con)->diff($couponCountries); + + + //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->couponCountriesScheduledForDeletion = clone $couponCountriesToDelete; + + foreach ($couponCountriesToDelete as $couponCountryRemoved) { + $couponCountryRemoved->setCoupon(null); + } + + $this->collCouponCountries = null; + foreach ($couponCountries as $couponCountry) { + $this->addCouponCountry($couponCountry); + } + + $this->collCouponCountries = $couponCountries; + $this->collCouponCountriesPartial = false; + + return $this; + } + + /** + * Returns the number of related CouponCountry objects. + * + * @param Criteria $criteria + * @param boolean $distinct + * @param ConnectionInterface $con + * @return int Count of related CouponCountry objects. + * @throws PropelException + */ + public function countCouponCountries(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) + { + $partial = $this->collCouponCountriesPartial && !$this->isNew(); + if (null === $this->collCouponCountries || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collCouponCountries) { + return 0; + } + + if ($partial && !$criteria) { + return count($this->getCouponCountries()); + } + + $query = ChildCouponCountryQuery::create(null, $criteria); + if ($distinct) { + $query->distinct(); + } + + return $query + ->filterByCoupon($this) + ->count($con); + } + + return count($this->collCouponCountries); + } + + /** + * Method called to associate a ChildCouponCountry object to this object + * through the ChildCouponCountry foreign key attribute. + * + * @param ChildCouponCountry $l ChildCouponCountry + * @return \Thelia\Model\Coupon The current object (for fluent API support) + */ + public function addCouponCountry(ChildCouponCountry $l) + { + if ($this->collCouponCountries === null) { + $this->initCouponCountries(); + $this->collCouponCountriesPartial = true; + } + + if (!in_array($l, $this->collCouponCountries->getArrayCopy(), true)) { // only add it if the **same** object is not already associated + $this->doAddCouponCountry($l); + } + + return $this; + } + + /** + * @param CouponCountry $couponCountry The couponCountry object to add. + */ + protected function doAddCouponCountry($couponCountry) + { + $this->collCouponCountries[]= $couponCountry; + $couponCountry->setCoupon($this); + } + + /** + * @param CouponCountry $couponCountry The couponCountry object to remove. + * @return ChildCoupon The current object (for fluent API support) + */ + public function removeCouponCountry($couponCountry) + { + if ($this->getCouponCountries()->contains($couponCountry)) { + $this->collCouponCountries->remove($this->collCouponCountries->search($couponCountry)); + if (null === $this->couponCountriesScheduledForDeletion) { + $this->couponCountriesScheduledForDeletion = clone $this->collCouponCountries; + $this->couponCountriesScheduledForDeletion->clear(); + } + $this->couponCountriesScheduledForDeletion[]= clone $couponCountry; + $couponCountry->setCoupon(null); + } + + return $this; + } + + + /** + * If this collection has already been initialized with + * an identical criteria, it returns the collection. + * Otherwise if this Coupon is new, it will return + * an empty collection; or if this Coupon has previously + * been saved, it will retrieve related CouponCountries from storage. + * + * This method is protected by default in order to keep the public + * api reasonable. You can provide public methods for those you + * actually need in Coupon. + * + * @param Criteria $criteria optional Criteria object to narrow the query + * @param ConnectionInterface $con optional connection object + * @param string $joinBehavior optional join type to use (defaults to Criteria::LEFT_JOIN) + * @return Collection|ChildCouponCountry[] List of ChildCouponCountry objects + */ + public function getCouponCountriesJoinCountry($criteria = null, $con = null, $joinBehavior = Criteria::LEFT_JOIN) + { + $query = ChildCouponCountryQuery::create(null, $criteria); + $query->joinWith('Country', $joinBehavior); + + return $this->getCouponCountries($query, $con); + } + + /** + * Clears out the collCouponModules 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 addCouponModules() + */ + public function clearCouponModules() + { + $this->collCouponModules = null; // important to set this to NULL since that means it is uninitialized + } + + /** + * Reset is the collCouponModules collection loaded partially. + */ + public function resetPartialCouponModules($v = true) + { + $this->collCouponModulesPartial = $v; + } + + /** + * Initializes the collCouponModules collection. + * + * By default this just sets the collCouponModules collection to an empty array (like clearcollCouponModules()); + * 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 initCouponModules($overrideExisting = true) + { + if (null !== $this->collCouponModules && !$overrideExisting) { + return; + } + $this->collCouponModules = new ObjectCollection(); + $this->collCouponModules->setModel('\Thelia\Model\CouponModule'); + } + + /** + * Gets an array of ChildCouponModule 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 ChildCoupon 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|ChildCouponModule[] List of ChildCouponModule objects + * @throws PropelException + */ + public function getCouponModules($criteria = null, ConnectionInterface $con = null) + { + $partial = $this->collCouponModulesPartial && !$this->isNew(); + if (null === $this->collCouponModules || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collCouponModules) { + // return empty collection + $this->initCouponModules(); + } else { + $collCouponModules = ChildCouponModuleQuery::create(null, $criteria) + ->filterByCoupon($this) + ->find($con); + + if (null !== $criteria) { + if (false !== $this->collCouponModulesPartial && count($collCouponModules)) { + $this->initCouponModules(false); + + foreach ($collCouponModules as $obj) { + if (false == $this->collCouponModules->contains($obj)) { + $this->collCouponModules->append($obj); + } + } + + $this->collCouponModulesPartial = true; + } + + reset($collCouponModules); + + return $collCouponModules; + } + + if ($partial && $this->collCouponModules) { + foreach ($this->collCouponModules as $obj) { + if ($obj->isNew()) { + $collCouponModules[] = $obj; + } + } + } + + $this->collCouponModules = $collCouponModules; + $this->collCouponModulesPartial = false; + } + } + + return $this->collCouponModules; + } + + /** + * Sets a collection of CouponModule 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 $couponModules A Propel collection. + * @param ConnectionInterface $con Optional connection object + * @return ChildCoupon The current object (for fluent API support) + */ + public function setCouponModules(Collection $couponModules, ConnectionInterface $con = null) + { + $couponModulesToDelete = $this->getCouponModules(new Criteria(), $con)->diff($couponModules); + + + //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->couponModulesScheduledForDeletion = clone $couponModulesToDelete; + + foreach ($couponModulesToDelete as $couponModuleRemoved) { + $couponModuleRemoved->setCoupon(null); + } + + $this->collCouponModules = null; + foreach ($couponModules as $couponModule) { + $this->addCouponModule($couponModule); + } + + $this->collCouponModules = $couponModules; + $this->collCouponModulesPartial = false; + + return $this; + } + + /** + * Returns the number of related CouponModule objects. + * + * @param Criteria $criteria + * @param boolean $distinct + * @param ConnectionInterface $con + * @return int Count of related CouponModule objects. + * @throws PropelException + */ + public function countCouponModules(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) + { + $partial = $this->collCouponModulesPartial && !$this->isNew(); + if (null === $this->collCouponModules || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collCouponModules) { + return 0; + } + + if ($partial && !$criteria) { + return count($this->getCouponModules()); + } + + $query = ChildCouponModuleQuery::create(null, $criteria); + if ($distinct) { + $query->distinct(); + } + + return $query + ->filterByCoupon($this) + ->count($con); + } + + return count($this->collCouponModules); + } + + /** + * Method called to associate a ChildCouponModule object to this object + * through the ChildCouponModule foreign key attribute. + * + * @param ChildCouponModule $l ChildCouponModule + * @return \Thelia\Model\Coupon The current object (for fluent API support) + */ + public function addCouponModule(ChildCouponModule $l) + { + if ($this->collCouponModules === null) { + $this->initCouponModules(); + $this->collCouponModulesPartial = true; + } + + if (!in_array($l, $this->collCouponModules->getArrayCopy(), true)) { // only add it if the **same** object is not already associated + $this->doAddCouponModule($l); + } + + return $this; + } + + /** + * @param CouponModule $couponModule The couponModule object to add. + */ + protected function doAddCouponModule($couponModule) + { + $this->collCouponModules[]= $couponModule; + $couponModule->setCoupon($this); + } + + /** + * @param CouponModule $couponModule The couponModule object to remove. + * @return ChildCoupon The current object (for fluent API support) + */ + public function removeCouponModule($couponModule) + { + if ($this->getCouponModules()->contains($couponModule)) { + $this->collCouponModules->remove($this->collCouponModules->search($couponModule)); + if (null === $this->couponModulesScheduledForDeletion) { + $this->couponModulesScheduledForDeletion = clone $this->collCouponModules; + $this->couponModulesScheduledForDeletion->clear(); + } + $this->couponModulesScheduledForDeletion[]= clone $couponModule; + $couponModule->setCoupon(null); + } + + return $this; + } + + + /** + * If this collection has already been initialized with + * an identical criteria, it returns the collection. + * Otherwise if this Coupon is new, it will return + * an empty collection; or if this Coupon has previously + * been saved, it will retrieve related CouponModules from storage. + * + * This method is protected by default in order to keep the public + * api reasonable. You can provide public methods for those you + * actually need in Coupon. + * + * @param Criteria $criteria optional Criteria object to narrow the query + * @param ConnectionInterface $con optional connection object + * @param string $joinBehavior optional join type to use (defaults to Criteria::LEFT_JOIN) + * @return Collection|ChildCouponModule[] List of ChildCouponModule objects + */ + public function getCouponModulesJoinModule($criteria = null, $con = null, $joinBehavior = Criteria::LEFT_JOIN) + { + $query = ChildCouponModuleQuery::create(null, $criteria); + $query->joinWith('Module', $joinBehavior); + + return $this->getCouponModules($query, $con); + } + /** * Clears out the collCouponI18ns collection * @@ -2391,6 +3055,372 @@ abstract class Coupon implements ActiveRecordInterface return $this; } + /** + * Clears out the collCountries 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 addCountries() + */ + public function clearCountries() + { + $this->collCountries = null; // important to set this to NULL since that means it is uninitialized + $this->collCountriesPartial = null; + } + + /** + * Initializes the collCountries collection. + * + * By default this just sets the collCountries collection to an empty collection (like clearCountries()); + * 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. + * + * @return void + */ + public function initCountries() + { + $this->collCountries = new ObjectCollection(); + $this->collCountries->setModel('\Thelia\Model\Country'); + } + + /** + * Gets a collection of ChildCountry objects related by a many-to-many relationship + * to the current object by way of the coupon_country cross-reference table. + * + * 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 ChildCoupon is new, it will return + * an empty collection or the current collection; the criteria is ignored on a new object. + * + * @param Criteria $criteria Optional query object to filter the query + * @param ConnectionInterface $con Optional connection object + * + * @return ObjectCollection|ChildCountry[] List of ChildCountry objects + */ + public function getCountries($criteria = null, ConnectionInterface $con = null) + { + if (null === $this->collCountries || null !== $criteria) { + if ($this->isNew() && null === $this->collCountries) { + // return empty collection + $this->initCountries(); + } else { + $collCountries = ChildCountryQuery::create(null, $criteria) + ->filterByCoupon($this) + ->find($con); + if (null !== $criteria) { + return $collCountries; + } + $this->collCountries = $collCountries; + } + } + + return $this->collCountries; + } + + /** + * Sets a collection of Country objects related by a many-to-many relationship + * to the current object by way of the coupon_country cross-reference table. + * 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 $countries A Propel collection. + * @param ConnectionInterface $con Optional connection object + * @return ChildCoupon The current object (for fluent API support) + */ + public function setCountries(Collection $countries, ConnectionInterface $con = null) + { + $this->clearCountries(); + $currentCountries = $this->getCountries(); + + $this->countriesScheduledForDeletion = $currentCountries->diff($countries); + + foreach ($countries as $country) { + if (!$currentCountries->contains($country)) { + $this->doAddCountry($country); + } + } + + $this->collCountries = $countries; + + return $this; + } + + /** + * Gets the number of ChildCountry objects related by a many-to-many relationship + * to the current object by way of the coupon_country cross-reference table. + * + * @param Criteria $criteria Optional query object to filter the query + * @param boolean $distinct Set to true to force count distinct + * @param ConnectionInterface $con Optional connection object + * + * @return int the number of related ChildCountry objects + */ + public function countCountries($criteria = null, $distinct = false, ConnectionInterface $con = null) + { + if (null === $this->collCountries || null !== $criteria) { + if ($this->isNew() && null === $this->collCountries) { + return 0; + } else { + $query = ChildCountryQuery::create(null, $criteria); + if ($distinct) { + $query->distinct(); + } + + return $query + ->filterByCoupon($this) + ->count($con); + } + } else { + return count($this->collCountries); + } + } + + /** + * Associate a ChildCountry object to this object + * through the coupon_country cross reference table. + * + * @param ChildCountry $country The ChildCouponCountry object to relate + * @return ChildCoupon The current object (for fluent API support) + */ + public function addCountry(ChildCountry $country) + { + if ($this->collCountries === null) { + $this->initCountries(); + } + + if (!$this->collCountries->contains($country)) { // only add it if the **same** object is not already associated + $this->doAddCountry($country); + $this->collCountries[] = $country; + } + + return $this; + } + + /** + * @param Country $country The country object to add. + */ + protected function doAddCountry($country) + { + $couponCountry = new ChildCouponCountry(); + $couponCountry->setCountry($country); + $this->addCouponCountry($couponCountry); + // set the back reference to this object directly as using provided method either results + // in endless loop or in multiple relations + if (!$country->getCoupons()->contains($this)) { + $foreignCollection = $country->getCoupons(); + $foreignCollection[] = $this; + } + } + + /** + * Remove a ChildCountry object to this object + * through the coupon_country cross reference table. + * + * @param ChildCountry $country The ChildCouponCountry object to relate + * @return ChildCoupon The current object (for fluent API support) + */ + public function removeCountry(ChildCountry $country) + { + if ($this->getCountries()->contains($country)) { + $this->collCountries->remove($this->collCountries->search($country)); + + if (null === $this->countriesScheduledForDeletion) { + $this->countriesScheduledForDeletion = clone $this->collCountries; + $this->countriesScheduledForDeletion->clear(); + } + + $this->countriesScheduledForDeletion[] = $country; + } + + return $this; + } + + /** + * Clears out the collModules 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 addModules() + */ + public function clearModules() + { + $this->collModules = null; // important to set this to NULL since that means it is uninitialized + $this->collModulesPartial = null; + } + + /** + * Initializes the collModules collection. + * + * By default this just sets the collModules collection to an empty collection (like clearModules()); + * 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. + * + * @return void + */ + public function initModules() + { + $this->collModules = new ObjectCollection(); + $this->collModules->setModel('\Thelia\Model\Module'); + } + + /** + * Gets a collection of ChildModule objects related by a many-to-many relationship + * to the current object by way of the coupon_module cross-reference table. + * + * 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 ChildCoupon is new, it will return + * an empty collection or the current collection; the criteria is ignored on a new object. + * + * @param Criteria $criteria Optional query object to filter the query + * @param ConnectionInterface $con Optional connection object + * + * @return ObjectCollection|ChildModule[] List of ChildModule objects + */ + public function getModules($criteria = null, ConnectionInterface $con = null) + { + if (null === $this->collModules || null !== $criteria) { + if ($this->isNew() && null === $this->collModules) { + // return empty collection + $this->initModules(); + } else { + $collModules = ChildModuleQuery::create(null, $criteria) + ->filterByCoupon($this) + ->find($con); + if (null !== $criteria) { + return $collModules; + } + $this->collModules = $collModules; + } + } + + return $this->collModules; + } + + /** + * Sets a collection of Module objects related by a many-to-many relationship + * to the current object by way of the coupon_module cross-reference table. + * 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 $modules A Propel collection. + * @param ConnectionInterface $con Optional connection object + * @return ChildCoupon The current object (for fluent API support) + */ + public function setModules(Collection $modules, ConnectionInterface $con = null) + { + $this->clearModules(); + $currentModules = $this->getModules(); + + $this->modulesScheduledForDeletion = $currentModules->diff($modules); + + foreach ($modules as $module) { + if (!$currentModules->contains($module)) { + $this->doAddModule($module); + } + } + + $this->collModules = $modules; + + return $this; + } + + /** + * Gets the number of ChildModule objects related by a many-to-many relationship + * to the current object by way of the coupon_module cross-reference table. + * + * @param Criteria $criteria Optional query object to filter the query + * @param boolean $distinct Set to true to force count distinct + * @param ConnectionInterface $con Optional connection object + * + * @return int the number of related ChildModule objects + */ + public function countModules($criteria = null, $distinct = false, ConnectionInterface $con = null) + { + if (null === $this->collModules || null !== $criteria) { + if ($this->isNew() && null === $this->collModules) { + return 0; + } else { + $query = ChildModuleQuery::create(null, $criteria); + if ($distinct) { + $query->distinct(); + } + + return $query + ->filterByCoupon($this) + ->count($con); + } + } else { + return count($this->collModules); + } + } + + /** + * Associate a ChildModule object to this object + * through the coupon_module cross reference table. + * + * @param ChildModule $module The ChildCouponModule object to relate + * @return ChildCoupon The current object (for fluent API support) + */ + public function addModule(ChildModule $module) + { + if ($this->collModules === null) { + $this->initModules(); + } + + if (!$this->collModules->contains($module)) { // only add it if the **same** object is not already associated + $this->doAddModule($module); + $this->collModules[] = $module; + } + + return $this; + } + + /** + * @param Module $module The module object to add. + */ + protected function doAddModule($module) + { + $couponModule = new ChildCouponModule(); + $couponModule->setModule($module); + $this->addCouponModule($couponModule); + // set the back reference to this object directly as using provided method either results + // in endless loop or in multiple relations + if (!$module->getCoupons()->contains($this)) { + $foreignCollection = $module->getCoupons(); + $foreignCollection[] = $this; + } + } + + /** + * Remove a ChildModule object to this object + * through the coupon_module cross reference table. + * + * @param ChildModule $module The ChildCouponModule object to relate + * @return ChildCoupon The current object (for fluent API support) + */ + public function removeModule(ChildModule $module) + { + if ($this->getModules()->contains($module)) { + $this->collModules->remove($this->collModules->search($module)); + + if (null === $this->modulesScheduledForDeletion) { + $this->modulesScheduledForDeletion = clone $this->collModules; + $this->modulesScheduledForDeletion->clear(); + } + + $this->modulesScheduledForDeletion[] = $module; + } + + return $this; + } + /** * Clears the current object and sets all attributes to their default values */ @@ -2431,6 +3461,16 @@ abstract class Coupon implements ActiveRecordInterface public function clearAllReferences($deep = false) { if ($deep) { + if ($this->collCouponCountries) { + foreach ($this->collCouponCountries as $o) { + $o->clearAllReferences($deep); + } + } + if ($this->collCouponModules) { + foreach ($this->collCouponModules as $o) { + $o->clearAllReferences($deep); + } + } if ($this->collCouponI18ns) { foreach ($this->collCouponI18ns as $o) { $o->clearAllReferences($deep); @@ -2441,14 +3481,28 @@ abstract class Coupon implements ActiveRecordInterface $o->clearAllReferences($deep); } } + if ($this->collCountries) { + foreach ($this->collCountries as $o) { + $o->clearAllReferences($deep); + } + } + if ($this->collModules) { + foreach ($this->collModules as $o) { + $o->clearAllReferences($deep); + } + } } // if ($deep) // i18n behavior $this->currentLocale = 'en_US'; $this->currentTranslations = null; + $this->collCouponCountries = null; + $this->collCouponModules = null; $this->collCouponI18ns = null; $this->collCouponVersions = null; + $this->collCountries = null; + $this->collModules = null; } /** diff --git a/core/lib/Thelia/Model/Base/CouponCountry.php b/core/lib/Thelia/Model/Base/CouponCountry.php new file mode 100644 index 000000000..7d400f640 --- /dev/null +++ b/core/lib/Thelia/Model/Base/CouponCountry.php @@ -0,0 +1,1268 @@ +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 CouponCountry instance. If + * obj is an instance of CouponCountry, delegates to + * equals(CouponCountry). 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 CouponCountry 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 CouponCountry 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 [coupon_id] column value. + * + * @return int + */ + public function getCouponId() + { + + return $this->coupon_id; + } + + /** + * Get the [country_id] column value. + * + * @return int + */ + public function getCountryId() + { + + return $this->country_id; + } + + /** + * Set the value of [coupon_id] column. + * + * @param int $v new value + * @return \Thelia\Model\CouponCountry The current object (for fluent API support) + */ + public function setCouponId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->coupon_id !== $v) { + $this->coupon_id = $v; + $this->modifiedColumns[CouponCountryTableMap::COUPON_ID] = true; + } + + if ($this->aCoupon !== null && $this->aCoupon->getId() !== $v) { + $this->aCoupon = null; + } + + + return $this; + } // setCouponId() + + /** + * Set the value of [country_id] column. + * + * @param int $v new value + * @return \Thelia\Model\CouponCountry The current object (for fluent API support) + */ + public function setCountryId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->country_id !== $v) { + $this->country_id = $v; + $this->modifiedColumns[CouponCountryTableMap::COUNTRY_ID] = true; + } + + if ($this->aCountry !== null && $this->aCountry->getId() !== $v) { + $this->aCountry = null; + } + + + return $this; + } // setCountryId() + + /** + * 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() + { + // 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 : CouponCountryTableMap::translateFieldName('CouponId', TableMap::TYPE_PHPNAME, $indexType)]; + $this->coupon_id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : CouponCountryTableMap::translateFieldName('CountryId', TableMap::TYPE_PHPNAME, $indexType)]; + $this->country_id = (null !== $col) ? (int) $col : null; + $this->resetModified(); + + $this->setNew(false); + + if ($rehydrate) { + $this->ensureConsistency(); + } + + return $startcol + 2; // 2 = CouponCountryTableMap::NUM_HYDRATE_COLUMNS. + + } catch (Exception $e) { + throw new PropelException("Error populating \Thelia\Model\CouponCountry 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->aCoupon !== null && $this->coupon_id !== $this->aCoupon->getId()) { + $this->aCoupon = null; + } + if ($this->aCountry !== null && $this->country_id !== $this->aCountry->getId()) { + $this->aCountry = 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(CouponCountryTableMap::DATABASE_NAME); + } + + // We don't need to alter the object instance pool; we're just modifying this instance + // already in the pool. + + $dataFetcher = ChildCouponCountryQuery::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->aCountry = null; + $this->aCoupon = null; + } // if (deep) + } + + /** + * Removes this object from datastore and sets delete attribute. + * + * @param ConnectionInterface $con + * @return void + * @throws PropelException + * @see CouponCountry::setDeleted() + * @see CouponCountry::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(CouponCountryTableMap::DATABASE_NAME); + } + + $con->beginTransaction(); + try { + $deleteQuery = ChildCouponCountryQuery::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(CouponCountryTableMap::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); + CouponCountryTableMap::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->aCountry !== null) { + if ($this->aCountry->isModified() || $this->aCountry->isNew()) { + $affectedRows += $this->aCountry->save($con); + } + $this->setCountry($this->aCountry); + } + + if ($this->aCoupon !== null) { + if ($this->aCoupon->isModified() || $this->aCoupon->isNew()) { + $affectedRows += $this->aCoupon->save($con); + } + $this->setCoupon($this->aCoupon); + } + + 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(CouponCountryTableMap::COUPON_ID)) { + $modifiedColumns[':p' . $index++] = '`COUPON_ID`'; + } + if ($this->isColumnModified(CouponCountryTableMap::COUNTRY_ID)) { + $modifiedColumns[':p' . $index++] = '`COUNTRY_ID`'; + } + + $sql = sprintf( + 'INSERT INTO `coupon_country` (%s) VALUES (%s)', + implode(', ', $modifiedColumns), + implode(', ', array_keys($modifiedColumns)) + ); + + try { + $stmt = $con->prepare($sql); + foreach ($modifiedColumns as $identifier => $columnName) { + switch ($columnName) { + case '`COUPON_ID`': + $stmt->bindValue($identifier, $this->coupon_id, PDO::PARAM_INT); + break; + case '`COUNTRY_ID`': + $stmt->bindValue($identifier, $this->country_id, PDO::PARAM_INT); + 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 = CouponCountryTableMap::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->getCouponId(); + break; + case 1: + return $this->getCountryId(); + 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['CouponCountry'][serialize($this->getPrimaryKey())])) { + return '*RECURSION*'; + } + $alreadyDumpedObjects['CouponCountry'][serialize($this->getPrimaryKey())] = true; + $keys = CouponCountryTableMap::getFieldNames($keyType); + $result = array( + $keys[0] => $this->getCouponId(), + $keys[1] => $this->getCountryId(), + ); + $virtualColumns = $this->virtualColumns; + foreach ($virtualColumns as $key => $virtualColumn) { + $result[$key] = $virtualColumn; + } + + if ($includeForeignObjects) { + if (null !== $this->aCountry) { + $result['Country'] = $this->aCountry->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); + } + if (null !== $this->aCoupon) { + $result['Coupon'] = $this->aCoupon->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 = CouponCountryTableMap::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->setCouponId($value); + break; + case 1: + $this->setCountryId($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 = CouponCountryTableMap::getFieldNames($keyType); + + if (array_key_exists($keys[0], $arr)) $this->setCouponId($arr[$keys[0]]); + if (array_key_exists($keys[1], $arr)) $this->setCountryId($arr[$keys[1]]); + } + + /** + * 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(CouponCountryTableMap::DATABASE_NAME); + + if ($this->isColumnModified(CouponCountryTableMap::COUPON_ID)) $criteria->add(CouponCountryTableMap::COUPON_ID, $this->coupon_id); + if ($this->isColumnModified(CouponCountryTableMap::COUNTRY_ID)) $criteria->add(CouponCountryTableMap::COUNTRY_ID, $this->country_id); + + 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(CouponCountryTableMap::DATABASE_NAME); + $criteria->add(CouponCountryTableMap::COUPON_ID, $this->coupon_id); + $criteria->add(CouponCountryTableMap::COUNTRY_ID, $this->country_id); + + 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->getCouponId(); + $pks[1] = $this->getCountryId(); + + 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->setCouponId($keys[0]); + $this->setCountryId($keys[1]); + } + + /** + * Returns true if the primary key for this object is null. + * @return boolean + */ + public function isPrimaryKeyNull() + { + + return (null === $this->getCouponId()) && (null === $this->getCountryId()); + } + + /** + * 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\CouponCountry (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->setCouponId($this->getCouponId()); + $copyObj->setCountryId($this->getCountryId()); + 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\CouponCountry 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 ChildCountry object. + * + * @param ChildCountry $v + * @return \Thelia\Model\CouponCountry The current object (for fluent API support) + * @throws PropelException + */ + public function setCountry(ChildCountry $v = null) + { + if ($v === null) { + $this->setCountryId(NULL); + } else { + $this->setCountryId($v->getId()); + } + + $this->aCountry = $v; + + // Add binding for other direction of this n:n relationship. + // If this object has already been added to the ChildCountry object, it will not be re-added. + if ($v !== null) { + $v->addCouponCountry($this); + } + + + return $this; + } + + + /** + * Get the associated ChildCountry object + * + * @param ConnectionInterface $con Optional Connection object. + * @return ChildCountry The associated ChildCountry object. + * @throws PropelException + */ + public function getCountry(ConnectionInterface $con = null) + { + if ($this->aCountry === null && ($this->country_id !== null)) { + $this->aCountry = ChildCountryQuery::create()->findPk($this->country_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->aCountry->addCouponCountries($this); + */ + } + + return $this->aCountry; + } + + /** + * Declares an association between this object and a ChildCoupon object. + * + * @param ChildCoupon $v + * @return \Thelia\Model\CouponCountry The current object (for fluent API support) + * @throws PropelException + */ + public function setCoupon(ChildCoupon $v = null) + { + if ($v === null) { + $this->setCouponId(NULL); + } else { + $this->setCouponId($v->getId()); + } + + $this->aCoupon = $v; + + // Add binding for other direction of this n:n relationship. + // If this object has already been added to the ChildCoupon object, it will not be re-added. + if ($v !== null) { + $v->addCouponCountry($this); + } + + + return $this; + } + + + /** + * Get the associated ChildCoupon object + * + * @param ConnectionInterface $con Optional Connection object. + * @return ChildCoupon The associated ChildCoupon object. + * @throws PropelException + */ + public function getCoupon(ConnectionInterface $con = null) + { + if ($this->aCoupon === null && ($this->coupon_id !== null)) { + $this->aCoupon = ChildCouponQuery::create()->findPk($this->coupon_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->aCoupon->addCouponCountries($this); + */ + } + + return $this->aCoupon; + } + + /** + * Clears the current object and sets all attributes to their default values + */ + public function clear() + { + $this->coupon_id = null; + $this->country_id = null; + $this->alreadyInSave = false; + $this->clearAllReferences(); + $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->aCountry = null; + $this->aCoupon = null; + } + + /** + * Return the string representation of this object + * + * @return string + */ + public function __toString() + { + return (string) $this->exportTo(CouponCountryTableMap::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/CouponCountryQuery.php b/core/lib/Thelia/Model/Base/CouponCountryQuery.php new file mode 100644 index 000000000..43b2d6251 --- /dev/null +++ b/core/lib/Thelia/Model/Base/CouponCountryQuery.php @@ -0,0 +1,568 @@ +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[$coupon_id, $country_id] $key Primary key to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ChildCouponCountry|array|mixed the result, formatted by the current formatter + */ + public function findPk($key, $con = null) + { + if ($key === null) { + return null; + } + if ((null !== ($obj = CouponCountryTableMap::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(CouponCountryTableMap::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 ChildCouponCountry A model object, or null if the key is not found + */ + protected function findPkSimple($key, $con) + { + $sql = 'SELECT `COUPON_ID`, `COUNTRY_ID` FROM `coupon_country` WHERE `COUPON_ID` = :p0 AND `COUNTRY_ID` = :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 ChildCouponCountry(); + $obj->hydrate($row); + CouponCountryTableMap::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 ChildCouponCountry|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 ChildCouponCountryQuery The current query, for fluid interface + */ + public function filterByPrimaryKey($key) + { + $this->addUsingAlias(CouponCountryTableMap::COUPON_ID, $key[0], Criteria::EQUAL); + $this->addUsingAlias(CouponCountryTableMap::COUNTRY_ID, $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 ChildCouponCountryQuery 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(CouponCountryTableMap::COUPON_ID, $key[0], Criteria::EQUAL); + $cton1 = $this->getNewCriterion(CouponCountryTableMap::COUNTRY_ID, $key[1], Criteria::EQUAL); + $cton0->addAnd($cton1); + $this->addOr($cton0); + } + + return $this; + } + + /** + * Filter the query on the coupon_id column + * + * Example usage: + * + * $query->filterByCouponId(1234); // WHERE coupon_id = 1234 + * $query->filterByCouponId(array(12, 34)); // WHERE coupon_id IN (12, 34) + * $query->filterByCouponId(array('min' => 12)); // WHERE coupon_id > 12 + * + * + * @see filterByCoupon() + * + * @param mixed $couponId 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 ChildCouponCountryQuery The current query, for fluid interface + */ + public function filterByCouponId($couponId = null, $comparison = null) + { + if (is_array($couponId)) { + $useMinMax = false; + if (isset($couponId['min'])) { + $this->addUsingAlias(CouponCountryTableMap::COUPON_ID, $couponId['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($couponId['max'])) { + $this->addUsingAlias(CouponCountryTableMap::COUPON_ID, $couponId['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(CouponCountryTableMap::COUPON_ID, $couponId, $comparison); + } + + /** + * Filter the query on the country_id column + * + * Example usage: + * + * $query->filterByCountryId(1234); // WHERE country_id = 1234 + * $query->filterByCountryId(array(12, 34)); // WHERE country_id IN (12, 34) + * $query->filterByCountryId(array('min' => 12)); // WHERE country_id > 12 + * + * + * @see filterByCountry() + * + * @param mixed $countryId 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 ChildCouponCountryQuery The current query, for fluid interface + */ + public function filterByCountryId($countryId = null, $comparison = null) + { + if (is_array($countryId)) { + $useMinMax = false; + if (isset($countryId['min'])) { + $this->addUsingAlias(CouponCountryTableMap::COUNTRY_ID, $countryId['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($countryId['max'])) { + $this->addUsingAlias(CouponCountryTableMap::COUNTRY_ID, $countryId['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(CouponCountryTableMap::COUNTRY_ID, $countryId, $comparison); + } + + /** + * Filter the query by a related \Thelia\Model\Country object + * + * @param \Thelia\Model\Country|ObjectCollection $country The related object(s) to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildCouponCountryQuery The current query, for fluid interface + */ + public function filterByCountry($country, $comparison = null) + { + if ($country instanceof \Thelia\Model\Country) { + return $this + ->addUsingAlias(CouponCountryTableMap::COUNTRY_ID, $country->getId(), $comparison); + } elseif ($country instanceof ObjectCollection) { + if (null === $comparison) { + $comparison = Criteria::IN; + } + + return $this + ->addUsingAlias(CouponCountryTableMap::COUNTRY_ID, $country->toKeyValue('PrimaryKey', 'Id'), $comparison); + } else { + throw new PropelException('filterByCountry() only accepts arguments of type \Thelia\Model\Country or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the Country relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildCouponCountryQuery The current query, for fluid interface + */ + public function joinCountry($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('Country'); + + // 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, 'Country'); + } + + return $this; + } + + /** + * Use the Country relation Country 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\CountryQuery A secondary query class using the current class as primary query + */ + public function useCountryQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + return $this + ->joinCountry($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'Country', '\Thelia\Model\CountryQuery'); + } + + /** + * Filter the query by a related \Thelia\Model\Coupon object + * + * @param \Thelia\Model\Coupon|ObjectCollection $coupon The related object(s) to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildCouponCountryQuery The current query, for fluid interface + */ + public function filterByCoupon($coupon, $comparison = null) + { + if ($coupon instanceof \Thelia\Model\Coupon) { + return $this + ->addUsingAlias(CouponCountryTableMap::COUPON_ID, $coupon->getId(), $comparison); + } elseif ($coupon instanceof ObjectCollection) { + if (null === $comparison) { + $comparison = Criteria::IN; + } + + return $this + ->addUsingAlias(CouponCountryTableMap::COUPON_ID, $coupon->toKeyValue('PrimaryKey', 'Id'), $comparison); + } else { + throw new PropelException('filterByCoupon() only accepts arguments of type \Thelia\Model\Coupon or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the Coupon relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildCouponCountryQuery The current query, for fluid interface + */ + public function joinCoupon($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('Coupon'); + + // 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, 'Coupon'); + } + + return $this; + } + + /** + * Use the Coupon relation Coupon 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\CouponQuery A secondary query class using the current class as primary query + */ + public function useCouponQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + return $this + ->joinCoupon($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'Coupon', '\Thelia\Model\CouponQuery'); + } + + /** + * Exclude object from result + * + * @param ChildCouponCountry $couponCountry Object to remove from the list of results + * + * @return ChildCouponCountryQuery The current query, for fluid interface + */ + public function prune($couponCountry = null) + { + if ($couponCountry) { + $this->addCond('pruneCond0', $this->getAliasedColName(CouponCountryTableMap::COUPON_ID), $couponCountry->getCouponId(), Criteria::NOT_EQUAL); + $this->addCond('pruneCond1', $this->getAliasedColName(CouponCountryTableMap::COUNTRY_ID), $couponCountry->getCountryId(), Criteria::NOT_EQUAL); + $this->combine(array('pruneCond0', 'pruneCond1'), Criteria::LOGICAL_OR); + } + + return $this; + } + + /** + * Deletes all rows from the coupon_country 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(CouponCountryTableMap::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). + CouponCountryTableMap::clearInstancePool(); + CouponCountryTableMap::clearRelatedInstancePool(); + + $con->commit(); + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + + return $affectedRows; + } + + /** + * Performs a DELETE on the database, given a ChildCouponCountry or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or ChildCouponCountry 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(CouponCountryTableMap::DATABASE_NAME); + } + + $criteria = $this; + + // Set the correct dbName + $criteria->setDbName(CouponCountryTableMap::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(); + + + CouponCountryTableMap::removeInstanceFromPool($criteria); + + $affectedRows += ModelCriteria::delete($con); + CouponCountryTableMap::clearRelatedInstancePool(); + $con->commit(); + + return $affectedRows; + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + } + +} // CouponCountryQuery diff --git a/core/lib/Thelia/Model/Base/CouponModule.php b/core/lib/Thelia/Model/Base/CouponModule.php new file mode 100644 index 000000000..174ef9c15 --- /dev/null +++ b/core/lib/Thelia/Model/Base/CouponModule.php @@ -0,0 +1,1268 @@ +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 CouponModule instance. If + * obj is an instance of CouponModule, delegates to + * equals(CouponModule). 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 CouponModule 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 CouponModule 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 [coupon_id] column value. + * + * @return int + */ + public function getCouponId() + { + + return $this->coupon_id; + } + + /** + * Get the [module_id] column value. + * + * @return int + */ + public function getModuleId() + { + + return $this->module_id; + } + + /** + * Set the value of [coupon_id] column. + * + * @param int $v new value + * @return \Thelia\Model\CouponModule The current object (for fluent API support) + */ + public function setCouponId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->coupon_id !== $v) { + $this->coupon_id = $v; + $this->modifiedColumns[CouponModuleTableMap::COUPON_ID] = true; + } + + if ($this->aCoupon !== null && $this->aCoupon->getId() !== $v) { + $this->aCoupon = null; + } + + + return $this; + } // setCouponId() + + /** + * Set the value of [module_id] column. + * + * @param int $v new value + * @return \Thelia\Model\CouponModule The current object (for fluent API support) + */ + public function setModuleId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->module_id !== $v) { + $this->module_id = $v; + $this->modifiedColumns[CouponModuleTableMap::MODULE_ID] = true; + } + + if ($this->aModule !== null && $this->aModule->getId() !== $v) { + $this->aModule = null; + } + + + return $this; + } // setModuleId() + + /** + * 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() + { + // 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 : CouponModuleTableMap::translateFieldName('CouponId', TableMap::TYPE_PHPNAME, $indexType)]; + $this->coupon_id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : CouponModuleTableMap::translateFieldName('ModuleId', TableMap::TYPE_PHPNAME, $indexType)]; + $this->module_id = (null !== $col) ? (int) $col : null; + $this->resetModified(); + + $this->setNew(false); + + if ($rehydrate) { + $this->ensureConsistency(); + } + + return $startcol + 2; // 2 = CouponModuleTableMap::NUM_HYDRATE_COLUMNS. + + } catch (Exception $e) { + throw new PropelException("Error populating \Thelia\Model\CouponModule 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->aCoupon !== null && $this->coupon_id !== $this->aCoupon->getId()) { + $this->aCoupon = null; + } + if ($this->aModule !== null && $this->module_id !== $this->aModule->getId()) { + $this->aModule = 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(CouponModuleTableMap::DATABASE_NAME); + } + + // We don't need to alter the object instance pool; we're just modifying this instance + // already in the pool. + + $dataFetcher = ChildCouponModuleQuery::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->aCoupon = null; + $this->aModule = null; + } // if (deep) + } + + /** + * Removes this object from datastore and sets delete attribute. + * + * @param ConnectionInterface $con + * @return void + * @throws PropelException + * @see CouponModule::setDeleted() + * @see CouponModule::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(CouponModuleTableMap::DATABASE_NAME); + } + + $con->beginTransaction(); + try { + $deleteQuery = ChildCouponModuleQuery::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(CouponModuleTableMap::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); + CouponModuleTableMap::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->aCoupon !== null) { + if ($this->aCoupon->isModified() || $this->aCoupon->isNew()) { + $affectedRows += $this->aCoupon->save($con); + } + $this->setCoupon($this->aCoupon); + } + + if ($this->aModule !== null) { + if ($this->aModule->isModified() || $this->aModule->isNew()) { + $affectedRows += $this->aModule->save($con); + } + $this->setModule($this->aModule); + } + + 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(CouponModuleTableMap::COUPON_ID)) { + $modifiedColumns[':p' . $index++] = '`COUPON_ID`'; + } + if ($this->isColumnModified(CouponModuleTableMap::MODULE_ID)) { + $modifiedColumns[':p' . $index++] = '`MODULE_ID`'; + } + + $sql = sprintf( + 'INSERT INTO `coupon_module` (%s) VALUES (%s)', + implode(', ', $modifiedColumns), + implode(', ', array_keys($modifiedColumns)) + ); + + try { + $stmt = $con->prepare($sql); + foreach ($modifiedColumns as $identifier => $columnName) { + switch ($columnName) { + case '`COUPON_ID`': + $stmt->bindValue($identifier, $this->coupon_id, PDO::PARAM_INT); + break; + case '`MODULE_ID`': + $stmt->bindValue($identifier, $this->module_id, PDO::PARAM_INT); + 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 = CouponModuleTableMap::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->getCouponId(); + break; + case 1: + return $this->getModuleId(); + 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['CouponModule'][serialize($this->getPrimaryKey())])) { + return '*RECURSION*'; + } + $alreadyDumpedObjects['CouponModule'][serialize($this->getPrimaryKey())] = true; + $keys = CouponModuleTableMap::getFieldNames($keyType); + $result = array( + $keys[0] => $this->getCouponId(), + $keys[1] => $this->getModuleId(), + ); + $virtualColumns = $this->virtualColumns; + foreach ($virtualColumns as $key => $virtualColumn) { + $result[$key] = $virtualColumn; + } + + if ($includeForeignObjects) { + if (null !== $this->aCoupon) { + $result['Coupon'] = $this->aCoupon->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); + } + if (null !== $this->aModule) { + $result['Module'] = $this->aModule->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 = CouponModuleTableMap::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->setCouponId($value); + break; + case 1: + $this->setModuleId($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 = CouponModuleTableMap::getFieldNames($keyType); + + if (array_key_exists($keys[0], $arr)) $this->setCouponId($arr[$keys[0]]); + if (array_key_exists($keys[1], $arr)) $this->setModuleId($arr[$keys[1]]); + } + + /** + * 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(CouponModuleTableMap::DATABASE_NAME); + + if ($this->isColumnModified(CouponModuleTableMap::COUPON_ID)) $criteria->add(CouponModuleTableMap::COUPON_ID, $this->coupon_id); + if ($this->isColumnModified(CouponModuleTableMap::MODULE_ID)) $criteria->add(CouponModuleTableMap::MODULE_ID, $this->module_id); + + 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(CouponModuleTableMap::DATABASE_NAME); + $criteria->add(CouponModuleTableMap::COUPON_ID, $this->coupon_id); + $criteria->add(CouponModuleTableMap::MODULE_ID, $this->module_id); + + 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->getCouponId(); + $pks[1] = $this->getModuleId(); + + 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->setCouponId($keys[0]); + $this->setModuleId($keys[1]); + } + + /** + * Returns true if the primary key for this object is null. + * @return boolean + */ + public function isPrimaryKeyNull() + { + + return (null === $this->getCouponId()) && (null === $this->getModuleId()); + } + + /** + * 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\CouponModule (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->setCouponId($this->getCouponId()); + $copyObj->setModuleId($this->getModuleId()); + 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\CouponModule 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 ChildCoupon object. + * + * @param ChildCoupon $v + * @return \Thelia\Model\CouponModule The current object (for fluent API support) + * @throws PropelException + */ + public function setCoupon(ChildCoupon $v = null) + { + if ($v === null) { + $this->setCouponId(NULL); + } else { + $this->setCouponId($v->getId()); + } + + $this->aCoupon = $v; + + // Add binding for other direction of this n:n relationship. + // If this object has already been added to the ChildCoupon object, it will not be re-added. + if ($v !== null) { + $v->addCouponModule($this); + } + + + return $this; + } + + + /** + * Get the associated ChildCoupon object + * + * @param ConnectionInterface $con Optional Connection object. + * @return ChildCoupon The associated ChildCoupon object. + * @throws PropelException + */ + public function getCoupon(ConnectionInterface $con = null) + { + if ($this->aCoupon === null && ($this->coupon_id !== null)) { + $this->aCoupon = ChildCouponQuery::create()->findPk($this->coupon_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->aCoupon->addCouponModules($this); + */ + } + + return $this->aCoupon; + } + + /** + * Declares an association between this object and a ChildModule object. + * + * @param ChildModule $v + * @return \Thelia\Model\CouponModule The current object (for fluent API support) + * @throws PropelException + */ + public function setModule(ChildModule $v = null) + { + if ($v === null) { + $this->setModuleId(NULL); + } else { + $this->setModuleId($v->getId()); + } + + $this->aModule = $v; + + // Add binding for other direction of this n:n relationship. + // If this object has already been added to the ChildModule object, it will not be re-added. + if ($v !== null) { + $v->addCouponModule($this); + } + + + return $this; + } + + + /** + * Get the associated ChildModule object + * + * @param ConnectionInterface $con Optional Connection object. + * @return ChildModule The associated ChildModule object. + * @throws PropelException + */ + public function getModule(ConnectionInterface $con = null) + { + if ($this->aModule === null && ($this->module_id !== null)) { + $this->aModule = ChildModuleQuery::create()->findPk($this->module_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->aModule->addCouponModules($this); + */ + } + + return $this->aModule; + } + + /** + * Clears the current object and sets all attributes to their default values + */ + public function clear() + { + $this->coupon_id = null; + $this->module_id = null; + $this->alreadyInSave = false; + $this->clearAllReferences(); + $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->aCoupon = null; + $this->aModule = null; + } + + /** + * Return the string representation of this object + * + * @return string + */ + public function __toString() + { + return (string) $this->exportTo(CouponModuleTableMap::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/CouponModuleQuery.php b/core/lib/Thelia/Model/Base/CouponModuleQuery.php new file mode 100644 index 000000000..162748d9e --- /dev/null +++ b/core/lib/Thelia/Model/Base/CouponModuleQuery.php @@ -0,0 +1,568 @@ +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[$coupon_id, $module_id] $key Primary key to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ChildCouponModule|array|mixed the result, formatted by the current formatter + */ + public function findPk($key, $con = null) + { + if ($key === null) { + return null; + } + if ((null !== ($obj = CouponModuleTableMap::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(CouponModuleTableMap::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 ChildCouponModule A model object, or null if the key is not found + */ + protected function findPkSimple($key, $con) + { + $sql = 'SELECT `COUPON_ID`, `MODULE_ID` FROM `coupon_module` WHERE `COUPON_ID` = :p0 AND `MODULE_ID` = :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 ChildCouponModule(); + $obj->hydrate($row); + CouponModuleTableMap::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 ChildCouponModule|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 ChildCouponModuleQuery The current query, for fluid interface + */ + public function filterByPrimaryKey($key) + { + $this->addUsingAlias(CouponModuleTableMap::COUPON_ID, $key[0], Criteria::EQUAL); + $this->addUsingAlias(CouponModuleTableMap::MODULE_ID, $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 ChildCouponModuleQuery 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(CouponModuleTableMap::COUPON_ID, $key[0], Criteria::EQUAL); + $cton1 = $this->getNewCriterion(CouponModuleTableMap::MODULE_ID, $key[1], Criteria::EQUAL); + $cton0->addAnd($cton1); + $this->addOr($cton0); + } + + return $this; + } + + /** + * Filter the query on the coupon_id column + * + * Example usage: + * + * $query->filterByCouponId(1234); // WHERE coupon_id = 1234 + * $query->filterByCouponId(array(12, 34)); // WHERE coupon_id IN (12, 34) + * $query->filterByCouponId(array('min' => 12)); // WHERE coupon_id > 12 + * + * + * @see filterByCoupon() + * + * @param mixed $couponId 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 ChildCouponModuleQuery The current query, for fluid interface + */ + public function filterByCouponId($couponId = null, $comparison = null) + { + if (is_array($couponId)) { + $useMinMax = false; + if (isset($couponId['min'])) { + $this->addUsingAlias(CouponModuleTableMap::COUPON_ID, $couponId['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($couponId['max'])) { + $this->addUsingAlias(CouponModuleTableMap::COUPON_ID, $couponId['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(CouponModuleTableMap::COUPON_ID, $couponId, $comparison); + } + + /** + * Filter the query on the module_id column + * + * Example usage: + * + * $query->filterByModuleId(1234); // WHERE module_id = 1234 + * $query->filterByModuleId(array(12, 34)); // WHERE module_id IN (12, 34) + * $query->filterByModuleId(array('min' => 12)); // WHERE module_id > 12 + * + * + * @see filterByModule() + * + * @param mixed $moduleId 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 ChildCouponModuleQuery The current query, for fluid interface + */ + public function filterByModuleId($moduleId = null, $comparison = null) + { + if (is_array($moduleId)) { + $useMinMax = false; + if (isset($moduleId['min'])) { + $this->addUsingAlias(CouponModuleTableMap::MODULE_ID, $moduleId['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($moduleId['max'])) { + $this->addUsingAlias(CouponModuleTableMap::MODULE_ID, $moduleId['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(CouponModuleTableMap::MODULE_ID, $moduleId, $comparison); + } + + /** + * Filter the query by a related \Thelia\Model\Coupon object + * + * @param \Thelia\Model\Coupon|ObjectCollection $coupon The related object(s) to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildCouponModuleQuery The current query, for fluid interface + */ + public function filterByCoupon($coupon, $comparison = null) + { + if ($coupon instanceof \Thelia\Model\Coupon) { + return $this + ->addUsingAlias(CouponModuleTableMap::COUPON_ID, $coupon->getId(), $comparison); + } elseif ($coupon instanceof ObjectCollection) { + if (null === $comparison) { + $comparison = Criteria::IN; + } + + return $this + ->addUsingAlias(CouponModuleTableMap::COUPON_ID, $coupon->toKeyValue('PrimaryKey', 'Id'), $comparison); + } else { + throw new PropelException('filterByCoupon() only accepts arguments of type \Thelia\Model\Coupon or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the Coupon relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildCouponModuleQuery The current query, for fluid interface + */ + public function joinCoupon($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('Coupon'); + + // 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, 'Coupon'); + } + + return $this; + } + + /** + * Use the Coupon relation Coupon 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\CouponQuery A secondary query class using the current class as primary query + */ + public function useCouponQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + return $this + ->joinCoupon($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'Coupon', '\Thelia\Model\CouponQuery'); + } + + /** + * Filter the query by a related \Thelia\Model\Module object + * + * @param \Thelia\Model\Module|ObjectCollection $module The related object(s) to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildCouponModuleQuery The current query, for fluid interface + */ + public function filterByModule($module, $comparison = null) + { + if ($module instanceof \Thelia\Model\Module) { + return $this + ->addUsingAlias(CouponModuleTableMap::MODULE_ID, $module->getId(), $comparison); + } elseif ($module instanceof ObjectCollection) { + if (null === $comparison) { + $comparison = Criteria::IN; + } + + return $this + ->addUsingAlias(CouponModuleTableMap::MODULE_ID, $module->toKeyValue('PrimaryKey', 'Id'), $comparison); + } else { + throw new PropelException('filterByModule() only accepts arguments of type \Thelia\Model\Module or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the Module relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildCouponModuleQuery The current query, for fluid interface + */ + public function joinModule($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('Module'); + + // 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, 'Module'); + } + + return $this; + } + + /** + * Use the Module relation Module 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\ModuleQuery A secondary query class using the current class as primary query + */ + public function useModuleQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + return $this + ->joinModule($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'Module', '\Thelia\Model\ModuleQuery'); + } + + /** + * Exclude object from result + * + * @param ChildCouponModule $couponModule Object to remove from the list of results + * + * @return ChildCouponModuleQuery The current query, for fluid interface + */ + public function prune($couponModule = null) + { + if ($couponModule) { + $this->addCond('pruneCond0', $this->getAliasedColName(CouponModuleTableMap::COUPON_ID), $couponModule->getCouponId(), Criteria::NOT_EQUAL); + $this->addCond('pruneCond1', $this->getAliasedColName(CouponModuleTableMap::MODULE_ID), $couponModule->getModuleId(), Criteria::NOT_EQUAL); + $this->combine(array('pruneCond0', 'pruneCond1'), Criteria::LOGICAL_OR); + } + + return $this; + } + + /** + * Deletes all rows from the coupon_module 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(CouponModuleTableMap::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). + CouponModuleTableMap::clearInstancePool(); + CouponModuleTableMap::clearRelatedInstancePool(); + + $con->commit(); + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + + return $affectedRows; + } + + /** + * Performs a DELETE on the database, given a ChildCouponModule or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or ChildCouponModule 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(CouponModuleTableMap::DATABASE_NAME); + } + + $criteria = $this; + + // Set the correct dbName + $criteria->setDbName(CouponModuleTableMap::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(); + + + CouponModuleTableMap::removeInstanceFromPool($criteria); + + $affectedRows += ModelCriteria::delete($con); + CouponModuleTableMap::clearRelatedInstancePool(); + $con->commit(); + + return $affectedRows; + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + } + +} // CouponModuleQuery diff --git a/core/lib/Thelia/Model/Base/CouponQuery.php b/core/lib/Thelia/Model/Base/CouponQuery.php index 0967d21e2..3a07d41ca 100644 --- a/core/lib/Thelia/Model/Base/CouponQuery.php +++ b/core/lib/Thelia/Model/Base/CouponQuery.php @@ -58,6 +58,14 @@ use Thelia\Model\Map\CouponTableMap; * @method ChildCouponQuery rightJoin($relation) Adds a RIGHT JOIN clause to the query * @method ChildCouponQuery innerJoin($relation) Adds a INNER JOIN clause to the query * + * @method ChildCouponQuery leftJoinCouponCountry($relationAlias = null) Adds a LEFT JOIN clause to the query using the CouponCountry relation + * @method ChildCouponQuery rightJoinCouponCountry($relationAlias = null) Adds a RIGHT JOIN clause to the query using the CouponCountry relation + * @method ChildCouponQuery innerJoinCouponCountry($relationAlias = null) Adds a INNER JOIN clause to the query using the CouponCountry relation + * + * @method ChildCouponQuery leftJoinCouponModule($relationAlias = null) Adds a LEFT JOIN clause to the query using the CouponModule relation + * @method ChildCouponQuery rightJoinCouponModule($relationAlias = null) Adds a RIGHT JOIN clause to the query using the CouponModule relation + * @method ChildCouponQuery innerJoinCouponModule($relationAlias = null) Adds a INNER JOIN clause to the query using the CouponModule relation + * * @method ChildCouponQuery leftJoinCouponI18n($relationAlias = null) Adds a LEFT JOIN clause to the query using the CouponI18n relation * @method ChildCouponQuery rightJoinCouponI18n($relationAlias = null) Adds a RIGHT JOIN clause to the query using the CouponI18n relation * @method ChildCouponQuery innerJoinCouponI18n($relationAlias = null) Adds a INNER JOIN clause to the query using the CouponI18n relation @@ -787,6 +795,152 @@ abstract class CouponQuery extends ModelCriteria return $this->addUsingAlias(CouponTableMap::VERSION, $version, $comparison); } + /** + * Filter the query by a related \Thelia\Model\CouponCountry object + * + * @param \Thelia\Model\CouponCountry|ObjectCollection $couponCountry the related object to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildCouponQuery The current query, for fluid interface + */ + public function filterByCouponCountry($couponCountry, $comparison = null) + { + if ($couponCountry instanceof \Thelia\Model\CouponCountry) { + return $this + ->addUsingAlias(CouponTableMap::ID, $couponCountry->getCouponId(), $comparison); + } elseif ($couponCountry instanceof ObjectCollection) { + return $this + ->useCouponCountryQuery() + ->filterByPrimaryKeys($couponCountry->getPrimaryKeys()) + ->endUse(); + } else { + throw new PropelException('filterByCouponCountry() only accepts arguments of type \Thelia\Model\CouponCountry or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the CouponCountry relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildCouponQuery The current query, for fluid interface + */ + public function joinCouponCountry($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('CouponCountry'); + + // 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, 'CouponCountry'); + } + + return $this; + } + + /** + * Use the CouponCountry relation CouponCountry 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\CouponCountryQuery A secondary query class using the current class as primary query + */ + public function useCouponCountryQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + return $this + ->joinCouponCountry($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'CouponCountry', '\Thelia\Model\CouponCountryQuery'); + } + + /** + * Filter the query by a related \Thelia\Model\CouponModule object + * + * @param \Thelia\Model\CouponModule|ObjectCollection $couponModule the related object to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildCouponQuery The current query, for fluid interface + */ + public function filterByCouponModule($couponModule, $comparison = null) + { + if ($couponModule instanceof \Thelia\Model\CouponModule) { + return $this + ->addUsingAlias(CouponTableMap::ID, $couponModule->getCouponId(), $comparison); + } elseif ($couponModule instanceof ObjectCollection) { + return $this + ->useCouponModuleQuery() + ->filterByPrimaryKeys($couponModule->getPrimaryKeys()) + ->endUse(); + } else { + throw new PropelException('filterByCouponModule() only accepts arguments of type \Thelia\Model\CouponModule or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the CouponModule relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildCouponQuery The current query, for fluid interface + */ + public function joinCouponModule($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('CouponModule'); + + // 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, 'CouponModule'); + } + + return $this; + } + + /** + * Use the CouponModule relation CouponModule 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\CouponModuleQuery A secondary query class using the current class as primary query + */ + public function useCouponModuleQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + return $this + ->joinCouponModule($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'CouponModule', '\Thelia\Model\CouponModuleQuery'); + } + /** * Filter the query by a related \Thelia\Model\CouponI18n object * @@ -933,6 +1087,40 @@ abstract class CouponQuery extends ModelCriteria ->useQuery($relationAlias ? $relationAlias : 'CouponVersion', '\Thelia\Model\CouponVersionQuery'); } + /** + * Filter the query by a related Country object + * using the coupon_country table as cross reference + * + * @param Country $country the related object to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildCouponQuery The current query, for fluid interface + */ + public function filterByCountry($country, $comparison = Criteria::EQUAL) + { + return $this + ->useCouponCountryQuery() + ->filterByCountry($country, $comparison) + ->endUse(); + } + + /** + * Filter the query by a related Module object + * using the coupon_module table as cross reference + * + * @param Module $module the related object to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildCouponQuery The current query, for fluid interface + */ + public function filterByModule($module, $comparison = Criteria::EQUAL) + { + return $this + ->useCouponModuleQuery() + ->filterByModule($module, $comparison) + ->endUse(); + } + /** * Exclude object from result * diff --git a/core/lib/Thelia/Model/Base/Module.php b/core/lib/Thelia/Model/Base/Module.php index 5635c3028..159f1ecf0 100644 --- a/core/lib/Thelia/Model/Base/Module.php +++ b/core/lib/Thelia/Model/Base/Module.php @@ -19,6 +19,10 @@ use Propel\Runtime\Parser\AbstractParser; use Propel\Runtime\Util\PropelDateTime; use Thelia\Model\AreaDeliveryModule as ChildAreaDeliveryModule; use Thelia\Model\AreaDeliveryModuleQuery as ChildAreaDeliveryModuleQuery; +use Thelia\Model\Coupon as ChildCoupon; +use Thelia\Model\CouponModule as ChildCouponModule; +use Thelia\Model\CouponModuleQuery as ChildCouponModuleQuery; +use Thelia\Model\CouponQuery as ChildCouponQuery; use Thelia\Model\Module as ChildModule; use Thelia\Model\ModuleI18n as ChildModuleI18n; use Thelia\Model\ModuleI18nQuery as ChildModuleI18nQuery; @@ -143,12 +147,23 @@ abstract class Module implements ActiveRecordInterface protected $collModuleImages; protected $collModuleImagesPartial; + /** + * @var ObjectCollection|ChildCouponModule[] Collection to store aggregation of ChildCouponModule objects. + */ + protected $collCouponModules; + protected $collCouponModulesPartial; + /** * @var ObjectCollection|ChildModuleI18n[] Collection to store aggregation of ChildModuleI18n objects. */ protected $collModuleI18ns; protected $collModuleI18nsPartial; + /** + * @var ChildCoupon[] Collection to store aggregation of ChildCoupon objects. + */ + protected $collCoupons; + /** * Flag to prevent endless save loop, if this object is referenced * by another object which falls in this transaction. @@ -171,6 +186,12 @@ abstract class Module implements ActiveRecordInterface */ protected $currentTranslations; + /** + * An array of objects scheduled for deletion. + * @var ObjectCollection + */ + protected $couponsScheduledForDeletion = null; + /** * An array of objects scheduled for deletion. * @var ObjectCollection @@ -201,6 +222,12 @@ abstract class Module implements ActiveRecordInterface */ protected $moduleImagesScheduledForDeletion = null; + /** + * An array of objects scheduled for deletion. + * @var ObjectCollection + */ + protected $couponModulesScheduledForDeletion = null; + /** * An array of objects scheduled for deletion. * @var ObjectCollection @@ -884,8 +911,11 @@ abstract class Module implements ActiveRecordInterface $this->collModuleImages = null; + $this->collCouponModules = null; + $this->collModuleI18ns = null; + $this->collCoupons = null; } // if (deep) } @@ -1019,6 +1049,33 @@ abstract class Module implements ActiveRecordInterface $this->resetModified(); } + if ($this->couponsScheduledForDeletion !== null) { + if (!$this->couponsScheduledForDeletion->isEmpty()) { + $pks = array(); + $pk = $this->getPrimaryKey(); + foreach ($this->couponsScheduledForDeletion->getPrimaryKeys(false) as $remotePk) { + $pks[] = array($remotePk, $pk); + } + + CouponModuleQuery::create() + ->filterByPrimaryKeys($pks) + ->delete($con); + $this->couponsScheduledForDeletion = null; + } + + foreach ($this->getCoupons() as $coupon) { + if ($coupon->isModified()) { + $coupon->save($con); + } + } + } elseif ($this->collCoupons) { + foreach ($this->collCoupons as $coupon) { + if ($coupon->isModified()) { + $coupon->save($con); + } + } + } + if ($this->ordersRelatedByPaymentModuleIdScheduledForDeletion !== null) { if (!$this->ordersRelatedByPaymentModuleIdScheduledForDeletion->isEmpty()) { \Thelia\Model\OrderQuery::create() @@ -1104,6 +1161,23 @@ abstract class Module implements ActiveRecordInterface } } + if ($this->couponModulesScheduledForDeletion !== null) { + if (!$this->couponModulesScheduledForDeletion->isEmpty()) { + \Thelia\Model\CouponModuleQuery::create() + ->filterByPrimaryKeys($this->couponModulesScheduledForDeletion->getPrimaryKeys(false)) + ->delete($con); + $this->couponModulesScheduledForDeletion = null; + } + } + + if ($this->collCouponModules !== null) { + foreach ($this->collCouponModules as $referrerFK) { + if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) { + $affectedRows += $referrerFK->save($con); + } + } + } + if ($this->moduleI18nsScheduledForDeletion !== null) { if (!$this->moduleI18nsScheduledForDeletion->isEmpty()) { \Thelia\Model\ModuleI18nQuery::create() @@ -1351,6 +1425,9 @@ abstract class Module implements ActiveRecordInterface if (null !== $this->collModuleImages) { $result['ModuleImages'] = $this->collModuleImages->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); } + if (null !== $this->collCouponModules) { + $result['CouponModules'] = $this->collCouponModules->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); + } if (null !== $this->collModuleI18ns) { $result['ModuleI18ns'] = $this->collModuleI18ns->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); } @@ -1569,6 +1646,12 @@ abstract class Module implements ActiveRecordInterface } } + foreach ($this->getCouponModules() as $relObj) { + if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves + $copyObj->addCouponModule($relObj->copy($deepCopy)); + } + } + foreach ($this->getModuleI18ns() as $relObj) { if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves $copyObj->addModuleI18n($relObj->copy($deepCopy)); @@ -1631,6 +1714,9 @@ abstract class Module implements ActiveRecordInterface if ('ModuleImage' == $relationName) { return $this->initModuleImages(); } + if ('CouponModule' == $relationName) { + return $this->initCouponModules(); + } if ('ModuleI18n' == $relationName) { return $this->initModuleI18ns(); } @@ -3079,6 +3165,252 @@ abstract class Module implements ActiveRecordInterface return $this; } + /** + * Clears out the collCouponModules 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 addCouponModules() + */ + public function clearCouponModules() + { + $this->collCouponModules = null; // important to set this to NULL since that means it is uninitialized + } + + /** + * Reset is the collCouponModules collection loaded partially. + */ + public function resetPartialCouponModules($v = true) + { + $this->collCouponModulesPartial = $v; + } + + /** + * Initializes the collCouponModules collection. + * + * By default this just sets the collCouponModules collection to an empty array (like clearcollCouponModules()); + * 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 initCouponModules($overrideExisting = true) + { + if (null !== $this->collCouponModules && !$overrideExisting) { + return; + } + $this->collCouponModules = new ObjectCollection(); + $this->collCouponModules->setModel('\Thelia\Model\CouponModule'); + } + + /** + * Gets an array of ChildCouponModule 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 ChildModule 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|ChildCouponModule[] List of ChildCouponModule objects + * @throws PropelException + */ + public function getCouponModules($criteria = null, ConnectionInterface $con = null) + { + $partial = $this->collCouponModulesPartial && !$this->isNew(); + if (null === $this->collCouponModules || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collCouponModules) { + // return empty collection + $this->initCouponModules(); + } else { + $collCouponModules = ChildCouponModuleQuery::create(null, $criteria) + ->filterByModule($this) + ->find($con); + + if (null !== $criteria) { + if (false !== $this->collCouponModulesPartial && count($collCouponModules)) { + $this->initCouponModules(false); + + foreach ($collCouponModules as $obj) { + if (false == $this->collCouponModules->contains($obj)) { + $this->collCouponModules->append($obj); + } + } + + $this->collCouponModulesPartial = true; + } + + reset($collCouponModules); + + return $collCouponModules; + } + + if ($partial && $this->collCouponModules) { + foreach ($this->collCouponModules as $obj) { + if ($obj->isNew()) { + $collCouponModules[] = $obj; + } + } + } + + $this->collCouponModules = $collCouponModules; + $this->collCouponModulesPartial = false; + } + } + + return $this->collCouponModules; + } + + /** + * Sets a collection of CouponModule 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 $couponModules A Propel collection. + * @param ConnectionInterface $con Optional connection object + * @return ChildModule The current object (for fluent API support) + */ + public function setCouponModules(Collection $couponModules, ConnectionInterface $con = null) + { + $couponModulesToDelete = $this->getCouponModules(new Criteria(), $con)->diff($couponModules); + + + //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->couponModulesScheduledForDeletion = clone $couponModulesToDelete; + + foreach ($couponModulesToDelete as $couponModuleRemoved) { + $couponModuleRemoved->setModule(null); + } + + $this->collCouponModules = null; + foreach ($couponModules as $couponModule) { + $this->addCouponModule($couponModule); + } + + $this->collCouponModules = $couponModules; + $this->collCouponModulesPartial = false; + + return $this; + } + + /** + * Returns the number of related CouponModule objects. + * + * @param Criteria $criteria + * @param boolean $distinct + * @param ConnectionInterface $con + * @return int Count of related CouponModule objects. + * @throws PropelException + */ + public function countCouponModules(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) + { + $partial = $this->collCouponModulesPartial && !$this->isNew(); + if (null === $this->collCouponModules || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collCouponModules) { + return 0; + } + + if ($partial && !$criteria) { + return count($this->getCouponModules()); + } + + $query = ChildCouponModuleQuery::create(null, $criteria); + if ($distinct) { + $query->distinct(); + } + + return $query + ->filterByModule($this) + ->count($con); + } + + return count($this->collCouponModules); + } + + /** + * Method called to associate a ChildCouponModule object to this object + * through the ChildCouponModule foreign key attribute. + * + * @param ChildCouponModule $l ChildCouponModule + * @return \Thelia\Model\Module The current object (for fluent API support) + */ + public function addCouponModule(ChildCouponModule $l) + { + if ($this->collCouponModules === null) { + $this->initCouponModules(); + $this->collCouponModulesPartial = true; + } + + if (!in_array($l, $this->collCouponModules->getArrayCopy(), true)) { // only add it if the **same** object is not already associated + $this->doAddCouponModule($l); + } + + return $this; + } + + /** + * @param CouponModule $couponModule The couponModule object to add. + */ + protected function doAddCouponModule($couponModule) + { + $this->collCouponModules[]= $couponModule; + $couponModule->setModule($this); + } + + /** + * @param CouponModule $couponModule The couponModule object to remove. + * @return ChildModule The current object (for fluent API support) + */ + public function removeCouponModule($couponModule) + { + if ($this->getCouponModules()->contains($couponModule)) { + $this->collCouponModules->remove($this->collCouponModules->search($couponModule)); + if (null === $this->couponModulesScheduledForDeletion) { + $this->couponModulesScheduledForDeletion = clone $this->collCouponModules; + $this->couponModulesScheduledForDeletion->clear(); + } + $this->couponModulesScheduledForDeletion[]= clone $couponModule; + $couponModule->setModule(null); + } + + return $this; + } + + + /** + * If this collection has already been initialized with + * an identical criteria, it returns the collection. + * Otherwise if this Module is new, it will return + * an empty collection; or if this Module has previously + * been saved, it will retrieve related CouponModules from storage. + * + * This method is protected by default in order to keep the public + * api reasonable. You can provide public methods for those you + * actually need in Module. + * + * @param Criteria $criteria optional Criteria object to narrow the query + * @param ConnectionInterface $con optional connection object + * @param string $joinBehavior optional join type to use (defaults to Criteria::LEFT_JOIN) + * @return Collection|ChildCouponModule[] List of ChildCouponModule objects + */ + public function getCouponModulesJoinCoupon($criteria = null, $con = null, $joinBehavior = Criteria::LEFT_JOIN) + { + $query = ChildCouponModuleQuery::create(null, $criteria); + $query->joinWith('Coupon', $joinBehavior); + + return $this->getCouponModules($query, $con); + } + /** * Clears out the collModuleI18ns collection * @@ -3304,6 +3636,189 @@ abstract class Module implements ActiveRecordInterface return $this; } + /** + * Clears out the collCoupons 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 addCoupons() + */ + public function clearCoupons() + { + $this->collCoupons = null; // important to set this to NULL since that means it is uninitialized + $this->collCouponsPartial = null; + } + + /** + * Initializes the collCoupons collection. + * + * By default this just sets the collCoupons collection to an empty collection (like clearCoupons()); + * 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. + * + * @return void + */ + public function initCoupons() + { + $this->collCoupons = new ObjectCollection(); + $this->collCoupons->setModel('\Thelia\Model\Coupon'); + } + + /** + * Gets a collection of ChildCoupon objects related by a many-to-many relationship + * to the current object by way of the coupon_module cross-reference table. + * + * 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 ChildModule is new, it will return + * an empty collection or the current collection; the criteria is ignored on a new object. + * + * @param Criteria $criteria Optional query object to filter the query + * @param ConnectionInterface $con Optional connection object + * + * @return ObjectCollection|ChildCoupon[] List of ChildCoupon objects + */ + public function getCoupons($criteria = null, ConnectionInterface $con = null) + { + if (null === $this->collCoupons || null !== $criteria) { + if ($this->isNew() && null === $this->collCoupons) { + // return empty collection + $this->initCoupons(); + } else { + $collCoupons = ChildCouponQuery::create(null, $criteria) + ->filterByModule($this) + ->find($con); + if (null !== $criteria) { + return $collCoupons; + } + $this->collCoupons = $collCoupons; + } + } + + return $this->collCoupons; + } + + /** + * Sets a collection of Coupon objects related by a many-to-many relationship + * to the current object by way of the coupon_module cross-reference table. + * 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 $coupons A Propel collection. + * @param ConnectionInterface $con Optional connection object + * @return ChildModule The current object (for fluent API support) + */ + public function setCoupons(Collection $coupons, ConnectionInterface $con = null) + { + $this->clearCoupons(); + $currentCoupons = $this->getCoupons(); + + $this->couponsScheduledForDeletion = $currentCoupons->diff($coupons); + + foreach ($coupons as $coupon) { + if (!$currentCoupons->contains($coupon)) { + $this->doAddCoupon($coupon); + } + } + + $this->collCoupons = $coupons; + + return $this; + } + + /** + * Gets the number of ChildCoupon objects related by a many-to-many relationship + * to the current object by way of the coupon_module cross-reference table. + * + * @param Criteria $criteria Optional query object to filter the query + * @param boolean $distinct Set to true to force count distinct + * @param ConnectionInterface $con Optional connection object + * + * @return int the number of related ChildCoupon objects + */ + public function countCoupons($criteria = null, $distinct = false, ConnectionInterface $con = null) + { + if (null === $this->collCoupons || null !== $criteria) { + if ($this->isNew() && null === $this->collCoupons) { + return 0; + } else { + $query = ChildCouponQuery::create(null, $criteria); + if ($distinct) { + $query->distinct(); + } + + return $query + ->filterByModule($this) + ->count($con); + } + } else { + return count($this->collCoupons); + } + } + + /** + * Associate a ChildCoupon object to this object + * through the coupon_module cross reference table. + * + * @param ChildCoupon $coupon The ChildCouponModule object to relate + * @return ChildModule The current object (for fluent API support) + */ + public function addCoupon(ChildCoupon $coupon) + { + if ($this->collCoupons === null) { + $this->initCoupons(); + } + + if (!$this->collCoupons->contains($coupon)) { // only add it if the **same** object is not already associated + $this->doAddCoupon($coupon); + $this->collCoupons[] = $coupon; + } + + return $this; + } + + /** + * @param Coupon $coupon The coupon object to add. + */ + protected function doAddCoupon($coupon) + { + $couponModule = new ChildCouponModule(); + $couponModule->setCoupon($coupon); + $this->addCouponModule($couponModule); + // set the back reference to this object directly as using provided method either results + // in endless loop or in multiple relations + if (!$coupon->getModules()->contains($this)) { + $foreignCollection = $coupon->getModules(); + $foreignCollection[] = $this; + } + } + + /** + * Remove a ChildCoupon object to this object + * through the coupon_module cross reference table. + * + * @param ChildCoupon $coupon The ChildCouponModule object to relate + * @return ChildModule The current object (for fluent API support) + */ + public function removeCoupon(ChildCoupon $coupon) + { + if ($this->getCoupons()->contains($coupon)) { + $this->collCoupons->remove($this->collCoupons->search($coupon)); + + if (null === $this->couponsScheduledForDeletion) { + $this->couponsScheduledForDeletion = clone $this->collCoupons; + $this->couponsScheduledForDeletion->clear(); + } + + $this->couponsScheduledForDeletion[] = $coupon; + } + + return $this; + } + /** * Clears the current object and sets all attributes to their default values */ @@ -3361,11 +3876,21 @@ abstract class Module implements ActiveRecordInterface $o->clearAllReferences($deep); } } + if ($this->collCouponModules) { + foreach ($this->collCouponModules as $o) { + $o->clearAllReferences($deep); + } + } if ($this->collModuleI18ns) { foreach ($this->collModuleI18ns as $o) { $o->clearAllReferences($deep); } } + if ($this->collCoupons) { + foreach ($this->collCoupons as $o) { + $o->clearAllReferences($deep); + } + } } // if ($deep) // i18n behavior @@ -3377,7 +3902,9 @@ abstract class Module implements ActiveRecordInterface $this->collAreaDeliveryModules = null; $this->collProfileModules = null; $this->collModuleImages = null; + $this->collCouponModules = null; $this->collModuleI18ns = null; + $this->collCoupons = null; } /** diff --git a/core/lib/Thelia/Model/Base/ModuleQuery.php b/core/lib/Thelia/Model/Base/ModuleQuery.php index 006bfbe7a..0c7d4a726 100644 --- a/core/lib/Thelia/Model/Base/ModuleQuery.php +++ b/core/lib/Thelia/Model/Base/ModuleQuery.php @@ -64,6 +64,10 @@ use Thelia\Model\Map\ModuleTableMap; * @method ChildModuleQuery rightJoinModuleImage($relationAlias = null) Adds a RIGHT JOIN clause to the query using the ModuleImage relation * @method ChildModuleQuery innerJoinModuleImage($relationAlias = null) Adds a INNER JOIN clause to the query using the ModuleImage relation * + * @method ChildModuleQuery leftJoinCouponModule($relationAlias = null) Adds a LEFT JOIN clause to the query using the CouponModule relation + * @method ChildModuleQuery rightJoinCouponModule($relationAlias = null) Adds a RIGHT JOIN clause to the query using the CouponModule relation + * @method ChildModuleQuery innerJoinCouponModule($relationAlias = null) Adds a INNER JOIN clause to the query using the CouponModule relation + * * @method ChildModuleQuery leftJoinModuleI18n($relationAlias = null) Adds a LEFT JOIN clause to the query using the ModuleI18n relation * @method ChildModuleQuery rightJoinModuleI18n($relationAlias = null) Adds a RIGHT JOIN clause to the query using the ModuleI18n relation * @method ChildModuleQuery innerJoinModuleI18n($relationAlias = null) Adds a INNER JOIN clause to the query using the ModuleI18n relation @@ -938,6 +942,79 @@ abstract class ModuleQuery extends ModelCriteria ->useQuery($relationAlias ? $relationAlias : 'ModuleImage', '\Thelia\Model\ModuleImageQuery'); } + /** + * Filter the query by a related \Thelia\Model\CouponModule object + * + * @param \Thelia\Model\CouponModule|ObjectCollection $couponModule the related object to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildModuleQuery The current query, for fluid interface + */ + public function filterByCouponModule($couponModule, $comparison = null) + { + if ($couponModule instanceof \Thelia\Model\CouponModule) { + return $this + ->addUsingAlias(ModuleTableMap::ID, $couponModule->getModuleId(), $comparison); + } elseif ($couponModule instanceof ObjectCollection) { + return $this + ->useCouponModuleQuery() + ->filterByPrimaryKeys($couponModule->getPrimaryKeys()) + ->endUse(); + } else { + throw new PropelException('filterByCouponModule() only accepts arguments of type \Thelia\Model\CouponModule or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the CouponModule relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildModuleQuery The current query, for fluid interface + */ + public function joinCouponModule($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('CouponModule'); + + // 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, 'CouponModule'); + } + + return $this; + } + + /** + * Use the CouponModule relation CouponModule 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\CouponModuleQuery A secondary query class using the current class as primary query + */ + public function useCouponModuleQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + return $this + ->joinCouponModule($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'CouponModule', '\Thelia\Model\CouponModuleQuery'); + } + /** * Filter the query by a related \Thelia\Model\ModuleI18n object * @@ -1011,6 +1088,23 @@ abstract class ModuleQuery extends ModelCriteria ->useQuery($relationAlias ? $relationAlias : 'ModuleI18n', '\Thelia\Model\ModuleI18nQuery'); } + /** + * Filter the query by a related Coupon object + * using the coupon_module table as cross reference + * + * @param Coupon $coupon the related object to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildModuleQuery The current query, for fluid interface + */ + public function filterByCoupon($coupon, $comparison = Criteria::EQUAL) + { + return $this + ->useCouponModuleQuery() + ->filterByCoupon($coupon, $comparison) + ->endUse(); + } + /** * Exclude object from result * diff --git a/core/lib/Thelia/Model/Coupon.php b/core/lib/Thelia/Model/Coupon.php index b94a08f62..20cb4d24b 100644 --- a/core/lib/Thelia/Model/Coupon.php +++ b/core/lib/Thelia/Model/Coupon.php @@ -23,8 +23,11 @@ namespace Thelia\Model; +use Propel\Runtime\Propel; use Thelia\Model\Base\Coupon as BaseCoupon; use Thelia\Model\Exception\InvalidArgumentException; +use Thelia\Model\Map\CouponTableMap; +use Thelia\Model\Tools\ModelEventDispatcherTrait; /** * Used to provide an effect (mostly a discount) @@ -38,7 +41,7 @@ use Thelia\Model\Exception\InvalidArgumentException; class Coupon extends BaseCoupon { - use \Thelia\Model\Tools\ModelEventDispatcherTrait; + use ModelEventDispatcherTrait; /** * Create or Update this Coupon @@ -57,32 +60,79 @@ class Coupon extends BaseCoupon * @param int $maxUsage Coupon quantity * @param string $defaultSerializedRule Serialized default rule added if none found * @param string $locale Coupon Language code ISO (ex: fr_FR) + * @param array $freeShippingForCountries ID of Countries to which shipping is free + * @param array $freeShippingForMethods ID of Shipping modules for which shipping is free * * @throws \Exception */ - public function createOrUpdate($code, $title, array $effects, $type, $isRemovingPostage, $shortDescription, $description, $isEnabled, $expirationDate, $isAvailableOnSpecialOffers, $isCumulative, $maxUsage, $defaultSerializedRule, $locale = null) + public function createOrUpdate( + $code, $title, array $effects, $type, $isRemovingPostage, $shortDescription, $description, + $isEnabled, $expirationDate, $isAvailableOnSpecialOffers, $isCumulative, $maxUsage, $defaultSerializedRule, + $locale, $freeShippingForCountries, $freeShippingForMethods) { - $this - ->setCode($code) - ->setType($type) - ->setEffects($effects) - ->setIsRemovingPostage($isRemovingPostage) - ->setIsEnabled($isEnabled) - ->setExpirationDate($expirationDate) - ->setIsAvailableOnSpecialOffers($isAvailableOnSpecialOffers) - ->setIsCumulative($isCumulative) - ->setMaxUsage($maxUsage) - ->setLocale($locale) - ->setTitle($title) - ->setShortDescription($shortDescription) - ->setDescription($description); + $con = Propel::getWriteConnection(CouponTableMap::DATABASE_NAME); - // If no rule given, set default rule - if (null === $this->getSerializedConditions()) { - $this->setSerializedConditions($defaultSerializedRule); + $con->beginTransaction(); + + try { + $this + ->setCode($code) + ->setType($type) + ->setEffects($effects) + ->setIsRemovingPostage($isRemovingPostage) + ->setIsEnabled($isEnabled) + ->setExpirationDate($expirationDate) + ->setIsAvailableOnSpecialOffers($isAvailableOnSpecialOffers) + ->setIsCumulative($isCumulative) + ->setMaxUsage($maxUsage) + ->setLocale($locale) + ->setTitle($title) + ->setShortDescription($shortDescription) + ->setDescription($description); + + // If no rule given, set default rule + if (null === $this->getSerializedConditions()) { + $this->setSerializedConditions($defaultSerializedRule); + } + + $this->save(); + + // Update countries and modules relation for free shipping + CouponCountryQuery::create()->filterByCouponId($this->id)->delete(); + CouponModuleQuery::create()->filterByCouponId($this->id)->delete(); + + foreach($freeShippingForCountries as $countryId) { + + if ($countryId <= 0) continue; + + $couponCountry = new CouponCountry(); + + $couponCountry + ->setCouponId($this->getId()) + ->setCountryId($countryId) + ->save(); + ; + } + + foreach($freeShippingForMethods as $moduleId) { + + if ($moduleId <= 0) continue; + + $couponModule = new CouponModule(); + + $couponModule + ->setCouponId($this->getId()) + ->setModuleId($moduleId) + ->save() + ; + } + + } catch (\Exception $ex) { + + $con->rollback(); + + throw $ex; } - - $this->save(); } /** @@ -198,4 +248,4 @@ class Coupon extends BaseCoupon return $effects; } -} +} \ No newline at end of file diff --git a/core/lib/Thelia/Model/CouponCountry.php b/core/lib/Thelia/Model/CouponCountry.php new file mode 100644 index 000000000..901762c78 --- /dev/null +++ b/core/lib/Thelia/Model/CouponCountry.php @@ -0,0 +1,10 @@ +addRelation('Area', '\\Thelia\\Model\\Area', RelationMap::MANY_TO_ONE, array('area_id' => 'id', ), 'SET NULL', 'RESTRICT'); $this->addRelation('TaxRuleCountry', '\\Thelia\\Model\\TaxRuleCountry', RelationMap::ONE_TO_MANY, array('id' => 'country_id', ), 'CASCADE', 'RESTRICT', 'TaxRuleCountries'); $this->addRelation('Address', '\\Thelia\\Model\\Address', RelationMap::ONE_TO_MANY, array('id' => 'country_id', ), 'RESTRICT', 'RESTRICT', 'Addresses'); + $this->addRelation('CouponCountry', '\\Thelia\\Model\\CouponCountry', RelationMap::ONE_TO_MANY, array('id' => 'country_id', ), 'CASCADE', null, 'CouponCountries'); $this->addRelation('CountryI18n', '\\Thelia\\Model\\CountryI18n', RelationMap::ONE_TO_MANY, array('id' => 'id', ), 'CASCADE', null, 'CountryI18ns'); + $this->addRelation('Coupon', '\\Thelia\\Model\\Coupon', RelationMap::MANY_TO_MANY, array(), 'CASCADE', null, 'Coupons'); } // buildRelations() /** @@ -218,6 +220,7 @@ class CountryTableMap extends TableMap // Invalidate objects in ".$this->getClassNameFromBuilder($joinedTableTableMapBuilder)." instance pool, // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule. TaxRuleCountryTableMap::clearInstancePool(); + CouponCountryTableMap::clearInstancePool(); CountryI18nTableMap::clearInstancePool(); } diff --git a/core/lib/Thelia/Model/Map/CouponCountryTableMap.php b/core/lib/Thelia/Model/Map/CouponCountryTableMap.php new file mode 100644 index 000000000..53d504a99 --- /dev/null +++ b/core/lib/Thelia/Model/Map/CouponCountryTableMap.php @@ -0,0 +1,468 @@ + array('CouponId', 'CountryId', ), + self::TYPE_STUDLYPHPNAME => array('couponId', 'countryId', ), + self::TYPE_COLNAME => array(CouponCountryTableMap::COUPON_ID, CouponCountryTableMap::COUNTRY_ID, ), + self::TYPE_RAW_COLNAME => array('COUPON_ID', 'COUNTRY_ID', ), + self::TYPE_FIELDNAME => array('coupon_id', 'country_id', ), + self::TYPE_NUM => array(0, 1, ) + ); + + /** + * 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('CouponId' => 0, 'CountryId' => 1, ), + self::TYPE_STUDLYPHPNAME => array('couponId' => 0, 'countryId' => 1, ), + self::TYPE_COLNAME => array(CouponCountryTableMap::COUPON_ID => 0, CouponCountryTableMap::COUNTRY_ID => 1, ), + self::TYPE_RAW_COLNAME => array('COUPON_ID' => 0, 'COUNTRY_ID' => 1, ), + self::TYPE_FIELDNAME => array('coupon_id' => 0, 'country_id' => 1, ), + self::TYPE_NUM => array(0, 1, ) + ); + + /** + * 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('coupon_country'); + $this->setPhpName('CouponCountry'); + $this->setClassName('\\Thelia\\Model\\CouponCountry'); + $this->setPackage('Thelia.Model'); + $this->setUseIdGenerator(false); + $this->setIsCrossRef(true); + // columns + $this->addForeignPrimaryKey('COUPON_ID', 'CouponId', 'INTEGER' , 'coupon', 'ID', true, null, null); + $this->addForeignPrimaryKey('COUNTRY_ID', 'CountryId', 'INTEGER' , 'country', 'ID', true, null, null); + } // initialize() + + /** + * Build the RelationMap objects for this table relationships + */ + public function buildRelations() + { + $this->addRelation('Country', '\\Thelia\\Model\\Country', RelationMap::MANY_TO_ONE, array('country_id' => 'id', ), 'CASCADE', null); + $this->addRelation('Coupon', '\\Thelia\\Model\\Coupon', RelationMap::MANY_TO_ONE, array('coupon_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\CouponCountry $obj A \Thelia\Model\CouponCountry 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->getCouponId(), (string) $obj->getCountryId())); + } // 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\CouponCountry object or a primary key value. + */ + public static function removeInstanceFromPool($value) + { + if (Propel::isInstancePoolingEnabled() && null !== $value) { + if (is_object($value) && $value instanceof \Thelia\Model\CouponCountry) { + $key = serialize(array((string) $value->getCouponId(), (string) $value->getCountryId())); + + } 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\CouponCountry 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('CouponId', TableMap::TYPE_PHPNAME, $indexType)] === null && $row[TableMap::TYPE_NUM == $indexType ? 1 + $offset : static::translateFieldName('CountryId', TableMap::TYPE_PHPNAME, $indexType)] === null) { + return null; + } + + return serialize(array((string) $row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('CouponId', TableMap::TYPE_PHPNAME, $indexType)], (string) $row[TableMap::TYPE_NUM == $indexType ? 1 + $offset : static::translateFieldName('CountryId', 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 ? CouponCountryTableMap::CLASS_DEFAULT : CouponCountryTableMap::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 (CouponCountry object, last column rank) + */ + public static function populateObject($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + $key = CouponCountryTableMap::getPrimaryKeyHashFromRow($row, $offset, $indexType); + if (null !== ($obj = CouponCountryTableMap::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 + CouponCountryTableMap::NUM_HYDRATE_COLUMNS; + } else { + $cls = CouponCountryTableMap::OM_CLASS; + $obj = new $cls(); + $col = $obj->hydrate($row, $offset, false, $indexType); + CouponCountryTableMap::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 = CouponCountryTableMap::getPrimaryKeyHashFromRow($row, 0, $dataFetcher->getIndexType()); + if (null !== ($obj = CouponCountryTableMap::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; + CouponCountryTableMap::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(CouponCountryTableMap::COUPON_ID); + $criteria->addSelectColumn(CouponCountryTableMap::COUNTRY_ID); + } else { + $criteria->addSelectColumn($alias . '.COUPON_ID'); + $criteria->addSelectColumn($alias . '.COUNTRY_ID'); + } + } + + /** + * 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(CouponCountryTableMap::DATABASE_NAME)->getTable(CouponCountryTableMap::TABLE_NAME); + } + + /** + * Add a TableMap instance to the database for this tableMap class. + */ + public static function buildTableMap() + { + $dbMap = Propel::getServiceContainer()->getDatabaseMap(CouponCountryTableMap::DATABASE_NAME); + if (!$dbMap->hasTable(CouponCountryTableMap::TABLE_NAME)) { + $dbMap->addTableObject(new CouponCountryTableMap()); + } + } + + /** + * Performs a DELETE on the database, given a CouponCountry or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or CouponCountry 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(CouponCountryTableMap::DATABASE_NAME); + } + + if ($values instanceof Criteria) { + // rename for clarity + $criteria = $values; + } elseif ($values instanceof \Thelia\Model\CouponCountry) { // 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(CouponCountryTableMap::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(CouponCountryTableMap::COUPON_ID, $value[0]); + $criterion->addAnd($criteria->getNewCriterion(CouponCountryTableMap::COUNTRY_ID, $value[1])); + $criteria->addOr($criterion); + } + } + + $query = CouponCountryQuery::create()->mergeWith($criteria); + + if ($values instanceof Criteria) { CouponCountryTableMap::clearInstancePool(); + } elseif (!is_object($values)) { // it's a primary key, or an array of pks + foreach ((array) $values as $singleval) { CouponCountryTableMap::removeInstanceFromPool($singleval); + } + } + + return $query->delete($con); + } + + /** + * Deletes all rows from the coupon_country 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 CouponCountryQuery::create()->doDeleteAll($con); + } + + /** + * Performs an INSERT on the database, given a CouponCountry or Criteria object. + * + * @param mixed $criteria Criteria or CouponCountry 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(CouponCountryTableMap::DATABASE_NAME); + } + + if ($criteria instanceof Criteria) { + $criteria = clone $criteria; // rename for clarity + } else { + $criteria = $criteria->buildCriteria(); // build Criteria from CouponCountry object + } + + + // Set the correct dbName + $query = CouponCountryQuery::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; + } + +} // CouponCountryTableMap +// This is the static code needed to register the TableMap for this table with the main Propel class. +// +CouponCountryTableMap::buildTableMap(); diff --git a/core/lib/Thelia/Model/Map/CouponModuleTableMap.php b/core/lib/Thelia/Model/Map/CouponModuleTableMap.php new file mode 100644 index 000000000..c43f6704f --- /dev/null +++ b/core/lib/Thelia/Model/Map/CouponModuleTableMap.php @@ -0,0 +1,468 @@ + array('CouponId', 'ModuleId', ), + self::TYPE_STUDLYPHPNAME => array('couponId', 'moduleId', ), + self::TYPE_COLNAME => array(CouponModuleTableMap::COUPON_ID, CouponModuleTableMap::MODULE_ID, ), + self::TYPE_RAW_COLNAME => array('COUPON_ID', 'MODULE_ID', ), + self::TYPE_FIELDNAME => array('coupon_id', 'module_id', ), + self::TYPE_NUM => array(0, 1, ) + ); + + /** + * 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('CouponId' => 0, 'ModuleId' => 1, ), + self::TYPE_STUDLYPHPNAME => array('couponId' => 0, 'moduleId' => 1, ), + self::TYPE_COLNAME => array(CouponModuleTableMap::COUPON_ID => 0, CouponModuleTableMap::MODULE_ID => 1, ), + self::TYPE_RAW_COLNAME => array('COUPON_ID' => 0, 'MODULE_ID' => 1, ), + self::TYPE_FIELDNAME => array('coupon_id' => 0, 'module_id' => 1, ), + self::TYPE_NUM => array(0, 1, ) + ); + + /** + * 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('coupon_module'); + $this->setPhpName('CouponModule'); + $this->setClassName('\\Thelia\\Model\\CouponModule'); + $this->setPackage('Thelia.Model'); + $this->setUseIdGenerator(false); + $this->setIsCrossRef(true); + // columns + $this->addForeignPrimaryKey('COUPON_ID', 'CouponId', 'INTEGER' , 'coupon', 'ID', true, null, null); + $this->addForeignPrimaryKey('MODULE_ID', 'ModuleId', 'INTEGER' , 'module', 'ID', true, null, null); + } // initialize() + + /** + * Build the RelationMap objects for this table relationships + */ + public function buildRelations() + { + $this->addRelation('Coupon', '\\Thelia\\Model\\Coupon', RelationMap::MANY_TO_ONE, array('coupon_id' => 'id', ), 'CASCADE', null); + $this->addRelation('Module', '\\Thelia\\Model\\Module', RelationMap::MANY_TO_ONE, array('module_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\CouponModule $obj A \Thelia\Model\CouponModule 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->getCouponId(), (string) $obj->getModuleId())); + } // 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\CouponModule object or a primary key value. + */ + public static function removeInstanceFromPool($value) + { + if (Propel::isInstancePoolingEnabled() && null !== $value) { + if (is_object($value) && $value instanceof \Thelia\Model\CouponModule) { + $key = serialize(array((string) $value->getCouponId(), (string) $value->getModuleId())); + + } 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\CouponModule 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('CouponId', TableMap::TYPE_PHPNAME, $indexType)] === null && $row[TableMap::TYPE_NUM == $indexType ? 1 + $offset : static::translateFieldName('ModuleId', TableMap::TYPE_PHPNAME, $indexType)] === null) { + return null; + } + + return serialize(array((string) $row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('CouponId', TableMap::TYPE_PHPNAME, $indexType)], (string) $row[TableMap::TYPE_NUM == $indexType ? 1 + $offset : static::translateFieldName('ModuleId', 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 ? CouponModuleTableMap::CLASS_DEFAULT : CouponModuleTableMap::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 (CouponModule object, last column rank) + */ + public static function populateObject($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + $key = CouponModuleTableMap::getPrimaryKeyHashFromRow($row, $offset, $indexType); + if (null !== ($obj = CouponModuleTableMap::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 + CouponModuleTableMap::NUM_HYDRATE_COLUMNS; + } else { + $cls = CouponModuleTableMap::OM_CLASS; + $obj = new $cls(); + $col = $obj->hydrate($row, $offset, false, $indexType); + CouponModuleTableMap::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 = CouponModuleTableMap::getPrimaryKeyHashFromRow($row, 0, $dataFetcher->getIndexType()); + if (null !== ($obj = CouponModuleTableMap::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; + CouponModuleTableMap::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(CouponModuleTableMap::COUPON_ID); + $criteria->addSelectColumn(CouponModuleTableMap::MODULE_ID); + } else { + $criteria->addSelectColumn($alias . '.COUPON_ID'); + $criteria->addSelectColumn($alias . '.MODULE_ID'); + } + } + + /** + * 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(CouponModuleTableMap::DATABASE_NAME)->getTable(CouponModuleTableMap::TABLE_NAME); + } + + /** + * Add a TableMap instance to the database for this tableMap class. + */ + public static function buildTableMap() + { + $dbMap = Propel::getServiceContainer()->getDatabaseMap(CouponModuleTableMap::DATABASE_NAME); + if (!$dbMap->hasTable(CouponModuleTableMap::TABLE_NAME)) { + $dbMap->addTableObject(new CouponModuleTableMap()); + } + } + + /** + * Performs a DELETE on the database, given a CouponModule or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or CouponModule 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(CouponModuleTableMap::DATABASE_NAME); + } + + if ($values instanceof Criteria) { + // rename for clarity + $criteria = $values; + } elseif ($values instanceof \Thelia\Model\CouponModule) { // 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(CouponModuleTableMap::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(CouponModuleTableMap::COUPON_ID, $value[0]); + $criterion->addAnd($criteria->getNewCriterion(CouponModuleTableMap::MODULE_ID, $value[1])); + $criteria->addOr($criterion); + } + } + + $query = CouponModuleQuery::create()->mergeWith($criteria); + + if ($values instanceof Criteria) { CouponModuleTableMap::clearInstancePool(); + } elseif (!is_object($values)) { // it's a primary key, or an array of pks + foreach ((array) $values as $singleval) { CouponModuleTableMap::removeInstanceFromPool($singleval); + } + } + + return $query->delete($con); + } + + /** + * Deletes all rows from the coupon_module 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 CouponModuleQuery::create()->doDeleteAll($con); + } + + /** + * Performs an INSERT on the database, given a CouponModule or Criteria object. + * + * @param mixed $criteria Criteria or CouponModule 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(CouponModuleTableMap::DATABASE_NAME); + } + + if ($criteria instanceof Criteria) { + $criteria = clone $criteria; // rename for clarity + } else { + $criteria = $criteria->buildCriteria(); // build Criteria from CouponModule object + } + + + // Set the correct dbName + $query = CouponModuleQuery::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; + } + +} // CouponModuleTableMap +// This is the static code needed to register the TableMap for this table with the main Propel class. +// +CouponModuleTableMap::buildTableMap(); diff --git a/core/lib/Thelia/Model/Map/CouponTableMap.php b/core/lib/Thelia/Model/Map/CouponTableMap.php index d18038790..5e675f684 100644 --- a/core/lib/Thelia/Model/Map/CouponTableMap.php +++ b/core/lib/Thelia/Model/Map/CouponTableMap.php @@ -227,8 +227,12 @@ class CouponTableMap extends TableMap */ public function buildRelations() { + $this->addRelation('CouponCountry', '\\Thelia\\Model\\CouponCountry', RelationMap::ONE_TO_MANY, array('id' => 'coupon_id', ), 'CASCADE', null, 'CouponCountries'); + $this->addRelation('CouponModule', '\\Thelia\\Model\\CouponModule', RelationMap::ONE_TO_MANY, array('id' => 'coupon_id', ), 'CASCADE', null, 'CouponModules'); $this->addRelation('CouponI18n', '\\Thelia\\Model\\CouponI18n', RelationMap::ONE_TO_MANY, array('id' => 'id', ), 'CASCADE', null, 'CouponI18ns'); $this->addRelation('CouponVersion', '\\Thelia\\Model\\CouponVersion', RelationMap::ONE_TO_MANY, array('id' => 'id', ), 'CASCADE', null, 'CouponVersions'); + $this->addRelation('Country', '\\Thelia\\Model\\Country', RelationMap::MANY_TO_MANY, array(), 'CASCADE', null, 'Countries'); + $this->addRelation('Module', '\\Thelia\\Model\\Module', RelationMap::MANY_TO_MANY, array(), 'CASCADE', null, 'Modules'); } // buildRelations() /** @@ -252,6 +256,8 @@ class CouponTableMap extends TableMap { // Invalidate objects in ".$this->getClassNameFromBuilder($joinedTableTableMapBuilder)." instance pool, // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule. + CouponCountryTableMap::clearInstancePool(); + CouponModuleTableMap::clearInstancePool(); CouponI18nTableMap::clearInstancePool(); CouponVersionTableMap::clearInstancePool(); } diff --git a/core/lib/Thelia/Model/Map/ModuleTableMap.php b/core/lib/Thelia/Model/Map/ModuleTableMap.php index 16a14b1bb..5e162556e 100644 --- a/core/lib/Thelia/Model/Map/ModuleTableMap.php +++ b/core/lib/Thelia/Model/Map/ModuleTableMap.php @@ -190,7 +190,9 @@ class ModuleTableMap extends TableMap $this->addRelation('AreaDeliveryModule', '\\Thelia\\Model\\AreaDeliveryModule', RelationMap::ONE_TO_MANY, array('id' => 'delivery_module_id', ), 'CASCADE', 'RESTRICT', 'AreaDeliveryModules'); $this->addRelation('ProfileModule', '\\Thelia\\Model\\ProfileModule', RelationMap::ONE_TO_MANY, array('id' => 'module_id', ), 'CASCADE', 'RESTRICT', 'ProfileModules'); $this->addRelation('ModuleImage', '\\Thelia\\Model\\ModuleImage', RelationMap::ONE_TO_MANY, array('id' => 'module_id', ), 'CASCADE', 'RESTRICT', 'ModuleImages'); + $this->addRelation('CouponModule', '\\Thelia\\Model\\CouponModule', RelationMap::ONE_TO_MANY, array('id' => 'module_id', ), 'CASCADE', null, 'CouponModules'); $this->addRelation('ModuleI18n', '\\Thelia\\Model\\ModuleI18n', RelationMap::ONE_TO_MANY, array('id' => 'id', ), 'CASCADE', null, 'ModuleI18ns'); + $this->addRelation('Coupon', '\\Thelia\\Model\\Coupon', RelationMap::MANY_TO_MANY, array(), 'CASCADE', null, 'Coupons'); } // buildRelations() /** @@ -216,6 +218,7 @@ class ModuleTableMap extends TableMap AreaDeliveryModuleTableMap::clearInstancePool(); ProfileModuleTableMap::clearInstancePool(); ModuleImageTableMap::clearInstancePool(); + CouponModuleTableMap::clearInstancePool(); ModuleI18nTableMap::clearInstancePool(); } diff --git a/core/lib/Thelia/Model/RewritingUrlQuery.php b/core/lib/Thelia/Model/RewritingUrlQuery.php index bbfc58eee..8fd556ee4 100644 --- a/core/lib/Thelia/Model/RewritingUrlQuery.php +++ b/core/lib/Thelia/Model/RewritingUrlQuery.php @@ -1,112 +1,112 @@ -addExplicitCondition(RewritingUrlTableMap::TABLE_NAME, 'REDIRECTED', 'ru', RewritingUrlTableMap::TABLE_NAME, 'ID', 'is_redirected'); - $redirectedJoin->setJoinType(Criteria::LEFT_JOIN); - - $search = RewritingArgumentQuery::create() - ->joinRewritingUrl('ru', Criteria::RIGHT_JOIN) - ->addJoinObject($redirectedJoin) - ->where('`ru`.URL = ?', $rewrittenUrl, \PDO::PARAM_STR) - ->withColumn('`ru`.URL', 'ru_url') - ->withColumn('`ru`.VIEW', 'ru_view') - ->withColumn('`ru`.VIEW_LOCALE', 'ru_locale') - ->withColumn('`ru`.VIEW_ID', 'ru_viewId') - ->withColumn('`is_redirected`.URL', 'ru_redirected_to_url') - ->find(); - - return $search; - } - - /** - * @param $view - * @param $viewId - * @param $viewLocale - * - * @return null|RewritingUrl - */ - public function getViewUrlQuery($view, $viewLocale, $viewId) - { - return RewritingUrlQuery::create() - ->joinRewritingArgument('ra', Criteria::LEFT_JOIN) - ->where('ISNULL(`ra`.REWRITING_URL_ID)') - ->filterByView($view) - ->filterByViewLocale($viewLocale) - ->filterByViewId($viewId) - ->filterByRedirected(null) - ->orderByUpdatedAt(Criteria::DESC) - ->findOne(); - } - - /** - * @param $view - * @param $viewLocale - * @param $viewId - * @param $viewOtherParameters - * - * @return null|RewritingUrl - */ - public function getSpecificUrlQuery($view, $viewLocale, $viewId, $viewOtherParameters) - { - $urlQuery = RewritingUrlQuery::create() - ->joinRewritingArgument('ra', Criteria::LEFT_JOIN) - ->withColumn('`ra`.REWRITING_URL_ID', 'ra_REWRITING_URL_ID') - ->filterByView($view) - ->filterByViewLocale($viewLocale) - ->filterByViewId($viewId) - ->filterByRedirected(null) - ->orderByUpdatedAt(Criteria::DESC); - - $otherParametersCount = count($viewOtherParameters); - if ($otherParametersCount > 0) { - $parameterConditions = array(); - - foreach ($viewOtherParameters as $parameter => $value) { - $conditionName = 'other_parameter_condition_' . count($parameterConditions); - $urlQuery->condition('parameter_condition', '`ra`.PARAMETER= ?', $parameter, \PDO::PARAM_STR) - ->condition('value_condition', '`ra`.VALUE = ?', $value, \PDO::PARAM_STR) - ->combine(array('parameter_condition', 'value_condition'), Criteria::LOGICAL_AND, $conditionName); - $parameterConditions[] = $conditionName; - } - - $urlQuery->where($parameterConditions, Criteria::LOGICAL_OR); - - $urlQuery->groupBy(RewritingUrlTableMap::ID); - - $urlQuery->condition('count_condition_1', 'COUNT(' . RewritingUrlTableMap::ID . ') = ?', $otherParametersCount, \PDO::PARAM_INT) // ensure we got all the asked parameters (provided by the query) - ->condition('count_condition_2', 'COUNT(' . RewritingUrlTableMap::ID . ') = (SELECT COUNT(*) FROM rewriting_argument WHERE rewriting_argument.REWRITING_URL_ID = ra_REWRITING_URL_ID)'); // ensure we don't miss any parameters (needed to match the rewritten url) - - $urlQuery->having(array('count_condition_1', 'count_condition_2'), Criteria::LOGICAL_AND); - } else { - $urlQuery->where('ISNULL(`ra`.REWRITING_URL_ID)'); - } - - return $urlQuery->findOne(); - } -} // RewritingUrlQuery +addExplicitCondition(RewritingUrlTableMap::TABLE_NAME, 'REDIRECTED', 'ru', RewritingUrlTableMap::TABLE_NAME, 'ID', 'is_redirected'); + $redirectedJoin->setJoinType(Criteria::LEFT_JOIN); + + $search = RewritingArgumentQuery::create() + ->joinRewritingUrl('ru', Criteria::RIGHT_JOIN) + ->addJoinObject($redirectedJoin) + ->where('`ru`.URL = ?', $rewrittenUrl, \PDO::PARAM_STR) + ->withColumn('`ru`.URL', 'ru_url') + ->withColumn('`ru`.VIEW', 'ru_view') + ->withColumn('`ru`.VIEW_LOCALE', 'ru_locale') + ->withColumn('`ru`.VIEW_ID', 'ru_viewId') + ->withColumn('`is_redirected`.URL', 'ru_redirected_to_url') + ->find(); + + return $search; + } + + /** + * @param $view + * @param $viewId + * @param $viewLocale + * + * @return null|RewritingUrl + */ + public function getViewUrlQuery($view, $viewLocale, $viewId) + { + return RewritingUrlQuery::create() + ->joinRewritingArgument('ra', Criteria::LEFT_JOIN) + ->where('ISNULL(`ra`.REWRITING_URL_ID)') + ->filterByView($view) + ->filterByViewLocale($viewLocale) + ->filterByViewId($viewId) + ->filterByRedirected(null) + ->orderById(Criteria::DESC) + ->findOne(); + } + + /** + * @param $view + * @param $viewLocale + * @param $viewId + * @param $viewOtherParameters + * + * @return null|RewritingUrl + */ + public function getSpecificUrlQuery($view, $viewLocale, $viewId, $viewOtherParameters) + { + $urlQuery = RewritingUrlQuery::create() + ->joinRewritingArgument('ra', Criteria::LEFT_JOIN) + ->withColumn('`ra`.REWRITING_URL_ID', 'ra_REWRITING_URL_ID') + ->filterByView($view) + ->filterByViewLocale($viewLocale) + ->filterByViewId($viewId) + ->filterByRedirected(null) + ->orderById(Criteria::DESC); + + $otherParametersCount = count($viewOtherParameters); + if ($otherParametersCount > 0) { + $parameterConditions = array(); + + foreach ($viewOtherParameters as $parameter => $value) { + $conditionName = 'other_parameter_condition_' . count($parameterConditions); + $urlQuery->condition('parameter_condition', '`ra`.PARAMETER= ?', $parameter, \PDO::PARAM_STR) + ->condition('value_condition', '`ra`.VALUE = ?', $value, \PDO::PARAM_STR) + ->combine(array('parameter_condition', 'value_condition'), Criteria::LOGICAL_AND, $conditionName); + $parameterConditions[] = $conditionName; + } + + $urlQuery->where($parameterConditions, Criteria::LOGICAL_OR); + + $urlQuery->groupBy(RewritingUrlTableMap::ID); + + $urlQuery->condition('count_condition_1', 'COUNT(' . RewritingUrlTableMap::ID . ') = ?', $otherParametersCount, \PDO::PARAM_INT) // ensure we got all the asked parameters (provided by the query) + ->condition('count_condition_2', 'COUNT(' . RewritingUrlTableMap::ID . ') = (SELECT COUNT(*) FROM rewriting_argument WHERE rewriting_argument.REWRITING_URL_ID = ra_REWRITING_URL_ID)'); // ensure we don't miss any parameters (needed to match the rewritten url) + + $urlQuery->having(array('count_condition_1', 'count_condition_2'), Criteria::LOGICAL_AND); + } else { + $urlQuery->where('ISNULL(`ra`.REWRITING_URL_ID)'); + } + + return $urlQuery->findOne(); + } +} // RewritingUrlQuery diff --git a/local/config/schema.xml b/local/config/schema.xml index 5607438d1..4a7428dfb 100644 --- a/local/config/schema.xml +++ b/local/config/schema.xml @@ -1,9 +1,5 @@ - + - - - - @@ -37,7 +33,7 @@ - + @@ -110,7 +106,7 @@ - + @@ -162,9 +158,9 @@ - - - + + +
@@ -226,9 +222,9 @@ - - - + + + @@ -250,8 +246,8 @@ - - + + @@ -326,14 +322,14 @@ - - - - - + + + + + @@ -391,12 +387,12 @@ - - - + + +
@@ -462,7 +458,7 @@ - +
@@ -523,8 +519,8 @@ - - + + @@ -631,10 +627,10 @@ - + - + @@ -728,12 +724,12 @@ - - - + + + @@ -1083,8 +1079,8 @@ - - + + @@ -1107,8 +1103,8 @@ - - + + @@ -1131,8 +1127,8 @@ - - + + @@ -1253,16 +1249,6 @@ - - - - - - - - - - @@ -1301,8 +1287,8 @@ - - + + @@ -1357,4 +1343,30 @@
+ + + + + + + + + + + + +
+ + + + + + + + + + + + +
diff --git a/setup/thelia.sql b/setup/thelia.sql index 3ff2547b0..672d24926 100644 --- a/setup/thelia.sql +++ b/setup/thelia.sql @@ -23,7 +23,7 @@ CREATE TABLE `category` PRIMARY KEY (`id`), INDEX `idx_parent` (`parent`), INDEX `idx_parent_position` (`parent`, `position`) -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- product @@ -56,7 +56,7 @@ CREATE TABLE `product` CONSTRAINT `fk_product_template` FOREIGN KEY (`template_id`) REFERENCES `template` (`id`) -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- product_category @@ -85,7 +85,7 @@ CREATE TABLE `product_category` REFERENCES `category` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- country @@ -112,7 +112,7 @@ CREATE TABLE `country` REFERENCES `area` (`id`) ON UPDATE RESTRICT ON DELETE SET NULL -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- tax @@ -128,7 +128,7 @@ CREATE TABLE `tax` `created_at` DATETIME, `updated_at` DATETIME, PRIMARY KEY (`id`) -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- tax_rule @@ -143,7 +143,7 @@ CREATE TABLE `tax_rule` `created_at` DATETIME, `updated_at` DATETIME, PRIMARY KEY (`id`) -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- tax_rule_country @@ -179,7 +179,7 @@ CREATE TABLE `tax_rule_country` REFERENCES `country` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- feature @@ -195,7 +195,7 @@ CREATE TABLE `feature` `created_at` DATETIME, `updated_at` DATETIME, PRIMARY KEY (`id`) -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- feature_av @@ -217,7 +217,7 @@ CREATE TABLE `feature_av` REFERENCES `feature` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- feature_product @@ -255,7 +255,7 @@ CREATE TABLE `feature_product` REFERENCES `feature_av` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- feature_template @@ -283,7 +283,7 @@ CREATE TABLE `feature_template` CONSTRAINT `fk_feature_template` FOREIGN KEY (`template_id`) REFERENCES `template` (`id`) -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- attribute @@ -298,7 +298,7 @@ CREATE TABLE `attribute` `created_at` DATETIME, `updated_at` DATETIME, PRIMARY KEY (`id`) -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- attribute_av @@ -320,7 +320,7 @@ CREATE TABLE `attribute_av` REFERENCES `attribute` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- attribute_combination @@ -354,7 +354,7 @@ CREATE TABLE `attribute_combination` REFERENCES `product_sale_elements` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- product_sale_elements @@ -377,14 +377,14 @@ CREATE TABLE `product_sale_elements` `updated_at` DATETIME, PRIMARY KEY (`id`), INDEX `idx_product_sale_element_product_id` (`product_id`), - INDEX `idx_product_elements_product_id_promo_is_default` (`product_id`, `promo`, `is_default`), INDEX `ref` (`ref`), + INDEX `idx_product_elements_product_id_promo_is_default` (`product_id`, `promo`, `is_default`), CONSTRAINT `fk_product_sale_element_product_id` FOREIGN KEY (`product_id`) REFERENCES `product` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- attribute_template @@ -411,7 +411,7 @@ CREATE TABLE `attribute_template` CONSTRAINT `fk_attribute_template` FOREIGN KEY (`template_id`) REFERENCES `template` (`id`) -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- config @@ -430,7 +430,7 @@ CREATE TABLE `config` `updated_at` DATETIME, PRIMARY KEY (`id`), UNIQUE INDEX `name_UNIQUE` (`name`) -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- customer @@ -464,7 +464,7 @@ CREATE TABLE `customer` REFERENCES `customer_title` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- address @@ -511,7 +511,7 @@ CREATE TABLE `address` REFERENCES `country` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- customer_title @@ -527,7 +527,7 @@ CREATE TABLE `customer_title` `created_at` DATETIME, `updated_at` DATETIME, PRIMARY KEY (`id`) -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- lang @@ -554,7 +554,7 @@ CREATE TABLE `lang` `updated_at` DATETIME, PRIMARY KEY (`id`), INDEX `idx_lang_by_default` (`by_default`) -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- folder @@ -574,7 +574,7 @@ CREATE TABLE `folder` `version_created_at` DATETIME, `version_created_by` VARCHAR(100), PRIMARY KEY (`id`) -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- content @@ -593,7 +593,7 @@ CREATE TABLE `content` `version_created_at` DATETIME, `version_created_by` VARCHAR(100), PRIMARY KEY (`id`) -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- product_image @@ -617,7 +617,7 @@ CREATE TABLE `product_image` REFERENCES `product` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- product_document @@ -640,7 +640,7 @@ CREATE TABLE `product_document` REFERENCES `product` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- order @@ -719,7 +719,7 @@ CREATE TABLE `order` REFERENCES `lang` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- currency @@ -740,7 +740,7 @@ CREATE TABLE `currency` PRIMARY KEY (`id`), INDEX `idx_currency_by_default` (`by_default`), INDEX `idx_currency_code` (`code`) -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- order_address @@ -765,7 +765,7 @@ CREATE TABLE `order_address` `created_at` DATETIME, `updated_at` DATETIME, PRIMARY KEY (`id`) -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- order_product @@ -802,7 +802,7 @@ CREATE TABLE `order_product` REFERENCES `order` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- order_status @@ -818,7 +818,7 @@ CREATE TABLE `order_status` `updated_at` DATETIME, PRIMARY KEY (`id`), UNIQUE INDEX `code_UNIQUE` (`code`) -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- order_product_attribute_combination @@ -847,7 +847,7 @@ CREATE TABLE `order_product_attribute_combination` REFERENCES `order_product` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- module @@ -868,7 +868,7 @@ CREATE TABLE `module` PRIMARY KEY (`id`), UNIQUE INDEX `code_UNIQUE` (`code`), INDEX `idx_module_activate` (`activate`) -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- accessory @@ -897,7 +897,7 @@ CREATE TABLE `accessory` REFERENCES `product` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- area @@ -913,7 +913,7 @@ CREATE TABLE `area` `created_at` DATETIME, `updated_at` DATETIME, PRIMARY KEY (`id`) -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- area_delivery_module @@ -942,7 +942,7 @@ CREATE TABLE `area_delivery_module` REFERENCES `module` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- profile @@ -958,7 +958,7 @@ CREATE TABLE `profile` `updated_at` DATETIME, PRIMARY KEY (`id`), UNIQUE INDEX `code_UNIQUE` (`code`) -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- resource @@ -974,7 +974,7 @@ CREATE TABLE `resource` `updated_at` DATETIME, PRIMARY KEY (`id`), UNIQUE INDEX `code_UNIQUE` (`code`) -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- admin @@ -1005,7 +1005,7 @@ CREATE TABLE `admin` REFERENCES `profile` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- profile_resource @@ -1033,7 +1033,7 @@ CREATE TABLE `profile_resource` REFERENCES `resource` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- profile_module @@ -1061,7 +1061,7 @@ CREATE TABLE `profile_module` REFERENCES `module` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- message @@ -1085,7 +1085,7 @@ CREATE TABLE `message` `version_created_by` VARCHAR(100), PRIMARY KEY (`id`), UNIQUE INDEX `name_UNIQUE` (`name`) -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- coupon @@ -1120,7 +1120,7 @@ CREATE TABLE `coupon` INDEX `idx_is_removing_postage` (`is_removing_postage`), INDEX `idx_max_usage` (`max_usage`), INDEX `idx_is_available_on_special_offers` (`is_available_on_special_offers`) -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- admin_log @@ -1141,7 +1141,7 @@ CREATE TABLE `admin_log` `created_at` DATETIME, `updated_at` DATETIME, PRIMARY KEY (`id`) -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- content_folder @@ -1170,7 +1170,7 @@ CREATE TABLE `content_folder` REFERENCES `folder` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- cart @@ -1215,7 +1215,7 @@ CREATE TABLE `cart` REFERENCES `currency` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- cart_item @@ -1255,7 +1255,7 @@ CREATE TABLE `cart_item` REFERENCES `product_sale_elements` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- product_price @@ -1283,7 +1283,7 @@ CREATE TABLE `product_price` FOREIGN KEY (`currency_id`) REFERENCES `currency` (`id`) ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- category_image @@ -1307,7 +1307,7 @@ CREATE TABLE `category_image` REFERENCES `category` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- folder_image @@ -1331,7 +1331,7 @@ CREATE TABLE `folder_image` REFERENCES `folder` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- content_image @@ -1355,7 +1355,7 @@ CREATE TABLE `content_image` REFERENCES `content` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- category_document @@ -1378,7 +1378,7 @@ CREATE TABLE `category_document` REFERENCES `category` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- content_document @@ -1401,7 +1401,7 @@ CREATE TABLE `content_document` REFERENCES `content` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- folder_document @@ -1424,7 +1424,7 @@ CREATE TABLE `folder_document` REFERENCES `folder` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- product_associated_content @@ -1453,7 +1453,7 @@ CREATE TABLE `product_associated_content` REFERENCES `content` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- category_associated_content @@ -1482,7 +1482,7 @@ CREATE TABLE `category_associated_content` REFERENCES `content` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- rewriting_url @@ -1503,14 +1503,12 @@ CREATE TABLE `rewriting_url` PRIMARY KEY (`id`), UNIQUE INDEX `url_UNIQUE` (`url`), INDEX `idx_rewriting_url_redirected` (`redirected`), - INDEX `idx_rewriting_url_view_updated_at` (`view`, `updated_at`), - INDEX `idx_rewriting_url_view_id_view_view_locale_updated_at` (`view_id`, `view`, `view_locale`, `updated_at`), CONSTRAINT `fk_rewriting_url_redirected` FOREIGN KEY (`redirected`) REFERENCES `rewriting_url` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- rewriting_argument @@ -1532,7 +1530,7 @@ CREATE TABLE `rewriting_argument` REFERENCES `rewriting_url` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- template @@ -1546,7 +1544,7 @@ CREATE TABLE `template` `created_at` DATETIME, `updated_at` DATETIME, PRIMARY KEY (`id`) -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- module_image @@ -1570,7 +1568,7 @@ CREATE TABLE `module_image` REFERENCES `module` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- order_product_tax @@ -1595,7 +1593,7 @@ CREATE TABLE `order_product_tax` REFERENCES `order_product` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- newsletter @@ -1614,7 +1612,7 @@ CREATE TABLE `newsletter` `updated_at` DATETIME, PRIMARY KEY (`id`), UNIQUE INDEX `email_UNIQUE` (`email`) -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- order_coupon @@ -1646,7 +1644,51 @@ CREATE TABLE `order_coupon` REFERENCES `order` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; + +-- --------------------------------------------------------------------- +-- coupon_country +-- --------------------------------------------------------------------- + +DROP TABLE IF EXISTS `coupon_country`; + +CREATE TABLE `coupon_country` +( + `coupon_id` INTEGER NOT NULL, + `country_id` INTEGER NOT NULL, + PRIMARY KEY (`coupon_id`,`country_id`), + INDEX `fk_country_id_idx` (`country_id`), + CONSTRAINT `fk_coupon_country_country_id` + FOREIGN KEY (`country_id`) + REFERENCES `country` (`id`) + ON DELETE CASCADE, + CONSTRAINT `fk_coupon_country_coupon_id` + FOREIGN KEY (`coupon_id`) + REFERENCES `coupon` (`id`) + ON DELETE CASCADE +) ENGINE=InnoDB; + +-- --------------------------------------------------------------------- +-- coupon_module +-- --------------------------------------------------------------------- + +DROP TABLE IF EXISTS `coupon_module`; + +CREATE TABLE `coupon_module` +( + `coupon_id` INTEGER NOT NULL, + `module_id` INTEGER NOT NULL, + PRIMARY KEY (`coupon_id`,`module_id`), + INDEX `fk_module_id_idx` (`module_id`), + CONSTRAINT `fk_coupon_module_coupon_id` + FOREIGN KEY (`coupon_id`) + REFERENCES `coupon` (`id`) + ON DELETE CASCADE, + CONSTRAINT `fk_coupon_module_module_id` + FOREIGN KEY (`module_id`) + REFERENCES `module` (`id`) + ON DELETE CASCADE +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- category_i18n @@ -1670,7 +1712,7 @@ CREATE TABLE `category_i18n` FOREIGN KEY (`id`) REFERENCES `category` (`id`) ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- product_i18n @@ -1694,7 +1736,7 @@ CREATE TABLE `product_i18n` FOREIGN KEY (`id`) REFERENCES `product` (`id`) ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- country_i18n @@ -1715,7 +1757,7 @@ CREATE TABLE `country_i18n` FOREIGN KEY (`id`) REFERENCES `country` (`id`) ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- tax_i18n @@ -1734,7 +1776,7 @@ CREATE TABLE `tax_i18n` FOREIGN KEY (`id`) REFERENCES `tax` (`id`) ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- tax_rule_i18n @@ -1753,7 +1795,7 @@ CREATE TABLE `tax_rule_i18n` FOREIGN KEY (`id`) REFERENCES `tax_rule` (`id`) ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- feature_i18n @@ -1774,7 +1816,7 @@ CREATE TABLE `feature_i18n` FOREIGN KEY (`id`) REFERENCES `feature` (`id`) ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- feature_av_i18n @@ -1795,7 +1837,7 @@ CREATE TABLE `feature_av_i18n` FOREIGN KEY (`id`) REFERENCES `feature_av` (`id`) ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- attribute_i18n @@ -1816,7 +1858,7 @@ CREATE TABLE `attribute_i18n` FOREIGN KEY (`id`) REFERENCES `attribute` (`id`) ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- attribute_av_i18n @@ -1837,7 +1879,7 @@ CREATE TABLE `attribute_av_i18n` FOREIGN KEY (`id`) REFERENCES `attribute_av` (`id`) ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- config_i18n @@ -1858,7 +1900,7 @@ CREATE TABLE `config_i18n` FOREIGN KEY (`id`) REFERENCES `config` (`id`) ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- customer_title_i18n @@ -1877,7 +1919,7 @@ CREATE TABLE `customer_title_i18n` FOREIGN KEY (`id`) REFERENCES `customer_title` (`id`) ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- folder_i18n @@ -1901,7 +1943,7 @@ CREATE TABLE `folder_i18n` FOREIGN KEY (`id`) REFERENCES `folder` (`id`) ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- content_i18n @@ -1925,7 +1967,7 @@ CREATE TABLE `content_i18n` FOREIGN KEY (`id`) REFERENCES `content` (`id`) ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- product_image_i18n @@ -1946,7 +1988,7 @@ CREATE TABLE `product_image_i18n` FOREIGN KEY (`id`) REFERENCES `product_image` (`id`) ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- product_document_i18n @@ -1967,7 +2009,7 @@ CREATE TABLE `product_document_i18n` FOREIGN KEY (`id`) REFERENCES `product_document` (`id`) ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- currency_i18n @@ -1985,7 +2027,7 @@ CREATE TABLE `currency_i18n` FOREIGN KEY (`id`) REFERENCES `currency` (`id`) ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- order_status_i18n @@ -2006,7 +2048,7 @@ CREATE TABLE `order_status_i18n` FOREIGN KEY (`id`) REFERENCES `order_status` (`id`) ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- module_i18n @@ -2027,7 +2069,7 @@ CREATE TABLE `module_i18n` FOREIGN KEY (`id`) REFERENCES `module` (`id`) ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- profile_i18n @@ -2048,7 +2090,7 @@ CREATE TABLE `profile_i18n` FOREIGN KEY (`id`) REFERENCES `profile` (`id`) ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- resource_i18n @@ -2069,7 +2111,7 @@ CREATE TABLE `resource_i18n` FOREIGN KEY (`id`) REFERENCES `resource` (`id`) ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- message_i18n @@ -2090,7 +2132,7 @@ CREATE TABLE `message_i18n` FOREIGN KEY (`id`) REFERENCES `message` (`id`) ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- coupon_i18n @@ -2110,7 +2152,7 @@ CREATE TABLE `coupon_i18n` FOREIGN KEY (`id`) REFERENCES `coupon` (`id`) ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- category_image_i18n @@ -2131,7 +2173,7 @@ CREATE TABLE `category_image_i18n` FOREIGN KEY (`id`) REFERENCES `category_image` (`id`) ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- folder_image_i18n @@ -2152,7 +2194,7 @@ CREATE TABLE `folder_image_i18n` FOREIGN KEY (`id`) REFERENCES `folder_image` (`id`) ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- content_image_i18n @@ -2173,7 +2215,7 @@ CREATE TABLE `content_image_i18n` FOREIGN KEY (`id`) REFERENCES `content_image` (`id`) ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- category_document_i18n @@ -2194,7 +2236,7 @@ CREATE TABLE `category_document_i18n` FOREIGN KEY (`id`) REFERENCES `category_document` (`id`) ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- content_document_i18n @@ -2215,7 +2257,7 @@ CREATE TABLE `content_document_i18n` FOREIGN KEY (`id`) REFERENCES `content_document` (`id`) ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- folder_document_i18n @@ -2236,7 +2278,7 @@ CREATE TABLE `folder_document_i18n` FOREIGN KEY (`id`) REFERENCES `folder_document` (`id`) ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- template_i18n @@ -2254,7 +2296,7 @@ CREATE TABLE `template_i18n` FOREIGN KEY (`id`) REFERENCES `template` (`id`) ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- module_image_i18n @@ -2275,7 +2317,7 @@ CREATE TABLE `module_image_i18n` FOREIGN KEY (`id`) REFERENCES `module_image` (`id`) ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- category_version @@ -2299,7 +2341,7 @@ CREATE TABLE `category_version` FOREIGN KEY (`id`) REFERENCES `category` (`id`) ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- product_version @@ -2325,7 +2367,7 @@ CREATE TABLE `product_version` FOREIGN KEY (`id`) REFERENCES `product` (`id`) ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- folder_version @@ -2349,7 +2391,7 @@ CREATE TABLE `folder_version` FOREIGN KEY (`id`) REFERENCES `folder` (`id`) ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- content_version @@ -2372,7 +2414,7 @@ CREATE TABLE `content_version` FOREIGN KEY (`id`) REFERENCES `content` (`id`) ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- message_version @@ -2399,7 +2441,7 @@ CREATE TABLE `message_version` FOREIGN KEY (`id`) REFERENCES `message` (`id`) ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; -- --------------------------------------------------------------------- -- coupon_version @@ -2429,7 +2471,7 @@ CREATE TABLE `coupon_version` FOREIGN KEY (`id`) REFERENCES `coupon` (`id`) ON DELETE CASCADE -) ENGINE=InnoDB CHARACTER SET='utf8'; +) ENGINE=InnoDB; # This restores the fkey checks, after having unset them earlier SET FOREIGN_KEY_CHECKS = 1;