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