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