PageRenderTime 28ms CodeModel.GetById 1ms RepoModel.GetById 1ms app.codeStats 0ms

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

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