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