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