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