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