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