# File core/lib/Thelia/Model/om/BaseAdmin.php | thelia

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