1: <?php
2:
3: namespace Thelia\Model\om;
4:
5: use \BaseObject;
6: use \BasePeer;
7: use \Criteria;
8: use \DateTime;
9: use \Exception;
10: use \PDO;
11: use \Persistent;
12: use \Propel;
13: use \PropelDateTime;
14: use \PropelException;
15: use \PropelPDO;
16: use Thelia\Model\Lang;
17: use Thelia\Model\LangPeer;
18: use Thelia\Model\LangQuery;
19:
20: /**
21: * Base class that represents a row from the 'lang' table.
22: *
23: *
24: *
25: * @package propel.generator.Thelia.Model.om
26: */
27: abstract class BaseLang extends BaseObject implements Persistent
28: {
29: /**
30: * Peer class name
31: */
32: const PEER = 'Thelia\\Model\\LangPeer';
33:
34: /**
35: * The Peer class.
36: * Instance provides a convenient way of calling static methods on a class
37: * that calling code may not be able to identify.
38: * @var LangPeer
39: */
40: protected static $peer;
41:
42: /**
43: * The flag var to prevent infinit loop in deep copy
44: * @var boolean
45: */
46: protected $startCopy = false;
47:
48: /**
49: * The value for the id field.
50: * @var int
51: */
52: protected $id;
53:
54: /**
55: * The value for the title field.
56: * @var string
57: */
58: protected $title;
59:
60: /**
61: * The value for the code field.
62: * @var string
63: */
64: protected $code;
65:
66: /**
67: * The value for the locale field.
68: * @var string
69: */
70: protected $locale;
71:
72: /**
73: * The value for the url field.
74: * @var string
75: */
76: protected $url;
77:
78: /**
79: * The value for the by_default field.
80: * @var int
81: */
82: protected $by_default;
83:
84: /**
85: * The value for the created_at field.
86: * @var string
87: */
88: protected $created_at;
89:
90: /**
91: * The value for the updated_at field.
92: * @var string
93: */
94: protected $updated_at;
95:
96: /**
97: * Flag to prevent endless save loop, if this object is referenced
98: * by another object which falls in this transaction.
99: * @var boolean
100: */
101: protected $alreadyInSave = false;
102:
103: /**
104: * Flag to prevent endless validation loop, if this object is referenced
105: * by another object which falls in this transaction.
106: * @var boolean
107: */
108: protected $alreadyInValidation = false;
109:
110: /**
111: * Get the [id] column value.
112: *
113: * @return int
114: */
115: public function getId()
116: {
117: return $this->id;
118: }
119:
120: /**
121: * Get the [title] column value.
122: *
123: * @return string
124: */
125: public function getTitle()
126: {
127: return $this->title;
128: }
129:
130: /**
131: * Get the [code] column value.
132: *
133: * @return string
134: */
135: public function getCode()
136: {
137: return $this->code;
138: }
139:
140: /**
141: * Get the [locale] column value.
142: *
143: * @return string
144: */
145: public function getLocale()
146: {
147: return $this->locale;
148: }
149:
150: /**
151: * Get the [url] column value.
152: *
153: * @return string
154: */
155: public function getUrl()
156: {
157: return $this->url;
158: }
159:
160: /**
161: * Get the [by_default] column value.
162: *
163: * @return int
164: */
165: public function getByDefault()
166: {
167: return $this->by_default;
168: }
169:
170: /**
171: * Get the [optionally formatted] temporal [created_at] column value.
172: *
173: *
174: * @param string $format The date/time format string (either date()-style or strftime()-style).
175: * If format is null, then the raw DateTime object will be returned.
176: * @return mixed Formatted date/time value as string or DateTime object (if format is null), null if column is null, and 0 if column value is 0000-00-00 00:00:00
177: * @throws PropelException - if unable to parse/validate the date/time value.
178: */
179: public function getCreatedAt($format = 'Y-m-d H:i:s')
180: {
181: if ($this->created_at === null) {
182: return null;
183: }
184:
185: if ($this->created_at === '0000-00-00 00:00:00') {
186: // while technically this is not a default value of null,
187: // this seems to be closest in meaning.
188: return null;
189: } else {
190: try {
191: $dt = new DateTime($this->created_at);
192: } catch (Exception $x) {
193: throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->created_at, true), $x);
194: }
195: }
196:
197: if ($format === null) {
198: // Because propel.useDateTimeClass is true, we return a DateTime object.
199: return $dt;
200: } elseif (strpos($format, '%') !== false) {
201: return strftime($format, $dt->format('U'));
202: } else {
203: return $dt->format($format);
204: }
205: }
206:
207: /**
208: * Get the [optionally formatted] temporal [updated_at] column value.
209: *
210: *
211: * @param string $format The date/time format string (either date()-style or strftime()-style).
212: * If format is null, then the raw DateTime object will be returned.
213: * @return mixed Formatted date/time value as string or DateTime object (if format is null), null if column is null, and 0 if column value is 0000-00-00 00:00:00
214: * @throws PropelException - if unable to parse/validate the date/time value.
215: */
216: public function getUpdatedAt($format = 'Y-m-d H:i:s')
217: {
218: if ($this->updated_at === null) {
219: return null;
220: }
221:
222: if ($this->updated_at === '0000-00-00 00:00:00') {
223: // while technically this is not a default value of null,
224: // this seems to be closest in meaning.
225: return null;
226: } else {
227: try {
228: $dt = new DateTime($this->updated_at);
229: } catch (Exception $x) {
230: throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->updated_at, true), $x);
231: }
232: }
233:
234: if ($format === null) {
235: // Because propel.useDateTimeClass is true, we return a DateTime object.
236: return $dt;
237: } elseif (strpos($format, '%') !== false) {
238: return strftime($format, $dt->format('U'));
239: } else {
240: return $dt->format($format);
241: }
242: }
243:
244: /**
245: * Set the value of [id] column.
246: *
247: * @param int $v new value
248: * @return Lang The current object (for fluent API support)
249: */
250: public function setId($v)
251: {
252: if ($v !== null) {
253: $v = (int) $v;
254: }
255:
256: if ($this->id !== $v) {
257: $this->id = $v;
258: $this->modifiedColumns[] = LangPeer::ID;
259: }
260:
261:
262: return $this;
263: } // setId()
264:
265: /**
266: * Set the value of [title] column.
267: *
268: * @param string $v new value
269: * @return Lang The current object (for fluent API support)
270: */
271: public function setTitle($v)
272: {
273: if ($v !== null) {
274: $v = (string) $v;
275: }
276:
277: if ($this->title !== $v) {
278: $this->title = $v;
279: $this->modifiedColumns[] = LangPeer::TITLE;
280: }
281:
282:
283: return $this;
284: } // setTitle()
285:
286: /**
287: * Set the value of [code] column.
288: *
289: * @param string $v new value
290: * @return Lang The current object (for fluent API support)
291: */
292: public function setCode($v)
293: {
294: if ($v !== null) {
295: $v = (string) $v;
296: }
297:
298: if ($this->code !== $v) {
299: $this->code = $v;
300: $this->modifiedColumns[] = LangPeer::CODE;
301: }
302:
303:
304: return $this;
305: } // setCode()
306:
307: /**
308: * Set the value of [locale] column.
309: *
310: * @param string $v new value
311: * @return Lang The current object (for fluent API support)
312: */
313: public function setLocale($v)
314: {
315: if ($v !== null) {
316: $v = (string) $v;
317: }
318:
319: if ($this->locale !== $v) {
320: $this->locale = $v;
321: $this->modifiedColumns[] = LangPeer::LOCALE;
322: }
323:
324:
325: return $this;
326: } // setLocale()
327:
328: /**
329: * Set the value of [url] column.
330: *
331: * @param string $v new value
332: * @return Lang The current object (for fluent API support)
333: */
334: public function setUrl($v)
335: {
336: if ($v !== null) {
337: $v = (string) $v;
338: }
339:
340: if ($this->url !== $v) {
341: $this->url = $v;
342: $this->modifiedColumns[] = LangPeer::URL;
343: }
344:
345:
346: return $this;
347: } // setUrl()
348:
349: /**
350: * Set the value of [by_default] column.
351: *
352: * @param int $v new value
353: * @return Lang The current object (for fluent API support)
354: */
355: public function setByDefault($v)
356: {
357: if ($v !== null) {
358: $v = (int) $v;
359: }
360:
361: if ($this->by_default !== $v) {
362: $this->by_default = $v;
363: $this->modifiedColumns[] = LangPeer::BY_DEFAULT;
364: }
365:
366:
367: return $this;
368: } // setByDefault()
369:
370: /**
371: * Sets the value of [created_at] column to a normalized version of the date/time value specified.
372: *
373: * @param mixed $v string, integer (timestamp), or DateTime value.
374: * Empty strings are treated as null.
375: * @return Lang The current object (for fluent API support)
376: */
377: public function setCreatedAt($v)
378: {
379: $dt = PropelDateTime::newInstance($v, null, 'DateTime');
380: if ($this->created_at !== null || $dt !== null) {
381: $currentDateAsString = ($this->created_at !== null && $tmpDt = new DateTime($this->created_at)) ? $tmpDt->format('Y-m-d H:i:s') : null;
382: $newDateAsString = $dt ? $dt->format('Y-m-d H:i:s') : null;
383: if ($currentDateAsString !== $newDateAsString) {
384: $this->created_at = $newDateAsString;
385: $this->modifiedColumns[] = LangPeer::CREATED_AT;
386: }
387: } // if either are not null
388:
389:
390: return $this;
391: } // setCreatedAt()
392:
393: /**
394: * Sets the value of [updated_at] column to a normalized version of the date/time value specified.
395: *
396: * @param mixed $v string, integer (timestamp), or DateTime value.
397: * Empty strings are treated as null.
398: * @return Lang The current object (for fluent API support)
399: */
400: public function setUpdatedAt($v)
401: {
402: $dt = PropelDateTime::newInstance($v, null, 'DateTime');
403: if ($this->updated_at !== null || $dt !== null) {
404: $currentDateAsString = ($this->updated_at !== null && $tmpDt = new DateTime($this->updated_at)) ? $tmpDt->format('Y-m-d H:i:s') : null;
405: $newDateAsString = $dt ? $dt->format('Y-m-d H:i:s') : null;
406: if ($currentDateAsString !== $newDateAsString) {
407: $this->updated_at = $newDateAsString;
408: $this->modifiedColumns[] = LangPeer::UPDATED_AT;
409: }
410: } // if either are not null
411:
412:
413: return $this;
414: } // setUpdatedAt()
415:
416: /**
417: * Indicates whether the columns in this object are only set to default values.
418: *
419: * This method can be used in conjunction with isModified() to indicate whether an object is both
420: * modified _and_ has some values set which are non-default.
421: *
422: * @return boolean Whether the columns in this object are only been set with default values.
423: */
424: public function hasOnlyDefaultValues()
425: {
426: // otherwise, everything was equal, so return true
427: return true;
428: } // hasOnlyDefaultValues()
429:
430: /**
431: * Hydrates (populates) the object variables with values from the database resultset.
432: *
433: * An offset (0-based "start column") is specified so that objects can be hydrated
434: * with a subset of the columns in the resultset rows. This is needed, for example,
435: * for results of JOIN queries where the resultset row includes columns from two or
436: * more tables.
437: *
438: * @param array $row The row returned by PDOStatement->fetch(PDO::FETCH_NUM)
439: * @param int $startcol 0-based offset column which indicates which restultset column to start with.
440: * @param boolean $rehydrate Whether this object is being re-hydrated from the database.
441: * @return int next starting column
442: * @throws PropelException - Any caught Exception will be rewrapped as a PropelException.
443: */
444: public function hydrate($row, $startcol = 0, $rehydrate = false)
445: {
446: try {
447:
448: $this->id = ($row[$startcol + 0] !== null) ? (int) $row[$startcol + 0] : null;
449: $this->title = ($row[$startcol + 1] !== null) ? (string) $row[$startcol + 1] : null;
450: $this->code = ($row[$startcol + 2] !== null) ? (string) $row[$startcol + 2] : null;
451: $this->locale = ($row[$startcol + 3] !== null) ? (string) $row[$startcol + 3] : null;
452: $this->url = ($row[$startcol + 4] !== null) ? (string) $row[$startcol + 4] : null;
453: $this->by_default = ($row[$startcol + 5] !== null) ? (int) $row[$startcol + 5] : null;
454: $this->created_at = ($row[$startcol + 6] !== null) ? (string) $row[$startcol + 6] : null;
455: $this->updated_at = ($row[$startcol + 7] !== null) ? (string) $row[$startcol + 7] : null;
456: $this->resetModified();
457:
458: $this->setNew(false);
459:
460: if ($rehydrate) {
461: $this->ensureConsistency();
462: }
463:
464: return $startcol + 8; // 8 = LangPeer::NUM_HYDRATE_COLUMNS.
465:
466: } catch (Exception $e) {
467: throw new PropelException("Error populating Lang object", $e);
468: }
469: }
470:
471: /**
472: * Checks and repairs the internal consistency of the object.
473: *
474: * This method is executed after an already-instantiated object is re-hydrated
475: * from the database. It exists to check any foreign keys to make sure that
476: * the objects related to the current object are correct based on foreign key.
477: *
478: * You can override this method in the stub class, but you should always invoke
479: * the base method from the overridden method (i.e. parent::ensureConsistency()),
480: * in case your model changes.
481: *
482: * @throws PropelException
483: */
484: public function ensureConsistency()
485: {
486:
487: } // ensureConsistency
488:
489: /**
490: * Reloads this object from datastore based on primary key and (optionally) resets all associated objects.
491: *
492: * This will only work if the object has been saved and has a valid primary key set.
493: *
494: * @param boolean $deep (optional) Whether to also de-associated any related objects.
495: * @param PropelPDO $con (optional) The PropelPDO connection to use.
496: * @return void
497: * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db
498: */
499: public function reload($deep = false, PropelPDO $con = null)
500: {
501: if ($this->isDeleted()) {
502: throw new PropelException("Cannot reload a deleted object.");
503: }
504:
505: if ($this->isNew()) {
506: throw new PropelException("Cannot reload an unsaved object.");
507: }
508:
509: if ($con === null) {
510: $con = Propel::getConnection(LangPeer::DATABASE_NAME, Propel::CONNECTION_READ);
511: }
512:
513: // We don't need to alter the object instance pool; we're just modifying this instance
514: // already in the pool.
515:
516: $stmt = LangPeer::doSelectStmt($this->buildPkeyCriteria(), $con);
517: $row = $stmt->fetch(PDO::FETCH_NUM);
518: $stmt->closeCursor();
519: if (!$row) {
520: throw new PropelException('Cannot find matching row in the database to reload object values.');
521: }
522: $this->hydrate($row, 0, true); // rehydrate
523:
524: if ($deep) { // also de-associate any related objects?
525:
526: } // if (deep)
527: }
528:
529: /**
530: * Removes this object from datastore and sets delete attribute.
531: *
532: * @param PropelPDO $con
533: * @return void
534: * @throws PropelException
535: * @throws Exception
536: * @see BaseObject::setDeleted()
537: * @see BaseObject::isDeleted()
538: */
539: public function delete(PropelPDO $con = null)
540: {
541: if ($this->isDeleted()) {
542: throw new PropelException("This object has already been deleted.");
543: }
544:
545: if ($con === null) {
546: $con = Propel::getConnection(LangPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
547: }
548:
549: $con->beginTransaction();
550: try {
551: $deleteQuery = LangQuery::create()
552: ->filterByPrimaryKey($this->getPrimaryKey());
553: $ret = $this->preDelete($con);
554: if ($ret) {
555: $deleteQuery->delete($con);
556: $this->postDelete($con);
557: $con->commit();
558: $this->setDeleted(true);
559: } else {
560: $con->commit();
561: }
562: } catch (Exception $e) {
563: $con->rollBack();
564: throw $e;
565: }
566: }
567:
568: /**
569: * Persists this object to the database.
570: *
571: * If the object is new, it inserts it; otherwise an update is performed.
572: * All modified related objects will also be persisted in the doSave()
573: * method. This method wraps all precipitate database operations in a
574: * single transaction.
575: *
576: * @param PropelPDO $con
577: * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
578: * @throws PropelException
579: * @throws Exception
580: * @see doSave()
581: */
582: public function save(PropelPDO $con = null)
583: {
584: if ($this->isDeleted()) {
585: throw new PropelException("You cannot save an object that has been deleted.");
586: }
587:
588: if ($con === null) {
589: $con = Propel::getConnection(LangPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
590: }
591:
592: $con->beginTransaction();
593: $isInsert = $this->isNew();
594: try {
595: $ret = $this->preSave($con);
596: if ($isInsert) {
597: $ret = $ret && $this->preInsert($con);
598: // timestampable behavior
599: if (!$this->isColumnModified(LangPeer::CREATED_AT)) {
600: $this->setCreatedAt(time());
601: }
602: if (!$this->isColumnModified(LangPeer::UPDATED_AT)) {
603: $this->setUpdatedAt(time());
604: }
605: } else {
606: $ret = $ret && $this->preUpdate($con);
607: // timestampable behavior
608: if ($this->isModified() && !$this->isColumnModified(LangPeer::UPDATED_AT)) {
609: $this->setUpdatedAt(time());
610: }
611: }
612: if ($ret) {
613: $affectedRows = $this->doSave($con);
614: if ($isInsert) {
615: $this->postInsert($con);
616: } else {
617: $this->postUpdate($con);
618: }
619: $this->postSave($con);
620: LangPeer::addInstanceToPool($this);
621: } else {
622: $affectedRows = 0;
623: }
624: $con->commit();
625:
626: return $affectedRows;
627: } catch (Exception $e) {
628: $con->rollBack();
629: throw $e;
630: }
631: }
632:
633: /**
634: * Performs the work of inserting or updating the row in the database.
635: *
636: * If the object is new, it inserts it; otherwise an update is performed.
637: * All related objects are also updated in this method.
638: *
639: * @param PropelPDO $con
640: * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
641: * @throws PropelException
642: * @see save()
643: */
644: protected function doSave(PropelPDO $con)
645: {
646: $affectedRows = 0; // initialize var to track total num of affected rows
647: if (!$this->alreadyInSave) {
648: $this->alreadyInSave = true;
649:
650: if ($this->isNew() || $this->isModified()) {
651: // persist changes
652: if ($this->isNew()) {
653: $this->doInsert($con);
654: } else {
655: $this->doUpdate($con);
656: }
657: $affectedRows += 1;
658: $this->resetModified();
659: }
660:
661: $this->alreadyInSave = false;
662:
663: }
664:
665: return $affectedRows;
666: } // doSave()
667:
668: /**
669: * Insert the row in the database.
670: *
671: * @param PropelPDO $con
672: *
673: * @throws PropelException
674: * @see doSave()
675: */
676: protected function doInsert(PropelPDO $con)
677: {
678: $modifiedColumns = array();
679: $index = 0;
680:
681: $this->modifiedColumns[] = LangPeer::ID;
682: if (null !== $this->id) {
683: throw new PropelException('Cannot insert a value for auto-increment primary key (' . LangPeer::ID . ')');
684: }
685:
686: // check the columns in natural order for more readable SQL queries
687: if ($this->isColumnModified(LangPeer::ID)) {
688: $modifiedColumns[':p' . $index++] = '`ID`';
689: }
690: if ($this->isColumnModified(LangPeer::TITLE)) {
691: $modifiedColumns[':p' . $index++] = '`TITLE`';
692: }
693: if ($this->isColumnModified(LangPeer::CODE)) {
694: $modifiedColumns[':p' . $index++] = '`CODE`';
695: }
696: if ($this->isColumnModified(LangPeer::LOCALE)) {
697: $modifiedColumns[':p' . $index++] = '`LOCALE`';
698: }
699: if ($this->isColumnModified(LangPeer::URL)) {
700: $modifiedColumns[':p' . $index++] = '`URL`';
701: }
702: if ($this->isColumnModified(LangPeer::BY_DEFAULT)) {
703: $modifiedColumns[':p' . $index++] = '`BY_DEFAULT`';
704: }
705: if ($this->isColumnModified(LangPeer::CREATED_AT)) {
706: $modifiedColumns[':p' . $index++] = '`CREATED_AT`';
707: }
708: if ($this->isColumnModified(LangPeer::UPDATED_AT)) {
709: $modifiedColumns[':p' . $index++] = '`UPDATED_AT`';
710: }
711:
712: $sql = sprintf(
713: 'INSERT INTO `lang` (%s) VALUES (%s)',
714: implode(', ', $modifiedColumns),
715: implode(', ', array_keys($modifiedColumns))
716: );
717:
718: try {
719: $stmt = $con->prepare($sql);
720: foreach ($modifiedColumns as $identifier => $columnName) {
721: switch ($columnName) {
722: case '`ID`':
723: $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT);
724: break;
725: case '`TITLE`':
726: $stmt->bindValue($identifier, $this->title, PDO::PARAM_STR);
727: break;
728: case '`CODE`':
729: $stmt->bindValue($identifier, $this->code, PDO::PARAM_STR);
730: break;
731: case '`LOCALE`':
732: $stmt->bindValue($identifier, $this->locale, PDO::PARAM_STR);
733: break;
734: case '`URL`':
735: $stmt->bindValue($identifier, $this->url, PDO::PARAM_STR);
736: break;
737: case '`BY_DEFAULT`':
738: $stmt->bindValue($identifier, $this->by_default, PDO::PARAM_INT);
739: break;
740: case '`CREATED_AT`':
741: $stmt->bindValue($identifier, $this->created_at, PDO::PARAM_STR);
742: break;
743: case '`UPDATED_AT`':
744: $stmt->bindValue($identifier, $this->updated_at, PDO::PARAM_STR);
745: break;
746: }
747: }
748: $stmt->execute();
749: } catch (Exception $e) {
750: Propel::log($e->getMessage(), Propel::LOG_ERR);
751: throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), $e);
752: }
753:
754: try {
755: $pk = $con->lastInsertId();
756: } catch (Exception $e) {
757: throw new PropelException('Unable to get autoincrement id.', $e);
758: }
759: $this->setId($pk);
760:
761: $this->setNew(false);
762: }
763:
764: /**
765: * Update the row in the database.
766: *
767: * @param PropelPDO $con
768: *
769: * @see doSave()
770: */
771: protected function doUpdate(PropelPDO $con)
772: {
773: $selectCriteria = $this->buildPkeyCriteria();
774: $valuesCriteria = $this->buildCriteria();
775: BasePeer::doUpdate($selectCriteria, $valuesCriteria, $con);
776: }
777:
778: /**
779: * Array of ValidationFailed objects.
780: * @var array ValidationFailed[]
781: */
782: protected $validationFailures = array();
783:
784: /**
785: * Gets any ValidationFailed objects that resulted from last call to validate().
786: *
787: *
788: * @return array ValidationFailed[]
789: * @see validate()
790: */
791: public function getValidationFailures()
792: {
793: return $this->validationFailures;
794: }
795:
796: /**
797: * Validates the objects modified field values and all objects related to this table.
798: *
799: * If $columns is either a column name or an array of column names
800: * only those columns are validated.
801: *
802: * @param mixed $columns Column name or an array of column names.
803: * @return boolean Whether all columns pass validation.
804: * @see doValidate()
805: * @see getValidationFailures()
806: */
807: public function validate($columns = null)
808: {
809: $res = $this->doValidate($columns);
810: if ($res === true) {
811: $this->validationFailures = array();
812:
813: return true;
814: } else {
815: $this->validationFailures = $res;
816:
817: return false;
818: }
819: }
820:
821: /**
822: * This function performs the validation work for complex object models.
823: *
824: * In addition to checking the current object, all related objects will
825: * also be validated. If all pass then <code>true</code> is returned; otherwise
826: * an aggreagated array of ValidationFailed objects will be returned.
827: *
828: * @param array $columns Array of column names to validate.
829: * @return mixed <code>true</code> if all validations pass; array of <code>ValidationFailed</code> objets otherwise.
830: */
831: protected function doValidate($columns = null)
832: {
833: if (!$this->alreadyInValidation) {
834: $this->alreadyInValidation = true;
835: $retval = null;
836:
837: $failureMap = array();
838:
839:
840: if (($retval = LangPeer::doValidate($this, $columns)) !== true) {
841: $failureMap = array_merge($failureMap, $retval);
842: }
843:
844:
845:
846: $this->alreadyInValidation = false;
847: }
848:
849: return (!empty($failureMap) ? $failureMap : true);
850: }
851:
852: /**
853: * Retrieves a field from the object by name passed in as a string.
854: *
855: * @param string $name name
856: * @param string $type The type of fieldname the $name is of:
857: * one of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
858: * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
859: * Defaults to BasePeer::TYPE_PHPNAME
860: * @return mixed Value of field.
861: */
862: public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
863: {
864: $pos = LangPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
865: $field = $this->getByPosition($pos);
866:
867: return $field;
868: }
869:
870: /**
871: * Retrieves a field from the object by Position as specified in the xml schema.
872: * Zero-based.
873: *
874: * @param int $pos position in xml schema
875: * @return mixed Value of field at $pos
876: */
877: public function getByPosition($pos)
878: {
879: switch ($pos) {
880: case 0:
881: return $this->getId();
882: break;
883: case 1:
884: return $this->getTitle();
885: break;
886: case 2:
887: return $this->getCode();
888: break;
889: case 3:
890: return $this->getLocale();
891: break;
892: case 4:
893: return $this->getUrl();
894: break;
895: case 5:
896: return $this->getByDefault();
897: break;
898: case 6:
899: return $this->getCreatedAt();
900: break;
901: case 7:
902: return $this->getUpdatedAt();
903: break;
904: default:
905: return null;
906: break;
907: } // switch()
908: }
909:
910: /**
911: * Exports the object as an array.
912: *
913: * You can specify the key type of the array by passing one of the class
914: * type constants.
915: *
916: * @param string $keyType (optional) One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
917: * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
918: * Defaults to BasePeer::TYPE_PHPNAME.
919: * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to true.
920: * @param array $alreadyDumpedObjects List of objects to skip to avoid recursion
921: *
922: * @return array an associative array containing the field names (as keys) and field values
923: */
924: public function toArray($keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array())
925: {
926: if (isset($alreadyDumpedObjects['Lang'][$this->getPrimaryKey()])) {
927: return '*RECURSION*';
928: }
929: $alreadyDumpedObjects['Lang'][$this->getPrimaryKey()] = true;
930: $keys = LangPeer::getFieldNames($keyType);
931: $result = array(
932: $keys[0] => $this->getId(),
933: $keys[1] => $this->getTitle(),
934: $keys[2] => $this->getCode(),
935: $keys[3] => $this->getLocale(),
936: $keys[4] => $this->getUrl(),
937: $keys[5] => $this->getByDefault(),
938: $keys[6] => $this->getCreatedAt(),
939: $keys[7] => $this->getUpdatedAt(),
940: );
941:
942: return $result;
943: }
944:
945: /**
946: * Sets a field from the object by name passed in as a string.
947: *
948: * @param string $name peer name
949: * @param mixed $value field value
950: * @param string $type The type of fieldname the $name is of:
951: * one of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
952: * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
953: * Defaults to BasePeer::TYPE_PHPNAME
954: * @return void
955: */
956: public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
957: {
958: $pos = LangPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
959:
960: $this->setByPosition($pos, $value);
961: }
962:
963: /**
964: * Sets a field from the object by Position as specified in the xml schema.
965: * Zero-based.
966: *
967: * @param int $pos position in xml schema
968: * @param mixed $value field value
969: * @return void
970: */
971: public function setByPosition($pos, $value)
972: {
973: switch ($pos) {
974: case 0:
975: $this->setId($value);
976: break;
977: case 1:
978: $this->setTitle($value);
979: break;
980: case 2:
981: $this->setCode($value);
982: break;
983: case 3:
984: $this->setLocale($value);
985: break;
986: case 4:
987: $this->setUrl($value);
988: break;
989: case 5:
990: $this->setByDefault($value);
991: break;
992: case 6:
993: $this->setCreatedAt($value);
994: break;
995: case 7:
996: $this->setUpdatedAt($value);
997: break;
998: } // switch()
999: }
1000:
1001: /**
1002: * Populates the object using an array.
1003: *
1004: * This is particularly useful when populating an object from one of the
1005: * request arrays (e.g. $_POST). This method goes through the column
1006: * names, checking to see whether a matching key exists in populated
1007: * array. If so the setByName() method is called for that column.
1008: *
1009: * You can specify the key type of the array by additionally passing one
1010: * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
1011: * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
1012: * The default key type is the column's BasePeer::TYPE_PHPNAME
1013: *
1014: * @param array $arr An array to populate the object from.
1015: * @param string $keyType The type of keys the array uses.
1016: * @return void
1017: */
1018: public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
1019: {
1020: $keys = LangPeer::getFieldNames($keyType);
1021:
1022: if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
1023: if (array_key_exists($keys[1], $arr)) $this->setTitle($arr[$keys[1]]);
1024: if (array_key_exists($keys[2], $arr)) $this->setCode($arr[$keys[2]]);
1025: if (array_key_exists($keys[3], $arr)) $this->setLocale($arr[$keys[3]]);
1026: if (array_key_exists($keys[4], $arr)) $this->setUrl($arr[$keys[4]]);
1027: if (array_key_exists($keys[5], $arr)) $this->setByDefault($arr[$keys[5]]);
1028: if (array_key_exists($keys[6], $arr)) $this->setCreatedAt($arr[$keys[6]]);
1029: if (array_key_exists($keys[7], $arr)) $this->setUpdatedAt($arr[$keys[7]]);
1030: }
1031:
1032: /**
1033: * Build a Criteria object containing the values of all modified columns in this object.
1034: *
1035: * @return Criteria The Criteria object containing all modified values.
1036: */
1037: public function buildCriteria()
1038: {
1039: $criteria = new Criteria(LangPeer::DATABASE_NAME);
1040:
1041: if ($this->isColumnModified(LangPeer::ID)) $criteria->add(LangPeer::ID, $this->id);
1042: if ($this->isColumnModified(LangPeer::TITLE)) $criteria->add(LangPeer::TITLE, $this->title);
1043: if ($this->isColumnModified(LangPeer::CODE)) $criteria->add(LangPeer::CODE, $this->code);
1044: if ($this->isColumnModified(LangPeer::LOCALE)) $criteria->add(LangPeer::LOCALE, $this->locale);
1045: if ($this->isColumnModified(LangPeer::URL)) $criteria->add(LangPeer::URL, $this->url);
1046: if ($this->isColumnModified(LangPeer::BY_DEFAULT)) $criteria->add(LangPeer::BY_DEFAULT, $this->by_default);
1047: if ($this->isColumnModified(LangPeer::CREATED_AT)) $criteria->add(LangPeer::CREATED_AT, $this->created_at);
1048: if ($this->isColumnModified(LangPeer::UPDATED_AT)) $criteria->add(LangPeer::UPDATED_AT, $this->updated_at);
1049:
1050: return $criteria;
1051: }
1052:
1053: /**
1054: * Builds a Criteria object containing the primary key for this object.
1055: *
1056: * Unlike buildCriteria() this method includes the primary key values regardless
1057: * of whether or not they have been modified.
1058: *
1059: * @return Criteria The Criteria object containing value(s) for primary key(s).
1060: */
1061: public function buildPkeyCriteria()
1062: {
1063: $criteria = new Criteria(LangPeer::DATABASE_NAME);
1064: $criteria->add(LangPeer::ID, $this->id);
1065:
1066: return $criteria;
1067: }
1068:
1069: /**
1070: * Returns the primary key for this object (row).
1071: * @return int
1072: */
1073: public function getPrimaryKey()
1074: {
1075: return $this->getId();
1076: }
1077:
1078: /**
1079: * Generic method to set the primary key (id column).
1080: *
1081: * @param int $key Primary key.
1082: * @return void
1083: */
1084: public function setPrimaryKey($key)
1085: {
1086: $this->setId($key);
1087: }
1088:
1089: /**
1090: * Returns true if the primary key for this object is null.
1091: * @return boolean
1092: */
1093: public function isPrimaryKeyNull()
1094: {
1095:
1096: return null === $this->getId();
1097: }
1098:
1099: /**
1100: * Sets contents of passed object to values from current object.
1101: *
1102: * If desired, this method can also make copies of all associated (fkey referrers)
1103: * objects.
1104: *
1105: * @param object $copyObj An object of Lang (or compatible) type.
1106: * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
1107: * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new.
1108: * @throws PropelException
1109: */
1110: public function copyInto($copyObj, $deepCopy = false, $makeNew = true)
1111: {
1112: $copyObj->setTitle($this->getTitle());
1113: $copyObj->setCode($this->getCode());
1114: $copyObj->setLocale($this->getLocale());
1115: $copyObj->setUrl($this->getUrl());
1116: $copyObj->setByDefault($this->getByDefault());
1117: $copyObj->setCreatedAt($this->getCreatedAt());
1118: $copyObj->setUpdatedAt($this->getUpdatedAt());
1119: if ($makeNew) {
1120: $copyObj->setNew(true);
1121: $copyObj->setId(NULL); // this is a auto-increment column, so set to default value
1122: }
1123: }
1124:
1125: /**
1126: * Makes a copy of this object that will be inserted as a new row in table when saved.
1127: * It creates a new object filling in the simple attributes, but skipping any primary
1128: * keys that are defined for the table.
1129: *
1130: * If desired, this method can also make copies of all associated (fkey referrers)
1131: * objects.
1132: *
1133: * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
1134: * @return Lang Clone of current object.
1135: * @throws PropelException
1136: */
1137: public function copy($deepCopy = false)
1138: {
1139: // we use get_class(), because this might be a subclass
1140: $clazz = get_class($this);
1141: $copyObj = new $clazz();
1142: $this->copyInto($copyObj, $deepCopy);
1143:
1144: return $copyObj;
1145: }
1146:
1147: /**
1148: * Returns a peer instance associated with this om.
1149: *
1150: * Since Peer classes are not to have any instance attributes, this method returns the
1151: * same instance for all member of this class. The method could therefore
1152: * be static, but this would prevent one from overriding the behavior.
1153: *
1154: * @return LangPeer
1155: */
1156: public function getPeer()
1157: {
1158: if (self::$peer === null) {
1159: self::$peer = new LangPeer();
1160: }
1161:
1162: return self::$peer;
1163: }
1164:
1165: /**
1166: * Clears the current object and sets all attributes to their default values
1167: */
1168: public function clear()
1169: {
1170: $this->id = null;
1171: $this->title = null;
1172: $this->code = null;
1173: $this->locale = null;
1174: $this->url = null;
1175: $this->by_default = null;
1176: $this->created_at = null;
1177: $this->updated_at = null;
1178: $this->alreadyInSave = false;
1179: $this->alreadyInValidation = false;
1180: $this->clearAllReferences();
1181: $this->resetModified();
1182: $this->setNew(true);
1183: $this->setDeleted(false);
1184: }
1185:
1186: /**
1187: * Resets all references to other model objects or collections of model objects.
1188: *
1189: * This method is a user-space workaround for PHP's inability to garbage collect
1190: * objects with circular references (even in PHP 5.3). This is currently necessary
1191: * when using Propel in certain daemon or large-volumne/high-memory operations.
1192: *
1193: * @param boolean $deep Whether to also clear the references on all referrer objects.
1194: */
1195: public function clearAllReferences($deep = false)
1196: {
1197: if ($deep) {
1198: } // if ($deep)
1199:
1200: }
1201:
1202: /**
1203: * return the string representation of this object
1204: *
1205: * @return string
1206: */
1207: public function __toString()
1208: {
1209: return (string) $this->exportTo(LangPeer::DEFAULT_STRING_FORMAT);
1210: }
1211:
1212: /**
1213: * return true is the object is in saving state
1214: *
1215: * @return boolean
1216: */
1217: public function isAlreadyInSave()
1218: {
1219: return $this->alreadyInSave;
1220: }
1221:
1222: // timestampable behavior
1223:
1224: /**
1225: * Mark the current object so that the update date doesn't get updated during next save
1226: *
1227: * @return Lang The current object (for fluent API support)
1228: */
1229: public function keepUpdateDateUnchanged()
1230: {
1231: $this->modifiedColumns[] = LangPeer::UPDATED_AT;
1232:
1233: return $this;
1234: }
1235:
1236: }
1237: