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