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