PageRenderTime 26ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/oiserver/plugins/sfGuardPlugin/lib/model/om/BasesfGuardRememberKey.php

http://openirudi.googlecode.com/
PHP | 566 lines | 410 code | 156 blank | 0 comment | 65 complexity | bb468a9865ffa720d9a9c9d57d0eeafe MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-3.0
  1. <?php
  2. abstract class BasesfGuardRememberKey extends BaseObject implements Persistent {
  3. const PEER = 'sfGuardRememberKeyPeer';
  4. protected static $peer;
  5. protected $user_id;
  6. protected $remember_key;
  7. protected $ip_address;
  8. protected $created_at;
  9. protected $asfGuardUser;
  10. protected $alreadyInSave = false;
  11. protected $alreadyInValidation = false;
  12. public function __construct()
  13. {
  14. parent::__construct();
  15. $this->applyDefaultValues();
  16. }
  17. public function applyDefaultValues()
  18. {
  19. }
  20. public function getUserId()
  21. {
  22. return $this->user_id;
  23. }
  24. public function getRememberKey()
  25. {
  26. return $this->remember_key;
  27. }
  28. public function getIpAddress()
  29. {
  30. return $this->ip_address;
  31. }
  32. public function getCreatedAt($format = 'Y/m/d H:i:s')
  33. {
  34. if ($this->created_at === null) {
  35. return null;
  36. }
  37. if ($this->created_at === '0000-00-00 00:00:00') {
  38. return null;
  39. } else {
  40. try {
  41. $dt = new DateTime($this->created_at);
  42. } catch (Exception $x) {
  43. throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->created_at, true), $x);
  44. }
  45. }
  46. if ($format === null) {
  47. return $dt;
  48. } elseif (strpos($format, '%') !== false) {
  49. return strftime($format, $dt->format('U'));
  50. } else {
  51. return $dt->format($format);
  52. }
  53. }
  54. public function setUserId($v)
  55. {
  56. if ($v !== null) {
  57. $v = (int) $v;
  58. }
  59. if ($this->user_id !== $v) {
  60. $this->user_id = $v;
  61. $this->modifiedColumns[] = sfGuardRememberKeyPeer::USER_ID;
  62. }
  63. if ($this->asfGuardUser !== null && $this->asfGuardUser->getId() !== $v) {
  64. $this->asfGuardUser = null;
  65. }
  66. return $this;
  67. }
  68. public function setRememberKey($v)
  69. {
  70. if ($v !== null) {
  71. $v = (string) $v;
  72. }
  73. if ($this->remember_key !== $v) {
  74. $this->remember_key = $v;
  75. $this->modifiedColumns[] = sfGuardRememberKeyPeer::REMEMBER_KEY;
  76. }
  77. return $this;
  78. }
  79. public function setIpAddress($v)
  80. {
  81. if ($v !== null) {
  82. $v = (string) $v;
  83. }
  84. if ($this->ip_address !== $v) {
  85. $this->ip_address = $v;
  86. $this->modifiedColumns[] = sfGuardRememberKeyPeer::IP_ADDRESS;
  87. }
  88. return $this;
  89. }
  90. public function setCreatedAt($v)
  91. {
  92. if ($v === null || $v === '') {
  93. $dt = null;
  94. } elseif ($v instanceof DateTime) {
  95. $dt = $v;
  96. } else {
  97. try {
  98. if (is_numeric($v)) { $dt = new DateTime('@'.$v, new DateTimeZone('UTC'));
  99. $dt->setTimeZone(new DateTimeZone(date_default_timezone_get()));
  100. } else {
  101. $dt = new DateTime($v);
  102. }
  103. } catch (Exception $x) {
  104. throw new PropelException('Error parsing date/time value: ' . var_export($v, true), $x);
  105. }
  106. }
  107. if ( $this->created_at !== null || $dt !== null ) {
  108. $currNorm = ($this->created_at !== null && $tmpDt = new DateTime($this->created_at)) ? $tmpDt->format('Y-m-d H:i:s') : null;
  109. $newNorm = ($dt !== null) ? $dt->format('Y-m-d H:i:s') : null;
  110. if ( ($currNorm !== $newNorm) )
  111. {
  112. $this->created_at = ($dt ? $dt->format('Y-m-d H:i:s') : null);
  113. $this->modifiedColumns[] = sfGuardRememberKeyPeer::CREATED_AT;
  114. }
  115. }
  116. return $this;
  117. }
  118. public function hasOnlyDefaultValues()
  119. {
  120. if (array_diff($this->modifiedColumns, array())) {
  121. return false;
  122. }
  123. return true;
  124. }
  125. public function hydrate($row, $startcol = 0, $rehydrate = false)
  126. {
  127. try {
  128. $this->user_id = ($row[$startcol + 0] !== null) ? (int) $row[$startcol + 0] : null;
  129. $this->remember_key = ($row[$startcol + 1] !== null) ? (string) $row[$startcol + 1] : null;
  130. $this->ip_address = ($row[$startcol + 2] !== null) ? (string) $row[$startcol + 2] : null;
  131. $this->created_at = ($row[$startcol + 3] !== null) ? (string) $row[$startcol + 3] : null;
  132. $this->resetModified();
  133. $this->setNew(false);
  134. if ($rehydrate) {
  135. $this->ensureConsistency();
  136. }
  137. return $startcol + 4;
  138. } catch (Exception $e) {
  139. throw new PropelException("Error populating sfGuardRememberKey object", $e);
  140. }
  141. }
  142. public function ensureConsistency()
  143. {
  144. if ($this->asfGuardUser !== null && $this->user_id !== $this->asfGuardUser->getId()) {
  145. $this->asfGuardUser = null;
  146. }
  147. }
  148. public function reload($deep = false, PropelPDO $con = null)
  149. {
  150. if ($this->isDeleted()) {
  151. throw new PropelException("Cannot reload a deleted object.");
  152. }
  153. if ($this->isNew()) {
  154. throw new PropelException("Cannot reload an unsaved object.");
  155. }
  156. if ($con === null) {
  157. $con = Propel::getConnection(sfGuardRememberKeyPeer::DATABASE_NAME, Propel::CONNECTION_READ);
  158. }
  159. $stmt = sfGuardRememberKeyPeer::doSelectStmt($this->buildPkeyCriteria(), $con);
  160. $row = $stmt->fetch(PDO::FETCH_NUM);
  161. $stmt->closeCursor();
  162. if (!$row) {
  163. throw new PropelException('Cannot find matching row in the database to reload object values.');
  164. }
  165. $this->hydrate($row, 0, true);
  166. if ($deep) {
  167. $this->asfGuardUser = null;
  168. } }
  169. public function delete(PropelPDO $con = null)
  170. {
  171. if ($this->isDeleted()) {
  172. throw new PropelException("This object has already been deleted.");
  173. }
  174. if ($con === null) {
  175. $con = Propel::getConnection(sfGuardRememberKeyPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
  176. }
  177. $con->beginTransaction();
  178. try {
  179. sfGuardRememberKeyPeer::doDelete($this, $con);
  180. $this->setDeleted(true);
  181. $con->commit();
  182. } catch (PropelException $e) {
  183. $con->rollBack();
  184. throw $e;
  185. }
  186. }
  187. public function save(PropelPDO $con = null)
  188. {
  189. if ($this->isNew() && !$this->isColumnModified(sfGuardRememberKeyPeer::CREATED_AT))
  190. {
  191. $this->setCreatedAt(time());
  192. }
  193. if ($this->isDeleted()) {
  194. throw new PropelException("You cannot save an object that has been deleted.");
  195. }
  196. if ($con === null) {
  197. $con = Propel::getConnection(sfGuardRememberKeyPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
  198. }
  199. $con->beginTransaction();
  200. try {
  201. $affectedRows = $this->doSave($con);
  202. $con->commit();
  203. sfGuardRememberKeyPeer::addInstanceToPool($this);
  204. return $affectedRows;
  205. } catch (PropelException $e) {
  206. $con->rollBack();
  207. throw $e;
  208. }
  209. }
  210. protected function doSave(PropelPDO $con)
  211. {
  212. $affectedRows = 0; if (!$this->alreadyInSave) {
  213. $this->alreadyInSave = true;
  214. if ($this->asfGuardUser !== null) {
  215. if ($this->asfGuardUser->isModified() || $this->asfGuardUser->isNew()) {
  216. $affectedRows += $this->asfGuardUser->save($con);
  217. }
  218. $this->setsfGuardUser($this->asfGuardUser);
  219. }
  220. if ($this->isModified()) {
  221. if ($this->isNew()) {
  222. $pk = sfGuardRememberKeyPeer::doInsert($this, $con);
  223. $affectedRows += 1;
  224. $this->setNew(false);
  225. } else {
  226. $affectedRows += sfGuardRememberKeyPeer::doUpdate($this, $con);
  227. }
  228. $this->resetModified(); }
  229. $this->alreadyInSave = false;
  230. }
  231. return $affectedRows;
  232. }
  233. protected $validationFailures = array();
  234. public function getValidationFailures()
  235. {
  236. return $this->validationFailures;
  237. }
  238. public function validate($columns = null)
  239. {
  240. $res = $this->doValidate($columns);
  241. if ($res === true) {
  242. $this->validationFailures = array();
  243. return true;
  244. } else {
  245. $this->validationFailures = $res;
  246. return false;
  247. }
  248. }
  249. protected function doValidate($columns = null)
  250. {
  251. if (!$this->alreadyInValidation) {
  252. $this->alreadyInValidation = true;
  253. $retval = null;
  254. $failureMap = array();
  255. if ($this->asfGuardUser !== null) {
  256. if (!$this->asfGuardUser->validate($columns)) {
  257. $failureMap = array_merge($failureMap, $this->asfGuardUser->getValidationFailures());
  258. }
  259. }
  260. if (($retval = sfGuardRememberKeyPeer::doValidate($this, $columns)) !== true) {
  261. $failureMap = array_merge($failureMap, $retval);
  262. }
  263. $this->alreadyInValidation = false;
  264. }
  265. return (!empty($failureMap) ? $failureMap : true);
  266. }
  267. public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
  268. {
  269. $pos = sfGuardRememberKeyPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
  270. $field = $this->getByPosition($pos);
  271. return $field;
  272. }
  273. public function getByPosition($pos)
  274. {
  275. switch($pos) {
  276. case 0:
  277. return $this->getUserId();
  278. break;
  279. case 1:
  280. return $this->getRememberKey();
  281. break;
  282. case 2:
  283. return $this->getIpAddress();
  284. break;
  285. case 3:
  286. return $this->getCreatedAt();
  287. break;
  288. default:
  289. return null;
  290. break;
  291. } }
  292. public function toArray($keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true)
  293. {
  294. $keys = sfGuardRememberKeyPeer::getFieldNames($keyType);
  295. $result = array(
  296. $keys[0] => $this->getUserId(),
  297. $keys[1] => $this->getRememberKey(),
  298. $keys[2] => $this->getIpAddress(),
  299. $keys[3] => $this->getCreatedAt(),
  300. );
  301. return $result;
  302. }
  303. public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
  304. {
  305. $pos = sfGuardRememberKeyPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
  306. return $this->setByPosition($pos, $value);
  307. }
  308. public function setByPosition($pos, $value)
  309. {
  310. switch($pos) {
  311. case 0:
  312. $this->setUserId($value);
  313. break;
  314. case 1:
  315. $this->setRememberKey($value);
  316. break;
  317. case 2:
  318. $this->setIpAddress($value);
  319. break;
  320. case 3:
  321. $this->setCreatedAt($value);
  322. break;
  323. } }
  324. public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
  325. {
  326. $keys = sfGuardRememberKeyPeer::getFieldNames($keyType);
  327. if (array_key_exists($keys[0], $arr)) $this->setUserId($arr[$keys[0]]);
  328. if (array_key_exists($keys[1], $arr)) $this->setRememberKey($arr[$keys[1]]);
  329. if (array_key_exists($keys[2], $arr)) $this->setIpAddress($arr[$keys[2]]);
  330. if (array_key_exists($keys[3], $arr)) $this->setCreatedAt($arr[$keys[3]]);
  331. }
  332. public function buildCriteria()
  333. {
  334. $criteria = new Criteria(sfGuardRememberKeyPeer::DATABASE_NAME);
  335. if ($this->isColumnModified(sfGuardRememberKeyPeer::USER_ID)) $criteria->add(sfGuardRememberKeyPeer::USER_ID, $this->user_id);
  336. if ($this->isColumnModified(sfGuardRememberKeyPeer::REMEMBER_KEY)) $criteria->add(sfGuardRememberKeyPeer::REMEMBER_KEY, $this->remember_key);
  337. if ($this->isColumnModified(sfGuardRememberKeyPeer::IP_ADDRESS)) $criteria->add(sfGuardRememberKeyPeer::IP_ADDRESS, $this->ip_address);
  338. if ($this->isColumnModified(sfGuardRememberKeyPeer::CREATED_AT)) $criteria->add(sfGuardRememberKeyPeer::CREATED_AT, $this->created_at);
  339. return $criteria;
  340. }
  341. public function buildPkeyCriteria()
  342. {
  343. $criteria = new Criteria(sfGuardRememberKeyPeer::DATABASE_NAME);
  344. $criteria->add(sfGuardRememberKeyPeer::USER_ID, $this->user_id);
  345. $criteria->add(sfGuardRememberKeyPeer::IP_ADDRESS, $this->ip_address);
  346. return $criteria;
  347. }
  348. public function getPrimaryKey()
  349. {
  350. $pks = array();
  351. $pks[0] = $this->getUserId();
  352. $pks[1] = $this->getIpAddress();
  353. return $pks;
  354. }
  355. public function setPrimaryKey($keys)
  356. {
  357. $this->setUserId($keys[0]);
  358. $this->setIpAddress($keys[1]);
  359. }
  360. public function copyInto($copyObj, $deepCopy = false)
  361. {
  362. $copyObj->setUserId($this->user_id);
  363. $copyObj->setRememberKey($this->remember_key);
  364. $copyObj->setIpAddress($this->ip_address);
  365. $copyObj->setCreatedAt($this->created_at);
  366. $copyObj->setNew(true);
  367. }
  368. public function copy($deepCopy = false)
  369. {
  370. $clazz = get_class($this);
  371. $copyObj = new $clazz();
  372. $this->copyInto($copyObj, $deepCopy);
  373. return $copyObj;
  374. }
  375. public function getPeer()
  376. {
  377. if (self::$peer === null) {
  378. self::$peer = new sfGuardRememberKeyPeer();
  379. }
  380. return self::$peer;
  381. }
  382. public function setsfGuardUser(sfGuardUser $v = null)
  383. {
  384. if ($v === null) {
  385. $this->setUserId(NULL);
  386. } else {
  387. $this->setUserId($v->getId());
  388. }
  389. $this->asfGuardUser = $v;
  390. if ($v !== null) {
  391. $v->addsfGuardRememberKey($this);
  392. }
  393. return $this;
  394. }
  395. public function getsfGuardUser(PropelPDO $con = null)
  396. {
  397. if ($this->asfGuardUser === null && ($this->user_id !== null)) {
  398. $c = new Criteria(sfGuardUserPeer::DATABASE_NAME);
  399. $c->add(sfGuardUserPeer::ID, $this->user_id);
  400. $this->asfGuardUser = sfGuardUserPeer::doSelectOne($c, $con);
  401. }
  402. return $this->asfGuardUser;
  403. }
  404. public function clearAllReferences($deep = false)
  405. {
  406. if ($deep) {
  407. }
  408. $this->asfGuardUser = null;
  409. }
  410. }