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