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