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