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

/oiserver/lib/model/om/BaseSubsys.php

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