# File core/lib/Thelia/Model/om/BaseTax.php | thelia

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