BaseCcTimestamp.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946
  1. <?php
  2. /**
  3. * Base class that represents a row from the 'cc_timestamp' table.
  4. *
  5. *
  6. *
  7. * @package propel.generator.airtime.om
  8. */
  9. abstract class BaseCcTimestamp extends BaseObject implements Persistent
  10. {
  11. /**
  12. * Peer class name
  13. */
  14. const PEER = 'CcTimestampPeer';
  15. /**
  16. * The Peer class.
  17. * Instance provides a convenient way of calling static methods on a class
  18. * that calling code may not be able to identify.
  19. * @var CcTimestampPeer
  20. */
  21. protected static $peer;
  22. /**
  23. * The value for the id field.
  24. * @var int
  25. */
  26. protected $id;
  27. /**
  28. * The value for the timestamp field.
  29. * @var string
  30. */
  31. protected $timestamp;
  32. /**
  33. * @var array CcListenerCount[] Collection to store aggregation of CcListenerCount objects.
  34. */
  35. protected $collCcListenerCounts;
  36. /**
  37. * Flag to prevent endless save loop, if this object is referenced
  38. * by another object which falls in this transaction.
  39. * @var boolean
  40. */
  41. protected $alreadyInSave = false;
  42. /**
  43. * Flag to prevent endless validation loop, if this object is referenced
  44. * by another object which falls in this transaction.
  45. * @var boolean
  46. */
  47. protected $alreadyInValidation = false;
  48. /**
  49. * Get the [id] column value.
  50. *
  51. * @return int
  52. */
  53. public function getDbId()
  54. {
  55. return $this->id;
  56. }
  57. /**
  58. * Get the [optionally formatted] temporal [timestamp] column value.
  59. *
  60. *
  61. * @param string $format The date/time format string (either date()-style or strftime()-style).
  62. * If format is NULL, then the raw DateTime object will be returned.
  63. * @return mixed Formatted date/time value as string or DateTime object (if format is NULL), NULL if column is NULL
  64. * @throws PropelException - if unable to parse/validate the date/time value.
  65. */
  66. public function getDbTimestamp($format = 'Y-m-d H:i:s')
  67. {
  68. if ($this->timestamp === null) {
  69. return null;
  70. }
  71. try {
  72. $dt = new DateTime($this->timestamp);
  73. } catch (Exception $x) {
  74. throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->timestamp, true), $x);
  75. }
  76. if ($format === null) {
  77. // Because propel.useDateTimeClass is TRUE, we return a DateTime object.
  78. return $dt;
  79. } elseif (strpos($format, '%') !== false) {
  80. return strftime($format, $dt->format('U'));
  81. } else {
  82. return $dt->format($format);
  83. }
  84. }
  85. /**
  86. * Set the value of [id] column.
  87. *
  88. * @param int $v new value
  89. * @return CcTimestamp The current object (for fluent API support)
  90. */
  91. public function setDbId($v)
  92. {
  93. if ($v !== null) {
  94. $v = (int) $v;
  95. }
  96. if ($this->id !== $v) {
  97. $this->id = $v;
  98. $this->modifiedColumns[] = CcTimestampPeer::ID;
  99. }
  100. return $this;
  101. } // setDbId()
  102. /**
  103. * Sets the value of [timestamp] column to a normalized version of the date/time value specified.
  104. *
  105. * @param mixed $v string, integer (timestamp), or DateTime value. Empty string will
  106. * be treated as NULL for temporal objects.
  107. * @return CcTimestamp The current object (for fluent API support)
  108. */
  109. public function setDbTimestamp($v)
  110. {
  111. // we treat '' as NULL for temporal objects because DateTime('') == DateTime('now')
  112. // -- which is unexpected, to say the least.
  113. if ($v === null || $v === '') {
  114. $dt = null;
  115. } elseif ($v instanceof DateTime) {
  116. $dt = $v;
  117. } else {
  118. // some string/numeric value passed; we normalize that so that we can
  119. // validate it.
  120. try {
  121. if (is_numeric($v)) { // if it's a unix timestamp
  122. $dt = new DateTime('@'.$v, new DateTimeZone('UTC'));
  123. // We have to explicitly specify and then change the time zone because of a
  124. // DateTime bug: http://bugs.php.net/bug.php?id=43003
  125. $dt->setTimeZone(new DateTimeZone(date_default_timezone_get()));
  126. } else {
  127. $dt = new DateTime($v);
  128. }
  129. } catch (Exception $x) {
  130. throw new PropelException('Error parsing date/time value: ' . var_export($v, true), $x);
  131. }
  132. }
  133. if ( $this->timestamp !== null || $dt !== null ) {
  134. // (nested ifs are a little easier to read in this case)
  135. $currNorm = ($this->timestamp !== null && $tmpDt = new DateTime($this->timestamp)) ? $tmpDt->format('Y-m-d\\TH:i:sO') : null;
  136. $newNorm = ($dt !== null) ? $dt->format('Y-m-d\\TH:i:sO') : null;
  137. if ( ($currNorm !== $newNorm) // normalized values don't match
  138. )
  139. {
  140. $this->timestamp = ($dt ? $dt->format('Y-m-d\\TH:i:sO') : null);
  141. $this->modifiedColumns[] = CcTimestampPeer::TIMESTAMP;
  142. }
  143. } // if either are not null
  144. return $this;
  145. } // setDbTimestamp()
  146. /**
  147. * Indicates whether the columns in this object are only set to default values.
  148. *
  149. * This method can be used in conjunction with isModified() to indicate whether an object is both
  150. * modified _and_ has some values set which are non-default.
  151. *
  152. * @return boolean Whether the columns in this object are only been set with default values.
  153. */
  154. public function hasOnlyDefaultValues()
  155. {
  156. // otherwise, everything was equal, so return TRUE
  157. return true;
  158. } // hasOnlyDefaultValues()
  159. /**
  160. * Hydrates (populates) the object variables with values from the database resultset.
  161. *
  162. * An offset (0-based "start column") is specified so that objects can be hydrated
  163. * with a subset of the columns in the resultset rows. This is needed, for example,
  164. * for results of JOIN queries where the resultset row includes columns from two or
  165. * more tables.
  166. *
  167. * @param array $row The row returned by PDOStatement->fetch(PDO::FETCH_NUM)
  168. * @param int $startcol 0-based offset column which indicates which restultset column to start with.
  169. * @param boolean $rehydrate Whether this object is being re-hydrated from the database.
  170. * @return int next starting column
  171. * @throws PropelException - Any caught Exception will be rewrapped as a PropelException.
  172. */
  173. public function hydrate($row, $startcol = 0, $rehydrate = false)
  174. {
  175. try {
  176. $this->id = ($row[$startcol + 0] !== null) ? (int) $row[$startcol + 0] : null;
  177. $this->timestamp = ($row[$startcol + 1] !== null) ? (string) $row[$startcol + 1] : null;
  178. $this->resetModified();
  179. $this->setNew(false);
  180. if ($rehydrate) {
  181. $this->ensureConsistency();
  182. }
  183. return $startcol + 2; // 2 = CcTimestampPeer::NUM_COLUMNS - CcTimestampPeer::NUM_LAZY_LOAD_COLUMNS).
  184. } catch (Exception $e) {
  185. throw new PropelException("Error populating CcTimestamp object", $e);
  186. }
  187. }
  188. /**
  189. * Checks and repairs the internal consistency of the object.
  190. *
  191. * This method is executed after an already-instantiated object is re-hydrated
  192. * from the database. It exists to check any foreign keys to make sure that
  193. * the objects related to the current object are correct based on foreign key.
  194. *
  195. * You can override this method in the stub class, but you should always invoke
  196. * the base method from the overridden method (i.e. parent::ensureConsistency()),
  197. * in case your model changes.
  198. *
  199. * @throws PropelException
  200. */
  201. public function ensureConsistency()
  202. {
  203. } // ensureConsistency
  204. /**
  205. * Reloads this object from datastore based on primary key and (optionally) resets all associated objects.
  206. *
  207. * This will only work if the object has been saved and has a valid primary key set.
  208. *
  209. * @param boolean $deep (optional) Whether to also de-associated any related objects.
  210. * @param PropelPDO $con (optional) The PropelPDO connection to use.
  211. * @return void
  212. * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db
  213. */
  214. public function reload($deep = false, PropelPDO $con = null)
  215. {
  216. if ($this->isDeleted()) {
  217. throw new PropelException("Cannot reload a deleted object.");
  218. }
  219. if ($this->isNew()) {
  220. throw new PropelException("Cannot reload an unsaved object.");
  221. }
  222. if ($con === null) {
  223. $con = Propel::getConnection(CcTimestampPeer::DATABASE_NAME, Propel::CONNECTION_READ);
  224. }
  225. // We don't need to alter the object instance pool; we're just modifying this instance
  226. // already in the pool.
  227. $stmt = CcTimestampPeer::doSelectStmt($this->buildPkeyCriteria(), $con);
  228. $row = $stmt->fetch(PDO::FETCH_NUM);
  229. $stmt->closeCursor();
  230. if (!$row) {
  231. throw new PropelException('Cannot find matching row in the database to reload object values.');
  232. }
  233. $this->hydrate($row, 0, true); // rehydrate
  234. if ($deep) { // also de-associate any related objects?
  235. $this->collCcListenerCounts = null;
  236. } // if (deep)
  237. }
  238. /**
  239. * Removes this object from datastore and sets delete attribute.
  240. *
  241. * @param PropelPDO $con
  242. * @return void
  243. * @throws PropelException
  244. * @see BaseObject::setDeleted()
  245. * @see BaseObject::isDeleted()
  246. */
  247. public function delete(PropelPDO $con = null)
  248. {
  249. if ($this->isDeleted()) {
  250. throw new PropelException("This object has already been deleted.");
  251. }
  252. if ($con === null) {
  253. $con = Propel::getConnection(CcTimestampPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
  254. }
  255. $con->beginTransaction();
  256. try {
  257. $ret = $this->preDelete($con);
  258. if ($ret) {
  259. CcTimestampQuery::create()
  260. ->filterByPrimaryKey($this->getPrimaryKey())
  261. ->delete($con);
  262. $this->postDelete($con);
  263. $con->commit();
  264. $this->setDeleted(true);
  265. } else {
  266. $con->commit();
  267. }
  268. } catch (PropelException $e) {
  269. $con->rollBack();
  270. throw $e;
  271. }
  272. }
  273. /**
  274. * Persists this object to the database.
  275. *
  276. * If the object is new, it inserts it; otherwise an update is performed.
  277. * All modified related objects will also be persisted in the doSave()
  278. * method. This method wraps all precipitate database operations in a
  279. * single transaction.
  280. *
  281. * @param PropelPDO $con
  282. * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
  283. * @throws PropelException
  284. * @see doSave()
  285. */
  286. public function save(PropelPDO $con = null)
  287. {
  288. if ($this->isDeleted()) {
  289. throw new PropelException("You cannot save an object that has been deleted.");
  290. }
  291. if ($con === null) {
  292. $con = Propel::getConnection(CcTimestampPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
  293. }
  294. $con->beginTransaction();
  295. $isInsert = $this->isNew();
  296. try {
  297. $ret = $this->preSave($con);
  298. if ($isInsert) {
  299. $ret = $ret && $this->preInsert($con);
  300. } else {
  301. $ret = $ret && $this->preUpdate($con);
  302. }
  303. if ($ret) {
  304. $affectedRows = $this->doSave($con);
  305. if ($isInsert) {
  306. $this->postInsert($con);
  307. } else {
  308. $this->postUpdate($con);
  309. }
  310. $this->postSave($con);
  311. CcTimestampPeer::addInstanceToPool($this);
  312. } else {
  313. $affectedRows = 0;
  314. }
  315. $con->commit();
  316. return $affectedRows;
  317. } catch (PropelException $e) {
  318. $con->rollBack();
  319. throw $e;
  320. }
  321. }
  322. /**
  323. * Performs the work of inserting or updating the row in the database.
  324. *
  325. * If the object is new, it inserts it; otherwise an update is performed.
  326. * All related objects are also updated in this method.
  327. *
  328. * @param PropelPDO $con
  329. * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
  330. * @throws PropelException
  331. * @see save()
  332. */
  333. protected function doSave(PropelPDO $con)
  334. {
  335. $affectedRows = 0; // initialize var to track total num of affected rows
  336. if (!$this->alreadyInSave) {
  337. $this->alreadyInSave = true;
  338. if ($this->isNew() ) {
  339. $this->modifiedColumns[] = CcTimestampPeer::ID;
  340. }
  341. // If this object has been modified, then save it to the database.
  342. if ($this->isModified()) {
  343. if ($this->isNew()) {
  344. $criteria = $this->buildCriteria();
  345. if ($criteria->keyContainsValue(CcTimestampPeer::ID) ) {
  346. throw new PropelException('Cannot insert a value for auto-increment primary key ('.CcTimestampPeer::ID.')');
  347. }
  348. $pk = BasePeer::doInsert($criteria, $con);
  349. $affectedRows = 1;
  350. $this->setDbId($pk); //[IMV] update autoincrement primary key
  351. $this->setNew(false);
  352. } else {
  353. $affectedRows = CcTimestampPeer::doUpdate($this, $con);
  354. }
  355. $this->resetModified(); // [HL] After being saved an object is no longer 'modified'
  356. }
  357. if ($this->collCcListenerCounts !== null) {
  358. foreach ($this->collCcListenerCounts as $referrerFK) {
  359. if (!$referrerFK->isDeleted()) {
  360. $affectedRows += $referrerFK->save($con);
  361. }
  362. }
  363. }
  364. $this->alreadyInSave = false;
  365. }
  366. return $affectedRows;
  367. } // doSave()
  368. /**
  369. * Array of ValidationFailed objects.
  370. * @var array ValidationFailed[]
  371. */
  372. protected $validationFailures = array();
  373. /**
  374. * Gets any ValidationFailed objects that resulted from last call to validate().
  375. *
  376. *
  377. * @return array ValidationFailed[]
  378. * @see validate()
  379. */
  380. public function getValidationFailures()
  381. {
  382. return $this->validationFailures;
  383. }
  384. /**
  385. * Validates the objects modified field values and all objects related to this table.
  386. *
  387. * If $columns is either a column name or an array of column names
  388. * only those columns are validated.
  389. *
  390. * @param mixed $columns Column name or an array of column names.
  391. * @return boolean Whether all columns pass validation.
  392. * @see doValidate()
  393. * @see getValidationFailures()
  394. */
  395. public function validate($columns = null)
  396. {
  397. $res = $this->doValidate($columns);
  398. if ($res === true) {
  399. $this->validationFailures = array();
  400. return true;
  401. } else {
  402. $this->validationFailures = $res;
  403. return false;
  404. }
  405. }
  406. /**
  407. * This function performs the validation work for complex object models.
  408. *
  409. * In addition to checking the current object, all related objects will
  410. * also be validated. If all pass then <code>true</code> is returned; otherwise
  411. * an aggreagated array of ValidationFailed objects will be returned.
  412. *
  413. * @param array $columns Array of column names to validate.
  414. * @return mixed <code>true</code> if all validations pass; array of <code>ValidationFailed</code> objets otherwise.
  415. */
  416. protected function doValidate($columns = null)
  417. {
  418. if (!$this->alreadyInValidation) {
  419. $this->alreadyInValidation = true;
  420. $retval = null;
  421. $failureMap = array();
  422. if (($retval = CcTimestampPeer::doValidate($this, $columns)) !== true) {
  423. $failureMap = array_merge($failureMap, $retval);
  424. }
  425. if ($this->collCcListenerCounts !== null) {
  426. foreach ($this->collCcListenerCounts as $referrerFK) {
  427. if (!$referrerFK->validate($columns)) {
  428. $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
  429. }
  430. }
  431. }
  432. $this->alreadyInValidation = false;
  433. }
  434. return (!empty($failureMap) ? $failureMap : true);
  435. }
  436. /**
  437. * Retrieves a field from the object by name passed in as a string.
  438. *
  439. * @param string $name name
  440. * @param string $type The type of fieldname the $name is of:
  441. * one of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
  442. * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM
  443. * @return mixed Value of field.
  444. */
  445. public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
  446. {
  447. $pos = CcTimestampPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
  448. $field = $this->getByPosition($pos);
  449. return $field;
  450. }
  451. /**
  452. * Retrieves a field from the object by Position as specified in the xml schema.
  453. * Zero-based.
  454. *
  455. * @param int $pos position in xml schema
  456. * @return mixed Value of field at $pos
  457. */
  458. public function getByPosition($pos)
  459. {
  460. switch($pos) {
  461. case 0:
  462. return $this->getDbId();
  463. break;
  464. case 1:
  465. return $this->getDbTimestamp();
  466. break;
  467. default:
  468. return null;
  469. break;
  470. } // switch()
  471. }
  472. /**
  473. * Exports the object as an array.
  474. *
  475. * You can specify the key type of the array by passing one of the class
  476. * type constants.
  477. *
  478. * @param string $keyType (optional) One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
  479. * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
  480. * Defaults to BasePeer::TYPE_PHPNAME.
  481. * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE.
  482. *
  483. * @return array an associative array containing the field names (as keys) and field values
  484. */
  485. public function toArray($keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true)
  486. {
  487. $keys = CcTimestampPeer::getFieldNames($keyType);
  488. $result = array(
  489. $keys[0] => $this->getDbId(),
  490. $keys[1] => $this->getDbTimestamp(),
  491. );
  492. return $result;
  493. }
  494. /**
  495. * Sets a field from the object by name passed in as a string.
  496. *
  497. * @param string $name peer name
  498. * @param mixed $value field value
  499. * @param string $type The type of fieldname the $name is of:
  500. * one of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
  501. * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM
  502. * @return void
  503. */
  504. public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
  505. {
  506. $pos = CcTimestampPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
  507. return $this->setByPosition($pos, $value);
  508. }
  509. /**
  510. * Sets a field from the object by Position as specified in the xml schema.
  511. * Zero-based.
  512. *
  513. * @param int $pos position in xml schema
  514. * @param mixed $value field value
  515. * @return void
  516. */
  517. public function setByPosition($pos, $value)
  518. {
  519. switch($pos) {
  520. case 0:
  521. $this->setDbId($value);
  522. break;
  523. case 1:
  524. $this->setDbTimestamp($value);
  525. break;
  526. } // switch()
  527. }
  528. /**
  529. * Populates the object using an array.
  530. *
  531. * This is particularly useful when populating an object from one of the
  532. * request arrays (e.g. $_POST). This method goes through the column
  533. * names, checking to see whether a matching key exists in populated
  534. * array. If so the setByName() method is called for that column.
  535. *
  536. * You can specify the key type of the array by additionally passing one
  537. * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
  538. * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
  539. * The default key type is the column's phpname (e.g. 'AuthorId')
  540. *
  541. * @param array $arr An array to populate the object from.
  542. * @param string $keyType The type of keys the array uses.
  543. * @return void
  544. */
  545. public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
  546. {
  547. $keys = CcTimestampPeer::getFieldNames($keyType);
  548. if (array_key_exists($keys[0], $arr)) $this->setDbId($arr[$keys[0]]);
  549. if (array_key_exists($keys[1], $arr)) $this->setDbTimestamp($arr[$keys[1]]);
  550. }
  551. /**
  552. * Build a Criteria object containing the values of all modified columns in this object.
  553. *
  554. * @return Criteria The Criteria object containing all modified values.
  555. */
  556. public function buildCriteria()
  557. {
  558. $criteria = new Criteria(CcTimestampPeer::DATABASE_NAME);
  559. if ($this->isColumnModified(CcTimestampPeer::ID)) $criteria->add(CcTimestampPeer::ID, $this->id);
  560. if ($this->isColumnModified(CcTimestampPeer::TIMESTAMP)) $criteria->add(CcTimestampPeer::TIMESTAMP, $this->timestamp);
  561. return $criteria;
  562. }
  563. /**
  564. * Builds a Criteria object containing the primary key for this object.
  565. *
  566. * Unlike buildCriteria() this method includes the primary key values regardless
  567. * of whether or not they have been modified.
  568. *
  569. * @return Criteria The Criteria object containing value(s) for primary key(s).
  570. */
  571. public function buildPkeyCriteria()
  572. {
  573. $criteria = new Criteria(CcTimestampPeer::DATABASE_NAME);
  574. $criteria->add(CcTimestampPeer::ID, $this->id);
  575. return $criteria;
  576. }
  577. /**
  578. * Returns the primary key for this object (row).
  579. * @return int
  580. */
  581. public function getPrimaryKey()
  582. {
  583. return $this->getDbId();
  584. }
  585. /**
  586. * Generic method to set the primary key (id column).
  587. *
  588. * @param int $key Primary key.
  589. * @return void
  590. */
  591. public function setPrimaryKey($key)
  592. {
  593. $this->setDbId($key);
  594. }
  595. /**
  596. * Returns true if the primary key for this object is null.
  597. * @return boolean
  598. */
  599. public function isPrimaryKeyNull()
  600. {
  601. return null === $this->getDbId();
  602. }
  603. /**
  604. * Sets contents of passed object to values from current object.
  605. *
  606. * If desired, this method can also make copies of all associated (fkey referrers)
  607. * objects.
  608. *
  609. * @param object $copyObj An object of CcTimestamp (or compatible) type.
  610. * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
  611. * @throws PropelException
  612. */
  613. public function copyInto($copyObj, $deepCopy = false)
  614. {
  615. $copyObj->setDbTimestamp($this->timestamp);
  616. if ($deepCopy) {
  617. // important: temporarily setNew(false) because this affects the behavior of
  618. // the getter/setter methods for fkey referrer objects.
  619. $copyObj->setNew(false);
  620. foreach ($this->getCcListenerCounts() as $relObj) {
  621. if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves
  622. $copyObj->addCcListenerCount($relObj->copy($deepCopy));
  623. }
  624. }
  625. } // if ($deepCopy)
  626. $copyObj->setNew(true);
  627. $copyObj->setDbId(NULL); // this is a auto-increment column, so set to default value
  628. }
  629. /**
  630. * Makes a copy of this object that will be inserted as a new row in table when saved.
  631. * It creates a new object filling in the simple attributes, but skipping any primary
  632. * keys that are defined for the table.
  633. *
  634. * If desired, this method can also make copies of all associated (fkey referrers)
  635. * objects.
  636. *
  637. * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
  638. * @return CcTimestamp Clone of current object.
  639. * @throws PropelException
  640. */
  641. public function copy($deepCopy = false)
  642. {
  643. // we use get_class(), because this might be a subclass
  644. $clazz = get_class($this);
  645. $copyObj = new $clazz();
  646. $this->copyInto($copyObj, $deepCopy);
  647. return $copyObj;
  648. }
  649. /**
  650. * Returns a peer instance associated with this om.
  651. *
  652. * Since Peer classes are not to have any instance attributes, this method returns the
  653. * same instance for all member of this class. The method could therefore
  654. * be static, but this would prevent one from overriding the behavior.
  655. *
  656. * @return CcTimestampPeer
  657. */
  658. public function getPeer()
  659. {
  660. if (self::$peer === null) {
  661. self::$peer = new CcTimestampPeer();
  662. }
  663. return self::$peer;
  664. }
  665. /**
  666. * Clears out the collCcListenerCounts collection
  667. *
  668. * This does not modify the database; however, it will remove any associated objects, causing
  669. * them to be refetched by subsequent calls to accessor method.
  670. *
  671. * @return void
  672. * @see addCcListenerCounts()
  673. */
  674. public function clearCcListenerCounts()
  675. {
  676. $this->collCcListenerCounts = null; // important to set this to NULL since that means it is uninitialized
  677. }
  678. /**
  679. * Initializes the collCcListenerCounts collection.
  680. *
  681. * By default this just sets the collCcListenerCounts collection to an empty array (like clearcollCcListenerCounts());
  682. * however, you may wish to override this method in your stub class to provide setting appropriate
  683. * to your application -- for example, setting the initial array to the values stored in database.
  684. *
  685. * @return void
  686. */
  687. public function initCcListenerCounts()
  688. {
  689. $this->collCcListenerCounts = new PropelObjectCollection();
  690. $this->collCcListenerCounts->setModel('CcListenerCount');
  691. }
  692. /**
  693. * Gets an array of CcListenerCount objects which contain a foreign key that references this object.
  694. *
  695. * If the $criteria is not null, it is used to always fetch the results from the database.
  696. * Otherwise the results are fetched from the database the first time, then cached.
  697. * Next time the same method is called without $criteria, the cached collection is returned.
  698. * If this CcTimestamp is new, it will return
  699. * an empty collection or the current collection; the criteria is ignored on a new object.
  700. *
  701. * @param Criteria $criteria optional Criteria object to narrow the query
  702. * @param PropelPDO $con optional connection object
  703. * @return PropelCollection|array CcListenerCount[] List of CcListenerCount objects
  704. * @throws PropelException
  705. */
  706. public function getCcListenerCounts($criteria = null, PropelPDO $con = null)
  707. {
  708. if(null === $this->collCcListenerCounts || null !== $criteria) {
  709. if ($this->isNew() && null === $this->collCcListenerCounts) {
  710. // return empty collection
  711. $this->initCcListenerCounts();
  712. } else {
  713. $collCcListenerCounts = CcListenerCountQuery::create(null, $criteria)
  714. ->filterByCcTimestamp($this)
  715. ->find($con);
  716. if (null !== $criteria) {
  717. return $collCcListenerCounts;
  718. }
  719. $this->collCcListenerCounts = $collCcListenerCounts;
  720. }
  721. }
  722. return $this->collCcListenerCounts;
  723. }
  724. /**
  725. * Returns the number of related CcListenerCount objects.
  726. *
  727. * @param Criteria $criteria
  728. * @param boolean $distinct
  729. * @param PropelPDO $con
  730. * @return int Count of related CcListenerCount objects.
  731. * @throws PropelException
  732. */
  733. public function countCcListenerCounts(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
  734. {
  735. if(null === $this->collCcListenerCounts || null !== $criteria) {
  736. if ($this->isNew() && null === $this->collCcListenerCounts) {
  737. return 0;
  738. } else {
  739. $query = CcListenerCountQuery::create(null, $criteria);
  740. if($distinct) {
  741. $query->distinct();
  742. }
  743. return $query
  744. ->filterByCcTimestamp($this)
  745. ->count($con);
  746. }
  747. } else {
  748. return count($this->collCcListenerCounts);
  749. }
  750. }
  751. /**
  752. * Method called to associate a CcListenerCount object to this object
  753. * through the CcListenerCount foreign key attribute.
  754. *
  755. * @param CcListenerCount $l CcListenerCount
  756. * @return void
  757. * @throws PropelException
  758. */
  759. public function addCcListenerCount(CcListenerCount $l)
  760. {
  761. if ($this->collCcListenerCounts === null) {
  762. $this->initCcListenerCounts();
  763. }
  764. if (!$this->collCcListenerCounts->contains($l)) { // only add it if the **same** object is not already associated
  765. $this->collCcListenerCounts[]= $l;
  766. $l->setCcTimestamp($this);
  767. }
  768. }
  769. /**
  770. * If this collection has already been initialized with
  771. * an identical criteria, it returns the collection.
  772. * Otherwise if this CcTimestamp is new, it will return
  773. * an empty collection; or if this CcTimestamp has previously
  774. * been saved, it will retrieve related CcListenerCounts from storage.
  775. *
  776. * This method is protected by default in order to keep the public
  777. * api reasonable. You can provide public methods for those you
  778. * actually need in CcTimestamp.
  779. *
  780. * @param Criteria $criteria optional Criteria object to narrow the query
  781. * @param PropelPDO $con optional connection object
  782. * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN)
  783. * @return PropelCollection|array CcListenerCount[] List of CcListenerCount objects
  784. */
  785. public function getCcListenerCountsJoinCcMountName($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
  786. {
  787. $query = CcListenerCountQuery::create(null, $criteria);
  788. $query->joinWith('CcMountName', $join_behavior);
  789. return $this->getCcListenerCounts($query, $con);
  790. }
  791. /**
  792. * Clears the current object and sets all attributes to their default values
  793. */
  794. public function clear()
  795. {
  796. $this->id = null;
  797. $this->timestamp = null;
  798. $this->alreadyInSave = false;
  799. $this->alreadyInValidation = false;
  800. $this->clearAllReferences();
  801. $this->resetModified();
  802. $this->setNew(true);
  803. $this->setDeleted(false);
  804. }
  805. /**
  806. * Resets all collections of referencing foreign keys.
  807. *
  808. * This method is a user-space workaround for PHP's inability to garbage collect objects
  809. * with circular references. This is currently necessary when using Propel in certain
  810. * daemon or large-volumne/high-memory operations.
  811. *
  812. * @param boolean $deep Whether to also clear the references on all associated objects.
  813. */
  814. public function clearAllReferences($deep = false)
  815. {
  816. if ($deep) {
  817. if ($this->collCcListenerCounts) {
  818. foreach ((array) $this->collCcListenerCounts as $o) {
  819. $o->clearAllReferences($deep);
  820. }
  821. }
  822. } // if ($deep)
  823. $this->collCcListenerCounts = null;
  824. }
  825. /**
  826. * Catches calls to virtual methods
  827. */
  828. public function __call($name, $params)
  829. {
  830. if (preg_match('/get(\w+)/', $name, $matches)) {
  831. $virtualColumn = $matches[1];
  832. if ($this->hasVirtualColumn($virtualColumn)) {
  833. return $this->getVirtualColumn($virtualColumn);
  834. }
  835. // no lcfirst in php<5.3...
  836. $virtualColumn[0] = strtolower($virtualColumn[0]);
  837. if ($this->hasVirtualColumn($virtualColumn)) {
  838. return $this->getVirtualColumn($virtualColumn);
  839. }
  840. }
  841. throw new PropelException('Call to undefined method: ' . $name);
  842. }
  843. } // BaseCcTimestamp