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