/oiserver/plugins/sfGuardPlugin/lib/model/om/BasesfGuardRememberKey.php
PHP | 566 lines | 410 code | 156 blank | 0 comment | 65 complexity | bb468a9865ffa720d9a9c9d57d0eeafe MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-3.0
- <?php
- abstract class BasesfGuardRememberKey extends BaseObject implements Persistent {
- const PEER = 'sfGuardRememberKeyPeer';
-
- protected static $peer;
-
- protected $user_id;
-
- protected $remember_key;
-
- protected $ip_address;
-
- protected $created_at;
-
- protected $asfGuardUser;
-
- protected $alreadyInSave = false;
-
- protected $alreadyInValidation = false;
-
- public function __construct()
- {
- parent::__construct();
- $this->applyDefaultValues();
- }
-
- public function applyDefaultValues()
- {
- }
-
- public function getUserId()
- {
- return $this->user_id;
- }
-
- public function getRememberKey()
- {
- return $this->remember_key;
- }
-
- public function getIpAddress()
- {
- return $this->ip_address;
- }
-
- public function getCreatedAt($format = 'Y/m/d H:i:s')
- {
- if ($this->created_at === null) {
- return null;
- }
- if ($this->created_at === '0000-00-00 00:00:00') {
- return null;
- } else {
- try {
- $dt = new DateTime($this->created_at);
- } catch (Exception $x) {
- throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->created_at, true), $x);
- }
- }
- if ($format === null) {
- return $dt;
- } elseif (strpos($format, '%') !== false) {
- return strftime($format, $dt->format('U'));
- } else {
- return $dt->format($format);
- }
- }
-
- public function setUserId($v)
- {
- if ($v !== null) {
- $v = (int) $v;
- }
- if ($this->user_id !== $v) {
- $this->user_id = $v;
- $this->modifiedColumns[] = sfGuardRememberKeyPeer::USER_ID;
- }
- if ($this->asfGuardUser !== null && $this->asfGuardUser->getId() !== $v) {
- $this->asfGuardUser = null;
- }
- return $this;
- }
-
- public function setRememberKey($v)
- {
- if ($v !== null) {
- $v = (string) $v;
- }
- if ($this->remember_key !== $v) {
- $this->remember_key = $v;
- $this->modifiedColumns[] = sfGuardRememberKeyPeer::REMEMBER_KEY;
- }
- return $this;
- }
-
- public function setIpAddress($v)
- {
- if ($v !== null) {
- $v = (string) $v;
- }
- if ($this->ip_address !== $v) {
- $this->ip_address = $v;
- $this->modifiedColumns[] = sfGuardRememberKeyPeer::IP_ADDRESS;
- }
- return $this;
- }
-
- public function setCreatedAt($v)
- {
- if ($v === null || $v === '') {
- $dt = null;
- } elseif ($v instanceof DateTime) {
- $dt = $v;
- } else {
- try {
- if (is_numeric($v)) { $dt = new DateTime('@'.$v, new DateTimeZone('UTC'));
- $dt->setTimeZone(new DateTimeZone(date_default_timezone_get()));
- } else {
- $dt = new DateTime($v);
- }
- } catch (Exception $x) {
- throw new PropelException('Error parsing date/time value: ' . var_export($v, true), $x);
- }
- }
- if ( $this->created_at !== null || $dt !== null ) {
-
- $currNorm = ($this->created_at !== null && $tmpDt = new DateTime($this->created_at)) ? $tmpDt->format('Y-m-d H:i:s') : null;
- $newNorm = ($dt !== null) ? $dt->format('Y-m-d H:i:s') : null;
- if ( ($currNorm !== $newNorm) )
- {
- $this->created_at = ($dt ? $dt->format('Y-m-d H:i:s') : null);
- $this->modifiedColumns[] = sfGuardRememberKeyPeer::CREATED_AT;
- }
- }
- return $this;
- }
-
- public function hasOnlyDefaultValues()
- {
- if (array_diff($this->modifiedColumns, array())) {
- return false;
- }
- return true;
- }
-
- public function hydrate($row, $startcol = 0, $rehydrate = false)
- {
- try {
- $this->user_id = ($row[$startcol + 0] !== null) ? (int) $row[$startcol + 0] : null;
- $this->remember_key = ($row[$startcol + 1] !== null) ? (string) $row[$startcol + 1] : null;
- $this->ip_address = ($row[$startcol + 2] !== null) ? (string) $row[$startcol + 2] : null;
- $this->created_at = ($row[$startcol + 3] !== null) ? (string) $row[$startcol + 3] : null;
- $this->resetModified();
- $this->setNew(false);
- if ($rehydrate) {
- $this->ensureConsistency();
- }
- return $startcol + 4;
- } catch (Exception $e) {
- throw new PropelException("Error populating sfGuardRememberKey object", $e);
- }
- }
-
- public function ensureConsistency()
- {
- if ($this->asfGuardUser !== null && $this->user_id !== $this->asfGuardUser->getId()) {
- $this->asfGuardUser = null;
- }
- }
-
- public function reload($deep = false, PropelPDO $con = null)
- {
- if ($this->isDeleted()) {
- throw new PropelException("Cannot reload a deleted object.");
- }
- if ($this->isNew()) {
- throw new PropelException("Cannot reload an unsaved object.");
- }
- if ($con === null) {
- $con = Propel::getConnection(sfGuardRememberKeyPeer::DATABASE_NAME, Propel::CONNECTION_READ);
- }
-
- $stmt = sfGuardRememberKeyPeer::doSelectStmt($this->buildPkeyCriteria(), $con);
- $row = $stmt->fetch(PDO::FETCH_NUM);
- $stmt->closeCursor();
- if (!$row) {
- throw new PropelException('Cannot find matching row in the database to reload object values.');
- }
- $this->hydrate($row, 0, true);
- if ($deep) {
- $this->asfGuardUser = null;
- } }
-
- public function delete(PropelPDO $con = null)
- {
- if ($this->isDeleted()) {
- throw new PropelException("This object has already been deleted.");
- }
- if ($con === null) {
- $con = Propel::getConnection(sfGuardRememberKeyPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
- }
-
- $con->beginTransaction();
- try {
- sfGuardRememberKeyPeer::doDelete($this, $con);
- $this->setDeleted(true);
- $con->commit();
- } catch (PropelException $e) {
- $con->rollBack();
- throw $e;
- }
- }
-
- public function save(PropelPDO $con = null)
- {
- if ($this->isNew() && !$this->isColumnModified(sfGuardRememberKeyPeer::CREATED_AT))
- {
- $this->setCreatedAt(time());
- }
- if ($this->isDeleted()) {
- throw new PropelException("You cannot save an object that has been deleted.");
- }
- if ($con === null) {
- $con = Propel::getConnection(sfGuardRememberKeyPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
- }
-
- $con->beginTransaction();
- try {
- $affectedRows = $this->doSave($con);
- $con->commit();
- sfGuardRememberKeyPeer::addInstanceToPool($this);
- return $affectedRows;
- } catch (PropelException $e) {
- $con->rollBack();
- throw $e;
- }
- }
-
- protected function doSave(PropelPDO $con)
- {
- $affectedRows = 0; if (!$this->alreadyInSave) {
- $this->alreadyInSave = true;
-
- if ($this->asfGuardUser !== null) {
- if ($this->asfGuardUser->isModified() || $this->asfGuardUser->isNew()) {
- $affectedRows += $this->asfGuardUser->save($con);
- }
- $this->setsfGuardUser($this->asfGuardUser);
- }
- if ($this->isModified()) {
- if ($this->isNew()) {
- $pk = sfGuardRememberKeyPeer::doInsert($this, $con);
- $affectedRows += 1;
- $this->setNew(false);
- } else {
- $affectedRows += sfGuardRememberKeyPeer::doUpdate($this, $con);
- }
- $this->resetModified(); }
- $this->alreadyInSave = false;
- }
- return $affectedRows;
- }
-
- protected $validationFailures = array();
-
- public function getValidationFailures()
- {
- return $this->validationFailures;
- }
-
- public function validate($columns = null)
- {
- $res = $this->doValidate($columns);
- if ($res === true) {
- $this->validationFailures = array();
- return true;
- } else {
- $this->validationFailures = $res;
- return false;
- }
- }
-
- protected function doValidate($columns = null)
- {
- if (!$this->alreadyInValidation) {
- $this->alreadyInValidation = true;
- $retval = null;
- $failureMap = array();
-
- if ($this->asfGuardUser !== null) {
- if (!$this->asfGuardUser->validate($columns)) {
- $failureMap = array_merge($failureMap, $this->asfGuardUser->getValidationFailures());
- }
- }
- if (($retval = sfGuardRememberKeyPeer::doValidate($this, $columns)) !== true) {
- $failureMap = array_merge($failureMap, $retval);
- }
- $this->alreadyInValidation = false;
- }
- return (!empty($failureMap) ? $failureMap : true);
- }
-
- public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
- {
- $pos = sfGuardRememberKeyPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
- $field = $this->getByPosition($pos);
- return $field;
- }
-
- public function getByPosition($pos)
- {
- switch($pos) {
- case 0:
- return $this->getUserId();
- break;
- case 1:
- return $this->getRememberKey();
- break;
- case 2:
- return $this->getIpAddress();
- break;
- case 3:
- return $this->getCreatedAt();
- break;
- default:
- return null;
- break;
- } }
-
- public function toArray($keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true)
- {
- $keys = sfGuardRememberKeyPeer::getFieldNames($keyType);
- $result = array(
- $keys[0] => $this->getUserId(),
- $keys[1] => $this->getRememberKey(),
- $keys[2] => $this->getIpAddress(),
- $keys[3] => $this->getCreatedAt(),
- );
- return $result;
- }
-
- public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
- {
- $pos = sfGuardRememberKeyPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
- return $this->setByPosition($pos, $value);
- }
-
- public function setByPosition($pos, $value)
- {
- switch($pos) {
- case 0:
- $this->setUserId($value);
- break;
- case 1:
- $this->setRememberKey($value);
- break;
- case 2:
- $this->setIpAddress($value);
- break;
- case 3:
- $this->setCreatedAt($value);
- break;
- } }
-
- public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
- {
- $keys = sfGuardRememberKeyPeer::getFieldNames($keyType);
- if (array_key_exists($keys[0], $arr)) $this->setUserId($arr[$keys[0]]);
- if (array_key_exists($keys[1], $arr)) $this->setRememberKey($arr[$keys[1]]);
- if (array_key_exists($keys[2], $arr)) $this->setIpAddress($arr[$keys[2]]);
- if (array_key_exists($keys[3], $arr)) $this->setCreatedAt($arr[$keys[3]]);
- }
-
- public function buildCriteria()
- {
- $criteria = new Criteria(sfGuardRememberKeyPeer::DATABASE_NAME);
- if ($this->isColumnModified(sfGuardRememberKeyPeer::USER_ID)) $criteria->add(sfGuardRememberKeyPeer::USER_ID, $this->user_id);
- if ($this->isColumnModified(sfGuardRememberKeyPeer::REMEMBER_KEY)) $criteria->add(sfGuardRememberKeyPeer::REMEMBER_KEY, $this->remember_key);
- if ($this->isColumnModified(sfGuardRememberKeyPeer::IP_ADDRESS)) $criteria->add(sfGuardRememberKeyPeer::IP_ADDRESS, $this->ip_address);
- if ($this->isColumnModified(sfGuardRememberKeyPeer::CREATED_AT)) $criteria->add(sfGuardRememberKeyPeer::CREATED_AT, $this->created_at);
- return $criteria;
- }
-
- public function buildPkeyCriteria()
- {
- $criteria = new Criteria(sfGuardRememberKeyPeer::DATABASE_NAME);
- $criteria->add(sfGuardRememberKeyPeer::USER_ID, $this->user_id);
- $criteria->add(sfGuardRememberKeyPeer::IP_ADDRESS, $this->ip_address);
- return $criteria;
- }
-
- public function getPrimaryKey()
- {
- $pks = array();
- $pks[0] = $this->getUserId();
- $pks[1] = $this->getIpAddress();
- return $pks;
- }
-
- public function setPrimaryKey($keys)
- {
- $this->setUserId($keys[0]);
- $this->setIpAddress($keys[1]);
- }
-
- public function copyInto($copyObj, $deepCopy = false)
- {
- $copyObj->setUserId($this->user_id);
- $copyObj->setRememberKey($this->remember_key);
- $copyObj->setIpAddress($this->ip_address);
- $copyObj->setCreatedAt($this->created_at);
- $copyObj->setNew(true);
- }
-
- public function copy($deepCopy = false)
- {
- $clazz = get_class($this);
- $copyObj = new $clazz();
- $this->copyInto($copyObj, $deepCopy);
- return $copyObj;
- }
-
- public function getPeer()
- {
- if (self::$peer === null) {
- self::$peer = new sfGuardRememberKeyPeer();
- }
- return self::$peer;
- }
-
- public function setsfGuardUser(sfGuardUser $v = null)
- {
- if ($v === null) {
- $this->setUserId(NULL);
- } else {
- $this->setUserId($v->getId());
- }
- $this->asfGuardUser = $v;
- if ($v !== null) {
- $v->addsfGuardRememberKey($this);
- }
- return $this;
- }
-
- public function getsfGuardUser(PropelPDO $con = null)
- {
- if ($this->asfGuardUser === null && ($this->user_id !== null)) {
- $c = new Criteria(sfGuardUserPeer::DATABASE_NAME);
- $c->add(sfGuardUserPeer::ID, $this->user_id);
- $this->asfGuardUser = sfGuardUserPeer::doSelectOne($c, $con);
-
- }
- return $this->asfGuardUser;
- }
-
- public function clearAllReferences($deep = false)
- {
- if ($deep) {
- }
- $this->asfGuardUser = null;
- }
- }