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