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