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