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