PageRenderTime 38ms CodeModel.GetById 7ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://openirudi.googlecode.com/
PHP | 506 lines | 353 code | 153 blank | 0 comment | 49 complexity | a663c3b9c89fe69c90935152d161c1a1 MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-3.0
  1. <?php
  2. abstract class BasesfGuardUserPeer {
  3. const DATABASE_NAME = 'propel';
  4. const TABLE_NAME = 'sf_guard_user';
  5. const CLASS_DEFAULT = 'plugins.sfGuardPlugin.lib.model.sfGuardUser';
  6. const NUM_COLUMNS = 9;
  7. const NUM_LAZY_LOAD_COLUMNS = 0;
  8. const ID = 'sf_guard_user.ID';
  9. const USERNAME = 'sf_guard_user.USERNAME';
  10. const ALGORITHM = 'sf_guard_user.ALGORITHM';
  11. const SALT = 'sf_guard_user.SALT';
  12. const PASSWORD = 'sf_guard_user.PASSWORD';
  13. const CREATED_AT = 'sf_guard_user.CREATED_AT';
  14. const LAST_LOGIN = 'sf_guard_user.LAST_LOGIN';
  15. const IS_ACTIVE = 'sf_guard_user.IS_ACTIVE';
  16. const IS_SUPER_ADMIN = 'sf_guard_user.IS_SUPER_ADMIN';
  17. public static $instances = array();
  18. private static $mapBuilder = null;
  19. private static $fieldNames = array (
  20. BasePeer::TYPE_PHPNAME => array ('Id', 'Username', 'Algorithm', 'Salt', 'Password', 'CreatedAt', 'LastLogin', 'IsActive', 'IsSuperAdmin', ),
  21. BasePeer::TYPE_STUDLYPHPNAME => array ('id', 'username', 'algorithm', 'salt', 'password', 'createdAt', 'lastLogin', 'isActive', 'isSuperAdmin', ),
  22. BasePeer::TYPE_COLNAME => array (self::ID, self::USERNAME, self::ALGORITHM, self::SALT, self::PASSWORD, self::CREATED_AT, self::LAST_LOGIN, self::IS_ACTIVE, self::IS_SUPER_ADMIN, ),
  23. BasePeer::TYPE_FIELDNAME => array ('id', 'username', 'algorithm', 'salt', 'password', 'created_at', 'last_login', 'is_active', 'is_super_admin', ),
  24. BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, )
  25. );
  26. private static $fieldKeys = array (
  27. BasePeer::TYPE_PHPNAME => array ('Id' => 0, 'Username' => 1, 'Algorithm' => 2, 'Salt' => 3, 'Password' => 4, 'CreatedAt' => 5, 'LastLogin' => 6, 'IsActive' => 7, 'IsSuperAdmin' => 8, ),
  28. BasePeer::TYPE_STUDLYPHPNAME => array ('id' => 0, 'username' => 1, 'algorithm' => 2, 'salt' => 3, 'password' => 4, 'createdAt' => 5, 'lastLogin' => 6, 'isActive' => 7, 'isSuperAdmin' => 8, ),
  29. BasePeer::TYPE_COLNAME => array (self::ID => 0, self::USERNAME => 1, self::ALGORITHM => 2, self::SALT => 3, self::PASSWORD => 4, self::CREATED_AT => 5, self::LAST_LOGIN => 6, self::IS_ACTIVE => 7, self::IS_SUPER_ADMIN => 8, ),
  30. BasePeer::TYPE_FIELDNAME => array ('id' => 0, 'username' => 1, 'algorithm' => 2, 'salt' => 3, 'password' => 4, 'created_at' => 5, 'last_login' => 6, 'is_active' => 7, 'is_super_admin' => 8, ),
  31. BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, )
  32. );
  33. public static function getMapBuilder()
  34. {
  35. if (self::$mapBuilder === null) {
  36. self::$mapBuilder = new sfGuardUserMapBuilder();
  37. }
  38. return self::$mapBuilder;
  39. }
  40. static public function translateFieldName($name, $fromType, $toType)
  41. {
  42. $toNames = self::getFieldNames($toType);
  43. $key = isset(self::$fieldKeys[$fromType][$name]) ? self::$fieldKeys[$fromType][$name] : null;
  44. if ($key === null) {
  45. throw new PropelException("'$name' could not be found in the field names of type '$fromType'. These are: " . print_r(self::$fieldKeys[$fromType], true));
  46. }
  47. return $toNames[$key];
  48. }
  49. static public function getFieldNames($type = BasePeer::TYPE_PHPNAME)
  50. {
  51. if (!array_key_exists($type, self::$fieldNames)) {
  52. throw new PropelException('Method getFieldNames() expects the parameter $type to be one of the class constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME, BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM. ' . $type . ' was given.');
  53. }
  54. return self::$fieldNames[$type];
  55. }
  56. public static function alias($alias, $column)
  57. {
  58. return str_replace(sfGuardUserPeer::TABLE_NAME.'.', $alias.'.', $column);
  59. }
  60. public static function addSelectColumns(Criteria $criteria)
  61. {
  62. $criteria->addSelectColumn(sfGuardUserPeer::ID);
  63. $criteria->addSelectColumn(sfGuardUserPeer::USERNAME);
  64. $criteria->addSelectColumn(sfGuardUserPeer::ALGORITHM);
  65. $criteria->addSelectColumn(sfGuardUserPeer::SALT);
  66. $criteria->addSelectColumn(sfGuardUserPeer::PASSWORD);
  67. $criteria->addSelectColumn(sfGuardUserPeer::CREATED_AT);
  68. $criteria->addSelectColumn(sfGuardUserPeer::LAST_LOGIN);
  69. $criteria->addSelectColumn(sfGuardUserPeer::IS_ACTIVE);
  70. $criteria->addSelectColumn(sfGuardUserPeer::IS_SUPER_ADMIN);
  71. }
  72. public static function doCount(Criteria $criteria, $distinct = false, PropelPDO $con = null)
  73. {
  74. $criteria = clone $criteria;
  75. $criteria->setPrimaryTableName(sfGuardUserPeer::TABLE_NAME);
  76. if ($distinct && !in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
  77. $criteria->setDistinct();
  78. }
  79. if (!$criteria->hasSelectClause()) {
  80. sfGuardUserPeer::addSelectColumns($criteria);
  81. }
  82. $criteria->clearOrderByColumns(); $criteria->setDbName(self::DATABASE_NAME);
  83. if ($con === null) {
  84. $con = Propel::getConnection(sfGuardUserPeer::DATABASE_NAME, Propel::CONNECTION_READ);
  85. }
  86. $stmt = BasePeer::doCount($criteria, $con);
  87. if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
  88. $count = (int) $row[0];
  89. } else {
  90. $count = 0; }
  91. $stmt->closeCursor();
  92. return $count;
  93. }
  94. public static function doSelectOne(Criteria $criteria, PropelPDO $con = null)
  95. {
  96. $critcopy = clone $criteria;
  97. $critcopy->setLimit(1);
  98. $objects = sfGuardUserPeer::doSelect($critcopy, $con);
  99. if ($objects) {
  100. return $objects[0];
  101. }
  102. return null;
  103. }
  104. public static function doSelect(Criteria $criteria, PropelPDO $con = null)
  105. {
  106. return sfGuardUserPeer::populateObjects(sfGuardUserPeer::doSelectStmt($criteria, $con));
  107. }
  108. public static function doSelectStmt(Criteria $criteria, PropelPDO $con = null)
  109. {
  110. if ($con === null) {
  111. $con = Propel::getConnection(sfGuardUserPeer::DATABASE_NAME, Propel::CONNECTION_READ);
  112. }
  113. if (!$criteria->hasSelectClause()) {
  114. $criteria = clone $criteria;
  115. sfGuardUserPeer::addSelectColumns($criteria);
  116. }
  117. $criteria->setDbName(self::DATABASE_NAME);
  118. return BasePeer::doSelect($criteria, $con);
  119. }
  120. public static function addInstanceToPool(sfGuardUser $obj, $key = null)
  121. {
  122. if (Propel::isInstancePoolingEnabled()) {
  123. if ($key === null) {
  124. $key = (string) $obj->getId();
  125. } self::$instances[$key] = $obj;
  126. }
  127. }
  128. public static function removeInstanceFromPool($value)
  129. {
  130. if (Propel::isInstancePoolingEnabled() && $value !== null) {
  131. if (is_object($value) && $value instanceof sfGuardUser) {
  132. $key = (string) $value->getId();
  133. } elseif (is_scalar($value)) {
  134. $key = (string) $value;
  135. } else {
  136. $e = new PropelException("Invalid value passed to removeInstanceFromPool(). Expected primary key or sfGuardUser object; got " . (is_object($value) ? get_class($value) . ' object.' : var_export($value,true)));
  137. throw $e;
  138. }
  139. unset(self::$instances[$key]);
  140. }
  141. }
  142. public static function getInstanceFromPool($key)
  143. {
  144. if (Propel::isInstancePoolingEnabled()) {
  145. if (isset(self::$instances[$key])) {
  146. return self::$instances[$key];
  147. }
  148. }
  149. return null; }
  150. public static function clearInstancePool()
  151. {
  152. self::$instances = array();
  153. }
  154. public static function getPrimaryKeyHashFromRow($row, $startcol = 0)
  155. {
  156. if ($row[$startcol + 0] === null) {
  157. return null;
  158. }
  159. return (string) $row[$startcol + 0];
  160. }
  161. public static function populateObjects(PDOStatement $stmt)
  162. {
  163. $results = array();
  164. $cls = sfGuardUserPeer::getOMClass();
  165. $cls = substr('.'.$cls, strrpos('.'.$cls, '.') + 1);
  166. while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
  167. $key = sfGuardUserPeer::getPrimaryKeyHashFromRow($row, 0);
  168. if (null !== ($obj = sfGuardUserPeer::getInstanceFromPool($key))) {
  169. $results[] = $obj;
  170. } else {
  171. $obj = new $cls();
  172. $obj->hydrate($row);
  173. $results[] = $obj;
  174. sfGuardUserPeer::addInstanceToPool($obj, $key);
  175. } }
  176. $stmt->closeCursor();
  177. return $results;
  178. }
  179. static public function getUniqueColumnNames()
  180. {
  181. return array(array('username'));
  182. }
  183. public static function getTableMap()
  184. {
  185. return Propel::getDatabaseMap(self::DATABASE_NAME)->getTable(self::TABLE_NAME);
  186. }
  187. public static function getOMClass()
  188. {
  189. return sfGuardUserPeer::CLASS_DEFAULT;
  190. }
  191. public static function doInsert($values, PropelPDO $con = null)
  192. {
  193. if ($con === null) {
  194. $con = Propel::getConnection(sfGuardUserPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
  195. }
  196. if ($values instanceof Criteria) {
  197. $criteria = clone $values; } else {
  198. $criteria = $values->buildCriteria(); }
  199. if ($criteria->containsKey(sfGuardUserPeer::ID) && $criteria->keyContainsValue(sfGuardUserPeer::ID) ) {
  200. throw new PropelException('Cannot insert a value for auto-increment primary key ('.sfGuardUserPeer::ID.')');
  201. }
  202. $criteria->setDbName(self::DATABASE_NAME);
  203. try {
  204. $con->beginTransaction();
  205. $pk = BasePeer::doInsert($criteria, $con);
  206. $con->commit();
  207. } catch(PropelException $e) {
  208. $con->rollBack();
  209. throw $e;
  210. }
  211. return $pk;
  212. }
  213. public static function doUpdate($values, PropelPDO $con = null)
  214. {
  215. if ($con === null) {
  216. $con = Propel::getConnection(sfGuardUserPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
  217. }
  218. $selectCriteria = new Criteria(self::DATABASE_NAME);
  219. if ($values instanceof Criteria) {
  220. $criteria = clone $values;
  221. $comparison = $criteria->getComparison(sfGuardUserPeer::ID);
  222. $selectCriteria->add(sfGuardUserPeer::ID, $criteria->remove(sfGuardUserPeer::ID), $comparison);
  223. } else { $criteria = $values->buildCriteria(); $selectCriteria = $values->buildPkeyCriteria(); }
  224. $criteria->setDbName(self::DATABASE_NAME);
  225. return BasePeer::doUpdate($selectCriteria, $criteria, $con);
  226. }
  227. public static function doDeleteAll($con = null)
  228. {
  229. if ($con === null) {
  230. $con = Propel::getConnection(sfGuardUserPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
  231. }
  232. $affectedRows = 0; try {
  233. $con->beginTransaction();
  234. $affectedRows += sfGuardUserPeer::doOnDeleteCascade(new Criteria(sfGuardUserPeer::DATABASE_NAME), $con);
  235. $affectedRows += BasePeer::doDeleteAll(sfGuardUserPeer::TABLE_NAME, $con);
  236. $con->commit();
  237. return $affectedRows;
  238. } catch (PropelException $e) {
  239. $con->rollBack();
  240. throw $e;
  241. }
  242. }
  243. public static function doDelete($values, PropelPDO $con = null)
  244. {
  245. if ($con === null) {
  246. $con = Propel::getConnection(sfGuardUserPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
  247. }
  248. if ($values instanceof Criteria) {
  249. sfGuardUserPeer::clearInstancePool();
  250. $criteria = clone $values;
  251. } elseif ($values instanceof sfGuardUser) {
  252. sfGuardUserPeer::removeInstanceFromPool($values);
  253. $criteria = $values->buildPkeyCriteria();
  254. } else {
  255. $criteria = new Criteria(self::DATABASE_NAME);
  256. $criteria->add(sfGuardUserPeer::ID, (array) $values, Criteria::IN);
  257. foreach ((array) $values as $singleval) {
  258. sfGuardUserPeer::removeInstanceFromPool($singleval);
  259. }
  260. }
  261. $criteria->setDbName(self::DATABASE_NAME);
  262. $affectedRows = 0;
  263. try {
  264. $con->beginTransaction();
  265. $affectedRows += sfGuardUserPeer::doOnDeleteCascade($criteria, $con);
  266. if ($values instanceof Criteria) {
  267. sfGuardUserPeer::clearInstancePool();
  268. } else { sfGuardUserPeer::removeInstanceFromPool($values);
  269. }
  270. $affectedRows += BasePeer::doDelete($criteria, $con);
  271. sfGuardUserPermissionPeer::clearInstancePool();
  272. sfGuardUserGroupPeer::clearInstancePool();
  273. sfGuardRememberKeyPeer::clearInstancePool();
  274. $con->commit();
  275. return $affectedRows;
  276. } catch (PropelException $e) {
  277. $con->rollBack();
  278. throw $e;
  279. }
  280. }
  281. protected static function doOnDeleteCascade(Criteria $criteria, PropelPDO $con)
  282. {
  283. $affectedRows = 0;
  284. $objects = sfGuardUserPeer::doSelect($criteria, $con);
  285. foreach ($objects as $obj) {
  286. $c = new Criteria(sfGuardUserPermissionPeer::DATABASE_NAME);
  287. $c->add(sfGuardUserPermissionPeer::USER_ID, $obj->getId());
  288. $affectedRows += sfGuardUserPermissionPeer::doDelete($c, $con);
  289. $c = new Criteria(sfGuardUserGroupPeer::DATABASE_NAME);
  290. $c->add(sfGuardUserGroupPeer::USER_ID, $obj->getId());
  291. $affectedRows += sfGuardUserGroupPeer::doDelete($c, $con);
  292. $c = new Criteria(sfGuardRememberKeyPeer::DATABASE_NAME);
  293. $c->add(sfGuardRememberKeyPeer::USER_ID, $obj->getId());
  294. $affectedRows += sfGuardRememberKeyPeer::doDelete($c, $con);
  295. }
  296. return $affectedRows;
  297. }
  298. public static function doValidate(sfGuardUser $obj, $cols = null)
  299. {
  300. $columns = array();
  301. if ($cols) {
  302. $dbMap = Propel::getDatabaseMap(sfGuardUserPeer::DATABASE_NAME);
  303. $tableMap = $dbMap->getTable(sfGuardUserPeer::TABLE_NAME);
  304. if (! is_array($cols)) {
  305. $cols = array($cols);
  306. }
  307. foreach ($cols as $colName) {
  308. if ($tableMap->containsColumn($colName)) {
  309. $get = 'get' . $tableMap->getColumn($colName)->getPhpName();
  310. $columns[$colName] = $obj->$get();
  311. }
  312. }
  313. } else {
  314. }
  315. $res = BasePeer::doValidate(sfGuardUserPeer::DATABASE_NAME, sfGuardUserPeer::TABLE_NAME, $columns);
  316. if ($res !== true) {
  317. $request = sfContext::getInstance()->getRequest();
  318. foreach ($res as $failed) {
  319. $col = sfGuardUserPeer::translateFieldname($failed->getColumn(), BasePeer::TYPE_COLNAME, BasePeer::TYPE_PHPNAME);
  320. }
  321. }
  322. return $res;
  323. }
  324. public static function retrieveByPK($pk, PropelPDO $con = null)
  325. {
  326. if (null !== ($obj = sfGuardUserPeer::getInstanceFromPool((string) $pk))) {
  327. return $obj;
  328. }
  329. if ($con === null) {
  330. $con = Propel::getConnection(sfGuardUserPeer::DATABASE_NAME, Propel::CONNECTION_READ);
  331. }
  332. $criteria = new Criteria(sfGuardUserPeer::DATABASE_NAME);
  333. $criteria->add(sfGuardUserPeer::ID, $pk);
  334. $v = sfGuardUserPeer::doSelect($criteria, $con);
  335. return !empty($v) > 0 ? $v[0] : null;
  336. }
  337. public static function retrieveByPKs($pks, PropelPDO $con = null)
  338. {
  339. if ($con === null) {
  340. $con = Propel::getConnection(sfGuardUserPeer::DATABASE_NAME, Propel::CONNECTION_READ);
  341. }
  342. $objs = null;
  343. if (empty($pks)) {
  344. $objs = array();
  345. } else {
  346. $criteria = new Criteria(sfGuardUserPeer::DATABASE_NAME);
  347. $criteria->add(sfGuardUserPeer::ID, $pks, Criteria::IN);
  348. $objs = sfGuardUserPeer::doSelect($criteria, $con);
  349. }
  350. return $objs;
  351. }
  352. }
  353. Propel::getDatabaseMap(BasesfGuardUserPeer::DATABASE_NAME)->addTableBuilder(BasesfGuardUserPeer::TABLE_NAME, BasesfGuardUserPeer::getMapBuilder());