       1: <?php
       2:
       3: namespace Thelia\Model\om;
       4:
       5: use \BaseObject;
       6: use \BasePeer;
       7: use \Criteria;
       8: use \DateTime;
       9: use \Exception;
      10: use \PDO;
      11: use \Persistent;
      12: use \Propel;
      13: use \PropelCollection;
      14: use \PropelDateTime;
      15: use \PropelException;
      16: use \PropelObjectCollection;
      17: use \PropelPDO;
      18: use Thelia\Model\Product;
      19: use Thelia\Model\ProductQuery;
      20: use Thelia\Model\TaxRule;
      21: use Thelia\Model\TaxRuleCountry;
      22: use Thelia\Model\TaxRuleCountryQuery;
      23: use Thelia\Model\TaxRuleI18n;
      24: use Thelia\Model\TaxRuleI18nQuery;
      25: use Thelia\Model\TaxRulePeer;
      26: use Thelia\Model\TaxRuleQuery;
      27:
      28: /**
      29:  * Base class that represents a row from the 'tax_rule' table.
      30:  *
      31:  *
      32:  *
      33:  * @package    propel.generator.Thelia.Model.om
      34:  */
      35: abstract class BaseTaxRule extends BaseObject implements Persistent
      36: {
      37:     /**
      38:      * Peer class name
      39:      */
      40:     const PEER = 'Thelia\\Model\\TaxRulePeer';
      41:
      42:     /**
      43:      * The Peer class.
      44:      * Instance provides a convenient way of calling static methods on a class
      45:      * that calling code may not be able to identify.
      46:      * @var        TaxRulePeer
      47:      */
      48:     protected static $peer;
      49:
      50:     /**
      51:      * The flag var to prevent infinit loop in deep copy
      52:      * @var       boolean
      53:      */
      54:     protected $startCopy = false;
      55:
      56:     /**
      57:      * The value for the id field.
      58:      * @var        int
      59:      */
      60:     protected $id;
      61:
      62:     /**
      63:      * The value for the code field.
      64:      * @var        string
      65:      */
      66:     protected $code;
      67:
      68:     /**
      69:      * The value for the title field.
      70:      * @var        string
      71:      */
      72:     protected $title;
      73:
      74:     /**
      75:      * The value for the description field.
      76:      * @var        string
      77:      */
      78:     protected $description;
      79:
      80:     /**
      81:      * The value for the created_at field.
      82:      * @var        string
      83:      */
      84:     protected $created_at;
      85:
      86:     /**
      87:      * The value for the updated_at field.
      88:      * @var        string
      89:      */
      90:     protected $updated_at;
      91:
      92:     /**
      93:      * @var        PropelObjectCollection|Product[] Collection to store aggregation of Product objects.
      94:      */
      95:     protected $collProducts;
      96:     protected $collProductsPartial;
      97:
      98:     /**
      99:      * @var        PropelObjectCollection|TaxRuleCountry[] Collection to store aggregation of TaxRuleCountry objects.
     100:      */
     101:     protected $collTaxRuleCountrys;
     102:     protected $collTaxRuleCountrysPartial;
     103:
     104:     /**
     105:      * @var        PropelObjectCollection|TaxRuleI18n[] Collection to store aggregation of TaxRuleI18n objects.
     106:      */
     107:     protected $collTaxRuleI18ns;
     108:     protected $collTaxRuleI18nsPartial;
     109:
     110:     /**
     111:      * Flag to prevent endless save loop, if this object is referenced
     112:      * by another object which falls in this transaction.
     113:      * @var        boolean
     114:      */
     115:     protected $alreadyInSave = false;
     116:
     117:     /**
     118:      * Flag to prevent endless validation loop, if this object is referenced
     119:      * by another object which falls in this transaction.
     120:      * @var        boolean
     121:      */
     122:     protected $alreadyInValidation = false;
     123:
     124:     /**
     125:      * Flag to prevent endless clearAllReferences($deep=true) loop, if this object is referenced
     126:      * @var        boolean
     127:      */
     128:     protected $alreadyInClearAllReferencesDeep = false;
     129:
     130:     // i18n behavior
     131:
     132:     /**
     133:      * Current locale
     134:      * @var        string
     135:      */
     136:     protected $currentLocale = 'en_US';
     137:
     138:     /**
     139:      * Current translation objects
     140:      * @var        array[TaxRuleI18n]
     141:      */
     142:     protected $currentTranslations;
     143:
     144:     /**
     145:      * An array of objects scheduled for deletion.
     146:      * @var     PropelObjectCollection
     147:      */
     148:     protected $productsScheduledForDeletion = null;
     149:
     150:     /**
     151:      * An array of objects scheduled for deletion.
     152:      * @var     PropelObjectCollection
     153:      */
     154:     protected $taxRuleCountrysScheduledForDeletion = null;
     155:
     156:     /**
     157:      * An array of objects scheduled for deletion.
     158:      * @var     PropelObjectCollection
     159:      */
     160:     protected $taxRuleI18nsScheduledForDeletion = null;
     161:
     162:     /**
     163:      * Get the [id] column value.
     164:      *
     165:      * @return int
     166:      */
     167:     public function getId()
     168:     {
     169:         return $this->id;
     170:     }
     171:
     172:     /**
     173:      * Get the [code] column value.
     174:      *
     175:      * @return string
     176:      */
     177:     public function getCode()
     178:     {
     179:         return $this->code;
     180:     }
     181:
     182:     /**
     183:      * Get the [title] column value.
     184:      *
     185:      * @return string
     186:      */
     187:     public function getTitle()
     188:     {
     189:         return $this->title;
     190:     }
     191:
     192:     /**
     193:      * Get the [description] column value.
     194:      *
     195:      * @return string
     196:      */
     197:     public function getDescription()
     198:     {
     199:         return $this->description;
     200:     }
     201:
     202:     /**
     203:      * Get the [optionally formatted] temporal [created_at] column value.
     204:      *
     205:      *
     206:      * @param string $format The date/time format string (either date()-style or strftime()-style).
     207:      *               If format is null, then the raw DateTime object will be returned.
     208:      * @return mixed Formatted date/time value as string or DateTime object (if format is null), null if column is null, and 0 if column value is 0000-00-00 00:00:00
     209:      * @throws PropelException - if unable to parse/validate the date/time value.
     210:      */
     211:     public function getCreatedAt($format = 'Y-m-d H:i:s')
     212:     {
     213:         if ($this->created_at === null) {
     214:             return null;
     215:         }
     216:
     217:         if ($this->created_at === '0000-00-00 00:00:00') {
     218:             // while technically this is not a default value of null,
     219:             // this seems to be closest in meaning.
     220:             return null;
     221:         }
     222:
     223:         try {
     224:             $dt = new DateTime($this->created_at);
     225:         } catch (Exception $x) {
     226:             throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->created_at, true), $x);
     227:         }
     228:
     229:         if ($format === null) {
     230:             // Because propel.useDateTimeClass is true, we return a DateTime object.
     231:             return $dt;
     232:         }
     233:
     234:         if (strpos($format, '%') !== false) {
     235:             return strftime($format, $dt->format('U'));
     236:         }
     237:
     238:         return $dt->format($format);
     239:
     240:     }
     241:
     242:     /**
     243:      * Get the [optionally formatted] temporal [updated_at] column value.
     244:      *
     245:      *
     246:      * @param string $format The date/time format string (either date()-style or strftime()-style).
     247:      *               If format is null, then the raw DateTime object will be returned.
     248:      * @return mixed Formatted date/time value as string or DateTime object (if format is null), null if column is null, and 0 if column value is 0000-00-00 00:00:00
     249:      * @throws PropelException - if unable to parse/validate the date/time value.
     250:      */
     251:     public function getUpdatedAt($format = 'Y-m-d H:i:s')
     252:     {
     253:         if ($this->updated_at === null) {
     254:             return null;
     255:         }
     256:
     257:         if ($this->updated_at === '0000-00-00 00:00:00') {
     258:             // while technically this is not a default value of null,
     259:             // this seems to be closest in meaning.
     260:             return null;
     261:         }
     262:
     263:         try {
     264:             $dt = new DateTime($this->updated_at);
     265:         } catch (Exception $x) {
     266:             throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->updated_at, true), $x);
     267:         }
     268:
     269:         if ($format === null) {
     270:             // Because propel.useDateTimeClass is true, we return a DateTime object.
     271:             return $dt;
     272:         }
     273:
     274:         if (strpos($format, '%') !== false) {
     275:             return strftime($format, $dt->format('U'));
     276:         }
     277:
     278:         return $dt->format($format);
     279:
     280:     }
     281:
     282:     /**
     283:      * Set the value of [id] column.
     284:      *
     285:      * @param int $v new value
     286:      * @return TaxRule The current object (for fluent API support)
     287:      */
     288:     public function setId($v)
     289:     {
     290:         if ($v !== null && is_numeric($v)) {
     291:             $v = (int) $v;
     292:         }
     293:
     294:         if ($this->id !== $v) {
     295:             $this->id = $v;
     296:             $this->modifiedColumns[] = TaxRulePeer::ID;
     297:         }
     298:
     299:
     300:         return $this;
     301:     } // setId()
     302:
     303:     /**
     304:      * Set the value of [code] column.
     305:      *
     306:      * @param string $v new value
     307:      * @return TaxRule The current object (for fluent API support)
     308:      */
     309:     public function setCode($v)
     310:     {
     311:         if ($v !== null && is_numeric($v)) {
     312:             $v = (string) $v;
     313:         }
     314:
     315:         if ($this->code !== $v) {
     316:             $this->code = $v;
     317:             $this->modifiedColumns[] = TaxRulePeer::CODE;
     318:         }
     319:
     320:
     321:         return $this;
     322:     } // setCode()
     323:
     324:     /**
     325:      * Set the value of [title] column.
     326:      *
     327:      * @param string $v new value
     328:      * @return TaxRule The current object (for fluent API support)
     329:      */
     330:     public function setTitle($v)
     331:     {
     332:         if ($v !== null && is_numeric($v)) {
     333:             $v = (string) $v;
     334:         }
     335:
     336:         if ($this->title !== $v) {
     337:             $this->title = $v;
     338:             $this->modifiedColumns[] = TaxRulePeer::TITLE;
     339:         }
     340:
     341:
     342:         return $this;
     343:     } // setTitle()
     344:
     345:     /**
     346:      * Set the value of [description] column.
     347:      *
     348:      * @param string $v new value
     349:      * @return TaxRule The current object (for fluent API support)
     350:      */
     351:     public function setDescription($v)
     352:     {
     353:         if ($v !== null && is_numeric($v)) {
     354:             $v = (string) $v;
     355:         }
     356:
     357:         if ($this->description !== $v) {
     358:             $this->description = $v;
     359:             $this->modifiedColumns[] = TaxRulePeer::DESCRIPTION;
     360:         }
     361:
     362:
     363:         return $this;
     364:     } // setDescription()
     365:
     366:     /**
     367:      * Sets the value of [created_at] column to a normalized version of the date/time value specified.
     368:      *
     369:      * @param mixed $v string, integer (timestamp), or DateTime value.
     370:      *               Empty strings are treated as null.
     371:      * @return TaxRule The current object (for fluent API support)
     372:      */
     373:     public function setCreatedAt($v)
     374:     {
     375:         $dt = PropelDateTime::newInstance($v, null, 'DateTime');
     376:         if ($this->created_at !== null || $dt !== null) {
     377:             $currentDateAsString = ($this->created_at !== null && $tmpDt = new DateTime($this->created_at)) ? $tmpDt->format('Y-m-d H:i:s') : null;
     378:             $newDateAsString = $dt ? $dt->format('Y-m-d H:i:s') : null;
     379:             if ($currentDateAsString !== $newDateAsString) {
     380:                 $this->created_at = $newDateAsString;
     381:                 $this->modifiedColumns[] = TaxRulePeer::CREATED_AT;
     382:             }
     383:         } // if either are not null
     384:
     385:
     386:         return $this;
     387:     } // setCreatedAt()
     388:
     389:     /**
     390:      * Sets the value of [updated_at] column to a normalized version of the date/time value specified.
     391:      *
     392:      * @param mixed $v string, integer (timestamp), or DateTime value.
     393:      *               Empty strings are treated as null.
     394:      * @return TaxRule The current object (for fluent API support)
     395:      */
     396:     public function setUpdatedAt($v)
     397:     {
     398:         $dt = PropelDateTime::newInstance($v, null, 'DateTime');
     399:         if ($this->updated_at !== null || $dt !== null) {
     400:             $currentDateAsString = ($this->updated_at !== null && $tmpDt = new DateTime($this->updated_at)) ? $tmpDt->format('Y-m-d H:i:s') : null;
     401:             $newDateAsString = $dt ? $dt->format('Y-m-d H:i:s') : null;
     402:             if ($currentDateAsString !== $newDateAsString) {
     403:                 $this->updated_at = $newDateAsString;
     404:                 $this->modifiedColumns[] = TaxRulePeer::UPDATED_AT;
     405:             }
     406:         } // if either are not null
     407:
     408:
     409:         return $this;
     410:     } // setUpdatedAt()
     411:
     412:     /**
     413:      * Indicates whether the columns in this object are only set to default values.
     414:      *
     415:      * This method can be used in conjunction with isModified() to indicate whether an object is both
     416:      * modified _and_ has some values set which are non-default.
     417:      *
     418:      * @return boolean Whether the columns in this object are only been set with default values.
     419:      */
     420:     public function hasOnlyDefaultValues()
     421:     {
     422:         // otherwise, everything was equal, so return true
     423:         return true;
     424:     } // hasOnlyDefaultValues()
     425:
     426:     /**
     427:      * Hydrates (populates) the object variables with values from the database resultset.
     428:      *
     429:      * An offset (0-based "start column") is specified so that objects can be hydrated
     430:      * with a subset of the columns in the resultset rows.  This is needed, for example,
     431:      * for results of JOIN queries where the resultset row includes columns from two or
     432:      * more tables.
     433:      *
     434:      * @param array $row The row returned by PDOStatement->fetch(PDO::FETCH_NUM)
     435:      * @param int $startcol 0-based offset column which indicates which restultset column to start with.
     436:      * @param boolean $rehydrate Whether this object is being re-hydrated from the database.
     437:      * @return int             next starting column
     438:      * @throws PropelException - Any caught Exception will be rewrapped as a PropelException.
     439:      */
     440:     public function hydrate($row, $startcol = 0, $rehydrate = false)
     441:     {
     442:         try {
     443:
     444:             $this->id = ($row[$startcol + 0] !== null) ? (int) $row[$startcol + 0] : null;
     445:             $this->code = ($row[$startcol + 1] !== null) ? (string) $row[$startcol + 1] : null;
     446:             $this->title = ($row[$startcol + 2] !== null) ? (string) $row[$startcol + 2] : null;
     447:             $this->description = ($row[$startcol + 3] !== null) ? (string) $row[$startcol + 3] : null;
     448:             $this->created_at = ($row[$startcol + 4] !== null) ? (string) $row[$startcol + 4] : null;
     449:             $this->updated_at = ($row[$startcol + 5] !== null) ? (string) $row[$startcol + 5] : null;
     450:             $this->resetModified();
     451:
     452:             $this->setNew(false);
     453:
     454:             if ($rehydrate) {
     455:                 $this->ensureConsistency();
     456:             }
     457:             $this->postHydrate($row, $startcol, $rehydrate);
     458:             return $startcol + 6; // 6 = TaxRulePeer::NUM_HYDRATE_COLUMNS.
     459:
     460:         } catch (Exception $e) {
     461:             throw new PropelException("Error populating TaxRule object", $e);
     462:         }
     463:     }
     464:
     465:     /**
     466:      * Checks and repairs the internal consistency of the object.
     467:      *
     468:      * This method is executed after an already-instantiated object is re-hydrated
     469:      * from the database.  It exists to check any foreign keys to make sure that
     470:      * the objects related to the current object are correct based on foreign key.
     471:      *
     472:      * You can override this method in the stub class, but you should always invoke
     473:      * the base method from the overridden method (i.e. parent::ensureConsistency()),
     474:      * in case your model changes.
     475:      *
     476:      * @throws PropelException
     477:      */
     478:     public function ensureConsistency()
     479:     {
     480:
     481:     } // ensureConsistency
     482:
     483:     /**
     484:      * Reloads this object from datastore based on primary key and (optionally) resets all associated objects.
     485:      *
     486:      * This will only work if the object has been saved and has a valid primary key set.
     487:      *
     488:      * @param boolean $deep (optional) Whether to also de-associated any related objects.
     489:      * @param PropelPDO $con (optional) The PropelPDO connection to use.
     490:      * @return void
     491:      * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db
     492:      */
     493:     public function reload($deep = false, PropelPDO $con = null)
     494:     {
     495:         if ($this->isDeleted()) {
     496:             throw new PropelException("Cannot reload a deleted object.");
     497:         }
     498:
     499:         if ($this->isNew()) {
     500:             throw new PropelException("Cannot reload an unsaved object.");
     501:         }
     502:
     503:         if ($con === null) {
     504:             $con = Propel::getConnection(TaxRulePeer::DATABASE_NAME, Propel::CONNECTION_READ);
     505:         }
     506:
     507:         // We don't need to alter the object instance pool; we're just modifying this instance
     508:         // already in the pool.
     509:
     510:         $stmt = TaxRulePeer::doSelectStmt($this->buildPkeyCriteria(), $con);
     511:         $row = $stmt->fetch(PDO::FETCH_NUM);
     512:         $stmt->closeCursor();
     513:         if (!$row) {
     514:             throw new PropelException('Cannot find matching row in the database to reload object values.');
     515:         }
     516:         $this->hydrate($row, 0, true); // rehydrate
     517:
     518:         if ($deep) {  // also de-associate any related objects?
     519:
     520:             $this->collProducts = null;
     521:
     522:             $this->collTaxRuleCountrys = null;
     523:
     524:             $this->collTaxRuleI18ns = null;
     525:
     526:         } // if (deep)
     527:     }
     528:
     529:     /**
     530:      * Removes this object from datastore and sets delete attribute.
     531:      *
     532:      * @param PropelPDO $con
     533:      * @return void
     534:      * @throws PropelException
     535:      * @throws Exception
     536:      * @see        BaseObject::setDeleted()
     537:      * @see        BaseObject::isDeleted()
     538:      */
     539:     public function delete(PropelPDO $con = null)
     540:     {
     541:         if ($this->isDeleted()) {
     542:             throw new PropelException("This object has already been deleted.");
     543:         }
     544:
     545:         if ($con === null) {
     546:             $con = Propel::getConnection(TaxRulePeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     547:         }
     548:
     549:         $con->beginTransaction();
     550:         try {
     551:             $deleteQuery = TaxRuleQuery::create()
     552:                 ->filterByPrimaryKey($this->getPrimaryKey());
     553:             $ret = $this->preDelete($con);
     554:             if ($ret) {
     555:                 $deleteQuery->delete($con);
     556:                 $this->postDelete($con);
     557:                 $con->commit();
     558:                 $this->setDeleted(true);
     559:             } else {
     560:                 $con->commit();
     561:             }
     562:         } catch (Exception $e) {
     563:             $con->rollBack();
     564:             throw $e;
     565:         }
     566:     }
     567:
     568:     /**
     569:      * Persists this object to the database.
     570:      *
     571:      * If the object is new, it inserts it; otherwise an update is performed.
     572:      * All modified related objects will also be persisted in the doSave()
     573:      * method.  This method wraps all precipitate database operations in a
     574:      * single transaction.
     575:      *
     576:      * @param PropelPDO $con
     577:      * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
     578:      * @throws PropelException
     579:      * @throws Exception
     580:      * @see        doSave()
     581:      */
     582:     public function save(PropelPDO $con = null)
     583:     {
     584:         if ($this->isDeleted()) {
     585:             throw new PropelException("You cannot save an object that has been deleted.");
     586:         }
     587:
     588:         if ($con === null) {
     589:             $con = Propel::getConnection(TaxRulePeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     590:         }
     591:
     592:         $con->beginTransaction();
     593:         $isInsert = $this->isNew();
     594:         try {
     595:             $ret = $this->preSave($con);
     596:             if ($isInsert) {
     597:                 $ret = $ret && $this->preInsert($con);
     598:                 // timestampable behavior
     599:                 if (!$this->isColumnModified(TaxRulePeer::CREATED_AT)) {
     600:                     $this->setCreatedAt(time());
     601:                 }
     602:                 if (!$this->isColumnModified(TaxRulePeer::UPDATED_AT)) {
     603:                     $this->setUpdatedAt(time());
     604:                 }
     605:             } else {
     606:                 $ret = $ret && $this->preUpdate($con);
     607:                 // timestampable behavior
     608:                 if ($this->isModified() && !$this->isColumnModified(TaxRulePeer::UPDATED_AT)) {
     609:                     $this->setUpdatedAt(time());
     610:                 }
     611:             }
     612:             if ($ret) {
     613:                 $affectedRows = $this->doSave($con);
     614:                 if ($isInsert) {
     615:                     $this->postInsert($con);
     616:                 } else {
     617:                     $this->postUpdate($con);
     618:                 }
     619:                 $this->postSave($con);
     620:                 TaxRulePeer::addInstanceToPool($this);
     621:             } else {
     622:                 $affectedRows = 0;
     623:             }
     624:             $con->commit();
     625:
     626:             return $affectedRows;
     627:         } catch (Exception $e) {
     628:             $con->rollBack();
     629:             throw $e;
     630:         }
     631:     }
     632:
     633:     /**
     634:      * Performs the work of inserting or updating the row in the database.
     635:      *
     636:      * If the object is new, it inserts it; otherwise an update is performed.
     637:      * All related objects are also updated in this method.
     638:      *
     639:      * @param PropelPDO $con
     640:      * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
     641:      * @throws PropelException
     642:      * @see        save()
     643:      */
     644:     protected function doSave(PropelPDO $con)
     645:     {
     646:         $affectedRows = 0; // initialize var to track total num of affected rows
     647:         if (!$this->alreadyInSave) {
     648:             $this->alreadyInSave = true;
     649:
     650:             if ($this->isNew() || $this->isModified()) {
     651:                 // persist changes
     652:                 if ($this->isNew()) {
     653:                     $this->doInsert($con);
     654:                 } else {
     655:                     $this->doUpdate($con);
     656:                 }
     657:                 $affectedRows += 1;
     658:                 $this->resetModified();
     659:             }
     660:
     661:             if ($this->productsScheduledForDeletion !== null) {
     662:                 if (!$this->productsScheduledForDeletion->isEmpty()) {
     663:                     foreach ($this->productsScheduledForDeletion as $product) {
     664:                         // need to save related object because we set the relation to null
     665:                         $product->save($con);
     666:                     }
     667:                     $this->productsScheduledForDeletion = null;
     668:                 }
     669:             }
     670:
     671:             if ($this->collProducts !== null) {
     672:                 foreach ($this->collProducts as $referrerFK) {
     673:                     if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
     674:                         $affectedRows += $referrerFK->save($con);
     675:                     }
     676:                 }
     677:             }
     678:
     679:             if ($this->taxRuleCountrysScheduledForDeletion !== null) {
     680:                 if (!$this->taxRuleCountrysScheduledForDeletion->isEmpty()) {
     681:                     foreach ($this->taxRuleCountrysScheduledForDeletion as $taxRuleCountry) {
     682:                         // need to save related object because we set the relation to null
     683:                         $taxRuleCountry->save($con);
     684:                     }
     685:                     $this->taxRuleCountrysScheduledForDeletion = null;
     686:                 }
     687:             }
     688:
     689:             if ($this->collTaxRuleCountrys !== null) {
     690:                 foreach ($this->collTaxRuleCountrys as $referrerFK) {
     691:                     if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
     692:                         $affectedRows += $referrerFK->save($con);
     693:                     }
     694:                 }
     695:             }
     696:
     697:             if ($this->taxRuleI18nsScheduledForDeletion !== null) {
     698:                 if (!$this->taxRuleI18nsScheduledForDeletion->isEmpty()) {
     699:                     TaxRuleI18nQuery::create()
     700:                         ->filterByPrimaryKeys($this->taxRuleI18nsScheduledForDeletion->getPrimaryKeys(false))
     701:                         ->delete($con);
     702:                     $this->taxRuleI18nsScheduledForDeletion = null;
     703:                 }
     704:             }
     705:
     706:             if ($this->collTaxRuleI18ns !== null) {
     707:                 foreach ($this->collTaxRuleI18ns as $referrerFK) {
     708:                     if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
     709:                         $affectedRows += $referrerFK->save($con);
     710:                     }
     711:                 }
     712:             }
     713:
     714:             $this->alreadyInSave = false;
     715:
     716:         }
     717:
     718:         return $affectedRows;
     719:     } // doSave()
     720:
     721:     /**
     722:      * Insert the row in the database.
     723:      *
     724:      * @param PropelPDO $con
     725:      *
     726:      * @throws PropelException
     727:      * @see        doSave()
     728:      */
     729:     protected function doInsert(PropelPDO $con)
     730:     {
     731:         $modifiedColumns = array();
     732:         $index = 0;
     733:
     734:         $this->modifiedColumns[] = TaxRulePeer::ID;
     735:         if (null !== $this->id) {
     736:             throw new PropelException('Cannot insert a value for auto-increment primary key (' . TaxRulePeer::ID . ')');
     737:         }
     738:
     739:          // check the columns in natural order for more readable SQL queries
     740:         if ($this->isColumnModified(TaxRulePeer::ID)) {
     741:             $modifiedColumns[':p' . $index++]  = '`id`';
     742:         }
     743:         if ($this->isColumnModified(TaxRulePeer::CODE)) {
     744:             $modifiedColumns[':p' . $index++]  = '`code`';
     745:         }
     746:         if ($this->isColumnModified(TaxRulePeer::TITLE)) {
     747:             $modifiedColumns[':p' . $index++]  = '`title`';
     748:         }
     749:         if ($this->isColumnModified(TaxRulePeer::DESCRIPTION)) {
     750:             $modifiedColumns[':p' . $index++]  = '`description`';
     751:         }
     752:         if ($this->isColumnModified(TaxRulePeer::CREATED_AT)) {
     753:             $modifiedColumns[':p' . $index++]  = '`created_at`';
     754:         }
     755:         if ($this->isColumnModified(TaxRulePeer::UPDATED_AT)) {
     756:             $modifiedColumns[':p' . $index++]  = '`updated_at`';
     757:         }
     758:
     759:         $sql = sprintf(
     760:             'INSERT INTO `tax_rule` (%s) VALUES (%s)',
     761:             implode(', ', $modifiedColumns),
     762:             implode(', ', array_keys($modifiedColumns))
     763:         );
     764:
     765:         try {
     766:             $stmt = $con->prepare($sql);
     767:             foreach ($modifiedColumns as $identifier => $columnName) {
     768:                 switch ($columnName) {
     769:                     case '`id`':
     770:                         $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT);
     771:                         break;
     772:                     case '`code`':
     773:                         $stmt->bindValue($identifier, $this->code, PDO::PARAM_STR);
     774:                         break;
     775:                     case '`title`':
     776:                         $stmt->bindValue($identifier, $this->title, PDO::PARAM_STR);
     777:                         break;
     778:                     case '`description`':
     779:                         $stmt->bindValue($identifier, $this->description, PDO::PARAM_STR);
     780:                         break;
     781:                     case '`created_at`':
     782:                         $stmt->bindValue($identifier, $this->created_at, PDO::PARAM_STR);
     783:                         break;
     784:                     case '`updated_at`':
     785:                         $stmt->bindValue($identifier, $this->updated_at, PDO::PARAM_STR);
     786:                         break;
     787:                 }
     788:             }
     789:             $stmt->execute();
     790:         } catch (Exception $e) {
     791:             Propel::log($e->getMessage(), Propel::LOG_ERR);
     792:             throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), $e);
     793:         }
     794:
     795:         try {
     796:             $pk = $con->lastInsertId();
     797:         } catch (Exception $e) {
     798:             throw new PropelException('Unable to get autoincrement id.', $e);
     799:         }
     800:         $this->setId($pk);
     801:
     802:         $this->setNew(false);
     803:     }
     804:
     805:     /**
     806:      * Update the row in the database.
     807:      *
     808:      * @param PropelPDO $con
     809:      *
     810:      * @see        doSave()
     811:      */
     812:     protected function doUpdate(PropelPDO $con)
     813:     {
     814:         $selectCriteria = $this->buildPkeyCriteria();
     815:         $valuesCriteria = $this->buildCriteria();
     816:         BasePeer::doUpdate($selectCriteria, $valuesCriteria, $con);
     817:     }
     818:
     819:     /**
     820:      * Array of ValidationFailed objects.
     821:      * @var        array ValidationFailed[]
     822:      */
     823:     protected $validationFailures = array();
     824:
     825:     /**
     826:      * Gets any ValidationFailed objects that resulted from last call to validate().
     827:      *
     828:      *
     829:      * @return array ValidationFailed[]
     830:      * @see        validate()
     831:      */
     832:     public function getValidationFailures()
     833:     {
     834:         return $this->validationFailures;
     835:     }
     836:
     837:     /**
     838:      * Validates the objects modified field values and all objects related to this table.
     839:      *
     840:      * If $columns is either a column name or an array of column names
     841:      * only those columns are validated.
     842:      *
     843:      * @param mixed $columns Column name or an array of column names.
     844:      * @return boolean Whether all columns pass validation.
     845:      * @see        doValidate()
     846:      * @see        getValidationFailures()
     847:      */
     848:     public function validate($columns = null)
     849:     {
     850:         $res = $this->doValidate($columns);
     851:         if ($res === true) {
     852:             $this->validationFailures = array();
     853:
     854:             return true;
     855:         }
     856:
     857:         $this->validationFailures = $res;
     858:
     859:         return false;
     860:     }
     861:
     862:     /**
     863:      * This function performs the validation work for complex object models.
     864:      *
     865:      * In addition to checking the current object, all related objects will
     866:      * also be validated.  If all pass then <code>true</code> is returned; otherwise
     867:      * an aggreagated array of ValidationFailed objects will be returned.
     868:      *
     869:      * @param array $columns Array of column names to validate.
     870:      * @return mixed <code>true</code> if all validations pass; array of <code>ValidationFailed</code> objets otherwise.
     871:      */
     872:     protected function doValidate($columns = null)
     873:     {
     874:         if (!$this->alreadyInValidation) {
     875:             $this->alreadyInValidation = true;
     876:             $retval = null;
     877:
     878:             $failureMap = array();
     879:
     880:
     881:             if (($retval = TaxRulePeer::doValidate($this, $columns)) !== true) {
     882:                 $failureMap = array_merge($failureMap, $retval);
     883:             }
     884:
     885:
     886:                 if ($this->collProducts !== null) {
     887:                     foreach ($this->collProducts as $referrerFK) {
     888:                         if (!$referrerFK->validate($columns)) {
     889:                             $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
     890:                         }
     891:                     }
     892:                 }
     893:
     894:                 if ($this->collTaxRuleCountrys !== null) {
     895:                     foreach ($this->collTaxRuleCountrys as $referrerFK) {
     896:                         if (!$referrerFK->validate($columns)) {
     897:                             $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
     898:                         }
     899:                     }
     900:                 }
     901:
     902:                 if ($this->collTaxRuleI18ns !== null) {
     903:                     foreach ($this->collTaxRuleI18ns as $referrerFK) {
     904:                         if (!$referrerFK->validate($columns)) {
     905:                             $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
     906:                         }
     907:                     }
     908:                 }
     909:
     910:
     911:             $this->alreadyInValidation = false;
     912:         }
     913:
     914:         return (!empty($failureMap) ? $failureMap : true);
     915:     }
     916:
     917:     /**
     918:      * Retrieves a field from the object by name passed in as a string.
     919:      *
     920:      * @param string $name name
     921:      * @param string $type The type of fieldname the $name is of:
     922:      *               one of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
     923:      *               BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
     924:      *               Defaults to BasePeer::TYPE_PHPNAME
     925:      * @return mixed Value of field.
     926:      */
     927:     public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
     928:     {
     929:         $pos = TaxRulePeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
     930:         $field = $this->getByPosition($pos);
     931:
     932:         return $field;
     933:     }
     934:
     935:     /**
     936:      * Retrieves a field from the object by Position as specified in the xml schema.
     937:      * Zero-based.
     938:      *
     939:      * @param int $pos position in xml schema
     940:      * @return mixed Value of field at $pos
     941:      */
     942:     public function getByPosition($pos)
     943:     {
     944:         switch ($pos) {
     945:             case 0:
     946:                 return $this->getId();
     947:                 break;
     948:             case 1:
     949:                 return $this->getCode();
     950:                 break;
     951:             case 2:
     952:                 return $this->getTitle();
     953:                 break;
     954:             case 3:
     955:                 return $this->getDescription();
     956:                 break;
     957:             case 4:
     958:                 return $this->getCreatedAt();
     959:                 break;
     960:             case 5:
     961:                 return $this->getUpdatedAt();
     962:                 break;
     963:             default:
     964:                 return null;
     965:                 break;
     966:         } // switch()
     967:     }
     968:
     969:     /**
     970:      * Exports the object as an array.
     971:      *
     972:      * You can specify the key type of the array by passing one of the class
     973:      * type constants.
     974:      *
     975:      * @param     string  $keyType (optional) One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
     976:      *                    BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
     977:      *                    Defaults to BasePeer::TYPE_PHPNAME.
     978:      * @param     boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to true.
     979:      * @param     array $alreadyDumpedObjects List of objects to skip to avoid recursion
     980:      * @param     boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE.
     981:      *
     982:      * @return array an associative array containing the field names (as keys) and field values
     983:      */
     984:     public function toArray($keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false)
     985:     {
     986:         if (isset($alreadyDumpedObjects['TaxRule'][$this->getPrimaryKey()])) {
     987:             return '*RECURSION*';
     988:         }
     989:         $alreadyDumpedObjects['TaxRule'][$this->getPrimaryKey()] = true;
     990:         $keys = TaxRulePeer::getFieldNames($keyType);
     991:         $result = array(
     992:             $keys[0] => $this->getId(),
     993:             $keys[1] => $this->getCode(),
     994:             $keys[2] => $this->getTitle(),
     995:             $keys[3] => $this->getDescription(),
     996:             $keys[4] => $this->getCreatedAt(),
     997:             $keys[5] => $this->getUpdatedAt(),
     998:         );
     999:         if ($includeForeignObjects) {
    1000:             if (null !== $this->collProducts) {
    1001:                 $result['Products'] = $this->collProducts->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects);
    1002:             }
    1003:             if (null !== $this->collTaxRuleCountrys) {
    1004:                 $result['TaxRuleCountrys'] = $this->collTaxRuleCountrys->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects);
    1005:             }
    1006:             if (null !== $this->collTaxRuleI18ns) {
    1007:                 $result['TaxRuleI18ns'] = $this->collTaxRuleI18ns->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects);
    1008:             }
    1009:         }
    1010:
    1011:         return $result;
    1012:     }
    1013:
    1014:     /**
    1015:      * Sets a field from the object by name passed in as a string.
    1016:      *
    1017:      * @param string $name peer name
    1018:      * @param mixed $value field value
    1019:      * @param string $type The type of fieldname the $name is of:
    1020:      *                     one of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
    1021:      *                     BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
    1022:      *                     Defaults to BasePeer::TYPE_PHPNAME
    1023:      * @return void
    1024:      */
    1025:     public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
    1026:     {
    1027:         $pos = TaxRulePeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
    1028:
    1029:         $this->setByPosition($pos, $value);
    1030:     }
    1031:
    1032:     /**
    1033:      * Sets a field from the object by Position as specified in the xml schema.
    1034:      * Zero-based.
    1035:      *
    1036:      * @param int $pos position in xml schema
    1037:      * @param mixed $value field value
    1038:      * @return void
    1039:      */
    1040:     public function setByPosition($pos, $value)
    1041:     {
    1042:         switch ($pos) {
    1043:             case 0:
    1044:                 $this->setId($value);
    1045:                 break;
    1046:             case 1:
    1047:                 $this->setCode($value);
    1048:                 break;
    1049:             case 2:
    1050:                 $this->setTitle($value);
    1051:                 break;
    1052:             case 3:
    1053:                 $this->setDescription($value);
    1054:                 break;
    1055:             case 4:
    1056:                 $this->setCreatedAt($value);
    1057:                 break;
    1058:             case 5:
    1059:                 $this->setUpdatedAt($value);
    1060:                 break;
    1061:         } // switch()
    1062:     }
    1063:
    1064:     /**
    1065:      * Populates the object using an array.
    1066:      *
    1067:      * This is particularly useful when populating an object from one of the
    1068:      * request arrays (e.g. $_POST).  This method goes through the column
    1069:      * names, checking to see whether a matching key exists in populated
    1070:      * array. If so the setByName() method is called for that column.
    1071:      *
    1072:      * You can specify the key type of the array by additionally passing one
    1073:      * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
    1074:      * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
    1075:      * The default key type is the column's BasePeer::TYPE_PHPNAME
    1076:      *
    1077:      * @param array  $arr     An array to populate the object from.
    1078:      * @param string $keyType The type of keys the array uses.
    1079:      * @return void
    1080:      */
    1081:     public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
    1082:     {
    1083:         $keys = TaxRulePeer::getFieldNames($keyType);
    1084:
    1085:         if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
    1086:         if (array_key_exists($keys[1], $arr)) $this->setCode($arr[$keys[1]]);
    1087:         if (array_key_exists($keys[2], $arr)) $this->setTitle($arr[$keys[2]]);
    1088:         if (array_key_exists($keys[3], $arr)) $this->setDescription($arr[$keys[3]]);
    1089:         if (array_key_exists($keys[4], $arr)) $this->setCreatedAt($arr[$keys[4]]);
    1090:         if (array_key_exists($keys[5], $arr)) $this->setUpdatedAt($arr[$keys[5]]);
    1091:     }
    1092:
    1093:     /**
    1094:      * Build a Criteria object containing the values of all modified columns in this object.
    1095:      *
    1096:      * @return Criteria The Criteria object containing all modified values.
    1097:      */
    1098:     public function buildCriteria()
    1099:     {
    1100:         $criteria = new Criteria(TaxRulePeer::DATABASE_NAME);
    1101:
    1102:         if ($this->isColumnModified(TaxRulePeer::ID)) $criteria->add(TaxRulePeer::ID, $this->id);
    1103:         if ($this->isColumnModified(TaxRulePeer::CODE)) $criteria->add(TaxRulePeer::CODE, $this->code);
    1104:         if ($this->isColumnModified(TaxRulePeer::TITLE)) $criteria->add(TaxRulePeer::TITLE, $this->title);
    1105:         if ($this->isColumnModified(TaxRulePeer::DESCRIPTION)) $criteria->add(TaxRulePeer::DESCRIPTION, $this->description);
    1106:         if ($this->isColumnModified(TaxRulePeer::CREATED_AT)) $criteria->add(TaxRulePeer::CREATED_AT, $this->created_at);
    1107:         if ($this->isColumnModified(TaxRulePeer::UPDATED_AT)) $criteria->add(TaxRulePeer::UPDATED_AT, $this->updated_at);
    1108:
    1109:         return $criteria;
    1110:     }
    1111:
    1112:     /**
    1113:      * Builds a Criteria object containing the primary key for this object.
    1114:      *
    1115:      * Unlike buildCriteria() this method includes the primary key values regardless
    1116:      * of whether or not they have been modified.
    1117:      *
    1118:      * @return Criteria The Criteria object containing value(s) for primary key(s).
    1119:      */
    1120:     public function buildPkeyCriteria()
    1121:     {
    1122:         $criteria = new Criteria(TaxRulePeer::DATABASE_NAME);
    1123:         $criteria->add(TaxRulePeer::ID, $this->id);
    1124:
    1125:         return $criteria;
    1126:     }
    1127:
    1128:     /**
    1129:      * Returns the primary key for this object (row).
    1130:      * @return int
    1131:      */
    1132:     public function getPrimaryKey()
    1133:     {
    1134:         return $this->getId();
    1135:     }
    1136:
    1137:     /**
    1138:      * Generic method to set the primary key (id column).
    1139:      *
    1140:      * @param  int $key Primary key.
    1141:      * @return void
    1142:      */
    1143:     public function setPrimaryKey($key)
    1144:     {
    1145:         $this->setId($key);
    1146:     }
    1147:
    1148:     /**
    1149:      * Returns true if the primary key for this object is null.
    1150:      * @return boolean
    1151:      */
    1152:     public function isPrimaryKeyNull()
    1153:     {
    1154:
    1155:         return null === $this->getId();
    1156:     }
    1157:
    1158:     /**
    1159:      * Sets contents of passed object to values from current object.
    1160:      *
    1161:      * If desired, this method can also make copies of all associated (fkey referrers)
    1162:      * objects.
    1163:      *
    1164:      * @param object $copyObj An object of TaxRule (or compatible) type.
    1165:      * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
    1166:      * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new.
    1167:      * @throws PropelException
    1168:      */
    1169:     public function copyInto($copyObj, $deepCopy = false, $makeNew = true)
    1170:     {
    1171:         $copyObj->setCode($this->getCode());
    1172:         $copyObj->setTitle($this->getTitle());
    1173:         $copyObj->setDescription($this->getDescription());
    1174:         $copyObj->setCreatedAt($this->getCreatedAt());
    1175:         $copyObj->setUpdatedAt($this->getUpdatedAt());
    1176:
    1177:         if ($deepCopy && !$this->startCopy) {
    1178:             // important: temporarily setNew(false) because this affects the behavior of
    1179:             // the getter/setter methods for fkey referrer objects.
    1180:             $copyObj->setNew(false);
    1181:             // store object hash to prevent cycle
    1182:             $this->startCopy = true;
    1183:
    1184:             foreach ($this->getProducts() as $relObj) {
    1185:                 if ($relObj !== $this) {  // ensure that we don't try to copy a reference to ourselves
    1186:                     $copyObj->addProduct($relObj->copy($deepCopy));
    1187:                 }
    1188:             }
    1189:
    1190:             foreach ($this->getTaxRuleCountrys() as $relObj) {
    1191:                 if ($relObj !== $this) {  // ensure that we don't try to copy a reference to ourselves
    1192:                     $copyObj->addTaxRuleCountry($relObj->copy($deepCopy));
    1193:                 }
    1194:             }
    1195:
    1196:             foreach ($this->getTaxRuleI18ns() as $relObj) {
    1197:                 if ($relObj !== $this) {  // ensure that we don't try to copy a reference to ourselves
    1198:                     $copyObj->addTaxRuleI18n($relObj->copy($deepCopy));
    1199:                 }
    1200:             }
    1201:
    1202:             //unflag object copy
    1203:             $this->startCopy = false;
    1204:         } // if ($deepCopy)
    1205:
    1206:         if ($makeNew) {
    1207:             $copyObj->setNew(true);
    1208:             $copyObj->setId(NULL); // this is a auto-increment column, so set to default value
    1209:         }
    1210:     }
    1211:
    1212:     /**
    1213:      * Makes a copy of this object that will be inserted as a new row in table when saved.
    1214:      * It creates a new object filling in the simple attributes, but skipping any primary
    1215:      * keys that are defined for the table.
    1216:      *
    1217:      * If desired, this method can also make copies of all associated (fkey referrers)
    1218:      * objects.
    1219:      *
    1220:      * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
    1221:      * @return TaxRule Clone of current object.
    1222:      * @throws PropelException
    1223:      */
    1224:     public function copy($deepCopy = false)
    1225:     {
    1226:         // we use get_class(), because this might be a subclass
    1227:         $clazz = get_class($this);
    1228:         $copyObj = new $clazz();
    1229:         $this->copyInto($copyObj, $deepCopy);
    1230:
    1231:         return $copyObj;
    1232:     }
    1233:
    1234:     /**
    1235:      * Returns a peer instance associated with this om.
    1236:      *
    1237:      * Since Peer classes are not to have any instance attributes, this method returns the
    1238:      * same instance for all member of this class. The method could therefore
    1239:      * be static, but this would prevent one from overriding the behavior.
    1240:      *
    1241:      * @return TaxRulePeer
    1242:      */
    1243:     public function getPeer()
    1244:     {
    1245:         if (self::$peer === null) {
    1246:             self::$peer = new TaxRulePeer();
    1247:         }
    1248:
    1249:         return self::$peer;
    1250:     }
    1251:
    1252:
    1253:     /**
    1254:      * Initializes a collection based on the name of a relation.
    1255:      * Avoids crafting an 'init[$relationName]s' method name
    1256:      * that wouldn't work when StandardEnglishPluralizer is used.
    1257:      *
    1258:      * @param string $relationName The name of the relation to initialize
    1259:      * @return void
    1260:      */
    1261:     public function initRelation($relationName)
    1262:     {
    1263:         if ('Product' == $relationName) {
    1264:             $this->initProducts();
    1265:         }
    1266:         if ('TaxRuleCountry' == $relationName) {
    1267:             $this->initTaxRuleCountrys();
    1268:         }
    1269:         if ('TaxRuleI18n' == $relationName) {
    1270:             $this->initTaxRuleI18ns();
    1271:         }
    1272:     }
    1273:
    1274:     /**
    1275:      * Clears out the collProducts collection
    1276:      *
    1277:      * This does not modify the database; however, it will remove any associated objects, causing
    1278:      * them to be refetched by subsequent calls to accessor method.
    1279:      *
    1280:      * @return TaxRule The current object (for fluent API support)
    1281:      * @see        addProducts()
    1282:      */
    1283:     public function clearProducts()
    1284:     {
    1285:         $this->collProducts = null; // important to set this to null since that means it is uninitialized
    1286:         $this->collProductsPartial = null;
    1287:
    1288:         return $this;
    1289:     }
    1290:
    1291:     /**
    1292:      * reset is the collProducts collection loaded partially
    1293:      *
    1294:      * @return void
    1295:      */
    1296:     public function resetPartialProducts($v = true)
    1297:     {
    1298:         $this->collProductsPartial = $v;
    1299:     }
    1300:
    1301:     /**
    1302:      * Initializes the collProducts collection.
    1303:      *
    1304:      * By default this just sets the collProducts collection to an empty array (like clearcollProducts());
    1305:      * however, you may wish to override this method in your stub class to provide setting appropriate
    1306:      * to your application -- for example, setting the initial array to the values stored in database.
    1307:      *
    1308:      * @param boolean $overrideExisting If set to true, the method call initializes
    1309:      *                                        the collection even if it is not empty
    1310:      *
    1311:      * @return void
    1312:      */
    1313:     public function initProducts($overrideExisting = true)
    1314:     {
    1315:         if (null !== $this->collProducts && !$overrideExisting) {
    1316:             return;
    1317:         }
    1318:         $this->collProducts = new PropelObjectCollection();
    1319:         $this->collProducts->setModel('Product');
    1320:     }
    1321:
    1322:     /**
    1323:      * Gets an array of Product objects which contain a foreign key that references this object.
    1324:      *
    1325:      * If the $criteria is not null, it is used to always fetch the results from the database.
    1326:      * Otherwise the results are fetched from the database the first time, then cached.
    1327:      * Next time the same method is called without $criteria, the cached collection is returned.
    1328:      * If this TaxRule is new, it will return
    1329:      * an empty collection or the current collection; the criteria is ignored on a new object.
    1330:      *
    1331:      * @param Criteria $criteria optional Criteria object to narrow the query
    1332:      * @param PropelPDO $con optional connection object
    1333:      * @return PropelObjectCollection|Product[] List of Product objects
    1334:      * @throws PropelException
    1335:      */
    1336:     public function getProducts($criteria = null, PropelPDO $con = null)
    1337:     {
    1338:         $partial = $this->collProductsPartial && !$this->isNew();
    1339:         if (null === $this->collProducts || null !== $criteria  || $partial) {
    1340:             if ($this->isNew() && null === $this->collProducts) {
    1341:                 // return empty collection
    1342:                 $this->initProducts();
    1343:             } else {
    1344:                 $collProducts = ProductQuery::create(null, $criteria)
    1345:                     ->filterByTaxRule($this)
    1346:                     ->find($con);
    1347:                 if (null !== $criteria) {
    1348:                     if (false !== $this->collProductsPartial && count($collProducts)) {
    1349:                       $this->initProducts(false);
    1350:
    1351:                       foreach($collProducts as $obj) {
    1352:                         if (false == $this->collProducts->contains($obj)) {
    1353:                           $this->collProducts->append($obj);
    1354:                         }
    1355:                       }
    1356:
    1357:                       $this->collProductsPartial = true;
    1358:                     }
    1359:
    1360:                     $collProducts->getInternalIterator()->rewind();
    1361:                     return $collProducts;
    1362:                 }
    1363:
    1364:                 if($partial && $this->collProducts) {
    1365:                     foreach($this->collProducts as $obj) {
    1366:                         if($obj->isNew()) {
    1367:                             $collProducts[] = $obj;
    1368:                         }
    1369:                     }
    1370:                 }
    1371:
    1372:                 $this->collProducts = $collProducts;
    1373:                 $this->collProductsPartial = false;
    1374:             }
    1375:         }
    1376:
    1377:         return $this->collProducts;
    1378:     }
    1379:
    1380:     /**
    1381:      * Sets a collection of Product objects related by a one-to-many relationship
    1382:      * to the current object.
    1383:      * It will also schedule objects for deletion based on a diff between old objects (aka persisted)
    1384:      * and new objects from the given Propel collection.
    1385:      *
    1386:      * @param PropelCollection $products A Propel collection.
    1387:      * @param PropelPDO $con Optional connection object
    1388:      * @return TaxRule The current object (for fluent API support)
    1389:      */
    1390:     public function setProducts(PropelCollection $products, PropelPDO $con = null)
    1391:     {
    1392:         $productsToDelete = $this->getProducts(new Criteria(), $con)->diff($products);
    1393:
    1394:         $this->productsScheduledForDeletion = unserialize(serialize($productsToDelete));
    1395:
    1396:         foreach ($productsToDelete as $productRemoved) {
    1397:             $productRemoved->setTaxRule(null);
    1398:         }
    1399:
    1400:         $this->collProducts = null;
    1401:         foreach ($products as $product) {
    1402:             $this->addProduct($product);
    1403:         }
    1404:
    1405:         $this->collProducts = $products;
    1406:         $this->collProductsPartial = false;
    1407:
    1408:         return $this;
    1409:     }
    1410:
    1411:     /**
    1412:      * Returns the number of related Product objects.
    1413:      *
    1414:      * @param Criteria $criteria
    1415:      * @param boolean $distinct
    1416:      * @param PropelPDO $con
    1417:      * @return int             Count of related Product objects.
    1418:      * @throws PropelException
    1419:      */
    1420:     public function countProducts(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
    1421:     {
    1422:         $partial = $this->collProductsPartial && !$this->isNew();
    1423:         if (null === $this->collProducts || null !== $criteria || $partial) {
    1424:             if ($this->isNew() && null === $this->collProducts) {
    1425:                 return 0;
    1426:             }
    1427:
    1428:             if($partial && !$criteria) {
    1429:                 return count($this->getProducts());
    1430:             }
    1431:             $query = ProductQuery::create(null, $criteria);
    1432:             if ($distinct) {
    1433:                 $query->distinct();
    1434:             }
    1435:
    1436:             return $query
    1437:                 ->filterByTaxRule($this)
    1438:                 ->count($con);
    1439:         }
    1440:
    1441:         return count($this->collProducts);
    1442:     }
    1443:
    1444:     /**
    1445:      * Method called to associate a Product object to this object
    1446:      * through the Product foreign key attribute.
    1447:      *
    1448:      * @param    Product $l Product
    1449:      * @return TaxRule The current object (for fluent API support)
    1450:      */
    1451:     public function addProduct(Product $l)
    1452:     {
    1453:         if ($this->collProducts === null) {
    1454:             $this->initProducts();
    1455:             $this->collProductsPartial = true;
    1456:         }
    1457:         if (!in_array($l, $this->collProducts->getArrayCopy(), true)) { // only add it if the **same** object is not already associated
    1458:             $this->doAddProduct($l);
    1459:         }
    1460:
    1461:         return $this;
    1462:     }
    1463:
    1464:     /**
    1465:      * @param   Product $product The product object to add.
    1466:      */
    1467:     protected function doAddProduct($product)
    1468:     {
    1469:         $this->collProducts[]= $product;
    1470:         $product->setTaxRule($this);
    1471:     }
    1472:
    1473:     /**
    1474:      * @param   Product $product The product object to remove.
    1475:      * @return TaxRule The current object (for fluent API support)
    1476:      */
    1477:     public function removeProduct($product)
    1478:     {
    1479:         if ($this->getProducts()->contains($product)) {
    1480:             $this->collProducts->remove($this->collProducts->search($product));
    1481:             if (null === $this->productsScheduledForDeletion) {
    1482:                 $this->productsScheduledForDeletion = clone $this->collProducts;
    1483:                 $this->productsScheduledForDeletion->clear();
    1484:             }
    1485:             $this->productsScheduledForDeletion[]= $product;
    1486:             $product->setTaxRule(null);
    1487:         }
    1488:
    1489:         return $this;
    1490:     }
    1491:
    1492:     /**
    1493:      * Clears out the collTaxRuleCountrys collection
    1494:      *
    1495:      * This does not modify the database; however, it will remove any associated objects, causing
    1496:      * them to be refetched by subsequent calls to accessor method.
    1497:      *
    1498:      * @return TaxRule The current object (for fluent API support)
    1499:      * @see        addTaxRuleCountrys()
    1500:      */
    1501:     public function clearTaxRuleCountrys()
    1502:     {
    1503:         $this->collTaxRuleCountrys = null; // important to set this to null since that means it is uninitialized
    1504:         $this->collTaxRuleCountrysPartial = null;
    1505:
    1506:         return $this;
    1507:     }
    1508:
    1509:     /**
    1510:      * reset is the collTaxRuleCountrys collection loaded partially
    1511:      *
    1512:      * @return void
    1513:      */
    1514:     public function resetPartialTaxRuleCountrys($v = true)
    1515:     {
    1516:         $this->collTaxRuleCountrysPartial = $v;
    1517:     }
    1518:
    1519:     /**
    1520:      * Initializes the collTaxRuleCountrys collection.
    1521:      *
    1522:      * By default this just sets the collTaxRuleCountrys collection to an empty array (like clearcollTaxRuleCountrys());
    1523:      * however, you may wish to override this method in your stub class to provide setting appropriate
    1524:      * to your application -- for example, setting the initial array to the values stored in database.
    1525:      *
    1526:      * @param boolean $overrideExisting If set to true, the method call initializes
    1527:      *                                        the collection even if it is not empty
    1528:      *
    1529:      * @return void
    1530:      */
    1531:     public function initTaxRuleCountrys($overrideExisting = true)
    1532:     {
    1533:         if (null !== $this->collTaxRuleCountrys && !$overrideExisting) {
    1534:             return;
    1535:         }
    1536:         $this->collTaxRuleCountrys = new PropelObjectCollection();
    1537:         $this->collTaxRuleCountrys->setModel('TaxRuleCountry');
    1538:     }
    1539:
    1540:     /**
    1541:      * Gets an array of TaxRuleCountry objects which contain a foreign key that references this object.
    1542:      *
    1543:      * If the $criteria is not null, it is used to always fetch the results from the database.
    1544:      * Otherwise the results are fetched from the database the first time, then cached.
    1545:      * Next time the same method is called without $criteria, the cached collection is returned.
    1546:      * If this TaxRule is new, it will return
    1547:      * an empty collection or the current collection; the criteria is ignored on a new object.
    1548:      *
    1549:      * @param Criteria $criteria optional Criteria object to narrow the query
    1550:      * @param PropelPDO $con optional connection object
    1551:      * @return PropelObjectCollection|TaxRuleCountry[] List of TaxRuleCountry objects
    1552:      * @throws PropelException
    1553:      */
    1554:     public function getTaxRuleCountrys($criteria = null, PropelPDO $con = null)
    1555:     {
    1556:         $partial = $this->collTaxRuleCountrysPartial && !$this->isNew();
    1557:         if (null === $this->collTaxRuleCountrys || null !== $criteria  || $partial) {
    1558:             if ($this->isNew() && null === $this->collTaxRuleCountrys) {
    1559:                 // return empty collection
    1560:                 $this->initTaxRuleCountrys();
    1561:             } else {
    1562:                 $collTaxRuleCountrys = TaxRuleCountryQuery::create(null, $criteria)
    1563:                     ->filterByTaxRule($this)
    1564:                     ->find($con);
    1565:                 if (null !== $criteria) {
    1566:                     if (false !== $this->collTaxRuleCountrysPartial && count($collTaxRuleCountrys)) {
    1567:                       $this->initTaxRuleCountrys(false);
    1568:
    1569:                       foreach($collTaxRuleCountrys as $obj) {
    1570:                         if (false == $this->collTaxRuleCountrys->contains($obj)) {
    1571:                           $this->collTaxRuleCountrys->append($obj);
    1572:                         }
    1573:                       }
    1574:
    1575:                       $this->collTaxRuleCountrysPartial = true;
    1576:                     }
    1577:
    1578:                     $collTaxRuleCountrys->getInternalIterator()->rewind();
    1579:                     return $collTaxRuleCountrys;
    1580:                 }
    1581:
    1582:                 if($partial && $this->collTaxRuleCountrys) {
    1583:                     foreach($this->collTaxRuleCountrys as $obj) {
    1584:                         if($obj->isNew()) {
    1585:                             $collTaxRuleCountrys[] = $obj;
    1586:                         }
    1587:                     }
    1588:                 }
    1589:
    1590:                 $this->collTaxRuleCountrys = $collTaxRuleCountrys;
    1591:                 $this->collTaxRuleCountrysPartial = false;
    1592:             }
    1593:         }
    1594:
    1595:         return $this->collTaxRuleCountrys;
    1596:     }
    1597:
    1598:     /**
    1599:      * Sets a collection of TaxRuleCountry objects related by a one-to-many relationship
    1600:      * to the current object.
    1601:      * It will also schedule objects for deletion based on a diff between old objects (aka persisted)
    1602:      * and new objects from the given Propel collection.
    1603:      *
    1604:      * @param PropelCollection $taxRuleCountrys A Propel collection.
    1605:      * @param PropelPDO $con Optional connection object
    1606:      * @return TaxRule The current object (for fluent API support)
    1607:      */
    1608:     public function setTaxRuleCountrys(PropelCollection $taxRuleCountrys, PropelPDO $con = null)
    1609:     {
    1610:         $taxRuleCountrysToDelete = $this->getTaxRuleCountrys(new Criteria(), $con)->diff($taxRuleCountrys);
    1611:
    1612:         $this->taxRuleCountrysScheduledForDeletion = unserialize(serialize($taxRuleCountrysToDelete));
    1613:
    1614:         foreach ($taxRuleCountrysToDelete as $taxRuleCountryRemoved) {
    1615:             $taxRuleCountryRemoved->setTaxRule(null);
    1616:         }
    1617:
    1618:         $this->collTaxRuleCountrys = null;
    1619:         foreach ($taxRuleCountrys as $taxRuleCountry) {
    1620:             $this->addTaxRuleCountry($taxRuleCountry);
    1621:         }
    1622:
    1623:         $this->collTaxRuleCountrys = $taxRuleCountrys;
    1624:         $this->collTaxRuleCountrysPartial = false;
    1625:
    1626:         return $this;
    1627:     }
    1628:
    1629:     /**
    1630:      * Returns the number of related TaxRuleCountry objects.
    1631:      *
    1632:      * @param Criteria $criteria
    1633:      * @param boolean $distinct
    1634:      * @param PropelPDO $con
    1635:      * @return int             Count of related TaxRuleCountry objects.
    1636:      * @throws PropelException
    1637:      */
    1638:     public function countTaxRuleCountrys(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
    1639:     {
    1640:         $partial = $this->collTaxRuleCountrysPartial && !$this->isNew();
    1641:         if (null === $this->collTaxRuleCountrys || null !== $criteria || $partial) {
    1642:             if ($this->isNew() && null === $this->collTaxRuleCountrys) {
    1643:                 return 0;
    1644:             }
    1645:
    1646:             if($partial && !$criteria) {
    1647:                 return count($this->getTaxRuleCountrys());
    1648:             }
    1649:             $query = TaxRuleCountryQuery::create(null, $criteria);
    1650:             if ($distinct) {
    1651:                 $query->distinct();
    1652:             }
    1653:
    1654:             return $query
    1655:                 ->filterByTaxRule($this)
    1656:                 ->count($con);
    1657:         }
    1658:
    1659:         return count($this->collTaxRuleCountrys);
    1660:     }
    1661:
    1662:     /**
    1663:      * Method called to associate a TaxRuleCountry object to this object
    1664:      * through the TaxRuleCountry foreign key attribute.
    1665:      *
    1666:      * @param    TaxRuleCountry $l TaxRuleCountry
    1667:      * @return TaxRule The current object (for fluent API support)
    1668:      */
    1669:     public function addTaxRuleCountry(TaxRuleCountry $l)
    1670:     {
    1671:         if ($this->collTaxRuleCountrys === null) {
    1672:             $this->initTaxRuleCountrys();
    1673:             $this->collTaxRuleCountrysPartial = true;
    1674:         }
    1675:         if (!in_array($l, $this->collTaxRuleCountrys->getArrayCopy(), true)) { // only add it if the **same** object is not already associated
    1676:             $this->doAddTaxRuleCountry($l);
    1677:         }
    1678:
    1679:         return $this;
    1680:     }
    1681:
    1682:     /**
    1683:      * @param   TaxRuleCountry $taxRuleCountry The taxRuleCountry object to add.
    1684:      */
    1685:     protected function doAddTaxRuleCountry($taxRuleCountry)
    1686:     {
    1687:         $this->collTaxRuleCountrys[]= $taxRuleCountry;
    1688:         $taxRuleCountry->setTaxRule($this);
    1689:     }
    1690:
    1691:     /**
    1692:      * @param   TaxRuleCountry $taxRuleCountry The taxRuleCountry object to remove.
    1693:      * @return TaxRule The current object (for fluent API support)
    1694:      */
    1695:     public function removeTaxRuleCountry($taxRuleCountry)
    1696:     {
    1697:         if ($this->getTaxRuleCountrys()->contains($taxRuleCountry)) {
    1698:             $this->collTaxRuleCountrys->remove($this->collTaxRuleCountrys->search($taxRuleCountry));
    1699:             if (null === $this->taxRuleCountrysScheduledForDeletion) {
    1700:                 $this->taxRuleCountrysScheduledForDeletion = clone $this->collTaxRuleCountrys;
    1701:                 $this->taxRuleCountrysScheduledForDeletion->clear();
    1702:             }
    1703:             $this->taxRuleCountrysScheduledForDeletion[]= $taxRuleCountry;
    1704:             $taxRuleCountry->setTaxRule(null);
    1705:         }
    1706:
    1707:         return $this;
    1708:     }
    1709:
    1710:
    1711:     /**
    1712:      * If this collection has already been initialized with
    1713:      * an identical criteria, it returns the collection.
    1714:      * Otherwise if this TaxRule is new, it will return
    1715:      * an empty collection; or if this TaxRule has previously
    1716:      * been saved, it will retrieve related TaxRuleCountrys from storage.
    1717:      *
    1718:      * This method is protected by default in order to keep the public
    1719:      * api reasonable.  You can provide public methods for those you
    1720:      * actually need in TaxRule.
    1721:      *
    1722:      * @param Criteria $criteria optional Criteria object to narrow the query
    1723:      * @param PropelPDO $con optional connection object
    1724:      * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN)
    1725:      * @return PropelObjectCollection|TaxRuleCountry[] List of TaxRuleCountry objects
    1726:      */
    1727:     public function getTaxRuleCountrysJoinTax($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
    1728:     {
    1729:         $query = TaxRuleCountryQuery::create(null, $criteria);
    1730:         $query->joinWith('Tax', $join_behavior);
    1731:
    1732:         return $this->getTaxRuleCountrys($query, $con);
    1733:     }
    1734:
    1735:
    1736:     /**
    1737:      * If this collection has already been initialized with
    1738:      * an identical criteria, it returns the collection.
    1739:      * Otherwise if this TaxRule is new, it will return
    1740:      * an empty collection; or if this TaxRule has previously
    1741:      * been saved, it will retrieve related TaxRuleCountrys from storage.
    1742:      *
    1743:      * This method is protected by default in order to keep the public
    1744:      * api reasonable.  You can provide public methods for those you
    1745:      * actually need in TaxRule.
    1746:      *
    1747:      * @param Criteria $criteria optional Criteria object to narrow the query
    1748:      * @param PropelPDO $con optional connection object
    1749:      * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN)
    1750:      * @return PropelObjectCollection|TaxRuleCountry[] List of TaxRuleCountry objects
    1751:      */
    1752:     public function getTaxRuleCountrysJoinCountry($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
    1753:     {
    1754:         $query = TaxRuleCountryQuery::create(null, $criteria);
    1755:         $query->joinWith('Country', $join_behavior);
    1756:
    1757:         return $this->getTaxRuleCountrys($query, $con);
    1758:     }
    1759:
    1760:     /**
    1761:      * Clears out the collTaxRuleI18ns collection
    1762:      *
    1763:      * This does not modify the database; however, it will remove any associated objects, causing
    1764:      * them to be refetched by subsequent calls to accessor method.
    1765:      *
    1766:      * @return TaxRule The current object (for fluent API support)
    1767:      * @see        addTaxRuleI18ns()
    1768:      */
    1769:     public function clearTaxRuleI18ns()
    1770:     {
    1771:         $this->collTaxRuleI18ns = null; // important to set this to null since that means it is uninitialized
    1772:         $this->collTaxRuleI18nsPartial = null;
    1773:
    1774:         return $this;
    1775:     }
    1776:
    1777:     /**
    1778:      * reset is the collTaxRuleI18ns collection loaded partially
    1779:      *
    1780:      * @return void
    1781:      */
    1782:     public function resetPartialTaxRuleI18ns($v = true)
    1783:     {
    1784:         $this->collTaxRuleI18nsPartial = $v;
    1785:     }
    1786:
    1787:     /**
    1788:      * Initializes the collTaxRuleI18ns collection.
    1789:      *
    1790:      * By default this just sets the collTaxRuleI18ns collection to an empty array (like clearcollTaxRuleI18ns());
    1791:      * however, you may wish to override this method in your stub class to provide setting appropriate
    1792:      * to your application -- for example, setting the initial array to the values stored in database.
    1793:      *
    1794:      * @param boolean $overrideExisting If set to true, the method call initializes
    1795:      *                                        the collection even if it is not empty
    1796:      *
    1797:      * @return void
    1798:      */
    1799:     public function initTaxRuleI18ns($overrideExisting = true)
    1800:     {
    1801:         if (null !== $this->collTaxRuleI18ns && !$overrideExisting) {
    1802:             return;
    1803:         }
    1804:         $this->collTaxRuleI18ns = new PropelObjectCollection();
    1805:         $this->collTaxRuleI18ns->setModel('TaxRuleI18n');
    1806:     }
    1807:
    1808:     /**
    1809:      * Gets an array of TaxRuleI18n objects which contain a foreign key that references this object.
    1810:      *
    1811:      * If the $criteria is not null, it is used to always fetch the results from the database.
    1812:      * Otherwise the results are fetched from the database the first time, then cached.
    1813:      * Next time the same method is called without $criteria, the cached collection is returned.
    1814:      * If this TaxRule is new, it will return
    1815:      * an empty collection or the current collection; the criteria is ignored on a new object.
    1816:      *
    1817:      * @param Criteria $criteria optional Criteria object to narrow the query
    1818:      * @param PropelPDO $con optional connection object
    1819:      * @return PropelObjectCollection|TaxRuleI18n[] List of TaxRuleI18n objects
    1820:      * @throws PropelException
    1821:      */
    1822:     public function getTaxRuleI18ns($criteria = null, PropelPDO $con = null)
    1823:     {
    1824:         $partial = $this->collTaxRuleI18nsPartial && !$this->isNew();
    1825:         if (null === $this->collTaxRuleI18ns || null !== $criteria  || $partial) {
    1826:             if ($this->isNew() && null === $this->collTaxRuleI18ns) {
    1827:                 // return empty collection
    1828:                 $this->initTaxRuleI18ns();
    1829:             } else {
    1830:                 $collTaxRuleI18ns = TaxRuleI18nQuery::create(null, $criteria)
    1831:                     ->filterByTaxRule($this)
    1832:                     ->find($con);
    1833:                 if (null !== $criteria) {
    1834:                     if (false !== $this->collTaxRuleI18nsPartial && count($collTaxRuleI18ns)) {
    1835:                       $this->initTaxRuleI18ns(false);
    1836:
    1837:                       foreach($collTaxRuleI18ns as $obj) {
    1838:                         if (false == $this->collTaxRuleI18ns->contains($obj)) {
    1839:                           $this->collTaxRuleI18ns->append($obj);
    1840:                         }
    1841:                       }
    1842:
    1843:                       $this->collTaxRuleI18nsPartial = true;
    1844:                     }
    1845:
    1846:                     $collTaxRuleI18ns->getInternalIterator()->rewind();
    1847:                     return $collTaxRuleI18ns;
    1848:                 }
    1849:
    1850:                 if($partial && $this->collTaxRuleI18ns) {
    1851:                     foreach($this->collTaxRuleI18ns as $obj) {
    1852:                         if($obj->isNew()) {
    1853:                             $collTaxRuleI18ns[] = $obj;
    1854:                         }
    1855:                     }
    1856:                 }
    1857:
    1858:                 $this->collTaxRuleI18ns = $collTaxRuleI18ns;
    1859:                 $this->collTaxRuleI18nsPartial = false;
    1860:             }
    1861:         }
    1862:
    1863:         return $this->collTaxRuleI18ns;
    1864:     }
    1865:
    1866:     /**
    1867:      * Sets a collection of TaxRuleI18n objects related by a one-to-many relationship
    1868:      * to the current object.
    1869:      * It will also schedule objects for deletion based on a diff between old objects (aka persisted)
    1870:      * and new objects from the given Propel collection.
    1871:      *
    1872:      * @param PropelCollection $taxRuleI18ns A Propel collection.
    1873:      * @param PropelPDO $con Optional connection object
    1874:      * @return TaxRule The current object (for fluent API support)
    1875:      */
    1876:     public function setTaxRuleI18ns(PropelCollection $taxRuleI18ns, PropelPDO $con = null)
    1877:     {
    1878:         $taxRuleI18nsToDelete = $this->getTaxRuleI18ns(new Criteria(), $con)->diff($taxRuleI18ns);
    1879:
    1880:         $this->taxRuleI18nsScheduledForDeletion = unserialize(serialize($taxRuleI18nsToDelete));
    1881:
    1882:         foreach ($taxRuleI18nsToDelete as $taxRuleI18nRemoved) {
    1883:             $taxRuleI18nRemoved->setTaxRule(null);
    1884:         }
    1885:
    1886:         $this->collTaxRuleI18ns = null;
    1887:         foreach ($taxRuleI18ns as $taxRuleI18n) {
    1888:             $this->addTaxRuleI18n($taxRuleI18n);
    1889:         }
    1890:
    1891:         $this->collTaxRuleI18ns = $taxRuleI18ns;
    1892:         $this->collTaxRuleI18nsPartial = false;
    1893:
    1894:         return $this;
    1895:     }
    1896:
    1897:     /**
    1898:      * Returns the number of related TaxRuleI18n objects.
    1899:      *
    1900:      * @param Criteria $criteria
    1901:      * @param boolean $distinct
    1902:      * @param PropelPDO $con
    1903:      * @return int             Count of related TaxRuleI18n objects.
    1904:      * @throws PropelException
    1905:      */
    1906:     public function countTaxRuleI18ns(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
    1907:     {
    1908:         $partial = $this->collTaxRuleI18nsPartial && !$this->isNew();
    1909:         if (null === $this->collTaxRuleI18ns || null !== $criteria || $partial) {
    1910:             if ($this->isNew() && null === $this->collTaxRuleI18ns) {
    1911:                 return 0;
    1912:             }
    1913:
    1914:             if($partial && !$criteria) {
    1915:                 return count($this->getTaxRuleI18ns());
    1916:             }
    1917:             $query = TaxRuleI18nQuery::create(null, $criteria);
    1918:             if ($distinct) {
    1919:                 $query->distinct();
    1920:             }
    1921:
    1922:             return $query
    1923:                 ->filterByTaxRule($this)
    1924:                 ->count($con);
    1925:         }
    1926:
    1927:         return count($this->collTaxRuleI18ns);
    1928:     }
    1929:
    1930:     /**
    1931:      * Method called to associate a TaxRuleI18n object to this object
    1932:      * through the TaxRuleI18n foreign key attribute.
    1933:      *
    1934:      * @param    TaxRuleI18n $l TaxRuleI18n
    1935:      * @return TaxRule The current object (for fluent API support)
    1936:      */
    1937:     public function addTaxRuleI18n(TaxRuleI18n $l)
    1938:     {
    1939:         if ($l && $locale = $l->getLocale()) {
    1940:             $this->setLocale($locale);
    1941:             $this->currentTranslations[$locale] = $l;
    1942:         }
    1943:         if ($this->collTaxRuleI18ns === null) {
    1944:             $this->initTaxRuleI18ns();
    1945:             $this->collTaxRuleI18nsPartial = true;
    1946:         }
    1947:         if (!in_array($l, $this->collTaxRuleI18ns->getArrayCopy(), true)) { // only add it if the **same** object is not already associated
    1948:             $this->doAddTaxRuleI18n($l);
    1949:         }
    1950:
    1951:         return $this;
    1952:     }
    1953:
    1954:     /**
    1955:      * @param   TaxRuleI18n $taxRuleI18n The taxRuleI18n object to add.
    1956:      */
    1957:     protected function doAddTaxRuleI18n($taxRuleI18n)
    1958:     {
    1959:         $this->collTaxRuleI18ns[]= $taxRuleI18n;
    1960:         $taxRuleI18n->setTaxRule($this);
    1961:     }
    1962:
    1963:     /**
    1964:      * @param   TaxRuleI18n $taxRuleI18n The taxRuleI18n object to remove.
    1965:      * @return TaxRule The current object (for fluent API support)
    1966:      */
    1967:     public function removeTaxRuleI18n($taxRuleI18n)
    1968:     {
    1969:         if ($this->getTaxRuleI18ns()->contains($taxRuleI18n)) {
    1970:             $this->collTaxRuleI18ns->remove($this->collTaxRuleI18ns->search($taxRuleI18n));
    1971:             if (null === $this->taxRuleI18nsScheduledForDeletion) {
    1972:                 $this->taxRuleI18nsScheduledForDeletion = clone $this->collTaxRuleI18ns;
    1973:                 $this->taxRuleI18nsScheduledForDeletion->clear();
    1974:             }
    1975:             $this->taxRuleI18nsScheduledForDeletion[]= clone $taxRuleI18n;
    1976:             $taxRuleI18n->setTaxRule(null);
    1977:         }
    1978:
    1979:         return $this;
    1980:     }
    1981:
    1982:     /**
    1983:      * Clears the current object and sets all attributes to their default values
    1984:      */
    1985:     public function clear()
    1986:     {
    1987:         $this->id = null;
    1988:         $this->code = null;
    1989:         $this->title = null;
    1990:         $this->description = null;
    1991:         $this->created_at = null;
    1992:         $this->updated_at = null;
    1993:         $this->alreadyInSave = false;
    1994:         $this->alreadyInValidation = false;
    1995:         $this->alreadyInClearAllReferencesDeep = false;
    1996:         $this->clearAllReferences();
    1997:         $this->resetModified();
    1998:         $this->setNew(true);
    1999:         $this->setDeleted(false);
    2000:     }
    2001:
    2002:     /**
    2003:      * Resets all references to other model objects or collections of model objects.
    2004:      *
    2005:      * This method is a user-space workaround for PHP's inability to garbage collect
    2006:      * objects with circular references (even in PHP 5.3). This is currently necessary
    2007:      * when using Propel in certain daemon or large-volumne/high-memory operations.
    2008:      *
    2009:      * @param boolean $deep Whether to also clear the references on all referrer objects.
    2010:      */
    2011:     public function clearAllReferences($deep = false)
    2012:     {
    2013:         if ($deep && !$this->alreadyInClearAllReferencesDeep) {
    2014:             $this->alreadyInClearAllReferencesDeep = true;
    2015:             if ($this->collProducts) {
    2016:                 foreach ($this->collProducts as $o) {
    2017:                     $o->clearAllReferences($deep);
    2018:                 }
    2019:             }
    2020:             if ($this->collTaxRuleCountrys) {
    2021:                 foreach ($this->collTaxRuleCountrys as $o) {
    2022:                     $o->clearAllReferences($deep);
    2023:                 }
    2024:             }
    2025:             if ($this->collTaxRuleI18ns) {
    2026:                 foreach ($this->collTaxRuleI18ns as $o) {
    2027:                     $o->clearAllReferences($deep);
    2028:                 }
    2029:             }
    2030:
    2031:             $this->alreadyInClearAllReferencesDeep = false;
    2032:         } // if ($deep)
    2033:
    2034:         // i18n behavior
    2035:         $this->currentLocale = 'en_US';
    2036:         $this->currentTranslations = null;
    2037:
    2038:         if ($this->collProducts instanceof PropelCollection) {
    2039:             $this->collProducts->clearIterator();
    2040:         }
    2041:         $this->collProducts = null;
    2042:         if ($this->collTaxRuleCountrys instanceof PropelCollection) {
    2043:             $this->collTaxRuleCountrys->clearIterator();
    2044:         }
    2045:         $this->collTaxRuleCountrys = null;
    2046:         if ($this->collTaxRuleI18ns instanceof PropelCollection) {
    2047:             $this->collTaxRuleI18ns->clearIterator();
    2048:         }
    2049:         $this->collTaxRuleI18ns = null;
    2050:     }
    2051:
    2052:     /**
    2053:      * return the string representation of this object
    2054:      *
    2055:      * @return string
    2056:      */
    2057:     public function __toString()
    2058:     {
    2059:         return (string) $this->exportTo(TaxRulePeer::DEFAULT_STRING_FORMAT);
    2060:     }
    2061:
    2062:     /**
    2063:      * return true is the object is in saving state
    2064:      *
    2065:      * @return boolean
    2066:      */
    2067:     public function isAlreadyInSave()
    2068:     {
    2069:         return $this->alreadyInSave;
    2070:     }
    2071:
    2072:     // timestampable behavior
    2073:
    2074:     /**
    2075:      * Mark the current object so that the update date doesn't get updated during next save
    2076:      *
    2077:      * @return     TaxRule The current object (for fluent API support)
    2078:      */
    2079:     public function keepUpdateDateUnchanged()
    2080:     {
    2081:         $this->modifiedColumns[] = TaxRulePeer::UPDATED_AT;
    2082:
    2083:         return $this;
    2084:     }
    2085:
    2086:     // i18n behavior
    2087:
    2088:     /**
    2089:      * Sets the locale for translations
    2090:      *
    2091:      * @param     string $locale Locale to use for the translation, e.g. 'fr_FR'
    2092:      *
    2093:      * @return    TaxRule The current object (for fluent API support)
    2094:      */
    2095:     public function setLocale($locale = 'en_US')
    2096:     {
    2097:         $this->currentLocale = $locale;
    2098:
    2099:         return $this;
    2100:     }
    2101:
    2102:     /**
    2103:      * Gets the locale for translations
    2104:      *
    2105:      * @return    string $locale Locale to use for the translation, e.g. 'fr_FR'
    2106:      */
    2107:     public function getLocale()
    2108:     {
    2109:         return $this->currentLocale;
    2110:     }
    2111:
    2112:     /**
    2113:      * Returns the current translation for a given locale
    2114:      *
    2115:      * @param     string $locale Locale to use for the translation, e.g. 'fr_FR'
    2116:      * @param     PropelPDO $con an optional connection object
    2117:      *
    2118:      * @return TaxRuleI18n */
    2119:     public function getTranslation($locale = 'en_US', PropelPDO $con = null)
    2120:     {
    2121:         if (!isset($this->currentTranslations[$locale])) {
    2122:             if (null !== $this->collTaxRuleI18ns) {
    2123:                 foreach ($this->collTaxRuleI18ns as $translation) {
    2124:                     if ($translation->getLocale() == $locale) {
    2125:                         $this->currentTranslations[$locale] = $translation;
    2126:
    2127:                         return $translation;
    2128:                     }
    2129:                 }
    2130:             }
    2131:             if ($this->isNew()) {
    2132:                 $translation = new TaxRuleI18n();
    2133:                 $translation->setLocale($locale);
    2134:             } else {
    2135:                 $translation = TaxRuleI18nQuery::create()
    2136:                     ->filterByPrimaryKey(array($this->getPrimaryKey(), $locale))
    2137:                     ->findOneOrCreate($con);
    2138:                 $this->currentTranslations[$locale] = $translation;
    2139:             }
    2140:             $this->addTaxRuleI18n($translation);
    2141:         }
    2142:
    2143:         return $this->currentTranslations[$locale];
    2144:     }
    2145:
    2146:     /**
    2147:      * Remove the translation for a given locale
    2148:      *
    2149:      * @param     string $locale Locale to use for the translation, e.g. 'fr_FR'
    2150:      * @param     PropelPDO $con an optional connection object
    2151:      *
    2152:      * @return    TaxRule The current object (for fluent API support)
    2153:      */
    2154:     public function removeTranslation($locale = 'en_US', PropelPDO $con = null)
    2155:     {
    2156:         if (!$this->isNew()) {
    2157:             TaxRuleI18nQuery::create()
    2158:                 ->filterByPrimaryKey(array($this->getPrimaryKey(), $locale))
    2159:                 ->delete($con);
    2160:         }
    2161:         if (isset($this->currentTranslations[$locale])) {
    2162:             unset($this->currentTranslations[$locale]);
    2163:         }
    2164:         foreach ($this->collTaxRuleI18ns as $key => $translation) {
    2165:             if ($translation->getLocale() == $locale) {
    2166:                 unset($this->collTaxRuleI18ns[$key]);
    2167:                 break;
    2168:             }
    2169:         }
    2170:
    2171:         return $this;
    2172:     }
    2173:
    2174:     /**
    2175:      * Returns the current translation
    2176:      *
    2177:      * @param     PropelPDO $con an optional connection object
    2178:      *
    2179:      * @return TaxRuleI18n */
    2180:     public function getCurrentTranslation(PropelPDO $con = null)
    2181:     {
    2182:         return $this->getTranslation($this->getLocale(), $con);
    2183:     }
    2184:
    2185: }
    2186: