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