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