PageRenderTime 27ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/t/askeet/lib/model/om/BaseReportAnswer.php

https://github.com/mori-dev/emacs-symfony
PHP | 488 lines | 332 code | 156 blank | 0 comment | 57 complexity | 886cac6cee958f1d29138627c1a17c36 MD5 | raw file
  1. <?php
  2. abstract class BaseReportAnswer extends BaseObject implements Persistent {
  3. const DATABASE_NAME = 'symfony';
  4. protected static $peer;
  5. protected $answer_id;
  6. protected $user_id;
  7. protected $created_at;
  8. protected $aAnswer;
  9. protected $aUser;
  10. protected $alreadyInSave = false;
  11. protected $alreadyInValidation = false;
  12. public function getAnswerId()
  13. {
  14. return $this->answer_id;
  15. }
  16. public function getUserId()
  17. {
  18. return $this->user_id;
  19. }
  20. public function getCreatedAt($format = 'Y-m-d H:i:s')
  21. {
  22. if ($this->created_at === null || $this->created_at === '') {
  23. return null;
  24. } elseif (!is_int($this->created_at)) {
  25. $ts = strtotime($this->created_at);
  26. if ($ts === -1 || $ts === false) { throw new PropelException("Unable to parse value of [created_at] as date/time value: " . var_export($this->created_at, true));
  27. }
  28. } else {
  29. $ts = $this->created_at;
  30. }
  31. if ($format === null) {
  32. return $ts;
  33. } elseif (strpos($format, '%') !== false) {
  34. return strftime($format, $ts);
  35. } else {
  36. return date($format, $ts);
  37. }
  38. }
  39. public function setAnswerId($v)
  40. {
  41. if ($this->answer_id !== $v) {
  42. $this->answer_id = $v;
  43. $this->modifiedColumns[] = ReportAnswerPeer::ANSWER_ID;
  44. }
  45. if ($this->aAnswer !== null && $this->aAnswer->getId() !== $v) {
  46. $this->aAnswer = null;
  47. }
  48. }
  49. public function setUserId($v)
  50. {
  51. if ($this->user_id !== $v) {
  52. $this->user_id = $v;
  53. $this->modifiedColumns[] = ReportAnswerPeer::USER_ID;
  54. }
  55. if ($this->aUser !== null && $this->aUser->getId() !== $v) {
  56. $this->aUser = null;
  57. }
  58. }
  59. public function setCreatedAt($v)
  60. {
  61. if ($v !== null && !is_int($v)) {
  62. $ts = strtotime($v);
  63. if ($ts === -1 || $ts === false) { throw new PropelException("Unable to parse date/time value for [created_at] from input: " . var_export($v, true));
  64. }
  65. } else {
  66. $ts = $v;
  67. }
  68. if ($this->created_at !== $ts) {
  69. $this->created_at = $ts;
  70. $this->modifiedColumns[] = ReportAnswerPeer::CREATED_AT;
  71. }
  72. }
  73. public function hydrate(ResultSet $rs, $startcol = 1)
  74. {
  75. try {
  76. $this->answer_id = $rs->getInt($startcol + 0);
  77. $this->user_id = $rs->getInt($startcol + 1);
  78. $this->created_at = $rs->getTimestamp($startcol + 2, null);
  79. $this->resetModified();
  80. $this->setNew(false);
  81. return $startcol + 3;
  82. } catch (Exception $e) {
  83. throw new PropelException("Error populating ReportAnswer object", $e);
  84. }
  85. }
  86. public function delete($con = null)
  87. {
  88. if ($this->isDeleted()) {
  89. throw new PropelException("This object has already been deleted.");
  90. }
  91. if ($con === null) {
  92. $con = Propel::getConnection(ReportAnswerPeer::DATABASE_NAME);
  93. }
  94. try {
  95. $con->begin();
  96. ReportAnswerPeer::doDelete($this, $con);
  97. $this->setDeleted(true);
  98. $con->commit();
  99. } catch (PropelException $e) {
  100. $con->rollback();
  101. throw $e;
  102. }
  103. }
  104. public function save($con = null)
  105. {
  106. if ($this->isNew() && !$this->isColumnModified(ReportAnswerPeer::CREATED_AT))
  107. {
  108. $this->setCreatedAt(time());
  109. }
  110. if ($this->isDeleted()) {
  111. throw new PropelException("You cannot save an object that has been deleted.");
  112. }
  113. if ($con === null) {
  114. $con = Propel::getConnection(ReportAnswerPeer::DATABASE_NAME);
  115. }
  116. try {
  117. $con->begin();
  118. $affectedRows = $this->doSave($con);
  119. $con->commit();
  120. return $affectedRows;
  121. } catch (PropelException $e) {
  122. $con->rollback();
  123. throw $e;
  124. }
  125. }
  126. protected function doSave($con)
  127. {
  128. $affectedRows = 0; if (!$this->alreadyInSave) {
  129. $this->alreadyInSave = true;
  130. if ($this->aAnswer !== null) {
  131. if ($this->aAnswer->isModified()) {
  132. $affectedRows += $this->aAnswer->save($con);
  133. }
  134. $this->setAnswer($this->aAnswer);
  135. }
  136. if ($this->aUser !== null) {
  137. if ($this->aUser->isModified()) {
  138. $affectedRows += $this->aUser->save($con);
  139. }
  140. $this->setUser($this->aUser);
  141. }
  142. if ($this->isModified()) {
  143. if ($this->isNew()) {
  144. $pk = ReportAnswerPeer::doInsert($this, $con);
  145. $affectedRows += 1;
  146. $this->setNew(false);
  147. } else {
  148. $affectedRows += ReportAnswerPeer::doUpdate($this, $con);
  149. }
  150. $this->resetModified(); }
  151. $this->alreadyInSave = false;
  152. }
  153. return $affectedRows;
  154. }
  155. protected $validationFailures = array();
  156. public function getValidationFailures()
  157. {
  158. return $this->validationFailures;
  159. }
  160. public function validate($columns = null)
  161. {
  162. $res = $this->doValidate($columns);
  163. if ($res === true) {
  164. $this->validationFailures = array();
  165. return true;
  166. } else {
  167. $this->validationFailures = $res;
  168. return false;
  169. }
  170. }
  171. protected function doValidate($columns = null)
  172. {
  173. if (!$this->alreadyInValidation) {
  174. $this->alreadyInValidation = true;
  175. $retval = null;
  176. $failureMap = array();
  177. if ($this->aAnswer !== null) {
  178. if (!$this->aAnswer->validate($columns)) {
  179. $failureMap = array_merge($failureMap, $this->aAnswer->getValidationFailures());
  180. }
  181. }
  182. if ($this->aUser !== null) {
  183. if (!$this->aUser->validate($columns)) {
  184. $failureMap = array_merge($failureMap, $this->aUser->getValidationFailures());
  185. }
  186. }
  187. if (($retval = ReportAnswerPeer::doValidate($this, $columns)) !== true) {
  188. $failureMap = array_merge($failureMap, $retval);
  189. }
  190. $this->alreadyInValidation = false;
  191. }
  192. return (!empty($failureMap) ? $failureMap : true);
  193. }
  194. public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
  195. {
  196. $pos = ReportAnswerPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
  197. return $this->getByPosition($pos);
  198. }
  199. public function getByPosition($pos)
  200. {
  201. switch($pos) {
  202. case 0:
  203. return $this->getAnswerId();
  204. break;
  205. case 1:
  206. return $this->getUserId();
  207. break;
  208. case 2:
  209. return $this->getCreatedAt();
  210. break;
  211. default:
  212. return null;
  213. break;
  214. } }
  215. public function toArray($keyType = BasePeer::TYPE_PHPNAME)
  216. {
  217. $keys = ReportAnswerPeer::getFieldNames($keyType);
  218. $result = array(
  219. $keys[0] => $this->getAnswerId(),
  220. $keys[1] => $this->getUserId(),
  221. $keys[2] => $this->getCreatedAt(),
  222. );
  223. return $result;
  224. }
  225. public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
  226. {
  227. $pos = ReportAnswerPeer::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->setAnswerId($value);
  235. break;
  236. case 1:
  237. $this->setUserId($value);
  238. break;
  239. case 2:
  240. $this->setCreatedAt($value);
  241. break;
  242. } }
  243. public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
  244. {
  245. $keys = ReportAnswerPeer::getFieldNames($keyType);
  246. if (array_key_exists($keys[0], $arr)) $this->setAnswerId($arr[$keys[0]]);
  247. if (array_key_exists($keys[1], $arr)) $this->setUserId($arr[$keys[1]]);
  248. if (array_key_exists($keys[2], $arr)) $this->setCreatedAt($arr[$keys[2]]);
  249. }
  250. public function buildCriteria()
  251. {
  252. $criteria = new Criteria(ReportAnswerPeer::DATABASE_NAME);
  253. if ($this->isColumnModified(ReportAnswerPeer::ANSWER_ID)) $criteria->add(ReportAnswerPeer::ANSWER_ID, $this->answer_id);
  254. if ($this->isColumnModified(ReportAnswerPeer::USER_ID)) $criteria->add(ReportAnswerPeer::USER_ID, $this->user_id);
  255. if ($this->isColumnModified(ReportAnswerPeer::CREATED_AT)) $criteria->add(ReportAnswerPeer::CREATED_AT, $this->created_at);
  256. return $criteria;
  257. }
  258. public function buildPkeyCriteria()
  259. {
  260. $criteria = new Criteria(ReportAnswerPeer::DATABASE_NAME);
  261. $criteria->add(ReportAnswerPeer::ANSWER_ID, $this->answer_id);
  262. $criteria->add(ReportAnswerPeer::USER_ID, $this->user_id);
  263. return $criteria;
  264. }
  265. public function getPrimaryKey()
  266. {
  267. $pks = array();
  268. $pks[0] = $this->getAnswerId();
  269. $pks[1] = $this->getUserId();
  270. return $pks;
  271. }
  272. public function setPrimaryKey($keys)
  273. {
  274. $this->setAnswerId($keys[0]);
  275. $this->setUserId($keys[1]);
  276. }
  277. public function copyInto($copyObj, $deepCopy = false)
  278. {
  279. $copyObj->setCreatedAt($this->created_at);
  280. $copyObj->setNew(true);
  281. $copyObj->setAnswerId(NULL);
  282. $copyObj->setUserId(NULL);
  283. }
  284. public function copy($deepCopy = false)
  285. {
  286. $clazz = get_class($this);
  287. $copyObj = new $clazz();
  288. $this->copyInto($copyObj, $deepCopy);
  289. return $copyObj;
  290. }
  291. public function getPeer()
  292. {
  293. if (self::$peer === null) {
  294. self::$peer = new ReportAnswerPeer();
  295. }
  296. return self::$peer;
  297. }
  298. public function setAnswer($v)
  299. {
  300. if ($v === null) {
  301. $this->setAnswerId(NULL);
  302. } else {
  303. $this->setAnswerId($v->getId());
  304. }
  305. $this->aAnswer = $v;
  306. }
  307. public function getAnswer($con = null)
  308. {
  309. include_once 'lib/model/om/BaseAnswerPeer.php';
  310. if ($this->aAnswer === null && ($this->answer_id !== null)) {
  311. $this->aAnswer = AnswerPeer::retrieveByPK($this->answer_id, $con);
  312. }
  313. return $this->aAnswer;
  314. }
  315. public function setUser($v)
  316. {
  317. if ($v === null) {
  318. $this->setUserId(NULL);
  319. } else {
  320. $this->setUserId($v->getId());
  321. }
  322. $this->aUser = $v;
  323. }
  324. public function getUser($con = null)
  325. {
  326. include_once 'lib/model/om/BaseUserPeer.php';
  327. if ($this->aUser === null && ($this->user_id !== null)) {
  328. $this->aUser = UserPeer::retrieveByPK($this->user_id, $con);
  329. }
  330. return $this->aUser;
  331. }
  332. }