1: <?php
2:
3: namespace Thelia\Model\om;
4:
5: use \BaseObject;
6: use \BasePeer;
7: use \Criteria;
8: use \DateTime;
9: use \Exception;
10: use \PDO;
11: use \Persistent;
12: use \Propel;
13: use \PropelCollection;
14: use \PropelDateTime;
15: use \PropelException;
16: use \PropelObjectCollection;
17: use \PropelPDO;
18: use Thelia\Model\Message;
19: use Thelia\Model\MessageI18n;
20: use Thelia\Model\MessageI18nQuery;
21: use Thelia\Model\MessagePeer;
22: use Thelia\Model\MessageQuery;
23: use Thelia\Model\MessageVersion;
24: use Thelia\Model\MessageVersionPeer;
25: use Thelia\Model\MessageVersionQuery;
26:
27: 28: 29: 30: 31: 32: 33:
34: abstract class BaseMessage extends BaseObject implements Persistent
35: {
36: 37: 38:
39: const PEER = 'Thelia\\Model\\MessagePeer';
40:
41: 42: 43: 44: 45: 46:
47: protected static $peer;
48:
49: 50: 51: 52:
53: protected $startCopy = false;
54:
55: 56: 57: 58:
59: protected $id;
60:
61: 62: 63: 64:
65: protected $code;
66:
67: 68: 69: 70:
71: protected $secured;
72:
73: 74: 75: 76:
77: protected $ref;
78:
79: 80: 81: 82:
83: protected $created_at;
84:
85: 86: 87: 88:
89: protected $updated_at;
90:
91: 92: 93: 94: 95:
96: protected $version;
97:
98: 99: 100: 101:
102: protected $version_created_at;
103:
104: 105: 106: 107:
108: protected $version_created_by;
109:
110: 111: 112:
113: protected $collMessageI18ns;
114: protected $collMessageI18nsPartial;
115:
116: 117: 118:
119: protected $collMessageVersions;
120: protected $collMessageVersionsPartial;
121:
122: 123: 124: 125: 126:
127: protected $alreadyInSave = false;
128:
129: 130: 131: 132: 133:
134: protected $alreadyInValidation = false;
135:
136: 137: 138: 139:
140: protected $alreadyInClearAllReferencesDeep = false;
141:
142:
143:
144: 145: 146: 147:
148: protected $currentLocale = 'en_US';
149:
150: 151: 152: 153:
154: protected $currentTranslations;
155:
156:
157:
158:
159: 160: 161:
162: protected $enforceVersion = false;
163:
164: 165: 166: 167:
168: protected $messageI18nsScheduledForDeletion = null;
169:
170: 171: 172: 173:
174: protected $messageVersionsScheduledForDeletion = null;
175:
176: 177: 178: 179: 180: 181:
182: public function applyDefaultValues()
183: {
184: $this->version = 0;
185: }
186:
187: 188: 189: 190:
191: public function __construct()
192: {
193: parent::__construct();
194: $this->applyDefaultValues();
195: }
196:
197: 198: 199: 200: 201:
202: public function getId()
203: {
204: return $this->id;
205: }
206:
207: 208: 209: 210: 211:
212: public function getCode()
213: {
214: return $this->code;
215: }
216:
217: 218: 219: 220: 221:
222: public function getSecured()
223: {
224: return $this->secured;
225: }
226:
227: 228: 229: 230: 231:
232: public function getRef()
233: {
234: return $this->ref;
235: }
236:
237: 238: 239: 240: 241: 242: 243: 244: 245:
246: public function getCreatedAt($format = 'Y-m-d H:i:s')
247: {
248: if ($this->created_at === null) {
249: return null;
250: }
251:
252: if ($this->created_at === '0000-00-00 00:00:00') {
253:
254:
255: return null;
256: }
257:
258: try {
259: $dt = new DateTime($this->created_at);
260: } catch (Exception $x) {
261: throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->created_at, true), $x);
262: }
263:
264: if ($format === null) {
265:
266: return $dt;
267: }
268:
269: if (strpos($format, '%') !== false) {
270: return strftime($format, $dt->format('U'));
271: }
272:
273: return $dt->format($format);
274:
275: }
276:
277: 278: 279: 280: 281: 282: 283: 284: 285:
286: public function getUpdatedAt($format = 'Y-m-d H:i:s')
287: {
288: if ($this->updated_at === null) {
289: return null;
290: }
291:
292: if ($this->updated_at === '0000-00-00 00:00:00') {
293:
294:
295: return null;
296: }
297:
298: try {
299: $dt = new DateTime($this->updated_at);
300: } catch (Exception $x) {
301: throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->updated_at, true), $x);
302: }
303:
304: if ($format === null) {
305:
306: return $dt;
307: }
308:
309: if (strpos($format, '%') !== false) {
310: return strftime($format, $dt->format('U'));
311: }
312:
313: return $dt->format($format);
314:
315: }
316:
317: 318: 319: 320: 321:
322: public function getVersion()
323: {
324: return $this->version;
325: }
326:
327: 328: 329: 330: 331: 332: 333: 334: 335:
336: public function getVersionCreatedAt($format = 'Y-m-d H:i:s')
337: {
338: if ($this->version_created_at === null) {
339: return null;
340: }
341:
342: if ($this->version_created_at === '0000-00-00 00:00:00') {
343:
344:
345: return null;
346: }
347:
348: try {
349: $dt = new DateTime($this->version_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->version_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: public function getVersionCreatedBy()
373: {
374: return $this->version_created_by;
375: }
376:
377: 378: 379: 380: 381: 382:
383: public function setId($v)
384: {
385: if ($v !== null && is_numeric($v)) {
386: $v = (int) $v;
387: }
388:
389: if ($this->id !== $v) {
390: $this->id = $v;
391: $this->modifiedColumns[] = MessagePeer::ID;
392: }
393:
394:
395: return $this;
396: }
397:
398: 399: 400: 401: 402: 403:
404: public function setCode($v)
405: {
406: if ($v !== null && is_numeric($v)) {
407: $v = (string) $v;
408: }
409:
410: if ($this->code !== $v) {
411: $this->code = $v;
412: $this->modifiedColumns[] = MessagePeer::CODE;
413: }
414:
415:
416: return $this;
417: }
418:
419: 420: 421: 422: 423: 424:
425: public function setSecured($v)
426: {
427: if ($v !== null && is_numeric($v)) {
428: $v = (int) $v;
429: }
430:
431: if ($this->secured !== $v) {
432: $this->secured = $v;
433: $this->modifiedColumns[] = MessagePeer::SECURED;
434: }
435:
436:
437: return $this;
438: }
439:
440: 441: 442: 443: 444: 445:
446: public function setRef($v)
447: {
448: if ($v !== null && is_numeric($v)) {
449: $v = (string) $v;
450: }
451:
452: if ($this->ref !== $v) {
453: $this->ref = $v;
454: $this->modifiedColumns[] = MessagePeer::REF;
455: }
456:
457:
458: return $this;
459: }
460:
461: 462: 463: 464: 465: 466: 467:
468: public function setCreatedAt($v)
469: {
470: $dt = PropelDateTime::newInstance($v, null, 'DateTime');
471: if ($this->created_at !== null || $dt !== null) {
472: $currentDateAsString = ($this->created_at !== null && $tmpDt = new DateTime($this->created_at)) ? $tmpDt->format('Y-m-d H:i:s') : null;
473: $newDateAsString = $dt ? $dt->format('Y-m-d H:i:s') : null;
474: if ($currentDateAsString !== $newDateAsString) {
475: $this->created_at = $newDateAsString;
476: $this->modifiedColumns[] = MessagePeer::CREATED_AT;
477: }
478: }
479:
480:
481: return $this;
482: }
483:
484: 485: 486: 487: 488: 489: 490:
491: public function setUpdatedAt($v)
492: {
493: $dt = PropelDateTime::newInstance($v, null, 'DateTime');
494: if ($this->updated_at !== null || $dt !== null) {
495: $currentDateAsString = ($this->updated_at !== null && $tmpDt = new DateTime($this->updated_at)) ? $tmpDt->format('Y-m-d H:i:s') : null;
496: $newDateAsString = $dt ? $dt->format('Y-m-d H:i:s') : null;
497: if ($currentDateAsString !== $newDateAsString) {
498: $this->updated_at = $newDateAsString;
499: $this->modifiedColumns[] = MessagePeer::UPDATED_AT;
500: }
501: }
502:
503:
504: return $this;
505: }
506:
507: 508: 509: 510: 511: 512:
513: public function setVersion($v)
514: {
515: if ($v !== null && is_numeric($v)) {
516: $v = (int) $v;
517: }
518:
519: if ($this->version !== $v) {
520: $this->version = $v;
521: $this->modifiedColumns[] = MessagePeer::VERSION;
522: }
523:
524:
525: return $this;
526: }
527:
528: 529: 530: 531: 532: 533: 534:
535: public function setVersionCreatedAt($v)
536: {
537: $dt = PropelDateTime::newInstance($v, null, 'DateTime');
538: if ($this->version_created_at !== null || $dt !== null) {
539: $currentDateAsString = ($this->version_created_at !== null && $tmpDt = new DateTime($this->version_created_at)) ? $tmpDt->format('Y-m-d H:i:s') : null;
540: $newDateAsString = $dt ? $dt->format('Y-m-d H:i:s') : null;
541: if ($currentDateAsString !== $newDateAsString) {
542: $this->version_created_at = $newDateAsString;
543: $this->modifiedColumns[] = MessagePeer::VERSION_CREATED_AT;
544: }
545: }
546:
547:
548: return $this;
549: }
550:
551: 552: 553: 554: 555: 556:
557: public function setVersionCreatedBy($v)
558: {
559: if ($v !== null && is_numeric($v)) {
560: $v = (string) $v;
561: }
562:
563: if ($this->version_created_by !== $v) {
564: $this->version_created_by = $v;
565: $this->modifiedColumns[] = MessagePeer::VERSION_CREATED_BY;
566: }
567:
568:
569: return $this;
570: }
571:
572: 573: 574: 575: 576: 577: 578: 579:
580: public function hasOnlyDefaultValues()
581: {
582: if ($this->version !== 0) {
583: return false;
584: }
585:
586:
587: return true;
588: }
589:
590: 591: 592: 593: 594: 595: 596: 597: 598: 599: 600: 601: 602: 603:
604: public function hydrate($row, $startcol = 0, $rehydrate = false)
605: {
606: try {
607:
608: $this->id = ($row[$startcol + 0] !== null) ? (int) $row[$startcol + 0] : null;
609: $this->code = ($row[$startcol + 1] !== null) ? (string) $row[$startcol + 1] : null;
610: $this->secured = ($row[$startcol + 2] !== null) ? (int) $row[$startcol + 2] : null;
611: $this->ref = ($row[$startcol + 3] !== null) ? (string) $row[$startcol + 3] : null;
612: $this->created_at = ($row[$startcol + 4] !== null) ? (string) $row[$startcol + 4] : null;
613: $this->updated_at = ($row[$startcol + 5] !== null) ? (string) $row[$startcol + 5] : null;
614: $this->version = ($row[$startcol + 6] !== null) ? (int) $row[$startcol + 6] : null;
615: $this->version_created_at = ($row[$startcol + 7] !== null) ? (string) $row[$startcol + 7] : null;
616: $this->version_created_by = ($row[$startcol + 8] !== null) ? (string) $row[$startcol + 8] : null;
617: $this->resetModified();
618:
619: $this->setNew(false);
620:
621: if ($rehydrate) {
622: $this->ensureConsistency();
623: }
624: $this->postHydrate($row, $startcol, $rehydrate);
625: return $startcol + 9;
626:
627: } catch (Exception $e) {
628: throw new PropelException("Error populating Message object", $e);
629: }
630: }
631:
632: 633: 634: 635: 636: 637: 638: 639: 640: 641: 642: 643: 644:
645: public function ensureConsistency()
646: {
647:
648: }
649:
650: 651: 652: 653: 654: 655: 656: 657: 658: 659:
660: public function reload($deep = false, PropelPDO $con = null)
661: {
662: if ($this->isDeleted()) {
663: throw new PropelException("Cannot reload a deleted object.");
664: }
665:
666: if ($this->isNew()) {
667: throw new PropelException("Cannot reload an unsaved object.");
668: }
669:
670: if ($con === null) {
671: $con = Propel::getConnection(MessagePeer::DATABASE_NAME, Propel::CONNECTION_READ);
672: }
673:
674:
675:
676:
677: $stmt = MessagePeer::doSelectStmt($this->buildPkeyCriteria(), $con);
678: $row = $stmt->fetch(PDO::FETCH_NUM);
679: $stmt->closeCursor();
680: if (!$row) {
681: throw new PropelException('Cannot find matching row in the database to reload object values.');
682: }
683: $this->hydrate($row, 0, true);
684:
685: if ($deep) {
686:
687: $this->collMessageI18ns = null;
688:
689: $this->collMessageVersions = null;
690:
691: }
692: }
693:
694: 695: 696: 697: 698: 699: 700: 701: 702: 703:
704: public function delete(PropelPDO $con = null)
705: {
706: if ($this->isDeleted()) {
707: throw new PropelException("This object has already been deleted.");
708: }
709:
710: if ($con === null) {
711: $con = Propel::getConnection(MessagePeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
712: }
713:
714: $con->beginTransaction();
715: try {
716: $deleteQuery = MessageQuery::create()
717: ->filterByPrimaryKey($this->getPrimaryKey());
718: $ret = $this->preDelete($con);
719: if ($ret) {
720: $deleteQuery->delete($con);
721: $this->postDelete($con);
722: $con->commit();
723: $this->setDeleted(true);
724: } else {
725: $con->commit();
726: }
727: } catch (Exception $e) {
728: $con->rollBack();
729: throw $e;
730: }
731: }
732:
733: 734: 735: 736: 737: 738: 739: 740: 741: 742: 743: 744: 745: 746:
747: public function save(PropelPDO $con = null)
748: {
749: if ($this->isDeleted()) {
750: throw new PropelException("You cannot save an object that has been deleted.");
751: }
752:
753: if ($con === null) {
754: $con = Propel::getConnection(MessagePeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
755: }
756:
757: $con->beginTransaction();
758: $isInsert = $this->isNew();
759: try {
760: $ret = $this->preSave($con);
761:
762: if ($this->isVersioningNecessary()) {
763: $this->setVersion($this->isNew() ? 1 : $this->getLastVersionNumber($con) + 1);
764: if (!$this->isColumnModified(MessagePeer::VERSION_CREATED_AT)) {
765: $this->setVersionCreatedAt(time());
766: }
767: $createVersion = true;
768: }
769: if ($isInsert) {
770: $ret = $ret && $this->preInsert($con);
771:
772: if (!$this->isColumnModified(MessagePeer::CREATED_AT)) {
773: $this->setCreatedAt(time());
774: }
775: if (!$this->isColumnModified(MessagePeer::UPDATED_AT)) {
776: $this->setUpdatedAt(time());
777: }
778: } else {
779: $ret = $ret && $this->preUpdate($con);
780:
781: if ($this->isModified() && !$this->isColumnModified(MessagePeer::UPDATED_AT)) {
782: $this->setUpdatedAt(time());
783: }
784: }
785: if ($ret) {
786: $affectedRows = $this->doSave($con);
787: if ($isInsert) {
788: $this->postInsert($con);
789: } else {
790: $this->postUpdate($con);
791: }
792: $this->postSave($con);
793:
794: if (isset($createVersion)) {
795: $this->addVersion($con);
796: }
797: MessagePeer::addInstanceToPool($this);
798: } else {
799: $affectedRows = 0;
800: }
801: $con->commit();
802:
803: return $affectedRows;
804: } catch (Exception $e) {
805: $con->rollBack();
806: throw $e;
807: }
808: }
809:
810: 811: 812: 813: 814: 815: 816: 817: 818: 819: 820:
821: protected function doSave(PropelPDO $con)
822: {
823: $affectedRows = 0;
824: if (!$this->alreadyInSave) {
825: $this->alreadyInSave = true;
826:
827: if ($this->isNew() || $this->isModified()) {
828:
829: if ($this->isNew()) {
830: $this->doInsert($con);
831: } else {
832: $this->doUpdate($con);
833: }
834: $affectedRows += 1;
835: $this->resetModified();
836: }
837:
838: if ($this->messageI18nsScheduledForDeletion !== null) {
839: if (!$this->messageI18nsScheduledForDeletion->isEmpty()) {
840: MessageI18nQuery::create()
841: ->filterByPrimaryKeys($this->messageI18nsScheduledForDeletion->getPrimaryKeys(false))
842: ->delete($con);
843: $this->messageI18nsScheduledForDeletion = null;
844: }
845: }
846:
847: if ($this->collMessageI18ns !== null) {
848: foreach ($this->collMessageI18ns as $referrerFK) {
849: if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
850: $affectedRows += $referrerFK->save($con);
851: }
852: }
853: }
854:
855: if ($this->messageVersionsScheduledForDeletion !== null) {
856: if (!$this->messageVersionsScheduledForDeletion->isEmpty()) {
857: MessageVersionQuery::create()
858: ->filterByPrimaryKeys($this->messageVersionsScheduledForDeletion->getPrimaryKeys(false))
859: ->delete($con);
860: $this->messageVersionsScheduledForDeletion = null;
861: }
862: }
863:
864: if ($this->collMessageVersions !== null) {
865: foreach ($this->collMessageVersions as $referrerFK) {
866: if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
867: $affectedRows += $referrerFK->save($con);
868: }
869: }
870: }
871:
872: $this->alreadyInSave = false;
873:
874: }
875:
876: return $affectedRows;
877: }
878:
879: 880: 881: 882: 883: 884: 885: 886:
887: protected function doInsert(PropelPDO $con)
888: {
889: $modifiedColumns = array();
890: $index = 0;
891:
892: $this->modifiedColumns[] = MessagePeer::ID;
893: if (null !== $this->id) {
894: throw new PropelException('Cannot insert a value for auto-increment primary key (' . MessagePeer::ID . ')');
895: }
896:
897:
898: if ($this->isColumnModified(MessagePeer::ID)) {
899: $modifiedColumns[':p' . $index++] = '`id`';
900: }
901: if ($this->isColumnModified(MessagePeer::CODE)) {
902: $modifiedColumns[':p' . $index++] = '`code`';
903: }
904: if ($this->isColumnModified(MessagePeer::SECURED)) {
905: $modifiedColumns[':p' . $index++] = '`secured`';
906: }
907: if ($this->isColumnModified(MessagePeer::REF)) {
908: $modifiedColumns[':p' . $index++] = '`ref`';
909: }
910: if ($this->isColumnModified(MessagePeer::CREATED_AT)) {
911: $modifiedColumns[':p' . $index++] = '`created_at`';
912: }
913: if ($this->isColumnModified(MessagePeer::UPDATED_AT)) {
914: $modifiedColumns[':p' . $index++] = '`updated_at`';
915: }
916: if ($this->isColumnModified(MessagePeer::VERSION)) {
917: $modifiedColumns[':p' . $index++] = '`version`';
918: }
919: if ($this->isColumnModified(MessagePeer::VERSION_CREATED_AT)) {
920: $modifiedColumns[':p' . $index++] = '`version_created_at`';
921: }
922: if ($this->isColumnModified(MessagePeer::VERSION_CREATED_BY)) {
923: $modifiedColumns[':p' . $index++] = '`version_created_by`';
924: }
925:
926: $sql = sprintf(
927: 'INSERT INTO `message` (%s) VALUES (%s)',
928: implode(', ', $modifiedColumns),
929: implode(', ', array_keys($modifiedColumns))
930: );
931:
932: try {
933: $stmt = $con->prepare($sql);
934: foreach ($modifiedColumns as $identifier => $columnName) {
935: switch ($columnName) {
936: case '`id`':
937: $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT);
938: break;
939: case '`code`':
940: $stmt->bindValue($identifier, $this->code, PDO::PARAM_STR);
941: break;
942: case '`secured`':
943: $stmt->bindValue($identifier, $this->secured, PDO::PARAM_INT);
944: break;
945: case '`ref`':
946: $stmt->bindValue($identifier, $this->ref, PDO::PARAM_STR);
947: break;
948: case '`created_at`':
949: $stmt->bindValue($identifier, $this->created_at, PDO::PARAM_STR);
950: break;
951: case '`updated_at`':
952: $stmt->bindValue($identifier, $this->updated_at, PDO::PARAM_STR);
953: break;
954: case '`version`':
955: $stmt->bindValue($identifier, $this->version, PDO::PARAM_INT);
956: break;
957: case '`version_created_at`':
958: $stmt->bindValue($identifier, $this->version_created_at, PDO::PARAM_STR);
959: break;
960: case '`version_created_by`':
961: $stmt->bindValue($identifier, $this->version_created_by, PDO::PARAM_STR);
962: break;
963: }
964: }
965: $stmt->execute();
966: } catch (Exception $e) {
967: Propel::log($e->getMessage(), Propel::LOG_ERR);
968: throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), $e);
969: }
970:
971: try {
972: $pk = $con->lastInsertId();
973: } catch (Exception $e) {
974: throw new PropelException('Unable to get autoincrement id.', $e);
975: }
976: $this->setId($pk);
977:
978: $this->setNew(false);
979: }
980:
981: 982: 983: 984: 985: 986: 987:
988: protected function doUpdate(PropelPDO $con)
989: {
990: $selectCriteria = $this->buildPkeyCriteria();
991: $valuesCriteria = $this->buildCriteria();
992: BasePeer::doUpdate($selectCriteria, $valuesCriteria, $con);
993: }
994:
995: 996: 997: 998:
999: protected $validationFailures = array();
1000:
1001: 1002: 1003: 1004: 1005: 1006: 1007:
1008: public function getValidationFailures()
1009: {
1010: return $this->validationFailures;
1011: }
1012:
1013: 1014: 1015: 1016: 1017: 1018: 1019: 1020: 1021: 1022: 1023:
1024: public function validate($columns = null)
1025: {
1026: $res = $this->doValidate($columns);
1027: if ($res === true) {
1028: $this->validationFailures = array();
1029:
1030: return true;
1031: }
1032:
1033: $this->validationFailures = $res;
1034:
1035: return false;
1036: }
1037:
1038: 1039: 1040: 1041: 1042: 1043: 1044: 1045: 1046: 1047:
1048: protected function doValidate($columns = null)
1049: {
1050: if (!$this->alreadyInValidation) {
1051: $this->alreadyInValidation = true;
1052: $retval = null;
1053:
1054: $failureMap = array();
1055:
1056:
1057: if (($retval = MessagePeer::doValidate($this, $columns)) !== true) {
1058: $failureMap = array_merge($failureMap, $retval);
1059: }
1060:
1061:
1062: if ($this->collMessageI18ns !== null) {
1063: foreach ($this->collMessageI18ns as $referrerFK) {
1064: if (!$referrerFK->validate($columns)) {
1065: $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
1066: }
1067: }
1068: }
1069:
1070: if ($this->collMessageVersions !== null) {
1071: foreach ($this->collMessageVersions as $referrerFK) {
1072: if (!$referrerFK->validate($columns)) {
1073: $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
1074: }
1075: }
1076: }
1077:
1078:
1079: $this->alreadyInValidation = false;
1080: }
1081:
1082: return (!empty($failureMap) ? $failureMap : true);
1083: }
1084:
1085: 1086: 1087: 1088: 1089: 1090: 1091: 1092: 1093: 1094:
1095: public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
1096: {
1097: $pos = MessagePeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
1098: $field = $this->getByPosition($pos);
1099:
1100: return $field;
1101: }
1102:
1103: 1104: 1105: 1106: 1107: 1108: 1109:
1110: public function getByPosition($pos)
1111: {
1112: switch ($pos) {
1113: case 0:
1114: return $this->getId();
1115: break;
1116: case 1:
1117: return $this->getCode();
1118: break;
1119: case 2:
1120: return $this->getSecured();
1121: break;
1122: case 3:
1123: return $this->getRef();
1124: break;
1125: case 4:
1126: return $this->getCreatedAt();
1127: break;
1128: case 5:
1129: return $this->getUpdatedAt();
1130: break;
1131: case 6:
1132: return $this->getVersion();
1133: break;
1134: case 7:
1135: return $this->getVersionCreatedAt();
1136: break;
1137: case 8:
1138: return $this->getVersionCreatedBy();
1139: break;
1140: default:
1141: return null;
1142: break;
1143: }
1144: }
1145:
1146: 1147: 1148: 1149: 1150: 1151: 1152: 1153: 1154: 1155: 1156: 1157: 1158: 1159: 1160:
1161: public function toArray($keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false)
1162: {
1163: if (isset($alreadyDumpedObjects['Message'][$this->getPrimaryKey()])) {
1164: return '*RECURSION*';
1165: }
1166: $alreadyDumpedObjects['Message'][$this->getPrimaryKey()] = true;
1167: $keys = MessagePeer::getFieldNames($keyType);
1168: $result = array(
1169: $keys[0] => $this->getId(),
1170: $keys[1] => $this->getCode(),
1171: $keys[2] => $this->getSecured(),
1172: $keys[3] => $this->getRef(),
1173: $keys[4] => $this->getCreatedAt(),
1174: $keys[5] => $this->getUpdatedAt(),
1175: $keys[6] => $this->getVersion(),
1176: $keys[7] => $this->getVersionCreatedAt(),
1177: $keys[8] => $this->getVersionCreatedBy(),
1178: );
1179: if ($includeForeignObjects) {
1180: if (null !== $this->collMessageI18ns) {
1181: $result['MessageI18ns'] = $this->collMessageI18ns->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects);
1182: }
1183: if (null !== $this->collMessageVersions) {
1184: $result['MessageVersions'] = $this->collMessageVersions->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects);
1185: }
1186: }
1187:
1188: return $result;
1189: }
1190:
1191: 1192: 1193: 1194: 1195: 1196: 1197: 1198: 1199: 1200: 1201:
1202: public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
1203: {
1204: $pos = MessagePeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
1205:
1206: $this->setByPosition($pos, $value);
1207: }
1208:
1209: 1210: 1211: 1212: 1213: 1214: 1215: 1216:
1217: public function setByPosition($pos, $value)
1218: {
1219: switch ($pos) {
1220: case 0:
1221: $this->setId($value);
1222: break;
1223: case 1:
1224: $this->setCode($value);
1225: break;
1226: case 2:
1227: $this->setSecured($value);
1228: break;
1229: case 3:
1230: $this->setRef($value);
1231: break;
1232: case 4:
1233: $this->setCreatedAt($value);
1234: break;
1235: case 5:
1236: $this->setUpdatedAt($value);
1237: break;
1238: case 6:
1239: $this->setVersion($value);
1240: break;
1241: case 7:
1242: $this->setVersionCreatedAt($value);
1243: break;
1244: case 8:
1245: $this->setVersionCreatedBy($value);
1246: break;
1247: }
1248: }
1249:
1250: 1251: 1252: 1253: 1254: 1255: 1256: 1257: 1258: 1259: 1260: 1261: 1262: 1263: 1264: 1265: 1266:
1267: public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
1268: {
1269: $keys = MessagePeer::getFieldNames($keyType);
1270:
1271: if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
1272: if (array_key_exists($keys[1], $arr)) $this->setCode($arr[$keys[1]]);
1273: if (array_key_exists($keys[2], $arr)) $this->setSecured($arr[$keys[2]]);
1274: if (array_key_exists($keys[3], $arr)) $this->setRef($arr[$keys[3]]);
1275: if (array_key_exists($keys[4], $arr)) $this->setCreatedAt($arr[$keys[4]]);
1276: if (array_key_exists($keys[5], $arr)) $this->setUpdatedAt($arr[$keys[5]]);
1277: if (array_key_exists($keys[6], $arr)) $this->setVersion($arr[$keys[6]]);
1278: if (array_key_exists($keys[7], $arr)) $this->setVersionCreatedAt($arr[$keys[7]]);
1279: if (array_key_exists($keys[8], $arr)) $this->setVersionCreatedBy($arr[$keys[8]]);
1280: }
1281:
1282: 1283: 1284: 1285: 1286:
1287: public function buildCriteria()
1288: {
1289: $criteria = new Criteria(MessagePeer::DATABASE_NAME);
1290:
1291: if ($this->isColumnModified(MessagePeer::ID)) $criteria->add(MessagePeer::ID, $this->id);
1292: if ($this->isColumnModified(MessagePeer::CODE)) $criteria->add(MessagePeer::CODE, $this->code);
1293: if ($this->isColumnModified(MessagePeer::SECURED)) $criteria->add(MessagePeer::SECURED, $this->secured);
1294: if ($this->isColumnModified(MessagePeer::REF)) $criteria->add(MessagePeer::REF, $this->ref);
1295: if ($this->isColumnModified(MessagePeer::CREATED_AT)) $criteria->add(MessagePeer::CREATED_AT, $this->created_at);
1296: if ($this->isColumnModified(MessagePeer::UPDATED_AT)) $criteria->add(MessagePeer::UPDATED_AT, $this->updated_at);
1297: if ($this->isColumnModified(MessagePeer::VERSION)) $criteria->add(MessagePeer::VERSION, $this->version);
1298: if ($this->isColumnModified(MessagePeer::VERSION_CREATED_AT)) $criteria->add(MessagePeer::VERSION_CREATED_AT, $this->version_created_at);
1299: if ($this->isColumnModified(MessagePeer::VERSION_CREATED_BY)) $criteria->add(MessagePeer::VERSION_CREATED_BY, $this->version_created_by);
1300:
1301: return $criteria;
1302: }
1303:
1304: 1305: 1306: 1307: 1308: 1309: 1310: 1311:
1312: public function buildPkeyCriteria()
1313: {
1314: $criteria = new Criteria(MessagePeer::DATABASE_NAME);
1315: $criteria->add(MessagePeer::ID, $this->id);
1316:
1317: return $criteria;
1318: }
1319:
1320: 1321: 1322: 1323:
1324: public function getPrimaryKey()
1325: {
1326: return $this->getId();
1327: }
1328:
1329: 1330: 1331: 1332: 1333: 1334:
1335: public function setPrimaryKey($key)
1336: {
1337: $this->setId($key);
1338: }
1339:
1340: 1341: 1342: 1343:
1344: public function isPrimaryKeyNull()
1345: {
1346:
1347: return null === $this->getId();
1348: }
1349:
1350: 1351: 1352: 1353: 1354: 1355: 1356: 1357: 1358: 1359: 1360:
1361: public function copyInto($copyObj, $deepCopy = false, $makeNew = true)
1362: {
1363: $copyObj->setCode($this->getCode());
1364: $copyObj->setSecured($this->getSecured());
1365: $copyObj->setRef($this->getRef());
1366: $copyObj->setCreatedAt($this->getCreatedAt());
1367: $copyObj->setUpdatedAt($this->getUpdatedAt());
1368: $copyObj->setVersion($this->getVersion());
1369: $copyObj->setVersionCreatedAt($this->getVersionCreatedAt());
1370: $copyObj->setVersionCreatedBy($this->getVersionCreatedBy());
1371:
1372: if ($deepCopy && !$this->startCopy) {
1373:
1374:
1375: $copyObj->setNew(false);
1376:
1377: $this->startCopy = true;
1378:
1379: foreach ($this->getMessageI18ns() as $relObj) {
1380: if ($relObj !== $this) {
1381: $copyObj->addMessageI18n($relObj->copy($deepCopy));
1382: }
1383: }
1384:
1385: foreach ($this->getMessageVersions() as $relObj) {
1386: if ($relObj !== $this) {
1387: $copyObj->addMessageVersion($relObj->copy($deepCopy));
1388: }
1389: }
1390:
1391:
1392: $this->startCopy = false;
1393: }
1394:
1395: if ($makeNew) {
1396: $copyObj->setNew(true);
1397: $copyObj->setId(NULL);
1398: }
1399: }
1400:
1401: 1402: 1403: 1404: 1405: 1406: 1407: 1408: 1409: 1410: 1411: 1412:
1413: public function copy($deepCopy = false)
1414: {
1415:
1416: $clazz = get_class($this);
1417: $copyObj = new $clazz();
1418: $this->copyInto($copyObj, $deepCopy);
1419:
1420: return $copyObj;
1421: }
1422:
1423: 1424: 1425: 1426: 1427: 1428: 1429: 1430: 1431:
1432: public function getPeer()
1433: {
1434: if (self::$peer === null) {
1435: self::$peer = new MessagePeer();
1436: }
1437:
1438: return self::$peer;
1439: }
1440:
1441:
1442: 1443: 1444: 1445: 1446: 1447: 1448: 1449:
1450: public function initRelation($relationName)
1451: {
1452: if ('MessageI18n' == $relationName) {
1453: $this->initMessageI18ns();
1454: }
1455: if ('MessageVersion' == $relationName) {
1456: $this->initMessageVersions();
1457: }
1458: }
1459:
1460: 1461: 1462: 1463: 1464: 1465: 1466: 1467: 1468:
1469: public function clearMessageI18ns()
1470: {
1471: $this->collMessageI18ns = null;
1472: $this->collMessageI18nsPartial = null;
1473:
1474: return $this;
1475: }
1476:
1477: 1478: 1479: 1480: 1481:
1482: public function resetPartialMessageI18ns($v = true)
1483: {
1484: $this->collMessageI18nsPartial = $v;
1485: }
1486:
1487: 1488: 1489: 1490: 1491: 1492: 1493: 1494: 1495: 1496: 1497: 1498:
1499: public function initMessageI18ns($overrideExisting = true)
1500: {
1501: if (null !== $this->collMessageI18ns && !$overrideExisting) {
1502: return;
1503: }
1504: $this->collMessageI18ns = new PropelObjectCollection();
1505: $this->collMessageI18ns->setModel('MessageI18n');
1506: }
1507:
1508: 1509: 1510: 1511: 1512: 1513: 1514: 1515: 1516: 1517: 1518: 1519: 1520: 1521:
1522: public function getMessageI18ns($criteria = null, PropelPDO $con = null)
1523: {
1524: $partial = $this->collMessageI18nsPartial && !$this->isNew();
1525: if (null === $this->collMessageI18ns || null !== $criteria || $partial) {
1526: if ($this->isNew() && null === $this->collMessageI18ns) {
1527:
1528: $this->initMessageI18ns();
1529: } else {
1530: $collMessageI18ns = MessageI18nQuery::create(null, $criteria)
1531: ->filterByMessage($this)
1532: ->find($con);
1533: if (null !== $criteria) {
1534: if (false !== $this->collMessageI18nsPartial && count($collMessageI18ns)) {
1535: $this->initMessageI18ns(false);
1536:
1537: foreach($collMessageI18ns as $obj) {
1538: if (false == $this->collMessageI18ns->contains($obj)) {
1539: $this->collMessageI18ns->append($obj);
1540: }
1541: }
1542:
1543: $this->collMessageI18nsPartial = true;
1544: }
1545:
1546: $collMessageI18ns->getInternalIterator()->rewind();
1547: return $collMessageI18ns;
1548: }
1549:
1550: if($partial && $this->collMessageI18ns) {
1551: foreach($this->collMessageI18ns as $obj) {
1552: if($obj->isNew()) {
1553: $collMessageI18ns[] = $obj;
1554: }
1555: }
1556: }
1557:
1558: $this->collMessageI18ns = $collMessageI18ns;
1559: $this->collMessageI18nsPartial = false;
1560: }
1561: }
1562:
1563: return $this->collMessageI18ns;
1564: }
1565:
1566: 1567: 1568: 1569: 1570: 1571: 1572: 1573: 1574: 1575:
1576: public function setMessageI18ns(PropelCollection $messageI18ns, PropelPDO $con = null)
1577: {
1578: $messageI18nsToDelete = $this->getMessageI18ns(new Criteria(), $con)->diff($messageI18ns);
1579:
1580: $this->messageI18nsScheduledForDeletion = unserialize(serialize($messageI18nsToDelete));
1581:
1582: foreach ($messageI18nsToDelete as $messageI18nRemoved) {
1583: $messageI18nRemoved->setMessage(null);
1584: }
1585:
1586: $this->collMessageI18ns = null;
1587: foreach ($messageI18ns as $messageI18n) {
1588: $this->addMessageI18n($messageI18n);
1589: }
1590:
1591: $this->collMessageI18ns = $messageI18ns;
1592: $this->collMessageI18nsPartial = false;
1593:
1594: return $this;
1595: }
1596:
1597: 1598: 1599: 1600: 1601: 1602: 1603: 1604: 1605:
1606: public function countMessageI18ns(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
1607: {
1608: $partial = $this->collMessageI18nsPartial && !$this->isNew();
1609: if (null === $this->collMessageI18ns || null !== $criteria || $partial) {
1610: if ($this->isNew() && null === $this->collMessageI18ns) {
1611: return 0;
1612: }
1613:
1614: if($partial && !$criteria) {
1615: return count($this->getMessageI18ns());
1616: }
1617: $query = MessageI18nQuery::create(null, $criteria);
1618: if ($distinct) {
1619: $query->distinct();
1620: }
1621:
1622: return $query
1623: ->filterByMessage($this)
1624: ->count($con);
1625: }
1626:
1627: return count($this->collMessageI18ns);
1628: }
1629:
1630: 1631: 1632: 1633: 1634: 1635: 1636:
1637: public function addMessageI18n(MessageI18n $l)
1638: {
1639: if ($l && $locale = $l->getLocale()) {
1640: $this->setLocale($locale);
1641: $this->currentTranslations[$locale] = $l;
1642: }
1643: if ($this->collMessageI18ns === null) {
1644: $this->initMessageI18ns();
1645: $this->collMessageI18nsPartial = true;
1646: }
1647: if (!in_array($l, $this->collMessageI18ns->getArrayCopy(), true)) {
1648: $this->doAddMessageI18n($l);
1649: }
1650:
1651: return $this;
1652: }
1653:
1654: 1655: 1656:
1657: protected function doAddMessageI18n($messageI18n)
1658: {
1659: $this->collMessageI18ns[]= $messageI18n;
1660: $messageI18n->setMessage($this);
1661: }
1662:
1663: 1664: 1665: 1666:
1667: public function removeMessageI18n($messageI18n)
1668: {
1669: if ($this->getMessageI18ns()->contains($messageI18n)) {
1670: $this->collMessageI18ns->remove($this->collMessageI18ns->search($messageI18n));
1671: if (null === $this->messageI18nsScheduledForDeletion) {
1672: $this->messageI18nsScheduledForDeletion = clone $this->collMessageI18ns;
1673: $this->messageI18nsScheduledForDeletion->clear();
1674: }
1675: $this->messageI18nsScheduledForDeletion[]= clone $messageI18n;
1676: $messageI18n->setMessage(null);
1677: }
1678:
1679: return $this;
1680: }
1681:
1682: 1683: 1684: 1685: 1686: 1687: 1688: 1689: 1690:
1691: public function clearMessageVersions()
1692: {
1693: $this->collMessageVersions = null;
1694: $this->collMessageVersionsPartial = null;
1695:
1696: return $this;
1697: }
1698:
1699: 1700: 1701: 1702: 1703:
1704: public function resetPartialMessageVersions($v = true)
1705: {
1706: $this->collMessageVersionsPartial = $v;
1707: }
1708:
1709: 1710: 1711: 1712: 1713: 1714: 1715: 1716: 1717: 1718: 1719: 1720:
1721: public function initMessageVersions($overrideExisting = true)
1722: {
1723: if (null !== $this->collMessageVersions && !$overrideExisting) {
1724: return;
1725: }
1726: $this->collMessageVersions = new PropelObjectCollection();
1727: $this->collMessageVersions->setModel('MessageVersion');
1728: }
1729:
1730: 1731: 1732: 1733: 1734: 1735: 1736: 1737: 1738: 1739: 1740: 1741: 1742: 1743:
1744: public function getMessageVersions($criteria = null, PropelPDO $con = null)
1745: {
1746: $partial = $this->collMessageVersionsPartial && !$this->isNew();
1747: if (null === $this->collMessageVersions || null !== $criteria || $partial) {
1748: if ($this->isNew() && null === $this->collMessageVersions) {
1749:
1750: $this->initMessageVersions();
1751: } else {
1752: $collMessageVersions = MessageVersionQuery::create(null, $criteria)
1753: ->filterByMessage($this)
1754: ->find($con);
1755: if (null !== $criteria) {
1756: if (false !== $this->collMessageVersionsPartial && count($collMessageVersions)) {
1757: $this->initMessageVersions(false);
1758:
1759: foreach($collMessageVersions as $obj) {
1760: if (false == $this->collMessageVersions->contains($obj)) {
1761: $this->collMessageVersions->append($obj);
1762: }
1763: }
1764:
1765: $this->collMessageVersionsPartial = true;
1766: }
1767:
1768: $collMessageVersions->getInternalIterator()->rewind();
1769: return $collMessageVersions;
1770: }
1771:
1772: if($partial && $this->collMessageVersions) {
1773: foreach($this->collMessageVersions as $obj) {
1774: if($obj->isNew()) {
1775: $collMessageVersions[] = $obj;
1776: }
1777: }
1778: }
1779:
1780: $this->collMessageVersions = $collMessageVersions;
1781: $this->collMessageVersionsPartial = false;
1782: }
1783: }
1784:
1785: return $this->collMessageVersions;
1786: }
1787:
1788: 1789: 1790: 1791: 1792: 1793: 1794: 1795: 1796: 1797:
1798: public function setMessageVersions(PropelCollection $messageVersions, PropelPDO $con = null)
1799: {
1800: $messageVersionsToDelete = $this->getMessageVersions(new Criteria(), $con)->diff($messageVersions);
1801:
1802: $this->messageVersionsScheduledForDeletion = unserialize(serialize($messageVersionsToDelete));
1803:
1804: foreach ($messageVersionsToDelete as $messageVersionRemoved) {
1805: $messageVersionRemoved->setMessage(null);
1806: }
1807:
1808: $this->collMessageVersions = null;
1809: foreach ($messageVersions as $messageVersion) {
1810: $this->addMessageVersion($messageVersion);
1811: }
1812:
1813: $this->collMessageVersions = $messageVersions;
1814: $this->collMessageVersionsPartial = false;
1815:
1816: return $this;
1817: }
1818:
1819: 1820: 1821: 1822: 1823: 1824: 1825: 1826: 1827:
1828: public function countMessageVersions(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
1829: {
1830: $partial = $this->collMessageVersionsPartial && !$this->isNew();
1831: if (null === $this->collMessageVersions || null !== $criteria || $partial) {
1832: if ($this->isNew() && null === $this->collMessageVersions) {
1833: return 0;
1834: }
1835:
1836: if($partial && !$criteria) {
1837: return count($this->getMessageVersions());
1838: }
1839: $query = MessageVersionQuery::create(null, $criteria);
1840: if ($distinct) {
1841: $query->distinct();
1842: }
1843:
1844: return $query
1845: ->filterByMessage($this)
1846: ->count($con);
1847: }
1848:
1849: return count($this->collMessageVersions);
1850: }
1851:
1852: 1853: 1854: 1855: 1856: 1857: 1858:
1859: public function addMessageVersion(MessageVersion $l)
1860: {
1861: if ($this->collMessageVersions === null) {
1862: $this->initMessageVersions();
1863: $this->collMessageVersionsPartial = true;
1864: }
1865: if (!in_array($l, $this->collMessageVersions->getArrayCopy(), true)) {
1866: $this->doAddMessageVersion($l);
1867: }
1868:
1869: return $this;
1870: }
1871:
1872: 1873: 1874:
1875: protected function doAddMessageVersion($messageVersion)
1876: {
1877: $this->collMessageVersions[]= $messageVersion;
1878: $messageVersion->setMessage($this);
1879: }
1880:
1881: 1882: 1883: 1884:
1885: public function removeMessageVersion($messageVersion)
1886: {
1887: if ($this->getMessageVersions()->contains($messageVersion)) {
1888: $this->collMessageVersions->remove($this->collMessageVersions->search($messageVersion));
1889: if (null === $this->messageVersionsScheduledForDeletion) {
1890: $this->messageVersionsScheduledForDeletion = clone $this->collMessageVersions;
1891: $this->messageVersionsScheduledForDeletion->clear();
1892: }
1893: $this->messageVersionsScheduledForDeletion[]= clone $messageVersion;
1894: $messageVersion->setMessage(null);
1895: }
1896:
1897: return $this;
1898: }
1899:
1900: 1901: 1902:
1903: public function clear()
1904: {
1905: $this->id = null;
1906: $this->code = null;
1907: $this->secured = null;
1908: $this->ref = null;
1909: $this->created_at = null;
1910: $this->updated_at = null;
1911: $this->version = null;
1912: $this->version_created_at = null;
1913: $this->version_created_by = null;
1914: $this->alreadyInSave = false;
1915: $this->alreadyInValidation = false;
1916: $this->alreadyInClearAllReferencesDeep = false;
1917: $this->clearAllReferences();
1918: $this->applyDefaultValues();
1919: $this->resetModified();
1920: $this->setNew(true);
1921: $this->setDeleted(false);
1922: }
1923:
1924: 1925: 1926: 1927: 1928: 1929: 1930: 1931: 1932:
1933: public function clearAllReferences($deep = false)
1934: {
1935: if ($deep && !$this->alreadyInClearAllReferencesDeep) {
1936: $this->alreadyInClearAllReferencesDeep = true;
1937: if ($this->collMessageI18ns) {
1938: foreach ($this->collMessageI18ns as $o) {
1939: $o->clearAllReferences($deep);
1940: }
1941: }
1942: if ($this->collMessageVersions) {
1943: foreach ($this->collMessageVersions as $o) {
1944: $o->clearAllReferences($deep);
1945: }
1946: }
1947:
1948: $this->alreadyInClearAllReferencesDeep = false;
1949: }
1950:
1951:
1952: $this->currentLocale = 'en_US';
1953: $this->currentTranslations = null;
1954:
1955: if ($this->collMessageI18ns instanceof PropelCollection) {
1956: $this->collMessageI18ns->clearIterator();
1957: }
1958: $this->collMessageI18ns = null;
1959: if ($this->collMessageVersions instanceof PropelCollection) {
1960: $this->collMessageVersions->clearIterator();
1961: }
1962: $this->collMessageVersions = null;
1963: }
1964:
1965: 1966: 1967: 1968: 1969:
1970: public function __toString()
1971: {
1972: return (string) $this->exportTo(MessagePeer::DEFAULT_STRING_FORMAT);
1973: }
1974:
1975: 1976: 1977: 1978: 1979:
1980: public function isAlreadyInSave()
1981: {
1982: return $this->alreadyInSave;
1983: }
1984:
1985:
1986:
1987: 1988: 1989: 1990: 1991:
1992: public function keepUpdateDateUnchanged()
1993: {
1994: $this->modifiedColumns[] = MessagePeer::UPDATED_AT;
1995:
1996: return $this;
1997: }
1998:
1999:
2000:
2001: 2002: 2003: 2004: 2005: 2006: 2007:
2008: public function setLocale($locale = 'en_US')
2009: {
2010: $this->currentLocale = $locale;
2011:
2012: return $this;
2013: }
2014:
2015: 2016: 2017: 2018: 2019:
2020: public function getLocale()
2021: {
2022: return $this->currentLocale;
2023: }
2024:
2025: 2026: 2027: 2028: 2029: 2030: 2031:
2032: public function getTranslation($locale = 'en_US', PropelPDO $con = null)
2033: {
2034: if (!isset($this->currentTranslations[$locale])) {
2035: if (null !== $this->collMessageI18ns) {
2036: foreach ($this->collMessageI18ns as $translation) {
2037: if ($translation->getLocale() == $locale) {
2038: $this->currentTranslations[$locale] = $translation;
2039:
2040: return $translation;
2041: }
2042: }
2043: }
2044: if ($this->isNew()) {
2045: $translation = new MessageI18n();
2046: $translation->setLocale($locale);
2047: } else {
2048: $translation = MessageI18nQuery::create()
2049: ->filterByPrimaryKey(array($this->getPrimaryKey(), $locale))
2050: ->findOneOrCreate($con);
2051: $this->currentTranslations[$locale] = $translation;
2052: }
2053: $this->addMessageI18n($translation);
2054: }
2055:
2056: return $this->currentTranslations[$locale];
2057: }
2058:
2059: 2060: 2061: 2062: 2063: 2064: 2065: 2066:
2067: public function removeTranslation($locale = 'en_US', PropelPDO $con = null)
2068: {
2069: if (!$this->isNew()) {
2070: MessageI18nQuery::create()
2071: ->filterByPrimaryKey(array($this->getPrimaryKey(), $locale))
2072: ->delete($con);
2073: }
2074: if (isset($this->currentTranslations[$locale])) {
2075: unset($this->currentTranslations[$locale]);
2076: }
2077: foreach ($this->collMessageI18ns as $key => $translation) {
2078: if ($translation->getLocale() == $locale) {
2079: unset($this->collMessageI18ns[$key]);
2080: break;
2081: }
2082: }
2083:
2084: return $this;
2085: }
2086:
2087: 2088: 2089: 2090: 2091: 2092:
2093: public function getCurrentTranslation(PropelPDO $con = null)
2094: {
2095: return $this->getTranslation($this->getLocale(), $con);
2096: }
2097:
2098:
2099: 2100: 2101: 2102: 2103:
2104: public function getTitle()
2105: {
2106: return $this->getCurrentTranslation()->getTitle();
2107: }
2108:
2109:
2110: 2111: 2112: 2113: 2114: 2115:
2116: public function setTitle($v)
2117: { $this->getCurrentTranslation()->setTitle($v);
2118:
2119: return $this;
2120: }
2121:
2122:
2123: 2124: 2125: 2126: 2127:
2128: public function getDescription()
2129: {
2130: return $this->getCurrentTranslation()->getDescription();
2131: }
2132:
2133:
2134: 2135: 2136: 2137: 2138: 2139:
2140: public function setDescription($v)
2141: { $this->getCurrentTranslation()->setDescription($v);
2142:
2143: return $this;
2144: }
2145:
2146:
2147: 2148: 2149: 2150: 2151:
2152: public function getDescriptionHtml()
2153: {
2154: return $this->getCurrentTranslation()->getDescriptionHtml();
2155: }
2156:
2157:
2158: 2159: 2160: 2161: 2162: 2163:
2164: public function setDescriptionHtml($v)
2165: { $this->getCurrentTranslation()->setDescriptionHtml($v);
2166:
2167: return $this;
2168: }
2169:
2170:
2171:
2172: 2173: 2174: 2175: 2176:
2177: public function enforceVersioning()
2178: {
2179: $this->enforceVersion = true;
2180:
2181: return $this;
2182: }
2183:
2184: 2185: 2186: 2187: 2188: 2189: 2190:
2191: public function isVersioningNecessary($con = null)
2192: {
2193: if ($this->alreadyInSave) {
2194: return false;
2195: }
2196:
2197: if ($this->enforceVersion) {
2198: return true;
2199: }
2200:
2201: if (MessagePeer::isVersioningEnabled() && ($this->isNew() || $this->isModified() || $this->isDeleted())) {
2202: return true;
2203: }
2204:
2205: return false;
2206: }
2207:
2208: 2209: 2210: 2211: 2212: 2213: 2214:
2215: public function addVersion($con = null)
2216: {
2217: $this->enforceVersion = false;
2218:
2219: $version = new MessageVersion();
2220: $version->setId($this->getId());
2221: $version->setCode($this->getCode());
2222: $version->setSecured($this->getSecured());
2223: $version->setRef($this->getRef());
2224: $version->setCreatedAt($this->getCreatedAt());
2225: $version->setUpdatedAt($this->getUpdatedAt());
2226: $version->setVersion($this->getVersion());
2227: $version->setVersionCreatedAt($this->getVersionCreatedAt());
2228: $version->setVersionCreatedBy($this->getVersionCreatedBy());
2229: $version->setMessage($this);
2230: $version->save($con);
2231:
2232: return $version;
2233: }
2234:
2235: 2236: 2237: 2238: 2239: 2240: 2241: 2242: 2243:
2244: public function toVersion($versionNumber, $con = null)
2245: {
2246: $version = $this->getOneVersion($versionNumber, $con);
2247: if (!$version) {
2248: throw new PropelException(sprintf('No Message object found with version %d', $version));
2249: }
2250: $this->populateFromVersion($version, $con);
2251:
2252: return $this;
2253: }
2254:
2255: 2256: 2257: 2258: 2259: 2260: 2261: 2262: 2263:
2264: public function populateFromVersion($version, $con = null, &$loadedObjects = array())
2265: {
2266:
2267: $loadedObjects['Message'][$version->getId()][$version->getVersion()] = $this;
2268: $this->setId($version->getId());
2269: $this->setCode($version->getCode());
2270: $this->setSecured($version->getSecured());
2271: $this->setRef($version->getRef());
2272: $this->setCreatedAt($version->getCreatedAt());
2273: $this->setUpdatedAt($version->getUpdatedAt());
2274: $this->setVersion($version->getVersion());
2275: $this->setVersionCreatedAt($version->getVersionCreatedAt());
2276: $this->setVersionCreatedBy($version->getVersionCreatedBy());
2277:
2278: return $this;
2279: }
2280:
2281: 2282: 2283: 2284: 2285: 2286: 2287:
2288: public function getLastVersionNumber($con = null)
2289: {
2290: $v = MessageVersionQuery::create()
2291: ->filterByMessage($this)
2292: ->orderByVersion('desc')
2293: ->findOne($con);
2294: if (!$v) {
2295: return 0;
2296: }
2297:
2298: return $v->getVersion();
2299: }
2300:
2301: 2302: 2303: 2304: 2305: 2306: 2307:
2308: public function isLastVersion($con = null)
2309: {
2310: return $this->getLastVersionNumber($con) == $this->getVersion();
2311: }
2312:
2313: 2314: 2315: 2316: 2317: 2318: 2319: 2320:
2321: public function getOneVersion($versionNumber, $con = null)
2322: {
2323: return MessageVersionQuery::create()
2324: ->filterByMessage($this)
2325: ->filterByVersion($versionNumber)
2326: ->findOne($con);
2327: }
2328:
2329: 2330: 2331: 2332: 2333: 2334: 2335:
2336: public function getAllVersions($con = null)
2337: {
2338: $criteria = new Criteria();
2339: $criteria->addAscendingOrderByColumn(MessageVersionPeer::VERSION);
2340:
2341: return $this->getMessageVersions($criteria, $con);
2342: }
2343:
2344: 2345: 2346: 2347: 2348: 2349: 2350: 2351: 2352: 2353: 2354: 2355: 2356: 2357: 2358: 2359: 2360:
2361: public function compareVersion($versionNumber, $keys = 'columns', $con = null, $ignoredColumns = array())
2362: {
2363: $fromVersion = $this->toArray();
2364: $toVersion = $this->getOneVersion($versionNumber, $con)->toArray();
2365:
2366: return $this->computeDiff($fromVersion, $toVersion, $keys, $ignoredColumns);
2367: }
2368:
2369: 2370: 2371: 2372: 2373: 2374: 2375: 2376: 2377: 2378: 2379: 2380: 2381: 2382: 2383: 2384: 2385: 2386:
2387: public function compareVersions($fromVersionNumber, $toVersionNumber, $keys = 'columns', $con = null, $ignoredColumns = array())
2388: {
2389: $fromVersion = $this->getOneVersion($fromVersionNumber, $con)->toArray();
2390: $toVersion = $this->getOneVersion($toVersionNumber, $con)->toArray();
2391:
2392: return $this->computeDiff($fromVersion, $toVersion, $keys, $ignoredColumns);
2393: }
2394:
2395: 2396: 2397: 2398: 2399: 2400: 2401: 2402: 2403: 2404: 2405: 2406: 2407: 2408: 2409: 2410: 2411:
2412: protected function computeDiff($fromVersion, $toVersion, $keys = 'columns', $ignoredColumns = array())
2413: {
2414: $fromVersionNumber = $fromVersion['Version'];
2415: $toVersionNumber = $toVersion['Version'];
2416: $ignoredColumns = array_merge(array(
2417: 'Version',
2418: 'VersionCreatedAt',
2419: 'VersionCreatedBy',
2420: ), $ignoredColumns);
2421: $diff = array();
2422: foreach ($fromVersion as $key => $value) {
2423: if (in_array($key, $ignoredColumns)) {
2424: continue;
2425: }
2426: if ($toVersion[$key] != $value) {
2427: switch ($keys) {
2428: case 'versions':
2429: $diff[$fromVersionNumber][$key] = $value;
2430: $diff[$toVersionNumber][$key] = $toVersion[$key];
2431: break;
2432: default:
2433: $diff[$key] = array(
2434: $fromVersionNumber => $value,
2435: $toVersionNumber => $toVersion[$key],
2436: );
2437: break;
2438: }
2439: }
2440: }
2441:
2442: return $diff;
2443: }
2444: 2445: 2446: 2447: 2448: 2449: 2450: 2451: 2452:
2453: public function getLastVersions($number = 10, $criteria = null, PropelPDO $con = null)
2454: {
2455: $criteria = MessageVersionQuery::create(null, $criteria);
2456: $criteria->addDescendingOrderByColumn(MessageVersionPeer::VERSION);
2457: $criteria->limit($number);
2458:
2459: return $this->getMessageVersions($criteria, $con);
2460: }
2461: }
2462: