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