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