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 \PropelCollection;
14: use \PropelDateTime;
15: use \PropelException;
16: use \PropelObjectCollection;
17: use \PropelPDO;
18: use Thelia\Model\GroupResource;
19: use Thelia\Model\GroupResourceQuery;
20: use Thelia\Model\Resource;
21: use Thelia\Model\ResourceI18n;
22: use Thelia\Model\ResourceI18nQuery;
23: use Thelia\Model\ResourcePeer;
24: use Thelia\Model\ResourceQuery;
25:
26: /**
27: * Base class that represents a row from the 'resource' table.
28: *
29: *
30: *
31: * @package propel.generator.Thelia.Model.om
32: */
33: abstract class BaseResource extends BaseObject implements Persistent
34: {
35: /**
36: * Peer class name
37: */
38: const PEER = 'Thelia\\Model\\ResourcePeer';
39:
40: /**
41: * The Peer class.
42: * Instance provides a convenient way of calling static methods on a class
43: * that calling code may not be able to identify.
44: * @var ResourcePeer
45: */
46: protected static $peer;
47:
48: /**
49: * The flag var to prevent infinit loop in deep copy
50: * @var boolean
51: */
52: protected $startCopy = false;
53:
54: /**
55: * The value for the id field.
56: * @var int
57: */
58: protected $id;
59:
60: /**
61: * The value for the code field.
62: * @var string
63: */
64: protected $code;
65:
66: /**
67: * The value for the created_at field.
68: * @var string
69: */
70: protected $created_at;
71:
72: /**
73: * The value for the updated_at field.
74: * @var string
75: */
76: protected $updated_at;
77:
78: /**
79: * @var PropelObjectCollection|GroupResource[] Collection to store aggregation of GroupResource objects.
80: */
81: protected $collGroupResources;
82: protected $collGroupResourcesPartial;
83:
84: /**
85: * @var PropelObjectCollection|ResourceI18n[] Collection to store aggregation of ResourceI18n objects.
86: */
87: protected $collResourceI18ns;
88: protected $collResourceI18nsPartial;
89:
90: /**
91: * Flag to prevent endless save loop, if this object is referenced
92: * by another object which falls in this transaction.
93: * @var boolean
94: */
95: protected $alreadyInSave = false;
96:
97: /**
98: * Flag to prevent endless validation loop, if this object is referenced
99: * by another object which falls in this transaction.
100: * @var boolean
101: */
102: protected $alreadyInValidation = false;
103:
104: /**
105: * Flag to prevent endless clearAllReferences($deep=true) loop, if this object is referenced
106: * @var boolean
107: */
108: protected $alreadyInClearAllReferencesDeep = false;
109:
110: // i18n behavior
111:
112: /**
113: * Current locale
114: * @var string
115: */
116: protected $currentLocale = 'en_US';
117:
118: /**
119: * Current translation objects
120: * @var array[ResourceI18n]
121: */
122: protected $currentTranslations;
123:
124: /**
125: * An array of objects scheduled for deletion.
126: * @var PropelObjectCollection
127: */
128: protected $groupResourcesScheduledForDeletion = null;
129:
130: /**
131: * An array of objects scheduled for deletion.
132: * @var PropelObjectCollection
133: */
134: protected $resourceI18nsScheduledForDeletion = null;
135:
136: /**
137: * Get the [id] column value.
138: *
139: * @return int
140: */
141: public function getId()
142: {
143: return $this->id;
144: }
145:
146: /**
147: * Get the [code] column value.
148: *
149: * @return string
150: */
151: public function getCode()
152: {
153: return $this->code;
154: }
155:
156: /**
157: * Get the [optionally formatted] temporal [created_at] column value.
158: *
159: *
160: * @param string $format The date/time format string (either date()-style or strftime()-style).
161: * If format is null, then the raw DateTime object will be returned.
162: * @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
163: * @throws PropelException - if unable to parse/validate the date/time value.
164: */
165: public function getCreatedAt($format = 'Y-m-d H:i:s')
166: {
167: if ($this->created_at === null) {
168: return null;
169: }
170:
171: if ($this->created_at === '0000-00-00 00:00:00') {
172: // while technically this is not a default value of null,
173: // this seems to be closest in meaning.
174: return null;
175: }
176:
177: try {
178: $dt = new DateTime($this->created_at);
179: } catch (Exception $x) {
180: throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->created_at, true), $x);
181: }
182:
183: if ($format === null) {
184: // Because propel.useDateTimeClass is true, we return a DateTime object.
185: return $dt;
186: }
187:
188: if (strpos($format, '%') !== false) {
189: return strftime($format, $dt->format('U'));
190: }
191:
192: return $dt->format($format);
193:
194: }
195:
196: /**
197: * Get the [optionally formatted] temporal [updated_at] column value.
198: *
199: *
200: * @param string $format The date/time format string (either date()-style or strftime()-style).
201: * If format is null, then the raw DateTime object will be returned.
202: * @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
203: * @throws PropelException - if unable to parse/validate the date/time value.
204: */
205: public function getUpdatedAt($format = 'Y-m-d H:i:s')
206: {
207: if ($this->updated_at === null) {
208: return null;
209: }
210:
211: if ($this->updated_at === '0000-00-00 00:00:00') {
212: // while technically this is not a default value of null,
213: // this seems to be closest in meaning.
214: return null;
215: }
216:
217: try {
218: $dt = new DateTime($this->updated_at);
219: } catch (Exception $x) {
220: throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->updated_at, true), $x);
221: }
222:
223: if ($format === null) {
224: // Because propel.useDateTimeClass is true, we return a DateTime object.
225: return $dt;
226: }
227:
228: if (strpos($format, '%') !== false) {
229: return strftime($format, $dt->format('U'));
230: }
231:
232: return $dt->format($format);
233:
234: }
235:
236: /**
237: * Set the value of [id] column.
238: *
239: * @param int $v new value
240: * @return Resource The current object (for fluent API support)
241: */
242: public function setId($v)
243: {
244: if ($v !== null && is_numeric($v)) {
245: $v = (int) $v;
246: }
247:
248: if ($this->id !== $v) {
249: $this->id = $v;
250: $this->modifiedColumns[] = ResourcePeer::ID;
251: }
252:
253:
254: return $this;
255: } // setId()
256:
257: /**
258: * Set the value of [code] column.
259: *
260: * @param string $v new value
261: * @return Resource The current object (for fluent API support)
262: */
263: public function setCode($v)
264: {
265: if ($v !== null && is_numeric($v)) {
266: $v = (string) $v;
267: }
268:
269: if ($this->code !== $v) {
270: $this->code = $v;
271: $this->modifiedColumns[] = ResourcePeer::CODE;
272: }
273:
274:
275: return $this;
276: } // setCode()
277:
278: /**
279: * Sets the value of [created_at] column to a normalized version of the date/time value specified.
280: *
281: * @param mixed $v string, integer (timestamp), or DateTime value.
282: * Empty strings are treated as null.
283: * @return Resource The current object (for fluent API support)
284: */
285: public function setCreatedAt($v)
286: {
287: $dt = PropelDateTime::newInstance($v, null, 'DateTime');
288: if ($this->created_at !== null || $dt !== null) {
289: $currentDateAsString = ($this->created_at !== null && $tmpDt = new DateTime($this->created_at)) ? $tmpDt->format('Y-m-d H:i:s') : null;
290: $newDateAsString = $dt ? $dt->format('Y-m-d H:i:s') : null;
291: if ($currentDateAsString !== $newDateAsString) {
292: $this->created_at = $newDateAsString;
293: $this->modifiedColumns[] = ResourcePeer::CREATED_AT;
294: }
295: } // if either are not null
296:
297:
298: return $this;
299: } // setCreatedAt()
300:
301: /**
302: * Sets the value of [updated_at] column to a normalized version of the date/time value specified.
303: *
304: * @param mixed $v string, integer (timestamp), or DateTime value.
305: * Empty strings are treated as null.
306: * @return Resource The current object (for fluent API support)
307: */
308: public function setUpdatedAt($v)
309: {
310: $dt = PropelDateTime::newInstance($v, null, 'DateTime');
311: if ($this->updated_at !== null || $dt !== null) {
312: $currentDateAsString = ($this->updated_at !== null && $tmpDt = new DateTime($this->updated_at)) ? $tmpDt->format('Y-m-d H:i:s') : null;
313: $newDateAsString = $dt ? $dt->format('Y-m-d H:i:s') : null;
314: if ($currentDateAsString !== $newDateAsString) {
315: $this->updated_at = $newDateAsString;
316: $this->modifiedColumns[] = ResourcePeer::UPDATED_AT;
317: }
318: } // if either are not null
319:
320:
321: return $this;
322: } // setUpdatedAt()
323:
324: /**
325: * Indicates whether the columns in this object are only set to default values.
326: *
327: * This method can be used in conjunction with isModified() to indicate whether an object is both
328: * modified _and_ has some values set which are non-default.
329: *
330: * @return boolean Whether the columns in this object are only been set with default values.
331: */
332: public function hasOnlyDefaultValues()
333: {
334: // otherwise, everything was equal, so return true
335: return true;
336: } // hasOnlyDefaultValues()
337:
338: /**
339: * Hydrates (populates) the object variables with values from the database resultset.
340: *
341: * An offset (0-based "start column") is specified so that objects can be hydrated
342: * with a subset of the columns in the resultset rows. This is needed, for example,
343: * for results of JOIN queries where the resultset row includes columns from two or
344: * more tables.
345: *
346: * @param array $row The row returned by PDOStatement->fetch(PDO::FETCH_NUM)
347: * @param int $startcol 0-based offset column which indicates which restultset column to start with.
348: * @param boolean $rehydrate Whether this object is being re-hydrated from the database.
349: * @return int next starting column
350: * @throws PropelException - Any caught Exception will be rewrapped as a PropelException.
351: */
352: public function hydrate($row, $startcol = 0, $rehydrate = false)
353: {
354: try {
355:
356: $this->id = ($row[$startcol + 0] !== null) ? (int) $row[$startcol + 0] : null;
357: $this->code = ($row[$startcol + 1] !== null) ? (string) $row[$startcol + 1] : null;
358: $this->created_at = ($row[$startcol + 2] !== null) ? (string) $row[$startcol + 2] : null;
359: $this->updated_at = ($row[$startcol + 3] !== null) ? (string) $row[$startcol + 3] : null;
360: $this->resetModified();
361:
362: $this->setNew(false);
363:
364: if ($rehydrate) {
365: $this->ensureConsistency();
366: }
367: $this->postHydrate($row, $startcol, $rehydrate);
368: return $startcol + 4; // 4 = ResourcePeer::NUM_HYDRATE_COLUMNS.
369:
370: } catch (Exception $e) {
371: throw new PropelException("Error populating Resource object", $e);
372: }
373: }
374:
375: /**
376: * Checks and repairs the internal consistency of the object.
377: *
378: * This method is executed after an already-instantiated object is re-hydrated
379: * from the database. It exists to check any foreign keys to make sure that
380: * the objects related to the current object are correct based on foreign key.
381: *
382: * You can override this method in the stub class, but you should always invoke
383: * the base method from the overridden method (i.e. parent::ensureConsistency()),
384: * in case your model changes.
385: *
386: * @throws PropelException
387: */
388: public function ensureConsistency()
389: {
390:
391: } // ensureConsistency
392:
393: /**
394: * Reloads this object from datastore based on primary key and (optionally) resets all associated objects.
395: *
396: * This will only work if the object has been saved and has a valid primary key set.
397: *
398: * @param boolean $deep (optional) Whether to also de-associated any related objects.
399: * @param PropelPDO $con (optional) The PropelPDO connection to use.
400: * @return void
401: * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db
402: */
403: public function reload($deep = false, PropelPDO $con = null)
404: {
405: if ($this->isDeleted()) {
406: throw new PropelException("Cannot reload a deleted object.");
407: }
408:
409: if ($this->isNew()) {
410: throw new PropelException("Cannot reload an unsaved object.");
411: }
412:
413: if ($con === null) {
414: $con = Propel::getConnection(ResourcePeer::DATABASE_NAME, Propel::CONNECTION_READ);
415: }
416:
417: // We don't need to alter the object instance pool; we're just modifying this instance
418: // already in the pool.
419:
420: $stmt = ResourcePeer::doSelectStmt($this->buildPkeyCriteria(), $con);
421: $row = $stmt->fetch(PDO::FETCH_NUM);
422: $stmt->closeCursor();
423: if (!$row) {
424: throw new PropelException('Cannot find matching row in the database to reload object values.');
425: }
426: $this->hydrate($row, 0, true); // rehydrate
427:
428: if ($deep) { // also de-associate any related objects?
429:
430: $this->collGroupResources = null;
431:
432: $this->collResourceI18ns = null;
433:
434: } // if (deep)
435: }
436:
437: /**
438: * Removes this object from datastore and sets delete attribute.
439: *
440: * @param PropelPDO $con
441: * @return void
442: * @throws PropelException
443: * @throws Exception
444: * @see BaseObject::setDeleted()
445: * @see BaseObject::isDeleted()
446: */
447: public function delete(PropelPDO $con = null)
448: {
449: if ($this->isDeleted()) {
450: throw new PropelException("This object has already been deleted.");
451: }
452:
453: if ($con === null) {
454: $con = Propel::getConnection(ResourcePeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
455: }
456:
457: $con->beginTransaction();
458: try {
459: $deleteQuery = ResourceQuery::create()
460: ->filterByPrimaryKey($this->getPrimaryKey());
461: $ret = $this->preDelete($con);
462: if ($ret) {
463: $deleteQuery->delete($con);
464: $this->postDelete($con);
465: $con->commit();
466: $this->setDeleted(true);
467: } else {
468: $con->commit();
469: }
470: } catch (Exception $e) {
471: $con->rollBack();
472: throw $e;
473: }
474: }
475:
476: /**
477: * Persists this object to the database.
478: *
479: * If the object is new, it inserts it; otherwise an update is performed.
480: * All modified related objects will also be persisted in the doSave()
481: * method. This method wraps all precipitate database operations in a
482: * single transaction.
483: *
484: * @param PropelPDO $con
485: * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
486: * @throws PropelException
487: * @throws Exception
488: * @see doSave()
489: */
490: public function save(PropelPDO $con = null)
491: {
492: if ($this->isDeleted()) {
493: throw new PropelException("You cannot save an object that has been deleted.");
494: }
495:
496: if ($con === null) {
497: $con = Propel::getConnection(ResourcePeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
498: }
499:
500: $con->beginTransaction();
501: $isInsert = $this->isNew();
502: try {
503: $ret = $this->preSave($con);
504: if ($isInsert) {
505: $ret = $ret && $this->preInsert($con);
506: // timestampable behavior
507: if (!$this->isColumnModified(ResourcePeer::CREATED_AT)) {
508: $this->setCreatedAt(time());
509: }
510: if (!$this->isColumnModified(ResourcePeer::UPDATED_AT)) {
511: $this->setUpdatedAt(time());
512: }
513: } else {
514: $ret = $ret && $this->preUpdate($con);
515: // timestampable behavior
516: if ($this->isModified() && !$this->isColumnModified(ResourcePeer::UPDATED_AT)) {
517: $this->setUpdatedAt(time());
518: }
519: }
520: if ($ret) {
521: $affectedRows = $this->doSave($con);
522: if ($isInsert) {
523: $this->postInsert($con);
524: } else {
525: $this->postUpdate($con);
526: }
527: $this->postSave($con);
528: ResourcePeer::addInstanceToPool($this);
529: } else {
530: $affectedRows = 0;
531: }
532: $con->commit();
533:
534: return $affectedRows;
535: } catch (Exception $e) {
536: $con->rollBack();
537: throw $e;
538: }
539: }
540:
541: /**
542: * Performs the work of inserting or updating the row in the database.
543: *
544: * If the object is new, it inserts it; otherwise an update is performed.
545: * All related objects are also updated in this method.
546: *
547: * @param PropelPDO $con
548: * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
549: * @throws PropelException
550: * @see save()
551: */
552: protected function doSave(PropelPDO $con)
553: {
554: $affectedRows = 0; // initialize var to track total num of affected rows
555: if (!$this->alreadyInSave) {
556: $this->alreadyInSave = true;
557:
558: if ($this->isNew() || $this->isModified()) {
559: // persist changes
560: if ($this->isNew()) {
561: $this->doInsert($con);
562: } else {
563: $this->doUpdate($con);
564: }
565: $affectedRows += 1;
566: $this->resetModified();
567: }
568:
569: if ($this->groupResourcesScheduledForDeletion !== null) {
570: if (!$this->groupResourcesScheduledForDeletion->isEmpty()) {
571: GroupResourceQuery::create()
572: ->filterByPrimaryKeys($this->groupResourcesScheduledForDeletion->getPrimaryKeys(false))
573: ->delete($con);
574: $this->groupResourcesScheduledForDeletion = null;
575: }
576: }
577:
578: if ($this->collGroupResources !== null) {
579: foreach ($this->collGroupResources as $referrerFK) {
580: if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
581: $affectedRows += $referrerFK->save($con);
582: }
583: }
584: }
585:
586: if ($this->resourceI18nsScheduledForDeletion !== null) {
587: if (!$this->resourceI18nsScheduledForDeletion->isEmpty()) {
588: ResourceI18nQuery::create()
589: ->filterByPrimaryKeys($this->resourceI18nsScheduledForDeletion->getPrimaryKeys(false))
590: ->delete($con);
591: $this->resourceI18nsScheduledForDeletion = null;
592: }
593: }
594:
595: if ($this->collResourceI18ns !== null) {
596: foreach ($this->collResourceI18ns as $referrerFK) {
597: if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
598: $affectedRows += $referrerFK->save($con);
599: }
600: }
601: }
602:
603: $this->alreadyInSave = false;
604:
605: }
606:
607: return $affectedRows;
608: } // doSave()
609:
610: /**
611: * Insert the row in the database.
612: *
613: * @param PropelPDO $con
614: *
615: * @throws PropelException
616: * @see doSave()
617: */
618: protected function doInsert(PropelPDO $con)
619: {
620: $modifiedColumns = array();
621: $index = 0;
622:
623: $this->modifiedColumns[] = ResourcePeer::ID;
624: if (null !== $this->id) {
625: throw new PropelException('Cannot insert a value for auto-increment primary key (' . ResourcePeer::ID . ')');
626: }
627:
628: // check the columns in natural order for more readable SQL queries
629: if ($this->isColumnModified(ResourcePeer::ID)) {
630: $modifiedColumns[':p' . $index++] = '`id`';
631: }
632: if ($this->isColumnModified(ResourcePeer::CODE)) {
633: $modifiedColumns[':p' . $index++] = '`code`';
634: }
635: if ($this->isColumnModified(ResourcePeer::CREATED_AT)) {
636: $modifiedColumns[':p' . $index++] = '`created_at`';
637: }
638: if ($this->isColumnModified(ResourcePeer::UPDATED_AT)) {
639: $modifiedColumns[':p' . $index++] = '`updated_at`';
640: }
641:
642: $sql = sprintf(
643: 'INSERT INTO `resource` (%s) VALUES (%s)',
644: implode(', ', $modifiedColumns),
645: implode(', ', array_keys($modifiedColumns))
646: );
647:
648: try {
649: $stmt = $con->prepare($sql);
650: foreach ($modifiedColumns as $identifier => $columnName) {
651: switch ($columnName) {
652: case '`id`':
653: $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT);
654: break;
655: case '`code`':
656: $stmt->bindValue($identifier, $this->code, PDO::PARAM_STR);
657: break;
658: case '`created_at`':
659: $stmt->bindValue($identifier, $this->created_at, PDO::PARAM_STR);
660: break;
661: case '`updated_at`':
662: $stmt->bindValue($identifier, $this->updated_at, PDO::PARAM_STR);
663: break;
664: }
665: }
666: $stmt->execute();
667: } catch (Exception $e) {
668: Propel::log($e->getMessage(), Propel::LOG_ERR);
669: throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), $e);
670: }
671:
672: try {
673: $pk = $con->lastInsertId();
674: } catch (Exception $e) {
675: throw new PropelException('Unable to get autoincrement id.', $e);
676: }
677: $this->setId($pk);
678:
679: $this->setNew(false);
680: }
681:
682: /**
683: * Update the row in the database.
684: *
685: * @param PropelPDO $con
686: *
687: * @see doSave()
688: */
689: protected function doUpdate(PropelPDO $con)
690: {
691: $selectCriteria = $this->buildPkeyCriteria();
692: $valuesCriteria = $this->buildCriteria();
693: BasePeer::doUpdate($selectCriteria, $valuesCriteria, $con);
694: }
695:
696: /**
697: * Array of ValidationFailed objects.
698: * @var array ValidationFailed[]
699: */
700: protected $validationFailures = array();
701:
702: /**
703: * Gets any ValidationFailed objects that resulted from last call to validate().
704: *
705: *
706: * @return array ValidationFailed[]
707: * @see validate()
708: */
709: public function getValidationFailures()
710: {
711: return $this->validationFailures;
712: }
713:
714: /**
715: * Validates the objects modified field values and all objects related to this table.
716: *
717: * If $columns is either a column name or an array of column names
718: * only those columns are validated.
719: *
720: * @param mixed $columns Column name or an array of column names.
721: * @return boolean Whether all columns pass validation.
722: * @see doValidate()
723: * @see getValidationFailures()
724: */
725: public function validate($columns = null)
726: {
727: $res = $this->doValidate($columns);
728: if ($res === true) {
729: $this->validationFailures = array();
730:
731: return true;
732: }
733:
734: $this->validationFailures = $res;
735:
736: return false;
737: }
738:
739: /**
740: * This function performs the validation work for complex object models.
741: *
742: * In addition to checking the current object, all related objects will
743: * also be validated. If all pass then <code>true</code> is returned; otherwise
744: * an aggreagated array of ValidationFailed objects will be returned.
745: *
746: * @param array $columns Array of column names to validate.
747: * @return mixed <code>true</code> if all validations pass; array of <code>ValidationFailed</code> objets otherwise.
748: */
749: protected function doValidate($columns = null)
750: {
751: if (!$this->alreadyInValidation) {
752: $this->alreadyInValidation = true;
753: $retval = null;
754:
755: $failureMap = array();
756:
757:
758: if (($retval = ResourcePeer::doValidate($this, $columns)) !== true) {
759: $failureMap = array_merge($failureMap, $retval);
760: }
761:
762:
763: if ($this->collGroupResources !== null) {
764: foreach ($this->collGroupResources as $referrerFK) {
765: if (!$referrerFK->validate($columns)) {
766: $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
767: }
768: }
769: }
770:
771: if ($this->collResourceI18ns !== null) {
772: foreach ($this->collResourceI18ns as $referrerFK) {
773: if (!$referrerFK->validate($columns)) {
774: $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
775: }
776: }
777: }
778:
779:
780: $this->alreadyInValidation = false;
781: }
782:
783: return (!empty($failureMap) ? $failureMap : true);
784: }
785:
786: /**
787: * Retrieves a field from the object by name passed in as a string.
788: *
789: * @param string $name name
790: * @param string $type The type of fieldname the $name is of:
791: * one of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
792: * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
793: * Defaults to BasePeer::TYPE_PHPNAME
794: * @return mixed Value of field.
795: */
796: public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
797: {
798: $pos = ResourcePeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
799: $field = $this->getByPosition($pos);
800:
801: return $field;
802: }
803:
804: /**
805: * Retrieves a field from the object by Position as specified in the xml schema.
806: * Zero-based.
807: *
808: * @param int $pos position in xml schema
809: * @return mixed Value of field at $pos
810: */
811: public function getByPosition($pos)
812: {
813: switch ($pos) {
814: case 0:
815: return $this->getId();
816: break;
817: case 1:
818: return $this->getCode();
819: break;
820: case 2:
821: return $this->getCreatedAt();
822: break;
823: case 3:
824: return $this->getUpdatedAt();
825: break;
826: default:
827: return null;
828: break;
829: } // switch()
830: }
831:
832: /**
833: * Exports the object as an array.
834: *
835: * You can specify the key type of the array by passing one of the class
836: * type constants.
837: *
838: * @param string $keyType (optional) One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
839: * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
840: * Defaults to BasePeer::TYPE_PHPNAME.
841: * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to true.
842: * @param array $alreadyDumpedObjects List of objects to skip to avoid recursion
843: * @param boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE.
844: *
845: * @return array an associative array containing the field names (as keys) and field values
846: */
847: public function toArray($keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false)
848: {
849: if (isset($alreadyDumpedObjects['Resource'][$this->getPrimaryKey()])) {
850: return '*RECURSION*';
851: }
852: $alreadyDumpedObjects['Resource'][$this->getPrimaryKey()] = true;
853: $keys = ResourcePeer::getFieldNames($keyType);
854: $result = array(
855: $keys[0] => $this->getId(),
856: $keys[1] => $this->getCode(),
857: $keys[2] => $this->getCreatedAt(),
858: $keys[3] => $this->getUpdatedAt(),
859: );
860: if ($includeForeignObjects) {
861: if (null !== $this->collGroupResources) {
862: $result['GroupResources'] = $this->collGroupResources->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects);
863: }
864: if (null !== $this->collResourceI18ns) {
865: $result['ResourceI18ns'] = $this->collResourceI18ns->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects);
866: }
867: }
868:
869: return $result;
870: }
871:
872: /**
873: * Sets a field from the object by name passed in as a string.
874: *
875: * @param string $name peer name
876: * @param mixed $value field value
877: * @param string $type The type of fieldname the $name is of:
878: * one of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
879: * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
880: * Defaults to BasePeer::TYPE_PHPNAME
881: * @return void
882: */
883: public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
884: {
885: $pos = ResourcePeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
886:
887: $this->setByPosition($pos, $value);
888: }
889:
890: /**
891: * Sets a field from the object by Position as specified in the xml schema.
892: * Zero-based.
893: *
894: * @param int $pos position in xml schema
895: * @param mixed $value field value
896: * @return void
897: */
898: public function setByPosition($pos, $value)
899: {
900: switch ($pos) {
901: case 0:
902: $this->setId($value);
903: break;
904: case 1:
905: $this->setCode($value);
906: break;
907: case 2:
908: $this->setCreatedAt($value);
909: break;
910: case 3:
911: $this->setUpdatedAt($value);
912: break;
913: } // switch()
914: }
915:
916: /**
917: * Populates the object using an array.
918: *
919: * This is particularly useful when populating an object from one of the
920: * request arrays (e.g. $_POST). This method goes through the column
921: * names, checking to see whether a matching key exists in populated
922: * array. If so the setByName() method is called for that column.
923: *
924: * You can specify the key type of the array by additionally passing one
925: * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
926: * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
927: * The default key type is the column's BasePeer::TYPE_PHPNAME
928: *
929: * @param array $arr An array to populate the object from.
930: * @param string $keyType The type of keys the array uses.
931: * @return void
932: */
933: public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
934: {
935: $keys = ResourcePeer::getFieldNames($keyType);
936:
937: if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
938: if (array_key_exists($keys[1], $arr)) $this->setCode($arr[$keys[1]]);
939: if (array_key_exists($keys[2], $arr)) $this->setCreatedAt($arr[$keys[2]]);
940: if (array_key_exists($keys[3], $arr)) $this->setUpdatedAt($arr[$keys[3]]);
941: }
942:
943: /**
944: * Build a Criteria object containing the values of all modified columns in this object.
945: *
946: * @return Criteria The Criteria object containing all modified values.
947: */
948: public function buildCriteria()
949: {
950: $criteria = new Criteria(ResourcePeer::DATABASE_NAME);
951:
952: if ($this->isColumnModified(ResourcePeer::ID)) $criteria->add(ResourcePeer::ID, $this->id);
953: if ($this->isColumnModified(ResourcePeer::CODE)) $criteria->add(ResourcePeer::CODE, $this->code);
954: if ($this->isColumnModified(ResourcePeer::CREATED_AT)) $criteria->add(ResourcePeer::CREATED_AT, $this->created_at);
955: if ($this->isColumnModified(ResourcePeer::UPDATED_AT)) $criteria->add(ResourcePeer::UPDATED_AT, $this->updated_at);
956:
957: return $criteria;
958: }
959:
960: /**
961: * Builds a Criteria object containing the primary key for this object.
962: *
963: * Unlike buildCriteria() this method includes the primary key values regardless
964: * of whether or not they have been modified.
965: *
966: * @return Criteria The Criteria object containing value(s) for primary key(s).
967: */
968: public function buildPkeyCriteria()
969: {
970: $criteria = new Criteria(ResourcePeer::DATABASE_NAME);
971: $criteria->add(ResourcePeer::ID, $this->id);
972:
973: return $criteria;
974: }
975:
976: /**
977: * Returns the primary key for this object (row).
978: * @return int
979: */
980: public function getPrimaryKey()
981: {
982: return $this->getId();
983: }
984:
985: /**
986: * Generic method to set the primary key (id column).
987: *
988: * @param int $key Primary key.
989: * @return void
990: */
991: public function setPrimaryKey($key)
992: {
993: $this->setId($key);
994: }
995:
996: /**
997: * Returns true if the primary key for this object is null.
998: * @return boolean
999: */
1000: public function isPrimaryKeyNull()
1001: {
1002:
1003: return null === $this->getId();
1004: }
1005:
1006: /**
1007: * Sets contents of passed object to values from current object.
1008: *
1009: * If desired, this method can also make copies of all associated (fkey referrers)
1010: * objects.
1011: *
1012: * @param object $copyObj An object of Resource (or compatible) type.
1013: * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
1014: * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new.
1015: * @throws PropelException
1016: */
1017: public function copyInto($copyObj, $deepCopy = false, $makeNew = true)
1018: {
1019: $copyObj->setCode($this->getCode());
1020: $copyObj->setCreatedAt($this->getCreatedAt());
1021: $copyObj->setUpdatedAt($this->getUpdatedAt());
1022:
1023: if ($deepCopy && !$this->startCopy) {
1024: // important: temporarily setNew(false) because this affects the behavior of
1025: // the getter/setter methods for fkey referrer objects.
1026: $copyObj->setNew(false);
1027: // store object hash to prevent cycle
1028: $this->startCopy = true;
1029:
1030: foreach ($this->getGroupResources() as $relObj) {
1031: if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves
1032: $copyObj->addGroupResource($relObj->copy($deepCopy));
1033: }
1034: }
1035:
1036: foreach ($this->getResourceI18ns() as $relObj) {
1037: if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves
1038: $copyObj->addResourceI18n($relObj->copy($deepCopy));
1039: }
1040: }
1041:
1042: //unflag object copy
1043: $this->startCopy = false;
1044: } // if ($deepCopy)
1045:
1046: if ($makeNew) {
1047: $copyObj->setNew(true);
1048: $copyObj->setId(NULL); // this is a auto-increment column, so set to default value
1049: }
1050: }
1051:
1052: /**
1053: * Makes a copy of this object that will be inserted as a new row in table when saved.
1054: * It creates a new object filling in the simple attributes, but skipping any primary
1055: * keys that are defined for the table.
1056: *
1057: * If desired, this method can also make copies of all associated (fkey referrers)
1058: * objects.
1059: *
1060: * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
1061: * @return Resource Clone of current object.
1062: * @throws PropelException
1063: */
1064: public function copy($deepCopy = false)
1065: {
1066: // we use get_class(), because this might be a subclass
1067: $clazz = get_class($this);
1068: $copyObj = new $clazz();
1069: $this->copyInto($copyObj, $deepCopy);
1070:
1071: return $copyObj;
1072: }
1073:
1074: /**
1075: * Returns a peer instance associated with this om.
1076: *
1077: * Since Peer classes are not to have any instance attributes, this method returns the
1078: * same instance for all member of this class. The method could therefore
1079: * be static, but this would prevent one from overriding the behavior.
1080: *
1081: * @return ResourcePeer
1082: */
1083: public function getPeer()
1084: {
1085: if (self::$peer === null) {
1086: self::$peer = new ResourcePeer();
1087: }
1088:
1089: return self::$peer;
1090: }
1091:
1092:
1093: /**
1094: * Initializes a collection based on the name of a relation.
1095: * Avoids crafting an 'init[$relationName]s' method name
1096: * that wouldn't work when StandardEnglishPluralizer is used.
1097: *
1098: * @param string $relationName The name of the relation to initialize
1099: * @return void
1100: */
1101: public function initRelation($relationName)
1102: {
1103: if ('GroupResource' == $relationName) {
1104: $this->initGroupResources();
1105: }
1106: if ('ResourceI18n' == $relationName) {
1107: $this->initResourceI18ns();
1108: }
1109: }
1110:
1111: /**
1112: * Clears out the collGroupResources collection
1113: *
1114: * This does not modify the database; however, it will remove any associated objects, causing
1115: * them to be refetched by subsequent calls to accessor method.
1116: *
1117: * @return Resource The current object (for fluent API support)
1118: * @see addGroupResources()
1119: */
1120: public function clearGroupResources()
1121: {
1122: $this->collGroupResources = null; // important to set this to null since that means it is uninitialized
1123: $this->collGroupResourcesPartial = null;
1124:
1125: return $this;
1126: }
1127:
1128: /**
1129: * reset is the collGroupResources collection loaded partially
1130: *
1131: * @return void
1132: */
1133: public function resetPartialGroupResources($v = true)
1134: {
1135: $this->collGroupResourcesPartial = $v;
1136: }
1137:
1138: /**
1139: * Initializes the collGroupResources collection.
1140: *
1141: * By default this just sets the collGroupResources collection to an empty array (like clearcollGroupResources());
1142: * however, you may wish to override this method in your stub class to provide setting appropriate
1143: * to your application -- for example, setting the initial array to the values stored in database.
1144: *
1145: * @param boolean $overrideExisting If set to true, the method call initializes
1146: * the collection even if it is not empty
1147: *
1148: * @return void
1149: */
1150: public function initGroupResources($overrideExisting = true)
1151: {
1152: if (null !== $this->collGroupResources && !$overrideExisting) {
1153: return;
1154: }
1155: $this->collGroupResources = new PropelObjectCollection();
1156: $this->collGroupResources->setModel('GroupResource');
1157: }
1158:
1159: /**
1160: * Gets an array of GroupResource objects which contain a foreign key that references this object.
1161: *
1162: * If the $criteria is not null, it is used to always fetch the results from the database.
1163: * Otherwise the results are fetched from the database the first time, then cached.
1164: * Next time the same method is called without $criteria, the cached collection is returned.
1165: * If this Resource is new, it will return
1166: * an empty collection or the current collection; the criteria is ignored on a new object.
1167: *
1168: * @param Criteria $criteria optional Criteria object to narrow the query
1169: * @param PropelPDO $con optional connection object
1170: * @return PropelObjectCollection|GroupResource[] List of GroupResource objects
1171: * @throws PropelException
1172: */
1173: public function getGroupResources($criteria = null, PropelPDO $con = null)
1174: {
1175: $partial = $this->collGroupResourcesPartial && !$this->isNew();
1176: if (null === $this->collGroupResources || null !== $criteria || $partial) {
1177: if ($this->isNew() && null === $this->collGroupResources) {
1178: // return empty collection
1179: $this->initGroupResources();
1180: } else {
1181: $collGroupResources = GroupResourceQuery::create(null, $criteria)
1182: ->filterByResource($this)
1183: ->find($con);
1184: if (null !== $criteria) {
1185: if (false !== $this->collGroupResourcesPartial && count($collGroupResources)) {
1186: $this->initGroupResources(false);
1187:
1188: foreach($collGroupResources as $obj) {
1189: if (false == $this->collGroupResources->contains($obj)) {
1190: $this->collGroupResources->append($obj);
1191: }
1192: }
1193:
1194: $this->collGroupResourcesPartial = true;
1195: }
1196:
1197: $collGroupResources->getInternalIterator()->rewind();
1198: return $collGroupResources;
1199: }
1200:
1201: if($partial && $this->collGroupResources) {
1202: foreach($this->collGroupResources as $obj) {
1203: if($obj->isNew()) {
1204: $collGroupResources[] = $obj;
1205: }
1206: }
1207: }
1208:
1209: $this->collGroupResources = $collGroupResources;
1210: $this->collGroupResourcesPartial = false;
1211: }
1212: }
1213:
1214: return $this->collGroupResources;
1215: }
1216:
1217: /**
1218: * Sets a collection of GroupResource objects related by a one-to-many relationship
1219: * to the current object.
1220: * It will also schedule objects for deletion based on a diff between old objects (aka persisted)
1221: * and new objects from the given Propel collection.
1222: *
1223: * @param PropelCollection $groupResources A Propel collection.
1224: * @param PropelPDO $con Optional connection object
1225: * @return Resource The current object (for fluent API support)
1226: */
1227: public function setGroupResources(PropelCollection $groupResources, PropelPDO $con = null)
1228: {
1229: $groupResourcesToDelete = $this->getGroupResources(new Criteria(), $con)->diff($groupResources);
1230:
1231: $this->groupResourcesScheduledForDeletion = unserialize(serialize($groupResourcesToDelete));
1232:
1233: foreach ($groupResourcesToDelete as $groupResourceRemoved) {
1234: $groupResourceRemoved->setResource(null);
1235: }
1236:
1237: $this->collGroupResources = null;
1238: foreach ($groupResources as $groupResource) {
1239: $this->addGroupResource($groupResource);
1240: }
1241:
1242: $this->collGroupResources = $groupResources;
1243: $this->collGroupResourcesPartial = false;
1244:
1245: return $this;
1246: }
1247:
1248: /**
1249: * Returns the number of related GroupResource objects.
1250: *
1251: * @param Criteria $criteria
1252: * @param boolean $distinct
1253: * @param PropelPDO $con
1254: * @return int Count of related GroupResource objects.
1255: * @throws PropelException
1256: */
1257: public function countGroupResources(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
1258: {
1259: $partial = $this->collGroupResourcesPartial && !$this->isNew();
1260: if (null === $this->collGroupResources || null !== $criteria || $partial) {
1261: if ($this->isNew() && null === $this->collGroupResources) {
1262: return 0;
1263: }
1264:
1265: if($partial && !$criteria) {
1266: return count($this->getGroupResources());
1267: }
1268: $query = GroupResourceQuery::create(null, $criteria);
1269: if ($distinct) {
1270: $query->distinct();
1271: }
1272:
1273: return $query
1274: ->filterByResource($this)
1275: ->count($con);
1276: }
1277:
1278: return count($this->collGroupResources);
1279: }
1280:
1281: /**
1282: * Method called to associate a GroupResource object to this object
1283: * through the GroupResource foreign key attribute.
1284: *
1285: * @param GroupResource $l GroupResource
1286: * @return Resource The current object (for fluent API support)
1287: */
1288: public function addGroupResource(GroupResource $l)
1289: {
1290: if ($this->collGroupResources === null) {
1291: $this->initGroupResources();
1292: $this->collGroupResourcesPartial = true;
1293: }
1294: if (!in_array($l, $this->collGroupResources->getArrayCopy(), true)) { // only add it if the **same** object is not already associated
1295: $this->doAddGroupResource($l);
1296: }
1297:
1298: return $this;
1299: }
1300:
1301: /**
1302: * @param GroupResource $groupResource The groupResource object to add.
1303: */
1304: protected function doAddGroupResource($groupResource)
1305: {
1306: $this->collGroupResources[]= $groupResource;
1307: $groupResource->setResource($this);
1308: }
1309:
1310: /**
1311: * @param GroupResource $groupResource The groupResource object to remove.
1312: * @return Resource The current object (for fluent API support)
1313: */
1314: public function removeGroupResource($groupResource)
1315: {
1316: if ($this->getGroupResources()->contains($groupResource)) {
1317: $this->collGroupResources->remove($this->collGroupResources->search($groupResource));
1318: if (null === $this->groupResourcesScheduledForDeletion) {
1319: $this->groupResourcesScheduledForDeletion = clone $this->collGroupResources;
1320: $this->groupResourcesScheduledForDeletion->clear();
1321: }
1322: $this->groupResourcesScheduledForDeletion[]= clone $groupResource;
1323: $groupResource->setResource(null);
1324: }
1325:
1326: return $this;
1327: }
1328:
1329:
1330: /**
1331: * If this collection has already been initialized with
1332: * an identical criteria, it returns the collection.
1333: * Otherwise if this Resource is new, it will return
1334: * an empty collection; or if this Resource has previously
1335: * been saved, it will retrieve related GroupResources from storage.
1336: *
1337: * This method is protected by default in order to keep the public
1338: * api reasonable. You can provide public methods for those you
1339: * actually need in Resource.
1340: *
1341: * @param Criteria $criteria optional Criteria object to narrow the query
1342: * @param PropelPDO $con optional connection object
1343: * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN)
1344: * @return PropelObjectCollection|GroupResource[] List of GroupResource objects
1345: */
1346: public function getGroupResourcesJoinGroup($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
1347: {
1348: $query = GroupResourceQuery::create(null, $criteria);
1349: $query->joinWith('Group', $join_behavior);
1350:
1351: return $this->getGroupResources($query, $con);
1352: }
1353:
1354: /**
1355: * Clears out the collResourceI18ns collection
1356: *
1357: * This does not modify the database; however, it will remove any associated objects, causing
1358: * them to be refetched by subsequent calls to accessor method.
1359: *
1360: * @return Resource The current object (for fluent API support)
1361: * @see addResourceI18ns()
1362: */
1363: public function clearResourceI18ns()
1364: {
1365: $this->collResourceI18ns = null; // important to set this to null since that means it is uninitialized
1366: $this->collResourceI18nsPartial = null;
1367:
1368: return $this;
1369: }
1370:
1371: /**
1372: * reset is the collResourceI18ns collection loaded partially
1373: *
1374: * @return void
1375: */
1376: public function resetPartialResourceI18ns($v = true)
1377: {
1378: $this->collResourceI18nsPartial = $v;
1379: }
1380:
1381: /**
1382: * Initializes the collResourceI18ns collection.
1383: *
1384: * By default this just sets the collResourceI18ns collection to an empty array (like clearcollResourceI18ns());
1385: * however, you may wish to override this method in your stub class to provide setting appropriate
1386: * to your application -- for example, setting the initial array to the values stored in database.
1387: *
1388: * @param boolean $overrideExisting If set to true, the method call initializes
1389: * the collection even if it is not empty
1390: *
1391: * @return void
1392: */
1393: public function initResourceI18ns($overrideExisting = true)
1394: {
1395: if (null !== $this->collResourceI18ns && !$overrideExisting) {
1396: return;
1397: }
1398: $this->collResourceI18ns = new PropelObjectCollection();
1399: $this->collResourceI18ns->setModel('ResourceI18n');
1400: }
1401:
1402: /**
1403: * Gets an array of ResourceI18n objects which contain a foreign key that references this object.
1404: *
1405: * If the $criteria is not null, it is used to always fetch the results from the database.
1406: * Otherwise the results are fetched from the database the first time, then cached.
1407: * Next time the same method is called without $criteria, the cached collection is returned.
1408: * If this Resource is new, it will return
1409: * an empty collection or the current collection; the criteria is ignored on a new object.
1410: *
1411: * @param Criteria $criteria optional Criteria object to narrow the query
1412: * @param PropelPDO $con optional connection object
1413: * @return PropelObjectCollection|ResourceI18n[] List of ResourceI18n objects
1414: * @throws PropelException
1415: */
1416: public function getResourceI18ns($criteria = null, PropelPDO $con = null)
1417: {
1418: $partial = $this->collResourceI18nsPartial && !$this->isNew();
1419: if (null === $this->collResourceI18ns || null !== $criteria || $partial) {
1420: if ($this->isNew() && null === $this->collResourceI18ns) {
1421: // return empty collection
1422: $this->initResourceI18ns();
1423: } else {
1424: $collResourceI18ns = ResourceI18nQuery::create(null, $criteria)
1425: ->filterByResource($this)
1426: ->find($con);
1427: if (null !== $criteria) {
1428: if (false !== $this->collResourceI18nsPartial && count($collResourceI18ns)) {
1429: $this->initResourceI18ns(false);
1430:
1431: foreach($collResourceI18ns as $obj) {
1432: if (false == $this->collResourceI18ns->contains($obj)) {
1433: $this->collResourceI18ns->append($obj);
1434: }
1435: }
1436:
1437: $this->collResourceI18nsPartial = true;
1438: }
1439:
1440: $collResourceI18ns->getInternalIterator()->rewind();
1441: return $collResourceI18ns;
1442: }
1443:
1444: if($partial && $this->collResourceI18ns) {
1445: foreach($this->collResourceI18ns as $obj) {
1446: if($obj->isNew()) {
1447: $collResourceI18ns[] = $obj;
1448: }
1449: }
1450: }
1451:
1452: $this->collResourceI18ns = $collResourceI18ns;
1453: $this->collResourceI18nsPartial = false;
1454: }
1455: }
1456:
1457: return $this->collResourceI18ns;
1458: }
1459:
1460: /**
1461: * Sets a collection of ResourceI18n objects related by a one-to-many relationship
1462: * to the current object.
1463: * It will also schedule objects for deletion based on a diff between old objects (aka persisted)
1464: * and new objects from the given Propel collection.
1465: *
1466: * @param PropelCollection $resourceI18ns A Propel collection.
1467: * @param PropelPDO $con Optional connection object
1468: * @return Resource The current object (for fluent API support)
1469: */
1470: public function setResourceI18ns(PropelCollection $resourceI18ns, PropelPDO $con = null)
1471: {
1472: $resourceI18nsToDelete = $this->getResourceI18ns(new Criteria(), $con)->diff($resourceI18ns);
1473:
1474: $this->resourceI18nsScheduledForDeletion = unserialize(serialize($resourceI18nsToDelete));
1475:
1476: foreach ($resourceI18nsToDelete as $resourceI18nRemoved) {
1477: $resourceI18nRemoved->setResource(null);
1478: }
1479:
1480: $this->collResourceI18ns = null;
1481: foreach ($resourceI18ns as $resourceI18n) {
1482: $this->addResourceI18n($resourceI18n);
1483: }
1484:
1485: $this->collResourceI18ns = $resourceI18ns;
1486: $this->collResourceI18nsPartial = false;
1487:
1488: return $this;
1489: }
1490:
1491: /**
1492: * Returns the number of related ResourceI18n objects.
1493: *
1494: * @param Criteria $criteria
1495: * @param boolean $distinct
1496: * @param PropelPDO $con
1497: * @return int Count of related ResourceI18n objects.
1498: * @throws PropelException
1499: */
1500: public function countResourceI18ns(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
1501: {
1502: $partial = $this->collResourceI18nsPartial && !$this->isNew();
1503: if (null === $this->collResourceI18ns || null !== $criteria || $partial) {
1504: if ($this->isNew() && null === $this->collResourceI18ns) {
1505: return 0;
1506: }
1507:
1508: if($partial && !$criteria) {
1509: return count($this->getResourceI18ns());
1510: }
1511: $query = ResourceI18nQuery::create(null, $criteria);
1512: if ($distinct) {
1513: $query->distinct();
1514: }
1515:
1516: return $query
1517: ->filterByResource($this)
1518: ->count($con);
1519: }
1520:
1521: return count($this->collResourceI18ns);
1522: }
1523:
1524: /**
1525: * Method called to associate a ResourceI18n object to this object
1526: * through the ResourceI18n foreign key attribute.
1527: *
1528: * @param ResourceI18n $l ResourceI18n
1529: * @return Resource The current object (for fluent API support)
1530: */
1531: public function addResourceI18n(ResourceI18n $l)
1532: {
1533: if ($l && $locale = $l->getLocale()) {
1534: $this->setLocale($locale);
1535: $this->currentTranslations[$locale] = $l;
1536: }
1537: if ($this->collResourceI18ns === null) {
1538: $this->initResourceI18ns();
1539: $this->collResourceI18nsPartial = true;
1540: }
1541: if (!in_array($l, $this->collResourceI18ns->getArrayCopy(), true)) { // only add it if the **same** object is not already associated
1542: $this->doAddResourceI18n($l);
1543: }
1544:
1545: return $this;
1546: }
1547:
1548: /**
1549: * @param ResourceI18n $resourceI18n The resourceI18n object to add.
1550: */
1551: protected function doAddResourceI18n($resourceI18n)
1552: {
1553: $this->collResourceI18ns[]= $resourceI18n;
1554: $resourceI18n->setResource($this);
1555: }
1556:
1557: /**
1558: * @param ResourceI18n $resourceI18n The resourceI18n object to remove.
1559: * @return Resource The current object (for fluent API support)
1560: */
1561: public function removeResourceI18n($resourceI18n)
1562: {
1563: if ($this->getResourceI18ns()->contains($resourceI18n)) {
1564: $this->collResourceI18ns->remove($this->collResourceI18ns->search($resourceI18n));
1565: if (null === $this->resourceI18nsScheduledForDeletion) {
1566: $this->resourceI18nsScheduledForDeletion = clone $this->collResourceI18ns;
1567: $this->resourceI18nsScheduledForDeletion->clear();
1568: }
1569: $this->resourceI18nsScheduledForDeletion[]= clone $resourceI18n;
1570: $resourceI18n->setResource(null);
1571: }
1572:
1573: return $this;
1574: }
1575:
1576: /**
1577: * Clears the current object and sets all attributes to their default values
1578: */
1579: public function clear()
1580: {
1581: $this->id = null;
1582: $this->code = null;
1583: $this->created_at = null;
1584: $this->updated_at = null;
1585: $this->alreadyInSave = false;
1586: $this->alreadyInValidation = false;
1587: $this->alreadyInClearAllReferencesDeep = false;
1588: $this->clearAllReferences();
1589: $this->resetModified();
1590: $this->setNew(true);
1591: $this->setDeleted(false);
1592: }
1593:
1594: /**
1595: * Resets all references to other model objects or collections of model objects.
1596: *
1597: * This method is a user-space workaround for PHP's inability to garbage collect
1598: * objects with circular references (even in PHP 5.3). This is currently necessary
1599: * when using Propel in certain daemon or large-volumne/high-memory operations.
1600: *
1601: * @param boolean $deep Whether to also clear the references on all referrer objects.
1602: */
1603: public function clearAllReferences($deep = false)
1604: {
1605: if ($deep && !$this->alreadyInClearAllReferencesDeep) {
1606: $this->alreadyInClearAllReferencesDeep = true;
1607: if ($this->collGroupResources) {
1608: foreach ($this->collGroupResources as $o) {
1609: $o->clearAllReferences($deep);
1610: }
1611: }
1612: if ($this->collResourceI18ns) {
1613: foreach ($this->collResourceI18ns as $o) {
1614: $o->clearAllReferences($deep);
1615: }
1616: }
1617:
1618: $this->alreadyInClearAllReferencesDeep = false;
1619: } // if ($deep)
1620:
1621: // i18n behavior
1622: $this->currentLocale = 'en_US';
1623: $this->currentTranslations = null;
1624:
1625: if ($this->collGroupResources instanceof PropelCollection) {
1626: $this->collGroupResources->clearIterator();
1627: }
1628: $this->collGroupResources = null;
1629: if ($this->collResourceI18ns instanceof PropelCollection) {
1630: $this->collResourceI18ns->clearIterator();
1631: }
1632: $this->collResourceI18ns = null;
1633: }
1634:
1635: /**
1636: * return the string representation of this object
1637: *
1638: * @return string
1639: */
1640: public function __toString()
1641: {
1642: return (string) $this->exportTo(ResourcePeer::DEFAULT_STRING_FORMAT);
1643: }
1644:
1645: /**
1646: * return true is the object is in saving state
1647: *
1648: * @return boolean
1649: */
1650: public function isAlreadyInSave()
1651: {
1652: return $this->alreadyInSave;
1653: }
1654:
1655: // timestampable behavior
1656:
1657: /**
1658: * Mark the current object so that the update date doesn't get updated during next save
1659: *
1660: * @return Resource The current object (for fluent API support)
1661: */
1662: public function keepUpdateDateUnchanged()
1663: {
1664: $this->modifiedColumns[] = ResourcePeer::UPDATED_AT;
1665:
1666: return $this;
1667: }
1668:
1669: // i18n behavior
1670:
1671: /**
1672: * Sets the locale for translations
1673: *
1674: * @param string $locale Locale to use for the translation, e.g. 'fr_FR'
1675: *
1676: * @return Resource The current object (for fluent API support)
1677: */
1678: public function setLocale($locale = 'en_US')
1679: {
1680: $this->currentLocale = $locale;
1681:
1682: return $this;
1683: }
1684:
1685: /**
1686: * Gets the locale for translations
1687: *
1688: * @return string $locale Locale to use for the translation, e.g. 'fr_FR'
1689: */
1690: public function getLocale()
1691: {
1692: return $this->currentLocale;
1693: }
1694:
1695: /**
1696: * Returns the current translation for a given locale
1697: *
1698: * @param string $locale Locale to use for the translation, e.g. 'fr_FR'
1699: * @param PropelPDO $con an optional connection object
1700: *
1701: * @return ResourceI18n */
1702: public function getTranslation($locale = 'en_US', PropelPDO $con = null)
1703: {
1704: if (!isset($this->currentTranslations[$locale])) {
1705: if (null !== $this->collResourceI18ns) {
1706: foreach ($this->collResourceI18ns as $translation) {
1707: if ($translation->getLocale() == $locale) {
1708: $this->currentTranslations[$locale] = $translation;
1709:
1710: return $translation;
1711: }
1712: }
1713: }
1714: if ($this->isNew()) {
1715: $translation = new ResourceI18n();
1716: $translation->setLocale($locale);
1717: } else {
1718: $translation = ResourceI18nQuery::create()
1719: ->filterByPrimaryKey(array($this->getPrimaryKey(), $locale))
1720: ->findOneOrCreate($con);
1721: $this->currentTranslations[$locale] = $translation;
1722: }
1723: $this->addResourceI18n($translation);
1724: }
1725:
1726: return $this->currentTranslations[$locale];
1727: }
1728:
1729: /**
1730: * Remove the translation for a given locale
1731: *
1732: * @param string $locale Locale to use for the translation, e.g. 'fr_FR'
1733: * @param PropelPDO $con an optional connection object
1734: *
1735: * @return Resource The current object (for fluent API support)
1736: */
1737: public function removeTranslation($locale = 'en_US', PropelPDO $con = null)
1738: {
1739: if (!$this->isNew()) {
1740: ResourceI18nQuery::create()
1741: ->filterByPrimaryKey(array($this->getPrimaryKey(), $locale))
1742: ->delete($con);
1743: }
1744: if (isset($this->currentTranslations[$locale])) {
1745: unset($this->currentTranslations[$locale]);
1746: }
1747: foreach ($this->collResourceI18ns as $key => $translation) {
1748: if ($translation->getLocale() == $locale) {
1749: unset($this->collResourceI18ns[$key]);
1750: break;
1751: }
1752: }
1753:
1754: return $this;
1755: }
1756:
1757: /**
1758: * Returns the current translation
1759: *
1760: * @param PropelPDO $con an optional connection object
1761: *
1762: * @return ResourceI18n */
1763: public function getCurrentTranslation(PropelPDO $con = null)
1764: {
1765: return $this->getTranslation($this->getLocale(), $con);
1766: }
1767:
1768:
1769: /**
1770: * Get the [title] column value.
1771: *
1772: * @return string
1773: */
1774: public function getTitle()
1775: {
1776: return $this->getCurrentTranslation()->getTitle();
1777: }
1778:
1779:
1780: /**
1781: * Set the value of [title] column.
1782: *
1783: * @param string $v new value
1784: * @return ResourceI18n The current object (for fluent API support)
1785: */
1786: public function setTitle($v)
1787: { $this->getCurrentTranslation()->setTitle($v);
1788:
1789: return $this;
1790: }
1791:
1792:
1793: /**
1794: * Get the [description] column value.
1795: *
1796: * @return string
1797: */
1798: public function getDescription()
1799: {
1800: return $this->getCurrentTranslation()->getDescription();
1801: }
1802:
1803:
1804: /**
1805: * Set the value of [description] column.
1806: *
1807: * @param string $v new value
1808: * @return ResourceI18n The current object (for fluent API support)
1809: */
1810: public function setDescription($v)
1811: { $this->getCurrentTranslation()->setDescription($v);
1812:
1813: return $this;
1814: }
1815:
1816:
1817: /**
1818: * Get the [chapo] column value.
1819: *
1820: * @return string
1821: */
1822: public function getChapo()
1823: {
1824: return $this->getCurrentTranslation()->getChapo();
1825: }
1826:
1827:
1828: /**
1829: * Set the value of [chapo] column.
1830: *
1831: * @param string $v new value
1832: * @return ResourceI18n The current object (for fluent API support)
1833: */
1834: public function setChapo($v)
1835: { $this->getCurrentTranslation()->setChapo($v);
1836:
1837: return $this;
1838: }
1839:
1840:
1841: /**
1842: * Get the [postscriptum] column value.
1843: *
1844: * @return string
1845: */
1846: public function getPostscriptum()
1847: {
1848: return $this->getCurrentTranslation()->getPostscriptum();
1849: }
1850:
1851:
1852: /**
1853: * Set the value of [postscriptum] column.
1854: *
1855: * @param string $v new value
1856: * @return ResourceI18n The current object (for fluent API support)
1857: */
1858: public function setPostscriptum($v)
1859: { $this->getCurrentTranslation()->setPostscriptum($v);
1860:
1861: return $this;
1862: }
1863:
1864: }
1865: