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