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