       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\AdminGroup;
      19: use Thelia\Model\AdminGroupQuery;
      20: use Thelia\Model\Group;
      21: use Thelia\Model\GroupI18n;
      22: use Thelia\Model\GroupI18nQuery;
      23: use Thelia\Model\GroupModule;
      24: use Thelia\Model\GroupModuleQuery;
      25: use Thelia\Model\GroupPeer;
      26: use Thelia\Model\GroupQuery;
      27: use Thelia\Model\GroupResource;
      28: use Thelia\Model\GroupResourceQuery;
      29:
      30: /**
      31:  * Base class that represents a row from the 'group' table.
      32:  *
      33:  *
      34:  *
      35:  * @package    propel.generator.Thelia.Model.om
      36:  */
      37: abstract class BaseGroup extends BaseObject implements Persistent
      38: {
      39:     /**
      40:      * Peer class name
      41:      */
      42:     const PEER = 'Thelia\\Model\\GroupPeer';
      43:
      44:     /**
      45:      * The Peer class.
      46:      * Instance provides a convenient way of calling static methods on a class
      47:      * that calling code may not be able to identify.
      48:      * @var        GroupPeer
      49:      */
      50:     protected static $peer;
      51:
      52:     /**
      53:      * The flag var to prevent infinit loop in deep copy
      54:      * @var       boolean
      55:      */
      56:     protected $startCopy = false;
      57:
      58:     /**
      59:      * The value for the id field.
      60:      * @var        int
      61:      */
      62:     protected $id;
      63:
      64:     /**
      65:      * The value for the code field.
      66:      * @var        string
      67:      */
      68:     protected $code;
      69:
      70:     /**
      71:      * The value for the created_at field.
      72:      * @var        string
      73:      */
      74:     protected $created_at;
      75:
      76:     /**
      77:      * The value for the updated_at field.
      78:      * @var        string
      79:      */
      80:     protected $updated_at;
      81:
      82:     /**
      83:      * @var        PropelObjectCollection|AdminGroup[] Collection to store aggregation of AdminGroup objects.
      84:      */
      85:     protected $collAdminGroups;
      86:     protected $collAdminGroupsPartial;
      87:
      88:     /**
      89:      * @var        PropelObjectCollection|GroupResource[] Collection to store aggregation of GroupResource objects.
      90:      */
      91:     protected $collGroupResources;
      92:     protected $collGroupResourcesPartial;
      93:
      94:     /**
      95:      * @var        PropelObjectCollection|GroupModule[] Collection to store aggregation of GroupModule objects.
      96:      */
      97:     protected $collGroupModules;
      98:     protected $collGroupModulesPartial;
      99:
     100:     /**
     101:      * @var        PropelObjectCollection|GroupI18n[] Collection to store aggregation of GroupI18n objects.
     102:      */
     103:     protected $collGroupI18ns;
     104:     protected $collGroupI18nsPartial;
     105:
     106:     /**
     107:      * Flag to prevent endless save loop, if this object is referenced
     108:      * by another object which falls in this transaction.
     109:      * @var        boolean
     110:      */
     111:     protected $alreadyInSave = false;
     112:
     113:     /**
     114:      * Flag to prevent endless validation loop, if this object is referenced
     115:      * by another object which falls in this transaction.
     116:      * @var        boolean
     117:      */
     118:     protected $alreadyInValidation = false;
     119:
     120:     /**
     121:      * Flag to prevent endless clearAllReferences($deep=true) loop, if this object is referenced
     122:      * @var        boolean
     123:      */
     124:     protected $alreadyInClearAllReferencesDeep = false;
     125:
     126:     // i18n behavior
     127:
     128:     /**
     129:      * Current locale
     130:      * @var        string
     131:      */
     132:     protected $currentLocale = 'en_US';
     133:
     134:     /**
     135:      * Current translation objects
     136:      * @var        array[GroupI18n]
     137:      */
     138:     protected $currentTranslations;
     139:
     140:     /**
     141:      * An array of objects scheduled for deletion.
     142:      * @var     PropelObjectCollection
     143:      */
     144:     protected $adminGroupsScheduledForDeletion = null;
     145:
     146:     /**
     147:      * An array of objects scheduled for deletion.
     148:      * @var     PropelObjectCollection
     149:      */
     150:     protected $groupResourcesScheduledForDeletion = null;
     151:
     152:     /**
     153:      * An array of objects scheduled for deletion.
     154:      * @var     PropelObjectCollection
     155:      */
     156:     protected $groupModulesScheduledForDeletion = null;
     157:
     158:     /**
     159:      * An array of objects scheduled for deletion.
     160:      * @var     PropelObjectCollection
     161:      */
     162:     protected $groupI18nsScheduledForDeletion = null;
     163:
     164:     /**
     165:      * Get the [id] column value.
     166:      *
     167:      * @return int
     168:      */
     169:     public function getId()
     170:     {
     171:         return $this->id;
     172:     }
     173:
     174:     /**
     175:      * Get the [code] column value.
     176:      *
     177:      * @return string
     178:      */
     179:     public function getCode()
     180:     {
     181:         return $this->code;
     182:     }
     183:
     184:     /**
     185:      * Get the [optionally formatted] temporal [created_at] column value.
     186:      *
     187:      *
     188:      * @param string $format The date/time format string (either date()-style or strftime()-style).
     189:      *               If format is null, then the raw DateTime object will be returned.
     190:      * @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
     191:      * @throws PropelException - if unable to parse/validate the date/time value.
     192:      */
     193:     public function getCreatedAt($format = 'Y-m-d H:i:s')
     194:     {
     195:         if ($this->created_at === null) {
     196:             return null;
     197:         }
     198:
     199:         if ($this->created_at === '0000-00-00 00:00:00') {
     200:             // while technically this is not a default value of null,
     201:             // this seems to be closest in meaning.
     202:             return null;
     203:         }
     204:
     205:         try {
     206:             $dt = new DateTime($this->created_at);
     207:         } catch (Exception $x) {
     208:             throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->created_at, true), $x);
     209:         }
     210:
     211:         if ($format === null) {
     212:             // Because propel.useDateTimeClass is true, we return a DateTime object.
     213:             return $dt;
     214:         }
     215:
     216:         if (strpos($format, '%') !== false) {
     217:             return strftime($format, $dt->format('U'));
     218:         }
     219:
     220:         return $dt->format($format);
     221:
     222:     }
     223:
     224:     /**
     225:      * Get the [optionally formatted] temporal [updated_at] column value.
     226:      *
     227:      *
     228:      * @param string $format The date/time format string (either date()-style or strftime()-style).
     229:      *               If format is null, then the raw DateTime object will be returned.
     230:      * @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
     231:      * @throws PropelException - if unable to parse/validate the date/time value.
     232:      */
     233:     public function getUpdatedAt($format = 'Y-m-d H:i:s')
     234:     {
     235:         if ($this->updated_at === null) {
     236:             return null;
     237:         }
     238:
     239:         if ($this->updated_at === '0000-00-00 00:00:00') {
     240:             // while technically this is not a default value of null,
     241:             // this seems to be closest in meaning.
     242:             return null;
     243:         }
     244:
     245:         try {
     246:             $dt = new DateTime($this->updated_at);
     247:         } catch (Exception $x) {
     248:             throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->updated_at, true), $x);
     249:         }
     250:
     251:         if ($format === null) {
     252:             // Because propel.useDateTimeClass is true, we return a DateTime object.
     253:             return $dt;
     254:         }
     255:
     256:         if (strpos($format, '%') !== false) {
     257:             return strftime($format, $dt->format('U'));
     258:         }
     259:
     260:         return $dt->format($format);
     261:
     262:     }
     263:
     264:     /**
     265:      * Set the value of [id] column.
     266:      *
     267:      * @param int $v new value
     268:      * @return Group The current object (for fluent API support)
     269:      */
     270:     public function setId($v)
     271:     {
     272:         if ($v !== null && is_numeric($v)) {
     273:             $v = (int) $v;
     274:         }
     275:
     276:         if ($this->id !== $v) {
     277:             $this->id = $v;
     278:             $this->modifiedColumns[] = GroupPeer::ID;
     279:         }
     280:
     281:
     282:         return $this;
     283:     } // setId()
     284:
     285:     /**
     286:      * Set the value of [code] column.
     287:      *
     288:      * @param string $v new value
     289:      * @return Group The current object (for fluent API support)
     290:      */
     291:     public function setCode($v)
     292:     {
     293:         if ($v !== null && is_numeric($v)) {
     294:             $v = (string) $v;
     295:         }
     296:
     297:         if ($this->code !== $v) {
     298:             $this->code = $v;
     299:             $this->modifiedColumns[] = GroupPeer::CODE;
     300:         }
     301:
     302:
     303:         return $this;
     304:     } // setCode()
     305:
     306:     /**
     307:      * Sets the value of [created_at] column to a normalized version of the date/time value specified.
     308:      *
     309:      * @param mixed $v string, integer (timestamp), or DateTime value.
     310:      *               Empty strings are treated as null.
     311:      * @return Group The current object (for fluent API support)
     312:      */
     313:     public function setCreatedAt($v)
     314:     {
     315:         $dt = PropelDateTime::newInstance($v, null, 'DateTime');
     316:         if ($this->created_at !== null || $dt !== null) {
     317:             $currentDateAsString = ($this->created_at !== null && $tmpDt = new DateTime($this->created_at)) ? $tmpDt->format('Y-m-d H:i:s') : null;
     318:             $newDateAsString = $dt ? $dt->format('Y-m-d H:i:s') : null;
     319:             if ($currentDateAsString !== $newDateAsString) {
     320:                 $this->created_at = $newDateAsString;
     321:                 $this->modifiedColumns[] = GroupPeer::CREATED_AT;
     322:             }
     323:         } // if either are not null
     324:
     325:
     326:         return $this;
     327:     } // setCreatedAt()
     328:
     329:     /**
     330:      * Sets the value of [updated_at] column to a normalized version of the date/time value specified.
     331:      *
     332:      * @param mixed $v string, integer (timestamp), or DateTime value.
     333:      *               Empty strings are treated as null.
     334:      * @return Group The current object (for fluent API support)
     335:      */
     336:     public function setUpdatedAt($v)
     337:     {
     338:         $dt = PropelDateTime::newInstance($v, null, 'DateTime');
     339:         if ($this->updated_at !== null || $dt !== null) {
     340:             $currentDateAsString = ($this->updated_at !== null && $tmpDt = new DateTime($this->updated_at)) ? $tmpDt->format('Y-m-d H:i:s') : null;
     341:             $newDateAsString = $dt ? $dt->format('Y-m-d H:i:s') : null;
     342:             if ($currentDateAsString !== $newDateAsString) {
     343:                 $this->updated_at = $newDateAsString;
     344:                 $this->modifiedColumns[] = GroupPeer::UPDATED_AT;
     345:             }
     346:         } // if either are not null
     347:
     348:
     349:         return $this;
     350:     } // setUpdatedAt()
     351:
     352:     /**
     353:      * Indicates whether the columns in this object are only set to default values.
     354:      *
     355:      * This method can be used in conjunction with isModified() to indicate whether an object is both
     356:      * modified _and_ has some values set which are non-default.
     357:      *
     358:      * @return boolean Whether the columns in this object are only been set with default values.
     359:      */
     360:     public function hasOnlyDefaultValues()
     361:     {
     362:         // otherwise, everything was equal, so return true
     363:         return true;
     364:     } // hasOnlyDefaultValues()
     365:
     366:     /**
     367:      * Hydrates (populates) the object variables with values from the database resultset.
     368:      *
     369:      * An offset (0-based "start column") is specified so that objects can be hydrated
     370:      * with a subset of the columns in the resultset rows.  This is needed, for example,
     371:      * for results of JOIN queries where the resultset row includes columns from two or
     372:      * more tables.
     373:      *
     374:      * @param array $row The row returned by PDOStatement->fetch(PDO::FETCH_NUM)
     375:      * @param int $startcol 0-based offset column which indicates which restultset column to start with.
     376:      * @param boolean $rehydrate Whether this object is being re-hydrated from the database.
     377:      * @return int             next starting column
     378:      * @throws PropelException - Any caught Exception will be rewrapped as a PropelException.
     379:      */
     380:     public function hydrate($row, $startcol = 0, $rehydrate = false)
     381:     {
     382:         try {
     383:
     384:             $this->id = ($row[$startcol + 0] !== null) ? (int) $row[$startcol + 0] : null;
     385:             $this->code = ($row[$startcol + 1] !== null) ? (string) $row[$startcol + 1] : null;
     386:             $this->created_at = ($row[$startcol + 2] !== null) ? (string) $row[$startcol + 2] : null;
     387:             $this->updated_at = ($row[$startcol + 3] !== null) ? (string) $row[$startcol + 3] : null;
     388:             $this->resetModified();
     389:
     390:             $this->setNew(false);
     391:
     392:             if ($rehydrate) {
     393:                 $this->ensureConsistency();
     394:             }
     395:             $this->postHydrate($row, $startcol, $rehydrate);
     396:             return $startcol + 4; // 4 = GroupPeer::NUM_HYDRATE_COLUMNS.
     397:
     398:         } catch (Exception $e) {
     399:             throw new PropelException("Error populating Group object", $e);
     400:         }
     401:     }
     402:
     403:     /**
     404:      * Checks and repairs the internal consistency of the object.
     405:      *
     406:      * This method is executed after an already-instantiated object is re-hydrated
     407:      * from the database.  It exists to check any foreign keys to make sure that
     408:      * the objects related to the current object are correct based on foreign key.
     409:      *
     410:      * You can override this method in the stub class, but you should always invoke
     411:      * the base method from the overridden method (i.e. parent::ensureConsistency()),
     412:      * in case your model changes.
     413:      *
     414:      * @throws PropelException
     415:      */
     416:     public function ensureConsistency()
     417:     {
     418:
     419:     } // ensureConsistency
     420:
     421:     /**
     422:      * Reloads this object from datastore based on primary key and (optionally) resets all associated objects.
     423:      *
     424:      * This will only work if the object has been saved and has a valid primary key set.
     425:      *
     426:      * @param boolean $deep (optional) Whether to also de-associated any related objects.
     427:      * @param PropelPDO $con (optional) The PropelPDO connection to use.
     428:      * @return void
     429:      * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db
     430:      */
     431:     public function reload($deep = false, PropelPDO $con = null)
     432:     {
     433:         if ($this->isDeleted()) {
     434:             throw new PropelException("Cannot reload a deleted object.");
     435:         }
     436:
     437:         if ($this->isNew()) {
     438:             throw new PropelException("Cannot reload an unsaved object.");
     439:         }
     440:
     441:         if ($con === null) {
     442:             $con = Propel::getConnection(GroupPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     443:         }
     444:
     445:         // We don't need to alter the object instance pool; we're just modifying this instance
     446:         // already in the pool.
     447:
     448:         $stmt = GroupPeer::doSelectStmt($this->buildPkeyCriteria(), $con);
     449:         $row = $stmt->fetch(PDO::FETCH_NUM);
     450:         $stmt->closeCursor();
     451:         if (!$row) {
     452:             throw new PropelException('Cannot find matching row in the database to reload object values.');
     453:         }
     454:         $this->hydrate($row, 0, true); // rehydrate
     455:
     456:         if ($deep) {  // also de-associate any related objects?
     457:
     458:             $this->collAdminGroups = null;
     459:
     460:             $this->collGroupResources = null;
     461:
     462:             $this->collGroupModules = null;
     463:
     464:             $this->collGroupI18ns = null;
     465:
     466:         } // if (deep)
     467:     }
     468:
     469:     /**
     470:      * Removes this object from datastore and sets delete attribute.
     471:      *
     472:      * @param PropelPDO $con
     473:      * @return void
     474:      * @throws PropelException
     475:      * @throws Exception
     476:      * @see        BaseObject::setDeleted()
     477:      * @see        BaseObject::isDeleted()
     478:      */
     479:     public function delete(PropelPDO $con = null)
     480:     {
     481:         if ($this->isDeleted()) {
     482:             throw new PropelException("This object has already been deleted.");
     483:         }
     484:
     485:         if ($con === null) {
     486:             $con = Propel::getConnection(GroupPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     487:         }
     488:
     489:         $con->beginTransaction();
     490:         try {
     491:             $deleteQuery = GroupQuery::create()
     492:                 ->filterByPrimaryKey($this->getPrimaryKey());
     493:             $ret = $this->preDelete($con);
     494:             if ($ret) {
     495:                 $deleteQuery->delete($con);
     496:                 $this->postDelete($con);
     497:                 $con->commit();
     498:                 $this->setDeleted(true);
     499:             } else {
     500:                 $con->commit();
     501:             }
     502:         } catch (Exception $e) {
     503:             $con->rollBack();
     504:             throw $e;
     505:         }
     506:     }
     507:
     508:     /**
     509:      * Persists this object to the database.
     510:      *
     511:      * If the object is new, it inserts it; otherwise an update is performed.
     512:      * All modified related objects will also be persisted in the doSave()
     513:      * method.  This method wraps all precipitate database operations in a
     514:      * single transaction.
     515:      *
     516:      * @param PropelPDO $con
     517:      * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
     518:      * @throws PropelException
     519:      * @throws Exception
     520:      * @see        doSave()
     521:      */
     522:     public function save(PropelPDO $con = null)
     523:     {
     524:         if ($this->isDeleted()) {
     525:             throw new PropelException("You cannot save an object that has been deleted.");
     526:         }
     527:
     528:         if ($con === null) {
     529:             $con = Propel::getConnection(GroupPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     530:         }
     531:
     532:         $con->beginTransaction();
     533:         $isInsert = $this->isNew();
     534:         try {
     535:             $ret = $this->preSave($con);
     536:             if ($isInsert) {
     537:                 $ret = $ret && $this->preInsert($con);
     538:                 // timestampable behavior
     539:                 if (!$this->isColumnModified(GroupPeer::CREATED_AT)) {
     540:                     $this->setCreatedAt(time());
     541:                 }
     542:                 if (!$this->isColumnModified(GroupPeer::UPDATED_AT)) {
     543:                     $this->setUpdatedAt(time());
     544:                 }
     545:             } else {
     546:                 $ret = $ret && $this->preUpdate($con);
     547:                 // timestampable behavior
     548:                 if ($this->isModified() && !$this->isColumnModified(GroupPeer::UPDATED_AT)) {
     549:                     $this->setUpdatedAt(time());
     550:                 }
     551:             }
     552:             if ($ret) {
     553:                 $affectedRows = $this->doSave($con);
     554:                 if ($isInsert) {
     555:                     $this->postInsert($con);
     556:                 } else {
     557:                     $this->postUpdate($con);
     558:                 }
     559:                 $this->postSave($con);
     560:                 GroupPeer::addInstanceToPool($this);
     561:             } else {
     562:                 $affectedRows = 0;
     563:             }
     564:             $con->commit();
     565:
     566:             return $affectedRows;
     567:         } catch (Exception $e) {
     568:             $con->rollBack();
     569:             throw $e;
     570:         }
     571:     }
     572:
     573:     /**
     574:      * Performs the work of inserting or updating the row in the database.
     575:      *
     576:      * If the object is new, it inserts it; otherwise an update is performed.
     577:      * All related objects are also updated in this method.
     578:      *
     579:      * @param PropelPDO $con
     580:      * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
     581:      * @throws PropelException
     582:      * @see        save()
     583:      */
     584:     protected function doSave(PropelPDO $con)
     585:     {
     586:         $affectedRows = 0; // initialize var to track total num of affected rows
     587:         if (!$this->alreadyInSave) {
     588:             $this->alreadyInSave = true;
     589:
     590:             if ($this->isNew() || $this->isModified()) {
     591:                 // persist changes
     592:                 if ($this->isNew()) {
     593:                     $this->doInsert($con);
     594:                 } else {
     595:                     $this->doUpdate($con);
     596:                 }
     597:                 $affectedRows += 1;
     598:                 $this->resetModified();
     599:             }
     600:
     601:             if ($this->adminGroupsScheduledForDeletion !== null) {
     602:                 if (!$this->adminGroupsScheduledForDeletion->isEmpty()) {
     603:                     foreach ($this->adminGroupsScheduledForDeletion as $adminGroup) {
     604:                         // need to save related object because we set the relation to null
     605:                         $adminGroup->save($con);
     606:                     }
     607:                     $this->adminGroupsScheduledForDeletion = null;
     608:                 }
     609:             }
     610:
     611:             if ($this->collAdminGroups !== null) {
     612:                 foreach ($this->collAdminGroups as $referrerFK) {
     613:                     if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
     614:                         $affectedRows += $referrerFK->save($con);
     615:                     }
     616:                 }
     617:             }
     618:
     619:             if ($this->groupResourcesScheduledForDeletion !== null) {
     620:                 if (!$this->groupResourcesScheduledForDeletion->isEmpty()) {
     621:                     GroupResourceQuery::create()
     622:                         ->filterByPrimaryKeys($this->groupResourcesScheduledForDeletion->getPrimaryKeys(false))
     623:                         ->delete($con);
     624:                     $this->groupResourcesScheduledForDeletion = null;
     625:                 }
     626:             }
     627:
     628:             if ($this->collGroupResources !== null) {
     629:                 foreach ($this->collGroupResources as $referrerFK) {
     630:                     if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
     631:                         $affectedRows += $referrerFK->save($con);
     632:                     }
     633:                 }
     634:             }
     635:
     636:             if ($this->groupModulesScheduledForDeletion !== null) {
     637:                 if (!$this->groupModulesScheduledForDeletion->isEmpty()) {
     638:                     GroupModuleQuery::create()
     639:                         ->filterByPrimaryKeys($this->groupModulesScheduledForDeletion->getPrimaryKeys(false))
     640:                         ->delete($con);
     641:                     $this->groupModulesScheduledForDeletion = null;
     642:                 }
     643:             }
     644:
     645:             if ($this->collGroupModules !== null) {
     646:                 foreach ($this->collGroupModules as $referrerFK) {
     647:                     if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
     648:                         $affectedRows += $referrerFK->save($con);
     649:                     }
     650:                 }
     651:             }
     652:
     653:             if ($this->groupI18nsScheduledForDeletion !== null) {
     654:                 if (!$this->groupI18nsScheduledForDeletion->isEmpty()) {
     655:                     GroupI18nQuery::create()
     656:                         ->filterByPrimaryKeys($this->groupI18nsScheduledForDeletion->getPrimaryKeys(false))
     657:                         ->delete($con);
     658:                     $this->groupI18nsScheduledForDeletion = null;
     659:                 }
     660:             }
     661:
     662:             if ($this->collGroupI18ns !== null) {
     663:                 foreach ($this->collGroupI18ns as $referrerFK) {
     664:                     if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
     665:                         $affectedRows += $referrerFK->save($con);
     666:                     }
     667:                 }
     668:             }
     669:
     670:             $this->alreadyInSave = false;
     671:
     672:         }
     673:
     674:         return $affectedRows;
     675:     } // doSave()
     676:
     677:     /**
     678:      * Insert the row in the database.
     679:      *
     680:      * @param PropelPDO $con
     681:      *
     682:      * @throws PropelException
     683:      * @see        doSave()
     684:      */
     685:     protected function doInsert(PropelPDO $con)
     686:     {
     687:         $modifiedColumns = array();
     688:         $index = 0;
     689:
     690:         $this->modifiedColumns[] = GroupPeer::ID;
     691:         if (null !== $this->id) {
     692:             throw new PropelException('Cannot insert a value for auto-increment primary key (' . GroupPeer::ID . ')');
     693:         }
     694:
     695:          // check the columns in natural order for more readable SQL queries
     696:         if ($this->isColumnModified(GroupPeer::ID)) {
     697:             $modifiedColumns[':p' . $index++]  = '`id`';
     698:         }
     699:         if ($this->isColumnModified(GroupPeer::CODE)) {
     700:             $modifiedColumns[':p' . $index++]  = '`code`';
     701:         }
     702:         if ($this->isColumnModified(GroupPeer::CREATED_AT)) {
     703:             $modifiedColumns[':p' . $index++]  = '`created_at`';
     704:         }
     705:         if ($this->isColumnModified(GroupPeer::UPDATED_AT)) {
     706:             $modifiedColumns[':p' . $index++]  = '`updated_at`';
     707:         }
     708:
     709:         $sql = sprintf(
     710:             'INSERT INTO `group` (%s) VALUES (%s)',
     711:             implode(', ', $modifiedColumns),
     712:             implode(', ', array_keys($modifiedColumns))
     713:         );
     714:
     715:         try {
     716:             $stmt = $con->prepare($sql);
     717:             foreach ($modifiedColumns as $identifier => $columnName) {
     718:                 switch ($columnName) {
     719:                     case '`id`':
     720:                         $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT);
     721:                         break;
     722:                     case '`code`':
     723:                         $stmt->bindValue($identifier, $this->code, PDO::PARAM_STR);
     724:                         break;
     725:                     case '`created_at`':
     726:                         $stmt->bindValue($identifier, $this->created_at, PDO::PARAM_STR);
     727:                         break;
     728:                     case '`updated_at`':
     729:                         $stmt->bindValue($identifier, $this->updated_at, PDO::PARAM_STR);
     730:                         break;
     731:                 }
     732:             }
     733:             $stmt->execute();
     734:         } catch (Exception $e) {
     735:             Propel::log($e->getMessage(), Propel::LOG_ERR);
     736:             throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), $e);
     737:         }
     738:
     739:         try {
     740:             $pk = $con->lastInsertId();
     741:         } catch (Exception $e) {
     742:             throw new PropelException('Unable to get autoincrement id.', $e);
     743:         }
     744:         $this->setId($pk);
     745:
     746:         $this->setNew(false);
     747:     }
     748:
     749:     /**
     750:      * Update the row in the database.
     751:      *
     752:      * @param PropelPDO $con
     753:      *
     754:      * @see        doSave()
     755:      */
     756:     protected function doUpdate(PropelPDO $con)
     757:     {
     758:         $selectCriteria = $this->buildPkeyCriteria();
     759:         $valuesCriteria = $this->buildCriteria();
     760:         BasePeer::doUpdate($selectCriteria, $valuesCriteria, $con);
     761:     }
     762:
     763:     /**
     764:      * Array of ValidationFailed objects.
     765:      * @var        array ValidationFailed[]
     766:      */
     767:     protected $validationFailures = array();
     768:
     769:     /**
     770:      * Gets any ValidationFailed objects that resulted from last call to validate().
     771:      *
     772:      *
     773:      * @return array ValidationFailed[]
     774:      * @see        validate()
     775:      */
     776:     public function getValidationFailures()
     777:     {
     778:         return $this->validationFailures;
     779:     }
     780:
     781:     /**
     782:      * Validates the objects modified field values and all objects related to this table.
     783:      *
     784:      * If $columns is either a column name or an array of column names
     785:      * only those columns are validated.
     786:      *
     787:      * @param mixed $columns Column name or an array of column names.
     788:      * @return boolean Whether all columns pass validation.
     789:      * @see        doValidate()
     790:      * @see        getValidationFailures()
     791:      */
     792:     public function validate($columns = null)
     793:     {
     794:         $res = $this->doValidate($columns);
     795:         if ($res === true) {
     796:             $this->validationFailures = array();
     797:
     798:             return true;
     799:         }
     800:
     801:         $this->validationFailures = $res;
     802:
     803:         return false;
     804:     }
     805:
     806:     /**
     807:      * This function performs the validation work for complex object models.
     808:      *
     809:      * In addition to checking the current object, all related objects will
     810:      * also be validated.  If all pass then <code>true</code> is returned; otherwise
     811:      * an aggreagated array of ValidationFailed objects will be returned.
     812:      *
     813:      * @param array $columns Array of column names to validate.
     814:      * @return mixed <code>true</code> if all validations pass; array of <code>ValidationFailed</code> objets otherwise.
     815:      */
     816:     protected function doValidate($columns = null)
     817:     {
     818:         if (!$this->alreadyInValidation) {
     819:             $this->alreadyInValidation = true;
     820:             $retval = null;
     821:
     822:             $failureMap = array();
     823:
     824:
     825:             if (($retval = GroupPeer::doValidate($this, $columns)) !== true) {
     826:                 $failureMap = array_merge($failureMap, $retval);
     827:             }
     828:
     829:
     830:                 if ($this->collAdminGroups !== null) {
     831:                     foreach ($this->collAdminGroups as $referrerFK) {
     832:                         if (!$referrerFK->validate($columns)) {
     833:                             $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
     834:                         }
     835:                     }
     836:                 }
     837:
     838:                 if ($this->collGroupResources !== null) {
     839:                     foreach ($this->collGroupResources as $referrerFK) {
     840:                         if (!$referrerFK->validate($columns)) {
     841:                             $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
     842:                         }
     843:                     }
     844:                 }
     845:
     846:                 if ($this->collGroupModules !== null) {
     847:                     foreach ($this->collGroupModules as $referrerFK) {
     848:                         if (!$referrerFK->validate($columns)) {
     849:                             $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
     850:                         }
     851:                     }
     852:                 }
     853:
     854:                 if ($this->collGroupI18ns !== null) {
     855:                     foreach ($this->collGroupI18ns as $referrerFK) {
     856:                         if (!$referrerFK->validate($columns)) {
     857:                             $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
     858:                         }
     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 = GroupPeer::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->getCode();
     902:                 break;
     903:             case 2:
     904:                 return $this->getCreatedAt();
     905:                 break;
     906:             case 3:
     907:                 return $this->getUpdatedAt();
     908:                 break;
     909:             default:
     910:                 return null;
     911:                 break;
     912:         } // switch()
     913:     }
     914:
     915:     /**
     916:      * Exports the object as an array.
     917:      *
     918:      * You can specify the key type of the array by passing one of the class
     919:      * type constants.
     920:      *
     921:      * @param     string  $keyType (optional) One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
     922:      *                    BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
     923:      *                    Defaults to BasePeer::TYPE_PHPNAME.
     924:      * @param     boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to true.
     925:      * @param     array $alreadyDumpedObjects List of objects to skip to avoid recursion
     926:      * @param     boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE.
     927:      *
     928:      * @return array an associative array containing the field names (as keys) and field values
     929:      */
     930:     public function toArray($keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false)
     931:     {
     932:         if (isset($alreadyDumpedObjects['Group'][$this->getPrimaryKey()])) {
     933:             return '*RECURSION*';
     934:         }
     935:         $alreadyDumpedObjects['Group'][$this->getPrimaryKey()] = true;
     936:         $keys = GroupPeer::getFieldNames($keyType);
     937:         $result = array(
     938:             $keys[0] => $this->getId(),
     939:             $keys[1] => $this->getCode(),
     940:             $keys[2] => $this->getCreatedAt(),
     941:             $keys[3] => $this->getUpdatedAt(),
     942:         );
     943:         if ($includeForeignObjects) {
     944:             if (null !== $this->collAdminGroups) {
     945:                 $result['AdminGroups'] = $this->collAdminGroups->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects);
     946:             }
     947:             if (null !== $this->collGroupResources) {
     948:                 $result['GroupResources'] = $this->collGroupResources->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects);
     949:             }
     950:             if (null !== $this->collGroupModules) {
     951:                 $result['GroupModules'] = $this->collGroupModules->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects);
     952:             }
     953:             if (null !== $this->collGroupI18ns) {
     954:                 $result['GroupI18ns'] = $this->collGroupI18ns->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects);
     955:             }
     956:         }
     957:
     958:         return $result;
     959:     }
     960:
     961:     /**
     962:      * Sets a field from the object by name passed in as a string.
     963:      *
     964:      * @param string $name peer name
     965:      * @param mixed $value field value
     966:      * @param string $type The type of fieldname the $name is of:
     967:      *                     one of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
     968:      *                     BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
     969:      *                     Defaults to BasePeer::TYPE_PHPNAME
     970:      * @return void
     971:      */
     972:     public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
     973:     {
     974:         $pos = GroupPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
     975:
     976:         $this->setByPosition($pos, $value);
     977:     }
     978:
     979:     /**
     980:      * Sets a field from the object by Position as specified in the xml schema.
     981:      * Zero-based.
     982:      *
     983:      * @param int $pos position in xml schema
     984:      * @param mixed $value field value
     985:      * @return void
     986:      */
     987:     public function setByPosition($pos, $value)
     988:     {
     989:         switch ($pos) {
     990:             case 0:
     991:                 $this->setId($value);
     992:                 break;
     993:             case 1:
     994:                 $this->setCode($value);
     995:                 break;
     996:             case 2:
     997:                 $this->setCreatedAt($value);
     998:                 break;
     999:             case 3:
    1000:                 $this->setUpdatedAt($value);
    1001:                 break;
    1002:         } // switch()
    1003:     }
    1004:
    1005:     /**
    1006:      * Populates the object using an array.
    1007:      *
    1008:      * This is particularly useful when populating an object from one of the
    1009:      * request arrays (e.g. $_POST).  This method goes through the column
    1010:      * names, checking to see whether a matching key exists in populated
    1011:      * array. If so the setByName() method is called for that column.
    1012:      *
    1013:      * You can specify the key type of the array by additionally passing one
    1014:      * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
    1015:      * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
    1016:      * The default key type is the column's BasePeer::TYPE_PHPNAME
    1017:      *
    1018:      * @param array  $arr     An array to populate the object from.
    1019:      * @param string $keyType The type of keys the array uses.
    1020:      * @return void
    1021:      */
    1022:     public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
    1023:     {
    1024:         $keys = GroupPeer::getFieldNames($keyType);
    1025:
    1026:         if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
    1027:         if (array_key_exists($keys[1], $arr)) $this->setCode($arr[$keys[1]]);
    1028:         if (array_key_exists($keys[2], $arr)) $this->setCreatedAt($arr[$keys[2]]);
    1029:         if (array_key_exists($keys[3], $arr)) $this->setUpdatedAt($arr[$keys[3]]);
    1030:     }
    1031:
    1032:     /**
    1033:      * Build a Criteria object containing the values of all modified columns in this object.
    1034:      *
    1035:      * @return Criteria The Criteria object containing all modified values.
    1036:      */
    1037:     public function buildCriteria()
    1038:     {
    1039:         $criteria = new Criteria(GroupPeer::DATABASE_NAME);
    1040:
    1041:         if ($this->isColumnModified(GroupPeer::ID)) $criteria->add(GroupPeer::ID, $this->id);
    1042:         if ($this->isColumnModified(GroupPeer::CODE)) $criteria->add(GroupPeer::CODE, $this->code);
    1043:         if ($this->isColumnModified(GroupPeer::CREATED_AT)) $criteria->add(GroupPeer::CREATED_AT, $this->created_at);
    1044:         if ($this->isColumnModified(GroupPeer::UPDATED_AT)) $criteria->add(GroupPeer::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(GroupPeer::DATABASE_NAME);
    1060:         $criteria->add(GroupPeer::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 Group (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->setCode($this->getCode());
    1109:         $copyObj->setCreatedAt($this->getCreatedAt());
    1110:         $copyObj->setUpdatedAt($this->getUpdatedAt());
    1111:
    1112:         if ($deepCopy && !$this->startCopy) {
    1113:             // important: temporarily setNew(false) because this affects the behavior of
    1114:             // the getter/setter methods for fkey referrer objects.
    1115:             $copyObj->setNew(false);
    1116:             // store object hash to prevent cycle
    1117:             $this->startCopy = true;
    1118:
    1119:             foreach ($this->getAdminGroups() as $relObj) {
    1120:                 if ($relObj !== $this) {  // ensure that we don't try to copy a reference to ourselves
    1121:                     $copyObj->addAdminGroup($relObj->copy($deepCopy));
    1122:                 }
    1123:             }
    1124:
    1125:             foreach ($this->getGroupResources() as $relObj) {
    1126:                 if ($relObj !== $this) {  // ensure that we don't try to copy a reference to ourselves
    1127:                     $copyObj->addGroupResource($relObj->copy($deepCopy));
    1128:                 }
    1129:             }
    1130:
    1131:             foreach ($this->getGroupModules() as $relObj) {
    1132:                 if ($relObj !== $this) {  // ensure that we don't try to copy a reference to ourselves
    1133:                     $copyObj->addGroupModule($relObj->copy($deepCopy));
    1134:                 }
    1135:             }
    1136:
    1137:             foreach ($this->getGroupI18ns() as $relObj) {
    1138:                 if ($relObj !== $this) {  // ensure that we don't try to copy a reference to ourselves
    1139:                     $copyObj->addGroupI18n($relObj->copy($deepCopy));
    1140:                 }
    1141:             }
    1142:
    1143:             //unflag object copy
    1144:             $this->startCopy = false;
    1145:         } // if ($deepCopy)
    1146:
    1147:         if ($makeNew) {
    1148:             $copyObj->setNew(true);
    1149:             $copyObj->setId(NULL); // this is a auto-increment column, so set to default value
    1150:         }
    1151:     }
    1152:
    1153:     /**
    1154:      * Makes a copy of this object that will be inserted as a new row in table when saved.
    1155:      * It creates a new object filling in the simple attributes, but skipping any primary
    1156:      * keys that are defined for the table.
    1157:      *
    1158:      * If desired, this method can also make copies of all associated (fkey referrers)
    1159:      * objects.
    1160:      *
    1161:      * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
    1162:      * @return Group Clone of current object.
    1163:      * @throws PropelException
    1164:      */
    1165:     public function copy($deepCopy = false)
    1166:     {
    1167:         // we use get_class(), because this might be a subclass
    1168:         $clazz = get_class($this);
    1169:         $copyObj = new $clazz();
    1170:         $this->copyInto($copyObj, $deepCopy);
    1171:
    1172:         return $copyObj;
    1173:     }
    1174:
    1175:     /**
    1176:      * Returns a peer instance associated with this om.
    1177:      *
    1178:      * Since Peer classes are not to have any instance attributes, this method returns the
    1179:      * same instance for all member of this class. The method could therefore
    1180:      * be static, but this would prevent one from overriding the behavior.
    1181:      *
    1182:      * @return GroupPeer
    1183:      */
    1184:     public function getPeer()
    1185:     {
    1186:         if (self::$peer === null) {
    1187:             self::$peer = new GroupPeer();
    1188:         }
    1189:
    1190:         return self::$peer;
    1191:     }
    1192:
    1193:
    1194:     /**
    1195:      * Initializes a collection based on the name of a relation.
    1196:      * Avoids crafting an 'init[$relationName]s' method name
    1197:      * that wouldn't work when StandardEnglishPluralizer is used.
    1198:      *
    1199:      * @param string $relationName The name of the relation to initialize
    1200:      * @return void
    1201:      */
    1202:     public function initRelation($relationName)
    1203:     {
    1204:         if ('AdminGroup' == $relationName) {
    1205:             $this->initAdminGroups();
    1206:         }
    1207:         if ('GroupResource' == $relationName) {
    1208:             $this->initGroupResources();
    1209:         }
    1210:         if ('GroupModule' == $relationName) {
    1211:             $this->initGroupModules();
    1212:         }
    1213:         if ('GroupI18n' == $relationName) {
    1214:             $this->initGroupI18ns();
    1215:         }
    1216:     }
    1217:
    1218:     /**
    1219:      * Clears out the collAdminGroups collection
    1220:      *
    1221:      * This does not modify the database; however, it will remove any associated objects, causing
    1222:      * them to be refetched by subsequent calls to accessor method.
    1223:      *
    1224:      * @return Group The current object (for fluent API support)
    1225:      * @see        addAdminGroups()
    1226:      */
    1227:     public function clearAdminGroups()
    1228:     {
    1229:         $this->collAdminGroups = null; // important to set this to null since that means it is uninitialized
    1230:         $this->collAdminGroupsPartial = null;
    1231:
    1232:         return $this;
    1233:     }
    1234:
    1235:     /**
    1236:      * reset is the collAdminGroups collection loaded partially
    1237:      *
    1238:      * @return void
    1239:      */
    1240:     public function resetPartialAdminGroups($v = true)
    1241:     {
    1242:         $this->collAdminGroupsPartial = $v;
    1243:     }
    1244:
    1245:     /**
    1246:      * Initializes the collAdminGroups collection.
    1247:      *
    1248:      * By default this just sets the collAdminGroups collection to an empty array (like clearcollAdminGroups());
    1249:      * however, you may wish to override this method in your stub class to provide setting appropriate
    1250:      * to your application -- for example, setting the initial array to the values stored in database.
    1251:      *
    1252:      * @param boolean $overrideExisting If set to true, the method call initializes
    1253:      *                                        the collection even if it is not empty
    1254:      *
    1255:      * @return void
    1256:      */
    1257:     public function initAdminGroups($overrideExisting = true)
    1258:     {
    1259:         if (null !== $this->collAdminGroups && !$overrideExisting) {
    1260:             return;
    1261:         }
    1262:         $this->collAdminGroups = new PropelObjectCollection();
    1263:         $this->collAdminGroups->setModel('AdminGroup');
    1264:     }
    1265:
    1266:     /**
    1267:      * Gets an array of AdminGroup objects which contain a foreign key that references this object.
    1268:      *
    1269:      * If the $criteria is not null, it is used to always fetch the results from the database.
    1270:      * Otherwise the results are fetched from the database the first time, then cached.
    1271:      * Next time the same method is called without $criteria, the cached collection is returned.
    1272:      * If this Group is new, it will return
    1273:      * an empty collection or the current collection; the criteria is ignored on a new object.
    1274:      *
    1275:      * @param Criteria $criteria optional Criteria object to narrow the query
    1276:      * @param PropelPDO $con optional connection object
    1277:      * @return PropelObjectCollection|AdminGroup[] List of AdminGroup objects
    1278:      * @throws PropelException
    1279:      */
    1280:     public function getAdminGroups($criteria = null, PropelPDO $con = null)
    1281:     {
    1282:         $partial = $this->collAdminGroupsPartial && !$this->isNew();
    1283:         if (null === $this->collAdminGroups || null !== $criteria  || $partial) {
    1284:             if ($this->isNew() && null === $this->collAdminGroups) {
    1285:                 // return empty collection
    1286:                 $this->initAdminGroups();
    1287:             } else {
    1288:                 $collAdminGroups = AdminGroupQuery::create(null, $criteria)
    1289:                     ->filterByGroup($this)
    1290:                     ->find($con);
    1291:                 if (null !== $criteria) {
    1292:                     if (false !== $this->collAdminGroupsPartial && count($collAdminGroups)) {
    1293:                       $this->initAdminGroups(false);
    1294:
    1295:                       foreach($collAdminGroups as $obj) {
    1296:                         if (false == $this->collAdminGroups->contains($obj)) {
    1297:                           $this->collAdminGroups->append($obj);
    1298:                         }
    1299:                       }
    1300:
    1301:                       $this->collAdminGroupsPartial = true;
    1302:                     }
    1303:
    1304:                     $collAdminGroups->getInternalIterator()->rewind();
    1305:                     return $collAdminGroups;
    1306:                 }
    1307:
    1308:                 if($partial && $this->collAdminGroups) {
    1309:                     foreach($this->collAdminGroups as $obj) {
    1310:                         if($obj->isNew()) {
    1311:                             $collAdminGroups[] = $obj;
    1312:                         }
    1313:                     }
    1314:                 }
    1315:
    1316:                 $this->collAdminGroups = $collAdminGroups;
    1317:                 $this->collAdminGroupsPartial = false;
    1318:             }
    1319:         }
    1320:
    1321:         return $this->collAdminGroups;
    1322:     }
    1323:
    1324:     /**
    1325:      * Sets a collection of AdminGroup objects related by a one-to-many relationship
    1326:      * to the current object.
    1327:      * It will also schedule objects for deletion based on a diff between old objects (aka persisted)
    1328:      * and new objects from the given Propel collection.
    1329:      *
    1330:      * @param PropelCollection $adminGroups A Propel collection.
    1331:      * @param PropelPDO $con Optional connection object
    1332:      * @return Group The current object (for fluent API support)
    1333:      */
    1334:     public function setAdminGroups(PropelCollection $adminGroups, PropelPDO $con = null)
    1335:     {
    1336:         $adminGroupsToDelete = $this->getAdminGroups(new Criteria(), $con)->diff($adminGroups);
    1337:
    1338:         $this->adminGroupsScheduledForDeletion = unserialize(serialize($adminGroupsToDelete));
    1339:
    1340:         foreach ($adminGroupsToDelete as $adminGroupRemoved) {
    1341:             $adminGroupRemoved->setGroup(null);
    1342:         }
    1343:
    1344:         $this->collAdminGroups = null;
    1345:         foreach ($adminGroups as $adminGroup) {
    1346:             $this->addAdminGroup($adminGroup);
    1347:         }
    1348:
    1349:         $this->collAdminGroups = $adminGroups;
    1350:         $this->collAdminGroupsPartial = false;
    1351:
    1352:         return $this;
    1353:     }
    1354:
    1355:     /**
    1356:      * Returns the number of related AdminGroup objects.
    1357:      *
    1358:      * @param Criteria $criteria
    1359:      * @param boolean $distinct
    1360:      * @param PropelPDO $con
    1361:      * @return int             Count of related AdminGroup objects.
    1362:      * @throws PropelException
    1363:      */
    1364:     public function countAdminGroups(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
    1365:     {
    1366:         $partial = $this->collAdminGroupsPartial && !$this->isNew();
    1367:         if (null === $this->collAdminGroups || null !== $criteria || $partial) {
    1368:             if ($this->isNew() && null === $this->collAdminGroups) {
    1369:                 return 0;
    1370:             }
    1371:
    1372:             if($partial && !$criteria) {
    1373:                 return count($this->getAdminGroups());
    1374:             }
    1375:             $query = AdminGroupQuery::create(null, $criteria);
    1376:             if ($distinct) {
    1377:                 $query->distinct();
    1378:             }
    1379:
    1380:             return $query
    1381:                 ->filterByGroup($this)
    1382:                 ->count($con);
    1383:         }
    1384:
    1385:         return count($this->collAdminGroups);
    1386:     }
    1387:
    1388:     /**
    1389:      * Method called to associate a AdminGroup object to this object
    1390:      * through the AdminGroup foreign key attribute.
    1391:      *
    1392:      * @param    AdminGroup $l AdminGroup
    1393:      * @return Group The current object (for fluent API support)
    1394:      */
    1395:     public function addAdminGroup(AdminGroup $l)
    1396:     {
    1397:         if ($this->collAdminGroups === null) {
    1398:             $this->initAdminGroups();
    1399:             $this->collAdminGroupsPartial = true;
    1400:         }
    1401:         if (!in_array($l, $this->collAdminGroups->getArrayCopy(), true)) { // only add it if the **same** object is not already associated
    1402:             $this->doAddAdminGroup($l);
    1403:         }
    1404:
    1405:         return $this;
    1406:     }
    1407:
    1408:     /**
    1409:      * @param   AdminGroup $adminGroup The adminGroup object to add.
    1410:      */
    1411:     protected function doAddAdminGroup($adminGroup)
    1412:     {
    1413:         $this->collAdminGroups[]= $adminGroup;
    1414:         $adminGroup->setGroup($this);
    1415:     }
    1416:
    1417:     /**
    1418:      * @param   AdminGroup $adminGroup The adminGroup object to remove.
    1419:      * @return Group The current object (for fluent API support)
    1420:      */
    1421:     public function removeAdminGroup($adminGroup)
    1422:     {
    1423:         if ($this->getAdminGroups()->contains($adminGroup)) {
    1424:             $this->collAdminGroups->remove($this->collAdminGroups->search($adminGroup));
    1425:             if (null === $this->adminGroupsScheduledForDeletion) {
    1426:                 $this->adminGroupsScheduledForDeletion = clone $this->collAdminGroups;
    1427:                 $this->adminGroupsScheduledForDeletion->clear();
    1428:             }
    1429:             $this->adminGroupsScheduledForDeletion[]= $adminGroup;
    1430:             $adminGroup->setGroup(null);
    1431:         }
    1432:
    1433:         return $this;
    1434:     }
    1435:
    1436:
    1437:     /**
    1438:      * If this collection has already been initialized with
    1439:      * an identical criteria, it returns the collection.
    1440:      * Otherwise if this Group is new, it will return
    1441:      * an empty collection; or if this Group has previously
    1442:      * been saved, it will retrieve related AdminGroups from storage.
    1443:      *
    1444:      * This method is protected by default in order to keep the public
    1445:      * api reasonable.  You can provide public methods for those you
    1446:      * actually need in Group.
    1447:      *
    1448:      * @param Criteria $criteria optional Criteria object to narrow the query
    1449:      * @param PropelPDO $con optional connection object
    1450:      * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN)
    1451:      * @return PropelObjectCollection|AdminGroup[] List of AdminGroup objects
    1452:      */
    1453:     public function getAdminGroupsJoinAdmin($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
    1454:     {
    1455:         $query = AdminGroupQuery::create(null, $criteria);
    1456:         $query->joinWith('Admin', $join_behavior);
    1457:
    1458:         return $this->getAdminGroups($query, $con);
    1459:     }
    1460:
    1461:     /**
    1462:      * Clears out the collGroupResources collection
    1463:      *
    1464:      * This does not modify the database; however, it will remove any associated objects, causing
    1465:      * them to be refetched by subsequent calls to accessor method.
    1466:      *
    1467:      * @return Group The current object (for fluent API support)
    1468:      * @see        addGroupResources()
    1469:      */
    1470:     public function clearGroupResources()
    1471:     {
    1472:         $this->collGroupResources = null; // important to set this to null since that means it is uninitialized
    1473:         $this->collGroupResourcesPartial = null;
    1474:
    1475:         return $this;
    1476:     }
    1477:
    1478:     /**
    1479:      * reset is the collGroupResources collection loaded partially
    1480:      *
    1481:      * @return void
    1482:      */
    1483:     public function resetPartialGroupResources($v = true)
    1484:     {
    1485:         $this->collGroupResourcesPartial = $v;
    1486:     }
    1487:
    1488:     /**
    1489:      * Initializes the collGroupResources collection.
    1490:      *
    1491:      * By default this just sets the collGroupResources collection to an empty array (like clearcollGroupResources());
    1492:      * however, you may wish to override this method in your stub class to provide setting appropriate
    1493:      * to your application -- for example, setting the initial array to the values stored in database.
    1494:      *
    1495:      * @param boolean $overrideExisting If set to true, the method call initializes
    1496:      *                                        the collection even if it is not empty
    1497:      *
    1498:      * @return void
    1499:      */
    1500:     public function initGroupResources($overrideExisting = true)
    1501:     {
    1502:         if (null !== $this->collGroupResources && !$overrideExisting) {
    1503:             return;
    1504:         }
    1505:         $this->collGroupResources = new PropelObjectCollection();
    1506:         $this->collGroupResources->setModel('GroupResource');
    1507:     }
    1508:
    1509:     /**
    1510:      * Gets an array of GroupResource objects which contain a foreign key that references this object.
    1511:      *
    1512:      * If the $criteria is not null, it is used to always fetch the results from the database.
    1513:      * Otherwise the results are fetched from the database the first time, then cached.
    1514:      * Next time the same method is called without $criteria, the cached collection is returned.
    1515:      * If this Group is new, it will return
    1516:      * an empty collection or the current collection; the criteria is ignored on a new object.
    1517:      *
    1518:      * @param Criteria $criteria optional Criteria object to narrow the query
    1519:      * @param PropelPDO $con optional connection object
    1520:      * @return PropelObjectCollection|GroupResource[] List of GroupResource objects
    1521:      * @throws PropelException
    1522:      */
    1523:     public function getGroupResources($criteria = null, PropelPDO $con = null)
    1524:     {
    1525:         $partial = $this->collGroupResourcesPartial && !$this->isNew();
    1526:         if (null === $this->collGroupResources || null !== $criteria  || $partial) {
    1527:             if ($this->isNew() && null === $this->collGroupResources) {
    1528:                 // return empty collection
    1529:                 $this->initGroupResources();
    1530:             } else {
    1531:                 $collGroupResources = GroupResourceQuery::create(null, $criteria)
    1532:                     ->filterByGroup($this)
    1533:                     ->find($con);
    1534:                 if (null !== $criteria) {
    1535:                     if (false !== $this->collGroupResourcesPartial && count($collGroupResources)) {
    1536:                       $this->initGroupResources(false);
    1537:
    1538:                       foreach($collGroupResources as $obj) {
    1539:                         if (false == $this->collGroupResources->contains($obj)) {
    1540:                           $this->collGroupResources->append($obj);
    1541:                         }
    1542:                       }
    1543:
    1544:                       $this->collGroupResourcesPartial = true;
    1545:                     }
    1546:
    1547:                     $collGroupResources->getInternalIterator()->rewind();
    1548:                     return $collGroupResources;
    1549:                 }
    1550:
    1551:                 if($partial && $this->collGroupResources) {
    1552:                     foreach($this->collGroupResources as $obj) {
    1553:                         if($obj->isNew()) {
    1554:                             $collGroupResources[] = $obj;
    1555:                         }
    1556:                     }
    1557:                 }
    1558:
    1559:                 $this->collGroupResources = $collGroupResources;
    1560:                 $this->collGroupResourcesPartial = false;
    1561:             }
    1562:         }
    1563:
    1564:         return $this->collGroupResources;
    1565:     }
    1566:
    1567:     /**
    1568:      * Sets a collection of GroupResource objects related by a one-to-many relationship
    1569:      * to the current object.
    1570:      * It will also schedule objects for deletion based on a diff between old objects (aka persisted)
    1571:      * and new objects from the given Propel collection.
    1572:      *
    1573:      * @param PropelCollection $groupResources A Propel collection.
    1574:      * @param PropelPDO $con Optional connection object
    1575:      * @return Group The current object (for fluent API support)
    1576:      */
    1577:     public function setGroupResources(PropelCollection $groupResources, PropelPDO $con = null)
    1578:     {
    1579:         $groupResourcesToDelete = $this->getGroupResources(new Criteria(), $con)->diff($groupResources);
    1580:
    1581:         $this->groupResourcesScheduledForDeletion = unserialize(serialize($groupResourcesToDelete));
    1582:
    1583:         foreach ($groupResourcesToDelete as $groupResourceRemoved) {
    1584:             $groupResourceRemoved->setGroup(null);
    1585:         }
    1586:
    1587:         $this->collGroupResources = null;
    1588:         foreach ($groupResources as $groupResource) {
    1589:             $this->addGroupResource($groupResource);
    1590:         }
    1591:
    1592:         $this->collGroupResources = $groupResources;
    1593:         $this->collGroupResourcesPartial = false;
    1594:
    1595:         return $this;
    1596:     }
    1597:
    1598:     /**
    1599:      * Returns the number of related GroupResource objects.
    1600:      *
    1601:      * @param Criteria $criteria
    1602:      * @param boolean $distinct
    1603:      * @param PropelPDO $con
    1604:      * @return int             Count of related GroupResource objects.
    1605:      * @throws PropelException
    1606:      */
    1607:     public function countGroupResources(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
    1608:     {
    1609:         $partial = $this->collGroupResourcesPartial && !$this->isNew();
    1610:         if (null === $this->collGroupResources || null !== $criteria || $partial) {
    1611:             if ($this->isNew() && null === $this->collGroupResources) {
    1612:                 return 0;
    1613:             }
    1614:
    1615:             if($partial && !$criteria) {
    1616:                 return count($this->getGroupResources());
    1617:             }
    1618:             $query = GroupResourceQuery::create(null, $criteria);
    1619:             if ($distinct) {
    1620:                 $query->distinct();
    1621:             }
    1622:
    1623:             return $query
    1624:                 ->filterByGroup($this)
    1625:                 ->count($con);
    1626:         }
    1627:
    1628:         return count($this->collGroupResources);
    1629:     }
    1630:
    1631:     /**
    1632:      * Method called to associate a GroupResource object to this object
    1633:      * through the GroupResource foreign key attribute.
    1634:      *
    1635:      * @param    GroupResource $l GroupResource
    1636:      * @return Group The current object (for fluent API support)
    1637:      */
    1638:     public function addGroupResource(GroupResource $l)
    1639:     {
    1640:         if ($this->collGroupResources === null) {
    1641:             $this->initGroupResources();
    1642:             $this->collGroupResourcesPartial = true;
    1643:         }
    1644:         if (!in_array($l, $this->collGroupResources->getArrayCopy(), true)) { // only add it if the **same** object is not already associated
    1645:             $this->doAddGroupResource($l);
    1646:         }
    1647:
    1648:         return $this;
    1649:     }
    1650:
    1651:     /**
    1652:      * @param   GroupResource $groupResource The groupResource object to add.
    1653:      */
    1654:     protected function doAddGroupResource($groupResource)
    1655:     {
    1656:         $this->collGroupResources[]= $groupResource;
    1657:         $groupResource->setGroup($this);
    1658:     }
    1659:
    1660:     /**
    1661:      * @param   GroupResource $groupResource The groupResource object to remove.
    1662:      * @return Group The current object (for fluent API support)
    1663:      */
    1664:     public function removeGroupResource($groupResource)
    1665:     {
    1666:         if ($this->getGroupResources()->contains($groupResource)) {
    1667:             $this->collGroupResources->remove($this->collGroupResources->search($groupResource));
    1668:             if (null === $this->groupResourcesScheduledForDeletion) {
    1669:                 $this->groupResourcesScheduledForDeletion = clone $this->collGroupResources;
    1670:                 $this->groupResourcesScheduledForDeletion->clear();
    1671:             }
    1672:             $this->groupResourcesScheduledForDeletion[]= clone $groupResource;
    1673:             $groupResource->setGroup(null);
    1674:         }
    1675:
    1676:         return $this;
    1677:     }
    1678:
    1679:
    1680:     /**
    1681:      * If this collection has already been initialized with
    1682:      * an identical criteria, it returns the collection.
    1683:      * Otherwise if this Group is new, it will return
    1684:      * an empty collection; or if this Group has previously
    1685:      * been saved, it will retrieve related GroupResources from storage.
    1686:      *
    1687:      * This method is protected by default in order to keep the public
    1688:      * api reasonable.  You can provide public methods for those you
    1689:      * actually need in Group.
    1690:      *
    1691:      * @param Criteria $criteria optional Criteria object to narrow the query
    1692:      * @param PropelPDO $con optional connection object
    1693:      * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN)
    1694:      * @return PropelObjectCollection|GroupResource[] List of GroupResource objects
    1695:      */
    1696:     public function getGroupResourcesJoinResource($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
    1697:     {
    1698:         $query = GroupResourceQuery::create(null, $criteria);
    1699:         $query->joinWith('Resource', $join_behavior);
    1700:
    1701:         return $this->getGroupResources($query, $con);
    1702:     }
    1703:
    1704:     /**
    1705:      * Clears out the collGroupModules collection
    1706:      *
    1707:      * This does not modify the database; however, it will remove any associated objects, causing
    1708:      * them to be refetched by subsequent calls to accessor method.
    1709:      *
    1710:      * @return Group The current object (for fluent API support)
    1711:      * @see        addGroupModules()
    1712:      */
    1713:     public function clearGroupModules()
    1714:     {
    1715:         $this->collGroupModules = null; // important to set this to null since that means it is uninitialized
    1716:         $this->collGroupModulesPartial = null;
    1717:
    1718:         return $this;
    1719:     }
    1720:
    1721:     /**
    1722:      * reset is the collGroupModules collection loaded partially
    1723:      *
    1724:      * @return void
    1725:      */
    1726:     public function resetPartialGroupModules($v = true)
    1727:     {
    1728:         $this->collGroupModulesPartial = $v;
    1729:     }
    1730:
    1731:     /**
    1732:      * Initializes the collGroupModules collection.
    1733:      *
    1734:      * By default this just sets the collGroupModules collection to an empty array (like clearcollGroupModules());
    1735:      * however, you may wish to override this method in your stub class to provide setting appropriate
    1736:      * to your application -- for example, setting the initial array to the values stored in database.
    1737:      *
    1738:      * @param boolean $overrideExisting If set to true, the method call initializes
    1739:      *                                        the collection even if it is not empty
    1740:      *
    1741:      * @return void
    1742:      */
    1743:     public function initGroupModules($overrideExisting = true)
    1744:     {
    1745:         if (null !== $this->collGroupModules && !$overrideExisting) {
    1746:             return;
    1747:         }
    1748:         $this->collGroupModules = new PropelObjectCollection();
    1749:         $this->collGroupModules->setModel('GroupModule');
    1750:     }
    1751:
    1752:     /**
    1753:      * Gets an array of GroupModule objects which contain a foreign key that references this object.
    1754:      *
    1755:      * If the $criteria is not null, it is used to always fetch the results from the database.
    1756:      * Otherwise the results are fetched from the database the first time, then cached.
    1757:      * Next time the same method is called without $criteria, the cached collection is returned.
    1758:      * If this Group is new, it will return
    1759:      * an empty collection or the current collection; the criteria is ignored on a new object.
    1760:      *
    1761:      * @param Criteria $criteria optional Criteria object to narrow the query
    1762:      * @param PropelPDO $con optional connection object
    1763:      * @return PropelObjectCollection|GroupModule[] List of GroupModule objects
    1764:      * @throws PropelException
    1765:      */
    1766:     public function getGroupModules($criteria = null, PropelPDO $con = null)
    1767:     {
    1768:         $partial = $this->collGroupModulesPartial && !$this->isNew();
    1769:         if (null === $this->collGroupModules || null !== $criteria  || $partial) {
    1770:             if ($this->isNew() && null === $this->collGroupModules) {
    1771:                 // return empty collection
    1772:                 $this->initGroupModules();
    1773:             } else {
    1774:                 $collGroupModules = GroupModuleQuery::create(null, $criteria)
    1775:                     ->filterByGroup($this)
    1776:                     ->find($con);
    1777:                 if (null !== $criteria) {
    1778:                     if (false !== $this->collGroupModulesPartial && count($collGroupModules)) {
    1779:                       $this->initGroupModules(false);
    1780:
    1781:                       foreach($collGroupModules as $obj) {
    1782:                         if (false == $this->collGroupModules->contains($obj)) {
    1783:                           $this->collGroupModules->append($obj);
    1784:                         }
    1785:                       }
    1786:
    1787:                       $this->collGroupModulesPartial = true;
    1788:                     }
    1789:
    1790:                     $collGroupModules->getInternalIterator()->rewind();
    1791:                     return $collGroupModules;
    1792:                 }
    1793:
    1794:                 if($partial && $this->collGroupModules) {
    1795:                     foreach($this->collGroupModules as $obj) {
    1796:                         if($obj->isNew()) {
    1797:                             $collGroupModules[] = $obj;
    1798:                         }
    1799:                     }
    1800:                 }
    1801:
    1802:                 $this->collGroupModules = $collGroupModules;
    1803:                 $this->collGroupModulesPartial = false;
    1804:             }
    1805:         }
    1806:
    1807:         return $this->collGroupModules;
    1808:     }
    1809:
    1810:     /**
    1811:      * Sets a collection of GroupModule objects related by a one-to-many relationship
    1812:      * to the current object.
    1813:      * It will also schedule objects for deletion based on a diff between old objects (aka persisted)
    1814:      * and new objects from the given Propel collection.
    1815:      *
    1816:      * @param PropelCollection $groupModules A Propel collection.
    1817:      * @param PropelPDO $con Optional connection object
    1818:      * @return Group The current object (for fluent API support)
    1819:      */
    1820:     public function setGroupModules(PropelCollection $groupModules, PropelPDO $con = null)
    1821:     {
    1822:         $groupModulesToDelete = $this->getGroupModules(new Criteria(), $con)->diff($groupModules);
    1823:
    1824:         $this->groupModulesScheduledForDeletion = unserialize(serialize($groupModulesToDelete));
    1825:
    1826:         foreach ($groupModulesToDelete as $groupModuleRemoved) {
    1827:             $groupModuleRemoved->setGroup(null);
    1828:         }
    1829:
    1830:         $this->collGroupModules = null;
    1831:         foreach ($groupModules as $groupModule) {
    1832:             $this->addGroupModule($groupModule);
    1833:         }
    1834:
    1835:         $this->collGroupModules = $groupModules;
    1836:         $this->collGroupModulesPartial = false;
    1837:
    1838:         return $this;
    1839:     }
    1840:
    1841:     /**
    1842:      * Returns the number of related GroupModule objects.
    1843:      *
    1844:      * @param Criteria $criteria
    1845:      * @param boolean $distinct
    1846:      * @param PropelPDO $con
    1847:      * @return int             Count of related GroupModule objects.
    1848:      * @throws PropelException
    1849:      */
    1850:     public function countGroupModules(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
    1851:     {
    1852:         $partial = $this->collGroupModulesPartial && !$this->isNew();
    1853:         if (null === $this->collGroupModules || null !== $criteria || $partial) {
    1854:             if ($this->isNew() && null === $this->collGroupModules) {
    1855:                 return 0;
    1856:             }
    1857:
    1858:             if($partial && !$criteria) {
    1859:                 return count($this->getGroupModules());
    1860:             }
    1861:             $query = GroupModuleQuery::create(null, $criteria);
    1862:             if ($distinct) {
    1863:                 $query->distinct();
    1864:             }
    1865:
    1866:             return $query
    1867:                 ->filterByGroup($this)
    1868:                 ->count($con);
    1869:         }
    1870:
    1871:         return count($this->collGroupModules);
    1872:     }
    1873:
    1874:     /**
    1875:      * Method called to associate a GroupModule object to this object
    1876:      * through the GroupModule foreign key attribute.
    1877:      *
    1878:      * @param    GroupModule $l GroupModule
    1879:      * @return Group The current object (for fluent API support)
    1880:      */
    1881:     public function addGroupModule(GroupModule $l)
    1882:     {
    1883:         if ($this->collGroupModules === null) {
    1884:             $this->initGroupModules();
    1885:             $this->collGroupModulesPartial = true;
    1886:         }
    1887:         if (!in_array($l, $this->collGroupModules->getArrayCopy(), true)) { // only add it if the **same** object is not already associated
    1888:             $this->doAddGroupModule($l);
    1889:         }
    1890:
    1891:         return $this;
    1892:     }
    1893:
    1894:     /**
    1895:      * @param   GroupModule $groupModule The groupModule object to add.
    1896:      */
    1897:     protected function doAddGroupModule($groupModule)
    1898:     {
    1899:         $this->collGroupModules[]= $groupModule;
    1900:         $groupModule->setGroup($this);
    1901:     }
    1902:
    1903:     /**
    1904:      * @param   GroupModule $groupModule The groupModule object to remove.
    1905:      * @return Group The current object (for fluent API support)
    1906:      */
    1907:     public function removeGroupModule($groupModule)
    1908:     {
    1909:         if ($this->getGroupModules()->contains($groupModule)) {
    1910:             $this->collGroupModules->remove($this->collGroupModules->search($groupModule));
    1911:             if (null === $this->groupModulesScheduledForDeletion) {
    1912:                 $this->groupModulesScheduledForDeletion = clone $this->collGroupModules;
    1913:                 $this->groupModulesScheduledForDeletion->clear();
    1914:             }
    1915:             $this->groupModulesScheduledForDeletion[]= clone $groupModule;
    1916:             $groupModule->setGroup(null);
    1917:         }
    1918:
    1919:         return $this;
    1920:     }
    1921:
    1922:
    1923:     /**
    1924:      * If this collection has already been initialized with
    1925:      * an identical criteria, it returns the collection.
    1926:      * Otherwise if this Group is new, it will return
    1927:      * an empty collection; or if this Group has previously
    1928:      * been saved, it will retrieve related GroupModules from storage.
    1929:      *
    1930:      * This method is protected by default in order to keep the public
    1931:      * api reasonable.  You can provide public methods for those you
    1932:      * actually need in Group.
    1933:      *
    1934:      * @param Criteria $criteria optional Criteria object to narrow the query
    1935:      * @param PropelPDO $con optional connection object
    1936:      * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN)
    1937:      * @return PropelObjectCollection|GroupModule[] List of GroupModule objects
    1938:      */
    1939:     public function getGroupModulesJoinModule($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
    1940:     {
    1941:         $query = GroupModuleQuery::create(null, $criteria);
    1942:         $query->joinWith('Module', $join_behavior);
    1943:
    1944:         return $this->getGroupModules($query, $con);
    1945:     }
    1946:
    1947:     /**
    1948:      * Clears out the collGroupI18ns collection
    1949:      *
    1950:      * This does not modify the database; however, it will remove any associated objects, causing
    1951:      * them to be refetched by subsequent calls to accessor method.
    1952:      *
    1953:      * @return Group The current object (for fluent API support)
    1954:      * @see        addGroupI18ns()
    1955:      */
    1956:     public function clearGroupI18ns()
    1957:     {
    1958:         $this->collGroupI18ns = null; // important to set this to null since that means it is uninitialized
    1959:         $this->collGroupI18nsPartial = null;
    1960:
    1961:         return $this;
    1962:     }
    1963:
    1964:     /**
    1965:      * reset is the collGroupI18ns collection loaded partially
    1966:      *
    1967:      * @return void
    1968:      */
    1969:     public function resetPartialGroupI18ns($v = true)
    1970:     {
    1971:         $this->collGroupI18nsPartial = $v;
    1972:     }
    1973:
    1974:     /**
    1975:      * Initializes the collGroupI18ns collection.
    1976:      *
    1977:      * By default this just sets the collGroupI18ns collection to an empty array (like clearcollGroupI18ns());
    1978:      * however, you may wish to override this method in your stub class to provide setting appropriate
    1979:      * to your application -- for example, setting the initial array to the values stored in database.
    1980:      *
    1981:      * @param boolean $overrideExisting If set to true, the method call initializes
    1982:      *                                        the collection even if it is not empty
    1983:      *
    1984:      * @return void
    1985:      */
    1986:     public function initGroupI18ns($overrideExisting = true)
    1987:     {
    1988:         if (null !== $this->collGroupI18ns && !$overrideExisting) {
    1989:             return;
    1990:         }
    1991:         $this->collGroupI18ns = new PropelObjectCollection();
    1992:         $this->collGroupI18ns->setModel('GroupI18n');
    1993:     }
    1994:
    1995:     /**
    1996:      * Gets an array of GroupI18n objects which contain a foreign key that references this object.
    1997:      *
    1998:      * If the $criteria is not null, it is used to always fetch the results from the database.
    1999:      * Otherwise the results are fetched from the database the first time, then cached.
    2000:      * Next time the same method is called without $criteria, the cached collection is returned.
    2001:      * If this Group is new, it will return
    2002:      * an empty collection or the current collection; the criteria is ignored on a new object.
    2003:      *
    2004:      * @param Criteria $criteria optional Criteria object to narrow the query
    2005:      * @param PropelPDO $con optional connection object
    2006:      * @return PropelObjectCollection|GroupI18n[] List of GroupI18n objects
    2007:      * @throws PropelException
    2008:      */
    2009:     public function getGroupI18ns($criteria = null, PropelPDO $con = null)
    2010:     {
    2011:         $partial = $this->collGroupI18nsPartial && !$this->isNew();
    2012:         if (null === $this->collGroupI18ns || null !== $criteria  || $partial) {
    2013:             if ($this->isNew() && null === $this->collGroupI18ns) {
    2014:                 // return empty collection
    2015:                 $this->initGroupI18ns();
    2016:             } else {
    2017:                 $collGroupI18ns = GroupI18nQuery::create(null, $criteria)
    2018:                     ->filterByGroup($this)
    2019:                     ->find($con);
    2020:                 if (null !== $criteria) {
    2021:                     if (false !== $this->collGroupI18nsPartial && count($collGroupI18ns)) {
    2022:                       $this->initGroupI18ns(false);
    2023:
    2024:                       foreach($collGroupI18ns as $obj) {
    2025:                         if (false == $this->collGroupI18ns->contains($obj)) {
    2026:                           $this->collGroupI18ns->append($obj);
    2027:                         }
    2028:                       }
    2029:
    2030:                       $this->collGroupI18nsPartial = true;
    2031:                     }
    2032:
    2033:                     $collGroupI18ns->getInternalIterator()->rewind();
    2034:                     return $collGroupI18ns;
    2035:                 }
    2036:
    2037:                 if($partial && $this->collGroupI18ns) {
    2038:                     foreach($this->collGroupI18ns as $obj) {
    2039:                         if($obj->isNew()) {
    2040:                             $collGroupI18ns[] = $obj;
    2041:                         }
    2042:                     }
    2043:                 }
    2044:
    2045:                 $this->collGroupI18ns = $collGroupI18ns;
    2046:                 $this->collGroupI18nsPartial = false;
    2047:             }
    2048:         }
    2049:
    2050:         return $this->collGroupI18ns;
    2051:     }
    2052:
    2053:     /**
    2054:      * Sets a collection of GroupI18n objects related by a one-to-many relationship
    2055:      * to the current object.
    2056:      * It will also schedule objects for deletion based on a diff between old objects (aka persisted)
    2057:      * and new objects from the given Propel collection.
    2058:      *
    2059:      * @param PropelCollection $groupI18ns A Propel collection.
    2060:      * @param PropelPDO $con Optional connection object
    2061:      * @return Group The current object (for fluent API support)
    2062:      */
    2063:     public function setGroupI18ns(PropelCollection $groupI18ns, PropelPDO $con = null)
    2064:     {
    2065:         $groupI18nsToDelete = $this->getGroupI18ns(new Criteria(), $con)->diff($groupI18ns);
    2066:
    2067:         $this->groupI18nsScheduledForDeletion = unserialize(serialize($groupI18nsToDelete));
    2068:
    2069:         foreach ($groupI18nsToDelete as $groupI18nRemoved) {
    2070:             $groupI18nRemoved->setGroup(null);
    2071:         }
    2072:
    2073:         $this->collGroupI18ns = null;
    2074:         foreach ($groupI18ns as $groupI18n) {
    2075:             $this->addGroupI18n($groupI18n);
    2076:         }
    2077:
    2078:         $this->collGroupI18ns = $groupI18ns;
    2079:         $this->collGroupI18nsPartial = false;
    2080:
    2081:         return $this;
    2082:     }
    2083:
    2084:     /**
    2085:      * Returns the number of related GroupI18n objects.
    2086:      *
    2087:      * @param Criteria $criteria
    2088:      * @param boolean $distinct
    2089:      * @param PropelPDO $con
    2090:      * @return int             Count of related GroupI18n objects.
    2091:      * @throws PropelException
    2092:      */
    2093:     public function countGroupI18ns(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
    2094:     {
    2095:         $partial = $this->collGroupI18nsPartial && !$this->isNew();
    2096:         if (null === $this->collGroupI18ns || null !== $criteria || $partial) {
    2097:             if ($this->isNew() && null === $this->collGroupI18ns) {
    2098:                 return 0;
    2099:             }
    2100:
    2101:             if($partial && !$criteria) {
    2102:                 return count($this->getGroupI18ns());
    2103:             }
    2104:             $query = GroupI18nQuery::create(null, $criteria);
    2105:             if ($distinct) {
    2106:                 $query->distinct();
    2107:             }
    2108:
    2109:             return $query
    2110:                 ->filterByGroup($this)
    2111:                 ->count($con);
    2112:         }
    2113:
    2114:         return count($this->collGroupI18ns);
    2115:     }
    2116:
    2117:     /**
    2118:      * Method called to associate a GroupI18n object to this object
    2119:      * through the GroupI18n foreign key attribute.
    2120:      *
    2121:      * @param    GroupI18n $l GroupI18n
    2122:      * @return Group The current object (for fluent API support)
    2123:      */
    2124:     public function addGroupI18n(GroupI18n $l)
    2125:     {
    2126:         if ($l && $locale = $l->getLocale()) {
    2127:             $this->setLocale($locale);
    2128:             $this->currentTranslations[$locale] = $l;
    2129:         }
    2130:         if ($this->collGroupI18ns === null) {
    2131:             $this->initGroupI18ns();
    2132:             $this->collGroupI18nsPartial = true;
    2133:         }
    2134:         if (!in_array($l, $this->collGroupI18ns->getArrayCopy(), true)) { // only add it if the **same** object is not already associated
    2135:             $this->doAddGroupI18n($l);
    2136:         }
    2137:
    2138:         return $this;
    2139:     }
    2140:
    2141:     /**
    2142:      * @param   GroupI18n $groupI18n The groupI18n object to add.
    2143:      */
    2144:     protected function doAddGroupI18n($groupI18n)
    2145:     {
    2146:         $this->collGroupI18ns[]= $groupI18n;
    2147:         $groupI18n->setGroup($this);
    2148:     }
    2149:
    2150:     /**
    2151:      * @param   GroupI18n $groupI18n The groupI18n object to remove.
    2152:      * @return Group The current object (for fluent API support)
    2153:      */
    2154:     public function removeGroupI18n($groupI18n)
    2155:     {
    2156:         if ($this->getGroupI18ns()->contains($groupI18n)) {
    2157:             $this->collGroupI18ns->remove($this->collGroupI18ns->search($groupI18n));
    2158:             if (null === $this->groupI18nsScheduledForDeletion) {
    2159:                 $this->groupI18nsScheduledForDeletion = clone $this->collGroupI18ns;
    2160:                 $this->groupI18nsScheduledForDeletion->clear();
    2161:             }
    2162:             $this->groupI18nsScheduledForDeletion[]= clone $groupI18n;
    2163:             $groupI18n->setGroup(null);
    2164:         }
    2165:
    2166:         return $this;
    2167:     }
    2168:
    2169:     /**
    2170:      * Clears the current object and sets all attributes to their default values
    2171:      */
    2172:     public function clear()
    2173:     {
    2174:         $this->id = null;
    2175:         $this->code = null;
    2176:         $this->created_at = null;
    2177:         $this->updated_at = null;
    2178:         $this->alreadyInSave = false;
    2179:         $this->alreadyInValidation = false;
    2180:         $this->alreadyInClearAllReferencesDeep = false;
    2181:         $this->clearAllReferences();
    2182:         $this->resetModified();
    2183:         $this->setNew(true);
    2184:         $this->setDeleted(false);
    2185:     }
    2186:
    2187:     /**
    2188:      * Resets all references to other model objects or collections of model objects.
    2189:      *
    2190:      * This method is a user-space workaround for PHP's inability to garbage collect
    2191:      * objects with circular references (even in PHP 5.3). This is currently necessary
    2192:      * when using Propel in certain daemon or large-volumne/high-memory operations.
    2193:      *
    2194:      * @param boolean $deep Whether to also clear the references on all referrer objects.
    2195:      */
    2196:     public function clearAllReferences($deep = false)
    2197:     {
    2198:         if ($deep && !$this->alreadyInClearAllReferencesDeep) {
    2199:             $this->alreadyInClearAllReferencesDeep = true;
    2200:             if ($this->collAdminGroups) {
    2201:                 foreach ($this->collAdminGroups as $o) {
    2202:                     $o->clearAllReferences($deep);
    2203:                 }
    2204:             }
    2205:             if ($this->collGroupResources) {
    2206:                 foreach ($this->collGroupResources as $o) {
    2207:                     $o->clearAllReferences($deep);
    2208:                 }
    2209:             }
    2210:             if ($this->collGroupModules) {
    2211:                 foreach ($this->collGroupModules as $o) {
    2212:                     $o->clearAllReferences($deep);
    2213:                 }
    2214:             }
    2215:             if ($this->collGroupI18ns) {
    2216:                 foreach ($this->collGroupI18ns as $o) {
    2217:                     $o->clearAllReferences($deep);
    2218:                 }
    2219:             }
    2220:
    2221:             $this->alreadyInClearAllReferencesDeep = false;
    2222:         } // if ($deep)
    2223:
    2224:         // i18n behavior
    2225:         $this->currentLocale = 'en_US';
    2226:         $this->currentTranslations = null;
    2227:
    2228:         if ($this->collAdminGroups instanceof PropelCollection) {
    2229:             $this->collAdminGroups->clearIterator();
    2230:         }
    2231:         $this->collAdminGroups = null;
    2232:         if ($this->collGroupResources instanceof PropelCollection) {
    2233:             $this->collGroupResources->clearIterator();
    2234:         }
    2235:         $this->collGroupResources = null;
    2236:         if ($this->collGroupModules instanceof PropelCollection) {
    2237:             $this->collGroupModules->clearIterator();
    2238:         }
    2239:         $this->collGroupModules = null;
    2240:         if ($this->collGroupI18ns instanceof PropelCollection) {
    2241:             $this->collGroupI18ns->clearIterator();
    2242:         }
    2243:         $this->collGroupI18ns = null;
    2244:     }
    2245:
    2246:     /**
    2247:      * return the string representation of this object
    2248:      *
    2249:      * @return string
    2250:      */
    2251:     public function __toString()
    2252:     {
    2253:         return (string) $this->exportTo(GroupPeer::DEFAULT_STRING_FORMAT);
    2254:     }
    2255:
    2256:     /**
    2257:      * return true is the object is in saving state
    2258:      *
    2259:      * @return boolean
    2260:      */
    2261:     public function isAlreadyInSave()
    2262:     {
    2263:         return $this->alreadyInSave;
    2264:     }
    2265:
    2266:     // timestampable behavior
    2267:
    2268:     /**
    2269:      * Mark the current object so that the update date doesn't get updated during next save
    2270:      *
    2271:      * @return     Group The current object (for fluent API support)
    2272:      */
    2273:     public function keepUpdateDateUnchanged()
    2274:     {
    2275:         $this->modifiedColumns[] = GroupPeer::UPDATED_AT;
    2276:
    2277:         return $this;
    2278:     }
    2279:
    2280:     // i18n behavior
    2281:
    2282:     /**
    2283:      * Sets the locale for translations
    2284:      *
    2285:      * @param     string $locale Locale to use for the translation, e.g. 'fr_FR'
    2286:      *
    2287:      * @return    Group The current object (for fluent API support)
    2288:      */
    2289:     public function setLocale($locale = 'en_US')
    2290:     {
    2291:         $this->currentLocale = $locale;
    2292:
    2293:         return $this;
    2294:     }
    2295:
    2296:     /**
    2297:      * Gets the locale for translations
    2298:      *
    2299:      * @return    string $locale Locale to use for the translation, e.g. 'fr_FR'
    2300:      */
    2301:     public function getLocale()
    2302:     {
    2303:         return $this->currentLocale;
    2304:     }
    2305:
    2306:     /**
    2307:      * Returns the current translation for a given locale
    2308:      *
    2309:      * @param     string $locale Locale to use for the translation, e.g. 'fr_FR'
    2310:      * @param     PropelPDO $con an optional connection object
    2311:      *
    2312:      * @return GroupI18n */
    2313:     public function getTranslation($locale = 'en_US', PropelPDO $con = null)
    2314:     {
    2315:         if (!isset($this->currentTranslations[$locale])) {
    2316:             if (null !== $this->collGroupI18ns) {
    2317:                 foreach ($this->collGroupI18ns as $translation) {
    2318:                     if ($translation->getLocale() == $locale) {
    2319:                         $this->currentTranslations[$locale] = $translation;
    2320:
    2321:                         return $translation;
    2322:                     }
    2323:                 }
    2324:             }
    2325:             if ($this->isNew()) {
    2326:                 $translation = new GroupI18n();
    2327:                 $translation->setLocale($locale);
    2328:             } else {
    2329:                 $translation = GroupI18nQuery::create()
    2330:                     ->filterByPrimaryKey(array($this->getPrimaryKey(), $locale))
    2331:                     ->findOneOrCreate($con);
    2332:                 $this->currentTranslations[$locale] = $translation;
    2333:             }
    2334:             $this->addGroupI18n($translation);
    2335:         }
    2336:
    2337:         return $this->currentTranslations[$locale];
    2338:     }
    2339:
    2340:     /**
    2341:      * Remove the translation for a given locale
    2342:      *
    2343:      * @param     string $locale Locale to use for the translation, e.g. 'fr_FR'
    2344:      * @param     PropelPDO $con an optional connection object
    2345:      *
    2346:      * @return    Group The current object (for fluent API support)
    2347:      */
    2348:     public function removeTranslation($locale = 'en_US', PropelPDO $con = null)
    2349:     {
    2350:         if (!$this->isNew()) {
    2351:             GroupI18nQuery::create()
    2352:                 ->filterByPrimaryKey(array($this->getPrimaryKey(), $locale))
    2353:                 ->delete($con);
    2354:         }
    2355:         if (isset($this->currentTranslations[$locale])) {
    2356:             unset($this->currentTranslations[$locale]);
    2357:         }
    2358:         foreach ($this->collGroupI18ns as $key => $translation) {
    2359:             if ($translation->getLocale() == $locale) {
    2360:                 unset($this->collGroupI18ns[$key]);
    2361:                 break;
    2362:             }
    2363:         }
    2364:
    2365:         return $this;
    2366:     }
    2367:
    2368:     /**
    2369:      * Returns the current translation
    2370:      *
    2371:      * @param     PropelPDO $con an optional connection object
    2372:      *
    2373:      * @return GroupI18n */
    2374:     public function getCurrentTranslation(PropelPDO $con = null)
    2375:     {
    2376:         return $this->getTranslation($this->getLocale(), $con);
    2377:     }
    2378:
    2379:
    2380:         /**
    2381:          * Get the [title] column value.
    2382:          *
    2383:          * @return string
    2384:          */
    2385:         public function getTitle()
    2386:         {
    2387:         return $this->getCurrentTranslation()->getTitle();
    2388:     }
    2389:
    2390:
    2391:         /**
    2392:          * Set the value of [title] column.
    2393:          *
    2394:          * @param string $v new value
    2395:          * @return GroupI18n The current object (for fluent API support)
    2396:          */
    2397:         public function setTitle($v)
    2398:         {    $this->getCurrentTranslation()->setTitle($v);
    2399:
    2400:         return $this;
    2401:     }
    2402:
    2403:
    2404:         /**
    2405:          * Get the [description] column value.
    2406:          *
    2407:          * @return string
    2408:          */
    2409:         public function getDescription()
    2410:         {
    2411:         return $this->getCurrentTranslation()->getDescription();
    2412:     }
    2413:
    2414:
    2415:         /**
    2416:          * Set the value of [description] column.
    2417:          *
    2418:          * @param string $v new value
    2419:          * @return GroupI18n The current object (for fluent API support)
    2420:          */
    2421:         public function setDescription($v)
    2422:         {    $this->getCurrentTranslation()->setDescription($v);
    2423:
    2424:         return $this;
    2425:     }
    2426:
    2427:
    2428:         /**
    2429:          * Get the [chapo] column value.
    2430:          *
    2431:          * @return string
    2432:          */
    2433:         public function getChapo()
    2434:         {
    2435:         return $this->getCurrentTranslation()->getChapo();
    2436:     }
    2437:
    2438:
    2439:         /**
    2440:          * Set the value of [chapo] column.
    2441:          *
    2442:          * @param string $v new value
    2443:          * @return GroupI18n The current object (for fluent API support)
    2444:          */
    2445:         public function setChapo($v)
    2446:         {    $this->getCurrentTranslation()->setChapo($v);
    2447:
    2448:         return $this;
    2449:     }
    2450:
    2451:
    2452:         /**
    2453:          * Get the [postscriptum] column value.
    2454:          *
    2455:          * @return string
    2456:          */
    2457:         public function getPostscriptum()
    2458:         {
    2459:         return $this->getCurrentTranslation()->getPostscriptum();
    2460:     }
    2461:
    2462:
    2463:         /**
    2464:          * Set the value of [postscriptum] column.
    2465:          *
    2466:          * @param string $v new value
    2467:          * @return GroupI18n The current object (for fluent API support)
    2468:          */
    2469:         public function setPostscriptum($v)
    2470:         {    $this->getCurrentTranslation()->setPostscriptum($v);
    2471:
    2472:         return $this;
    2473:     }
    2474:
    2475: }
    2476: