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 \PropelDateTime;
14: use \PropelException;
15: use \PropelPDO;
16: use Thelia\Model\Area;
17: use Thelia\Model\AreaQuery;
18: use Thelia\Model\Delivzone;
19: use Thelia\Model\DelivzonePeer;
20: use Thelia\Model\DelivzoneQuery;
21:
22: /**
23: * Base class that represents a row from the 'delivzone' table.
24: *
25: *
26: *
27: * @package propel.generator.Thelia.Model.om
28: */
29: abstract class BaseDelivzone extends BaseObject implements Persistent
30: {
31: /**
32: * Peer class name
33: */
34: const PEER = 'Thelia\\Model\\DelivzonePeer';
35:
36: /**
37: * The Peer class.
38: * Instance provides a convenient way of calling static methods on a class
39: * that calling code may not be able to identify.
40: * @var DelivzonePeer
41: */
42: protected static $peer;
43:
44: /**
45: * The flag var to prevent infinit loop in deep copy
46: * @var boolean
47: */
48: protected $startCopy = false;
49:
50: /**
51: * The value for the id field.
52: * @var int
53: */
54: protected $id;
55:
56: /**
57: * The value for the area_id field.
58: * @var int
59: */
60: protected $area_id;
61:
62: /**
63: * The value for the delivery field.
64: * @var string
65: */
66: protected $delivery;
67:
68: /**
69: * The value for the created_at field.
70: * @var string
71: */
72: protected $created_at;
73:
74: /**
75: * The value for the updated_at field.
76: * @var string
77: */
78: protected $updated_at;
79:
80: /**
81: * @var Area
82: */
83: protected $aArea;
84:
85: /**
86: * Flag to prevent endless save loop, if this object is referenced
87: * by another object which falls in this transaction.
88: * @var boolean
89: */
90: protected $alreadyInSave = false;
91:
92: /**
93: * Flag to prevent endless validation loop, if this object is referenced
94: * by another object which falls in this transaction.
95: * @var boolean
96: */
97: protected $alreadyInValidation = false;
98:
99: /**
100: * Get the [id] column value.
101: *
102: * @return int
103: */
104: public function getId()
105: {
106: return $this->id;
107: }
108:
109: /**
110: * Get the [area_id] column value.
111: *
112: * @return int
113: */
114: public function getAreaId()
115: {
116: return $this->area_id;
117: }
118:
119: /**
120: * Get the [delivery] column value.
121: *
122: * @return string
123: */
124: public function getDelivery()
125: {
126: return $this->delivery;
127: }
128:
129: /**
130: * Get the [optionally formatted] temporal [created_at] column value.
131: *
132: *
133: * @param string $format The date/time format string (either date()-style or strftime()-style).
134: * If format is null, then the raw DateTime object will be returned.
135: * @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
136: * @throws PropelException - if unable to parse/validate the date/time value.
137: */
138: public function getCreatedAt($format = 'Y-m-d H:i:s')
139: {
140: if ($this->created_at === null) {
141: return null;
142: }
143:
144: if ($this->created_at === '0000-00-00 00:00:00') {
145: // while technically this is not a default value of null,
146: // this seems to be closest in meaning.
147: return null;
148: } else {
149: try {
150: $dt = new DateTime($this->created_at);
151: } catch (Exception $x) {
152: throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->created_at, true), $x);
153: }
154: }
155:
156: if ($format === null) {
157: // Because propel.useDateTimeClass is true, we return a DateTime object.
158: return $dt;
159: } elseif (strpos($format, '%') !== false) {
160: return strftime($format, $dt->format('U'));
161: } else {
162: return $dt->format($format);
163: }
164: }
165:
166: /**
167: * Get the [optionally formatted] temporal [updated_at] column value.
168: *
169: *
170: * @param string $format The date/time format string (either date()-style or strftime()-style).
171: * If format is null, then the raw DateTime object will be returned.
172: * @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
173: * @throws PropelException - if unable to parse/validate the date/time value.
174: */
175: public function getUpdatedAt($format = 'Y-m-d H:i:s')
176: {
177: if ($this->updated_at === null) {
178: return null;
179: }
180:
181: if ($this->updated_at === '0000-00-00 00:00:00') {
182: // while technically this is not a default value of null,
183: // this seems to be closest in meaning.
184: return null;
185: } else {
186: try {
187: $dt = new DateTime($this->updated_at);
188: } catch (Exception $x) {
189: throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->updated_at, true), $x);
190: }
191: }
192:
193: if ($format === null) {
194: // Because propel.useDateTimeClass is true, we return a DateTime object.
195: return $dt;
196: } elseif (strpos($format, '%') !== false) {
197: return strftime($format, $dt->format('U'));
198: } else {
199: return $dt->format($format);
200: }
201: }
202:
203: /**
204: * Set the value of [id] column.
205: *
206: * @param int $v new value
207: * @return Delivzone The current object (for fluent API support)
208: */
209: public function setId($v)
210: {
211: if ($v !== null) {
212: $v = (int) $v;
213: }
214:
215: if ($this->id !== $v) {
216: $this->id = $v;
217: $this->modifiedColumns[] = DelivzonePeer::ID;
218: }
219:
220:
221: return $this;
222: } // setId()
223:
224: /**
225: * Set the value of [area_id] column.
226: *
227: * @param int $v new value
228: * @return Delivzone The current object (for fluent API support)
229: */
230: public function setAreaId($v)
231: {
232: if ($v !== null) {
233: $v = (int) $v;
234: }
235:
236: if ($this->area_id !== $v) {
237: $this->area_id = $v;
238: $this->modifiedColumns[] = DelivzonePeer::AREA_ID;
239: }
240:
241: if ($this->aArea !== null && $this->aArea->getId() !== $v) {
242: $this->aArea = null;
243: }
244:
245:
246: return $this;
247: } // setAreaId()
248:
249: /**
250: * Set the value of [delivery] column.
251: *
252: * @param string $v new value
253: * @return Delivzone The current object (for fluent API support)
254: */
255: public function setDelivery($v)
256: {
257: if ($v !== null) {
258: $v = (string) $v;
259: }
260:
261: if ($this->delivery !== $v) {
262: $this->delivery = $v;
263: $this->modifiedColumns[] = DelivzonePeer::DELIVERY;
264: }
265:
266:
267: return $this;
268: } // setDelivery()
269:
270: /**
271: * Sets the value of [created_at] column to a normalized version of the date/time value specified.
272: *
273: * @param mixed $v string, integer (timestamp), or DateTime value.
274: * Empty strings are treated as null.
275: * @return Delivzone The current object (for fluent API support)
276: */
277: public function setCreatedAt($v)
278: {
279: $dt = PropelDateTime::newInstance($v, null, 'DateTime');
280: if ($this->created_at !== null || $dt !== null) {
281: $currentDateAsString = ($this->created_at !== null && $tmpDt = new DateTime($this->created_at)) ? $tmpDt->format('Y-m-d H:i:s') : null;
282: $newDateAsString = $dt ? $dt->format('Y-m-d H:i:s') : null;
283: if ($currentDateAsString !== $newDateAsString) {
284: $this->created_at = $newDateAsString;
285: $this->modifiedColumns[] = DelivzonePeer::CREATED_AT;
286: }
287: } // if either are not null
288:
289:
290: return $this;
291: } // setCreatedAt()
292:
293: /**
294: * Sets the value of [updated_at] column to a normalized version of the date/time value specified.
295: *
296: * @param mixed $v string, integer (timestamp), or DateTime value.
297: * Empty strings are treated as null.
298: * @return Delivzone The current object (for fluent API support)
299: */
300: public function setUpdatedAt($v)
301: {
302: $dt = PropelDateTime::newInstance($v, null, 'DateTime');
303: if ($this->updated_at !== null || $dt !== null) {
304: $currentDateAsString = ($this->updated_at !== null && $tmpDt = new DateTime($this->updated_at)) ? $tmpDt->format('Y-m-d H:i:s') : null;
305: $newDateAsString = $dt ? $dt->format('Y-m-d H:i:s') : null;
306: if ($currentDateAsString !== $newDateAsString) {
307: $this->updated_at = $newDateAsString;
308: $this->modifiedColumns[] = DelivzonePeer::UPDATED_AT;
309: }
310: } // if either are not null
311:
312:
313: return $this;
314: } // setUpdatedAt()
315:
316: /**
317: * Indicates whether the columns in this object are only set to default values.
318: *
319: * This method can be used in conjunction with isModified() to indicate whether an object is both
320: * modified _and_ has some values set which are non-default.
321: *
322: * @return boolean Whether the columns in this object are only been set with default values.
323: */
324: public function hasOnlyDefaultValues()
325: {
326: // otherwise, everything was equal, so return true
327: return true;
328: } // hasOnlyDefaultValues()
329:
330: /**
331: * Hydrates (populates) the object variables with values from the database resultset.
332: *
333: * An offset (0-based "start column") is specified so that objects can be hydrated
334: * with a subset of the columns in the resultset rows. This is needed, for example,
335: * for results of JOIN queries where the resultset row includes columns from two or
336: * more tables.
337: *
338: * @param array $row The row returned by PDOStatement->fetch(PDO::FETCH_NUM)
339: * @param int $startcol 0-based offset column which indicates which restultset column to start with.
340: * @param boolean $rehydrate Whether this object is being re-hydrated from the database.
341: * @return int next starting column
342: * @throws PropelException - Any caught Exception will be rewrapped as a PropelException.
343: */
344: public function hydrate($row, $startcol = 0, $rehydrate = false)
345: {
346: try {
347:
348: $this->id = ($row[$startcol + 0] !== null) ? (int) $row[$startcol + 0] : null;
349: $this->area_id = ($row[$startcol + 1] !== null) ? (int) $row[$startcol + 1] : null;
350: $this->delivery = ($row[$startcol + 2] !== null) ? (string) $row[$startcol + 2] : null;
351: $this->created_at = ($row[$startcol + 3] !== null) ? (string) $row[$startcol + 3] : null;
352: $this->updated_at = ($row[$startcol + 4] !== null) ? (string) $row[$startcol + 4] : null;
353: $this->resetModified();
354:
355: $this->setNew(false);
356:
357: if ($rehydrate) {
358: $this->ensureConsistency();
359: }
360:
361: return $startcol + 5; // 5 = DelivzonePeer::NUM_HYDRATE_COLUMNS.
362:
363: } catch (Exception $e) {
364: throw new PropelException("Error populating Delivzone object", $e);
365: }
366: }
367:
368: /**
369: * Checks and repairs the internal consistency of the object.
370: *
371: * This method is executed after an already-instantiated object is re-hydrated
372: * from the database. It exists to check any foreign keys to make sure that
373: * the objects related to the current object are correct based on foreign key.
374: *
375: * You can override this method in the stub class, but you should always invoke
376: * the base method from the overridden method (i.e. parent::ensureConsistency()),
377: * in case your model changes.
378: *
379: * @throws PropelException
380: */
381: public function ensureConsistency()
382: {
383:
384: if ($this->aArea !== null && $this->area_id !== $this->aArea->getId()) {
385: $this->aArea = null;
386: }
387: } // ensureConsistency
388:
389: /**
390: * Reloads this object from datastore based on primary key and (optionally) resets all associated objects.
391: *
392: * This will only work if the object has been saved and has a valid primary key set.
393: *
394: * @param boolean $deep (optional) Whether to also de-associated any related objects.
395: * @param PropelPDO $con (optional) The PropelPDO connection to use.
396: * @return void
397: * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db
398: */
399: public function reload($deep = false, PropelPDO $con = null)
400: {
401: if ($this->isDeleted()) {
402: throw new PropelException("Cannot reload a deleted object.");
403: }
404:
405: if ($this->isNew()) {
406: throw new PropelException("Cannot reload an unsaved object.");
407: }
408:
409: if ($con === null) {
410: $con = Propel::getConnection(DelivzonePeer::DATABASE_NAME, Propel::CONNECTION_READ);
411: }
412:
413: // We don't need to alter the object instance pool; we're just modifying this instance
414: // already in the pool.
415:
416: $stmt = DelivzonePeer::doSelectStmt($this->buildPkeyCriteria(), $con);
417: $row = $stmt->fetch(PDO::FETCH_NUM);
418: $stmt->closeCursor();
419: if (!$row) {
420: throw new PropelException('Cannot find matching row in the database to reload object values.');
421: }
422: $this->hydrate($row, 0, true); // rehydrate
423:
424: if ($deep) { // also de-associate any related objects?
425:
426: $this->aArea = null;
427: } // if (deep)
428: }
429:
430: /**
431: * Removes this object from datastore and sets delete attribute.
432: *
433: * @param PropelPDO $con
434: * @return void
435: * @throws PropelException
436: * @throws Exception
437: * @see BaseObject::setDeleted()
438: * @see BaseObject::isDeleted()
439: */
440: public function delete(PropelPDO $con = null)
441: {
442: if ($this->isDeleted()) {
443: throw new PropelException("This object has already been deleted.");
444: }
445:
446: if ($con === null) {
447: $con = Propel::getConnection(DelivzonePeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
448: }
449:
450: $con->beginTransaction();
451: try {
452: $deleteQuery = DelivzoneQuery::create()
453: ->filterByPrimaryKey($this->getPrimaryKey());
454: $ret = $this->preDelete($con);
455: if ($ret) {
456: $deleteQuery->delete($con);
457: $this->postDelete($con);
458: $con->commit();
459: $this->setDeleted(true);
460: } else {
461: $con->commit();
462: }
463: } catch (Exception $e) {
464: $con->rollBack();
465: throw $e;
466: }
467: }
468:
469: /**
470: * Persists this object to the database.
471: *
472: * If the object is new, it inserts it; otherwise an update is performed.
473: * All modified related objects will also be persisted in the doSave()
474: * method. This method wraps all precipitate database operations in a
475: * single transaction.
476: *
477: * @param PropelPDO $con
478: * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
479: * @throws PropelException
480: * @throws Exception
481: * @see doSave()
482: */
483: public function save(PropelPDO $con = null)
484: {
485: if ($this->isDeleted()) {
486: throw new PropelException("You cannot save an object that has been deleted.");
487: }
488:
489: if ($con === null) {
490: $con = Propel::getConnection(DelivzonePeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
491: }
492:
493: $con->beginTransaction();
494: $isInsert = $this->isNew();
495: try {
496: $ret = $this->preSave($con);
497: if ($isInsert) {
498: $ret = $ret && $this->preInsert($con);
499: // timestampable behavior
500: if (!$this->isColumnModified(DelivzonePeer::CREATED_AT)) {
501: $this->setCreatedAt(time());
502: }
503: if (!$this->isColumnModified(DelivzonePeer::UPDATED_AT)) {
504: $this->setUpdatedAt(time());
505: }
506: } else {
507: $ret = $ret && $this->preUpdate($con);
508: // timestampable behavior
509: if ($this->isModified() && !$this->isColumnModified(DelivzonePeer::UPDATED_AT)) {
510: $this->setUpdatedAt(time());
511: }
512: }
513: if ($ret) {
514: $affectedRows = $this->doSave($con);
515: if ($isInsert) {
516: $this->postInsert($con);
517: } else {
518: $this->postUpdate($con);
519: }
520: $this->postSave($con);
521: DelivzonePeer::addInstanceToPool($this);
522: } else {
523: $affectedRows = 0;
524: }
525: $con->commit();
526:
527: return $affectedRows;
528: } catch (Exception $e) {
529: $con->rollBack();
530: throw $e;
531: }
532: }
533:
534: /**
535: * Performs the work of inserting or updating the row in the database.
536: *
537: * If the object is new, it inserts it; otherwise an update is performed.
538: * All related objects are also updated in this method.
539: *
540: * @param PropelPDO $con
541: * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
542: * @throws PropelException
543: * @see save()
544: */
545: protected function doSave(PropelPDO $con)
546: {
547: $affectedRows = 0; // initialize var to track total num of affected rows
548: if (!$this->alreadyInSave) {
549: $this->alreadyInSave = true;
550:
551: // We call the save method on the following object(s) if they
552: // were passed to this object by their coresponding set
553: // method. This object relates to these object(s) by a
554: // foreign key reference.
555:
556: if ($this->aArea !== null) {
557: if ($this->aArea->isModified() || $this->aArea->isNew()) {
558: $affectedRows += $this->aArea->save($con);
559: }
560: $this->setArea($this->aArea);
561: }
562:
563: if ($this->isNew() || $this->isModified()) {
564: // persist changes
565: if ($this->isNew()) {
566: $this->doInsert($con);
567: } else {
568: $this->doUpdate($con);
569: }
570: $affectedRows += 1;
571: $this->resetModified();
572: }
573:
574: $this->alreadyInSave = false;
575:
576: }
577:
578: return $affectedRows;
579: } // doSave()
580:
581: /**
582: * Insert the row in the database.
583: *
584: * @param PropelPDO $con
585: *
586: * @throws PropelException
587: * @see doSave()
588: */
589: protected function doInsert(PropelPDO $con)
590: {
591: $modifiedColumns = array();
592: $index = 0;
593:
594: $this->modifiedColumns[] = DelivzonePeer::ID;
595: if (null !== $this->id) {
596: throw new PropelException('Cannot insert a value for auto-increment primary key (' . DelivzonePeer::ID . ')');
597: }
598:
599: // check the columns in natural order for more readable SQL queries
600: if ($this->isColumnModified(DelivzonePeer::ID)) {
601: $modifiedColumns[':p' . $index++] = '`ID`';
602: }
603: if ($this->isColumnModified(DelivzonePeer::AREA_ID)) {
604: $modifiedColumns[':p' . $index++] = '`AREA_ID`';
605: }
606: if ($this->isColumnModified(DelivzonePeer::DELIVERY)) {
607: $modifiedColumns[':p' . $index++] = '`DELIVERY`';
608: }
609: if ($this->isColumnModified(DelivzonePeer::CREATED_AT)) {
610: $modifiedColumns[':p' . $index++] = '`CREATED_AT`';
611: }
612: if ($this->isColumnModified(DelivzonePeer::UPDATED_AT)) {
613: $modifiedColumns[':p' . $index++] = '`UPDATED_AT`';
614: }
615:
616: $sql = sprintf(
617: 'INSERT INTO `delivzone` (%s) VALUES (%s)',
618: implode(', ', $modifiedColumns),
619: implode(', ', array_keys($modifiedColumns))
620: );
621:
622: try {
623: $stmt = $con->prepare($sql);
624: foreach ($modifiedColumns as $identifier => $columnName) {
625: switch ($columnName) {
626: case '`ID`':
627: $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT);
628: break;
629: case '`AREA_ID`':
630: $stmt->bindValue($identifier, $this->area_id, PDO::PARAM_INT);
631: break;
632: case '`DELIVERY`':
633: $stmt->bindValue($identifier, $this->delivery, PDO::PARAM_STR);
634: break;
635: case '`CREATED_AT`':
636: $stmt->bindValue($identifier, $this->created_at, PDO::PARAM_STR);
637: break;
638: case '`UPDATED_AT`':
639: $stmt->bindValue($identifier, $this->updated_at, PDO::PARAM_STR);
640: break;
641: }
642: }
643: $stmt->execute();
644: } catch (Exception $e) {
645: Propel::log($e->getMessage(), Propel::LOG_ERR);
646: throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), $e);
647: }
648:
649: try {
650: $pk = $con->lastInsertId();
651: } catch (Exception $e) {
652: throw new PropelException('Unable to get autoincrement id.', $e);
653: }
654: $this->setId($pk);
655:
656: $this->setNew(false);
657: }
658:
659: /**
660: * Update the row in the database.
661: *
662: * @param PropelPDO $con
663: *
664: * @see doSave()
665: */
666: protected function doUpdate(PropelPDO $con)
667: {
668: $selectCriteria = $this->buildPkeyCriteria();
669: $valuesCriteria = $this->buildCriteria();
670: BasePeer::doUpdate($selectCriteria, $valuesCriteria, $con);
671: }
672:
673: /**
674: * Array of ValidationFailed objects.
675: * @var array ValidationFailed[]
676: */
677: protected $validationFailures = array();
678:
679: /**
680: * Gets any ValidationFailed objects that resulted from last call to validate().
681: *
682: *
683: * @return array ValidationFailed[]
684: * @see validate()
685: */
686: public function getValidationFailures()
687: {
688: return $this->validationFailures;
689: }
690:
691: /**
692: * Validates the objects modified field values and all objects related to this table.
693: *
694: * If $columns is either a column name or an array of column names
695: * only those columns are validated.
696: *
697: * @param mixed $columns Column name or an array of column names.
698: * @return boolean Whether all columns pass validation.
699: * @see doValidate()
700: * @see getValidationFailures()
701: */
702: public function validate($columns = null)
703: {
704: $res = $this->doValidate($columns);
705: if ($res === true) {
706: $this->validationFailures = array();
707:
708: return true;
709: } else {
710: $this->validationFailures = $res;
711:
712: return false;
713: }
714: }
715:
716: /**
717: * This function performs the validation work for complex object models.
718: *
719: * In addition to checking the current object, all related objects will
720: * also be validated. If all pass then <code>true</code> is returned; otherwise
721: * an aggreagated array of ValidationFailed objects will be returned.
722: *
723: * @param array $columns Array of column names to validate.
724: * @return mixed <code>true</code> if all validations pass; array of <code>ValidationFailed</code> objets otherwise.
725: */
726: protected function doValidate($columns = null)
727: {
728: if (!$this->alreadyInValidation) {
729: $this->alreadyInValidation = true;
730: $retval = null;
731:
732: $failureMap = array();
733:
734:
735: // We call the validate method on the following object(s) if they
736: // were passed to this object by their coresponding set
737: // method. This object relates to these object(s) by a
738: // foreign key reference.
739:
740: if ($this->aArea !== null) {
741: if (!$this->aArea->validate($columns)) {
742: $failureMap = array_merge($failureMap, $this->aArea->getValidationFailures());
743: }
744: }
745:
746:
747: if (($retval = DelivzonePeer::doValidate($this, $columns)) !== true) {
748: $failureMap = array_merge($failureMap, $retval);
749: }
750:
751:
752:
753: $this->alreadyInValidation = false;
754: }
755:
756: return (!empty($failureMap) ? $failureMap : true);
757: }
758:
759: /**
760: * Retrieves a field from the object by name passed in as a string.
761: *
762: * @param string $name name
763: * @param string $type The type of fieldname the $name is of:
764: * one of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
765: * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
766: * Defaults to BasePeer::TYPE_PHPNAME
767: * @return mixed Value of field.
768: */
769: public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
770: {
771: $pos = DelivzonePeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
772: $field = $this->getByPosition($pos);
773:
774: return $field;
775: }
776:
777: /**
778: * Retrieves a field from the object by Position as specified in the xml schema.
779: * Zero-based.
780: *
781: * @param int $pos position in xml schema
782: * @return mixed Value of field at $pos
783: */
784: public function getByPosition($pos)
785: {
786: switch ($pos) {
787: case 0:
788: return $this->getId();
789: break;
790: case 1:
791: return $this->getAreaId();
792: break;
793: case 2:
794: return $this->getDelivery();
795: break;
796: case 3:
797: return $this->getCreatedAt();
798: break;
799: case 4:
800: return $this->getUpdatedAt();
801: break;
802: default:
803: return null;
804: break;
805: } // switch()
806: }
807:
808: /**
809: * Exports the object as an array.
810: *
811: * You can specify the key type of the array by passing one of the class
812: * type constants.
813: *
814: * @param string $keyType (optional) One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
815: * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
816: * Defaults to BasePeer::TYPE_PHPNAME.
817: * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to true.
818: * @param array $alreadyDumpedObjects List of objects to skip to avoid recursion
819: * @param boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE.
820: *
821: * @return array an associative array containing the field names (as keys) and field values
822: */
823: public function toArray($keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false)
824: {
825: if (isset($alreadyDumpedObjects['Delivzone'][$this->getPrimaryKey()])) {
826: return '*RECURSION*';
827: }
828: $alreadyDumpedObjects['Delivzone'][$this->getPrimaryKey()] = true;
829: $keys = DelivzonePeer::getFieldNames($keyType);
830: $result = array(
831: $keys[0] => $this->getId(),
832: $keys[1] => $this->getAreaId(),
833: $keys[2] => $this->getDelivery(),
834: $keys[3] => $this->getCreatedAt(),
835: $keys[4] => $this->getUpdatedAt(),
836: );
837: if ($includeForeignObjects) {
838: if (null !== $this->aArea) {
839: $result['Area'] = $this->aArea->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true);
840: }
841: }
842:
843: return $result;
844: }
845:
846: /**
847: * Sets a field from the object by name passed in as a string.
848: *
849: * @param string $name peer name
850: * @param mixed $value field value
851: * @param string $type The type of fieldname the $name is of:
852: * one of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
853: * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
854: * Defaults to BasePeer::TYPE_PHPNAME
855: * @return void
856: */
857: public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
858: {
859: $pos = DelivzonePeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
860:
861: $this->setByPosition($pos, $value);
862: }
863:
864: /**
865: * Sets a field from the object by Position as specified in the xml schema.
866: * Zero-based.
867: *
868: * @param int $pos position in xml schema
869: * @param mixed $value field value
870: * @return void
871: */
872: public function setByPosition($pos, $value)
873: {
874: switch ($pos) {
875: case 0:
876: $this->setId($value);
877: break;
878: case 1:
879: $this->setAreaId($value);
880: break;
881: case 2:
882: $this->setDelivery($value);
883: break;
884: case 3:
885: $this->setCreatedAt($value);
886: break;
887: case 4:
888: $this->setUpdatedAt($value);
889: break;
890: } // switch()
891: }
892:
893: /**
894: * Populates the object using an array.
895: *
896: * This is particularly useful when populating an object from one of the
897: * request arrays (e.g. $_POST). This method goes through the column
898: * names, checking to see whether a matching key exists in populated
899: * array. If so the setByName() method is called for that column.
900: *
901: * You can specify the key type of the array by additionally passing one
902: * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
903: * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
904: * The default key type is the column's BasePeer::TYPE_PHPNAME
905: *
906: * @param array $arr An array to populate the object from.
907: * @param string $keyType The type of keys the array uses.
908: * @return void
909: */
910: public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
911: {
912: $keys = DelivzonePeer::getFieldNames($keyType);
913:
914: if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
915: if (array_key_exists($keys[1], $arr)) $this->setAreaId($arr[$keys[1]]);
916: if (array_key_exists($keys[2], $arr)) $this->setDelivery($arr[$keys[2]]);
917: if (array_key_exists($keys[3], $arr)) $this->setCreatedAt($arr[$keys[3]]);
918: if (array_key_exists($keys[4], $arr)) $this->setUpdatedAt($arr[$keys[4]]);
919: }
920:
921: /**
922: * Build a Criteria object containing the values of all modified columns in this object.
923: *
924: * @return Criteria The Criteria object containing all modified values.
925: */
926: public function buildCriteria()
927: {
928: $criteria = new Criteria(DelivzonePeer::DATABASE_NAME);
929:
930: if ($this->isColumnModified(DelivzonePeer::ID)) $criteria->add(DelivzonePeer::ID, $this->id);
931: if ($this->isColumnModified(DelivzonePeer::AREA_ID)) $criteria->add(DelivzonePeer::AREA_ID, $this->area_id);
932: if ($this->isColumnModified(DelivzonePeer::DELIVERY)) $criteria->add(DelivzonePeer::DELIVERY, $this->delivery);
933: if ($this->isColumnModified(DelivzonePeer::CREATED_AT)) $criteria->add(DelivzonePeer::CREATED_AT, $this->created_at);
934: if ($this->isColumnModified(DelivzonePeer::UPDATED_AT)) $criteria->add(DelivzonePeer::UPDATED_AT, $this->updated_at);
935:
936: return $criteria;
937: }
938:
939: /**
940: * Builds a Criteria object containing the primary key for this object.
941: *
942: * Unlike buildCriteria() this method includes the primary key values regardless
943: * of whether or not they have been modified.
944: *
945: * @return Criteria The Criteria object containing value(s) for primary key(s).
946: */
947: public function buildPkeyCriteria()
948: {
949: $criteria = new Criteria(DelivzonePeer::DATABASE_NAME);
950: $criteria->add(DelivzonePeer::ID, $this->id);
951:
952: return $criteria;
953: }
954:
955: /**
956: * Returns the primary key for this object (row).
957: * @return int
958: */
959: public function getPrimaryKey()
960: {
961: return $this->getId();
962: }
963:
964: /**
965: * Generic method to set the primary key (id column).
966: *
967: * @param int $key Primary key.
968: * @return void
969: */
970: public function setPrimaryKey($key)
971: {
972: $this->setId($key);
973: }
974:
975: /**
976: * Returns true if the primary key for this object is null.
977: * @return boolean
978: */
979: public function isPrimaryKeyNull()
980: {
981:
982: return null === $this->getId();
983: }
984:
985: /**
986: * Sets contents of passed object to values from current object.
987: *
988: * If desired, this method can also make copies of all associated (fkey referrers)
989: * objects.
990: *
991: * @param object $copyObj An object of Delivzone (or compatible) type.
992: * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
993: * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new.
994: * @throws PropelException
995: */
996: public function copyInto($copyObj, $deepCopy = false, $makeNew = true)
997: {
998: $copyObj->setAreaId($this->getAreaId());
999: $copyObj->setDelivery($this->getDelivery());
1000: $copyObj->setCreatedAt($this->getCreatedAt());
1001: $copyObj->setUpdatedAt($this->getUpdatedAt());
1002:
1003: if ($deepCopy && !$this->startCopy) {
1004: // important: temporarily setNew(false) because this affects the behavior of
1005: // the getter/setter methods for fkey referrer objects.
1006: $copyObj->setNew(false);
1007: // store object hash to prevent cycle
1008: $this->startCopy = true;
1009:
1010: //unflag object copy
1011: $this->startCopy = false;
1012: } // if ($deepCopy)
1013:
1014: if ($makeNew) {
1015: $copyObj->setNew(true);
1016: $copyObj->setId(NULL); // this is a auto-increment column, so set to default value
1017: }
1018: }
1019:
1020: /**
1021: * Makes a copy of this object that will be inserted as a new row in table when saved.
1022: * It creates a new object filling in the simple attributes, but skipping any primary
1023: * keys that are defined for the table.
1024: *
1025: * If desired, this method can also make copies of all associated (fkey referrers)
1026: * objects.
1027: *
1028: * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
1029: * @return Delivzone Clone of current object.
1030: * @throws PropelException
1031: */
1032: public function copy($deepCopy = false)
1033: {
1034: // we use get_class(), because this might be a subclass
1035: $clazz = get_class($this);
1036: $copyObj = new $clazz();
1037: $this->copyInto($copyObj, $deepCopy);
1038:
1039: return $copyObj;
1040: }
1041:
1042: /**
1043: * Returns a peer instance associated with this om.
1044: *
1045: * Since Peer classes are not to have any instance attributes, this method returns the
1046: * same instance for all member of this class. The method could therefore
1047: * be static, but this would prevent one from overriding the behavior.
1048: *
1049: * @return DelivzonePeer
1050: */
1051: public function getPeer()
1052: {
1053: if (self::$peer === null) {
1054: self::$peer = new DelivzonePeer();
1055: }
1056:
1057: return self::$peer;
1058: }
1059:
1060: /**
1061: * Declares an association between this object and a Area object.
1062: *
1063: * @param Area $v
1064: * @return Delivzone The current object (for fluent API support)
1065: * @throws PropelException
1066: */
1067: public function setArea(Area $v = null)
1068: {
1069: if ($v === null) {
1070: $this->setAreaId(NULL);
1071: } else {
1072: $this->setAreaId($v->getId());
1073: }
1074:
1075: $this->aArea = $v;
1076:
1077: // Add binding for other direction of this n:n relationship.
1078: // If this object has already been added to the Area object, it will not be re-added.
1079: if ($v !== null) {
1080: $v->addDelivzone($this);
1081: }
1082:
1083:
1084: return $this;
1085: }
1086:
1087:
1088: /**
1089: * Get the associated Area object
1090: *
1091: * @param PropelPDO $con Optional Connection object.
1092: * @return Area The associated Area object.
1093: * @throws PropelException
1094: */
1095: public function getArea(PropelPDO $con = null)
1096: {
1097: if ($this->aArea === null && ($this->area_id !== null)) {
1098: $this->aArea = AreaQuery::create()->findPk($this->area_id, $con);
1099: /* The following can be used additionally to
1100: guarantee the related object contains a reference
1101: to this object. This level of coupling may, however, be
1102: undesirable since it could result in an only partially populated collection
1103: in the referenced object.
1104: $this->aArea->addDelivzones($this);
1105: */
1106: }
1107:
1108: return $this->aArea;
1109: }
1110:
1111: /**
1112: * Clears the current object and sets all attributes to their default values
1113: */
1114: public function clear()
1115: {
1116: $this->id = null;
1117: $this->area_id = null;
1118: $this->delivery = null;
1119: $this->created_at = null;
1120: $this->updated_at = null;
1121: $this->alreadyInSave = false;
1122: $this->alreadyInValidation = false;
1123: $this->clearAllReferences();
1124: $this->resetModified();
1125: $this->setNew(true);
1126: $this->setDeleted(false);
1127: }
1128:
1129: /**
1130: * Resets all references to other model objects or collections of model objects.
1131: *
1132: * This method is a user-space workaround for PHP's inability to garbage collect
1133: * objects with circular references (even in PHP 5.3). This is currently necessary
1134: * when using Propel in certain daemon or large-volumne/high-memory operations.
1135: *
1136: * @param boolean $deep Whether to also clear the references on all referrer objects.
1137: */
1138: public function clearAllReferences($deep = false)
1139: {
1140: if ($deep) {
1141: } // if ($deep)
1142:
1143: $this->aArea = null;
1144: }
1145:
1146: /**
1147: * return the string representation of this object
1148: *
1149: * @return string
1150: */
1151: public function __toString()
1152: {
1153: return (string) $this->exportTo(DelivzonePeer::DEFAULT_STRING_FORMAT);
1154: }
1155:
1156: /**
1157: * return true is the object is in saving state
1158: *
1159: * @return boolean
1160: */
1161: public function isAlreadyInSave()
1162: {
1163: return $this->alreadyInSave;
1164: }
1165:
1166: // timestampable behavior
1167:
1168: /**
1169: * Mark the current object so that the update date doesn't get updated during next save
1170: *
1171: * @return Delivzone The current object (for fluent API support)
1172: */
1173: public function keepUpdateDateUnchanged()
1174: {
1175: $this->modifiedColumns[] = DelivzonePeer::UPDATED_AT;
1176:
1177: return $this;
1178: }
1179:
1180: }
1181: