PageRenderTime 48ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/oiserver/lib/model/om/BasePcgroup.php

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