BaseCcPlayoutHistory.php 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289
  1. <?php
  2. /**
  3. * Base class that represents a row from the 'cc_playout_history' table.
  4. *
  5. *
  6. *
  7. * @package propel.generator.airtime.om
  8. */
  9. abstract class BaseCcPlayoutHistory extends BaseObject implements Persistent
  10. {
  11. /**
  12. * Peer class name
  13. */
  14. const PEER = 'CcPlayoutHistoryPeer';
  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 CcPlayoutHistoryPeer
  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 file_id field.
  29. * @var int
  30. */
  31. protected $file_id;
  32. /**
  33. * The value for the starts field.
  34. * @var string
  35. */
  36. protected $starts;
  37. /**
  38. * The value for the ends field.
  39. * @var string
  40. */
  41. protected $ends;
  42. /**
  43. * The value for the instance_id field.
  44. * @var int
  45. */
  46. protected $instance_id;
  47. /**
  48. * @var CcFiles
  49. */
  50. protected $aCcFiles;
  51. /**
  52. * @var CcShowInstances
  53. */
  54. protected $aCcShowInstances;
  55. /**
  56. * @var array CcPlayoutHistoryMetaData[] Collection to store aggregation of CcPlayoutHistoryMetaData objects.
  57. */
  58. protected $collCcPlayoutHistoryMetaDatas;
  59. /**
  60. * Flag to prevent endless save loop, if this object is referenced
  61. * by another object which falls in this transaction.
  62. * @var boolean
  63. */
  64. protected $alreadyInSave = false;
  65. /**
  66. * Flag to prevent endless validation loop, if this object is referenced
  67. * by another object which falls in this transaction.
  68. * @var boolean
  69. */
  70. protected $alreadyInValidation = false;
  71. /**
  72. * Get the [id] column value.
  73. *
  74. * @return int
  75. */
  76. public function getDbId()
  77. {
  78. return $this->id;
  79. }
  80. /**
  81. * Get the [file_id] column value.
  82. *
  83. * @return int
  84. */
  85. public function getDbFileId()
  86. {
  87. return $this->file_id;
  88. }
  89. /**
  90. * Get the [optionally formatted] temporal [starts] column value.
  91. *
  92. *
  93. * @param string $format The date/time format string (either date()-style or strftime()-style).
  94. * If format is NULL, then the raw DateTime object will be returned.
  95. * @return mixed Formatted date/time value as string or DateTime object (if format is NULL), NULL if column is NULL
  96. * @throws PropelException - if unable to parse/validate the date/time value.
  97. */
  98. public function getDbStarts($format = 'Y-m-d H:i:s')
  99. {
  100. if ($this->starts === null) {
  101. return null;
  102. }
  103. try {
  104. $dt = new DateTime($this->starts);
  105. } catch (Exception $x) {
  106. throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->starts, true), $x);
  107. }
  108. if ($format === null) {
  109. // Because propel.useDateTimeClass is TRUE, we return a DateTime object.
  110. return $dt;
  111. } elseif (strpos($format, '%') !== false) {
  112. return strftime($format, $dt->format('U'));
  113. } else {
  114. return $dt->format($format);
  115. }
  116. }
  117. /**
  118. * Get the [optionally formatted] temporal [ends] column value.
  119. *
  120. *
  121. * @param string $format The date/time format string (either date()-style or strftime()-style).
  122. * If format is NULL, then the raw DateTime object will be returned.
  123. * @return mixed Formatted date/time value as string or DateTime object (if format is NULL), NULL if column is NULL
  124. * @throws PropelException - if unable to parse/validate the date/time value.
  125. */
  126. public function getDbEnds($format = 'Y-m-d H:i:s')
  127. {
  128. if ($this->ends === null) {
  129. return null;
  130. }
  131. try {
  132. $dt = new DateTime($this->ends);
  133. } catch (Exception $x) {
  134. throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->ends, true), $x);
  135. }
  136. if ($format === null) {
  137. // Because propel.useDateTimeClass is TRUE, we return a DateTime object.
  138. return $dt;
  139. } elseif (strpos($format, '%') !== false) {
  140. return strftime($format, $dt->format('U'));
  141. } else {
  142. return $dt->format($format);
  143. }
  144. }
  145. /**
  146. * Get the [instance_id] column value.
  147. *
  148. * @return int
  149. */
  150. public function getDbInstanceId()
  151. {
  152. return $this->instance_id;
  153. }
  154. /**
  155. * Set the value of [id] column.
  156. *
  157. * @param int $v new value
  158. * @return CcPlayoutHistory The current object (for fluent API support)
  159. */
  160. public function setDbId($v)
  161. {
  162. if ($v !== null) {
  163. $v = (int) $v;
  164. }
  165. if ($this->id !== $v) {
  166. $this->id = $v;
  167. $this->modifiedColumns[] = CcPlayoutHistoryPeer::ID;
  168. }
  169. return $this;
  170. } // setDbId()
  171. /**
  172. * Set the value of [file_id] column.
  173. *
  174. * @param int $v new value
  175. * @return CcPlayoutHistory The current object (for fluent API support)
  176. */
  177. public function setDbFileId($v)
  178. {
  179. if ($v !== null) {
  180. $v = (int) $v;
  181. }
  182. if ($this->file_id !== $v) {
  183. $this->file_id = $v;
  184. $this->modifiedColumns[] = CcPlayoutHistoryPeer::FILE_ID;
  185. }
  186. if ($this->aCcFiles !== null && $this->aCcFiles->getDbId() !== $v) {
  187. $this->aCcFiles = null;
  188. }
  189. return $this;
  190. } // setDbFileId()
  191. /**
  192. * Sets the value of [starts] column to a normalized version of the date/time value specified.
  193. *
  194. * @param mixed $v string, integer (timestamp), or DateTime value. Empty string will
  195. * be treated as NULL for temporal objects.
  196. * @return CcPlayoutHistory The current object (for fluent API support)
  197. */
  198. public function setDbStarts($v)
  199. {
  200. // we treat '' as NULL for temporal objects because DateTime('') == DateTime('now')
  201. // -- which is unexpected, to say the least.
  202. if ($v === null || $v === '') {
  203. $dt = null;
  204. } elseif ($v instanceof DateTime) {
  205. $dt = $v;
  206. } else {
  207. // some string/numeric value passed; we normalize that so that we can
  208. // validate it.
  209. try {
  210. if (is_numeric($v)) { // if it's a unix timestamp
  211. $dt = new DateTime('@'.$v, new DateTimeZone('UTC'));
  212. // We have to explicitly specify and then change the time zone because of a
  213. // DateTime bug: http://bugs.php.net/bug.php?id=43003
  214. $dt->setTimeZone(new DateTimeZone(date_default_timezone_get()));
  215. } else {
  216. $dt = new DateTime($v);
  217. }
  218. } catch (Exception $x) {
  219. throw new PropelException('Error parsing date/time value: ' . var_export($v, true), $x);
  220. }
  221. }
  222. if ( $this->starts !== null || $dt !== null ) {
  223. // (nested ifs are a little easier to read in this case)
  224. $currNorm = ($this->starts !== null && $tmpDt = new DateTime($this->starts)) ? $tmpDt->format('Y-m-d\\TH:i:sO') : null;
  225. $newNorm = ($dt !== null) ? $dt->format('Y-m-d\\TH:i:sO') : null;
  226. if ( ($currNorm !== $newNorm) // normalized values don't match
  227. )
  228. {
  229. $this->starts = ($dt ? $dt->format('Y-m-d\\TH:i:sO') : null);
  230. $this->modifiedColumns[] = CcPlayoutHistoryPeer::STARTS;
  231. }
  232. } // if either are not null
  233. return $this;
  234. } // setDbStarts()
  235. /**
  236. * Sets the value of [ends] column to a normalized version of the date/time value specified.
  237. *
  238. * @param mixed $v string, integer (timestamp), or DateTime value. Empty string will
  239. * be treated as NULL for temporal objects.
  240. * @return CcPlayoutHistory The current object (for fluent API support)
  241. */
  242. public function setDbEnds($v)
  243. {
  244. // we treat '' as NULL for temporal objects because DateTime('') == DateTime('now')
  245. // -- which is unexpected, to say the least.
  246. if ($v === null || $v === '') {
  247. $dt = null;
  248. } elseif ($v instanceof DateTime) {
  249. $dt = $v;
  250. } else {
  251. // some string/numeric value passed; we normalize that so that we can
  252. // validate it.
  253. try {
  254. if (is_numeric($v)) { // if it's a unix timestamp
  255. $dt = new DateTime('@'.$v, new DateTimeZone('UTC'));
  256. // We have to explicitly specify and then change the time zone because of a
  257. // DateTime bug: http://bugs.php.net/bug.php?id=43003
  258. $dt->setTimeZone(new DateTimeZone(date_default_timezone_get()));
  259. } else {
  260. $dt = new DateTime($v);
  261. }
  262. } catch (Exception $x) {
  263. throw new PropelException('Error parsing date/time value: ' . var_export($v, true), $x);
  264. }
  265. }
  266. if ( $this->ends !== null || $dt !== null ) {
  267. // (nested ifs are a little easier to read in this case)
  268. $currNorm = ($this->ends !== null && $tmpDt = new DateTime($this->ends)) ? $tmpDt->format('Y-m-d\\TH:i:sO') : null;
  269. $newNorm = ($dt !== null) ? $dt->format('Y-m-d\\TH:i:sO') : null;
  270. if ( ($currNorm !== $newNorm) // normalized values don't match
  271. )
  272. {
  273. $this->ends = ($dt ? $dt->format('Y-m-d\\TH:i:sO') : null);
  274. $this->modifiedColumns[] = CcPlayoutHistoryPeer::ENDS;
  275. }
  276. } // if either are not null
  277. return $this;
  278. } // setDbEnds()
  279. /**
  280. * Set the value of [instance_id] column.
  281. *
  282. * @param int $v new value
  283. * @return CcPlayoutHistory The current object (for fluent API support)
  284. */
  285. public function setDbInstanceId($v)
  286. {
  287. if ($v !== null) {
  288. $v = (int) $v;
  289. }
  290. if ($this->instance_id !== $v) {
  291. $this->instance_id = $v;
  292. $this->modifiedColumns[] = CcPlayoutHistoryPeer::INSTANCE_ID;
  293. }
  294. if ($this->aCcShowInstances !== null && $this->aCcShowInstances->getDbId() !== $v) {
  295. $this->aCcShowInstances = null;
  296. }
  297. return $this;
  298. } // setDbInstanceId()
  299. /**
  300. * Indicates whether the columns in this object are only set to default values.
  301. *
  302. * This method can be used in conjunction with isModified() to indicate whether an object is both
  303. * modified _and_ has some values set which are non-default.
  304. *
  305. * @return boolean Whether the columns in this object are only been set with default values.
  306. */
  307. public function hasOnlyDefaultValues()
  308. {
  309. // otherwise, everything was equal, so return TRUE
  310. return true;
  311. } // hasOnlyDefaultValues()
  312. /**
  313. * Hydrates (populates) the object variables with values from the database resultset.
  314. *
  315. * An offset (0-based "start column") is specified so that objects can be hydrated
  316. * with a subset of the columns in the resultset rows. This is needed, for example,
  317. * for results of JOIN queries where the resultset row includes columns from two or
  318. * more tables.
  319. *
  320. * @param array $row The row returned by PDOStatement->fetch(PDO::FETCH_NUM)
  321. * @param int $startcol 0-based offset column which indicates which restultset column to start with.
  322. * @param boolean $rehydrate Whether this object is being re-hydrated from the database.
  323. * @return int next starting column
  324. * @throws PropelException - Any caught Exception will be rewrapped as a PropelException.
  325. */
  326. public function hydrate($row, $startcol = 0, $rehydrate = false)
  327. {
  328. try {
  329. $this->id = ($row[$startcol + 0] !== null) ? (int) $row[$startcol + 0] : null;
  330. $this->file_id = ($row[$startcol + 1] !== null) ? (int) $row[$startcol + 1] : null;
  331. $this->starts = ($row[$startcol + 2] !== null) ? (string) $row[$startcol + 2] : null;
  332. $this->ends = ($row[$startcol + 3] !== null) ? (string) $row[$startcol + 3] : null;
  333. $this->instance_id = ($row[$startcol + 4] !== null) ? (int) $row[$startcol + 4] : null;
  334. $this->resetModified();
  335. $this->setNew(false);
  336. if ($rehydrate) {
  337. $this->ensureConsistency();
  338. }
  339. return $startcol + 5; // 5 = CcPlayoutHistoryPeer::NUM_COLUMNS - CcPlayoutHistoryPeer::NUM_LAZY_LOAD_COLUMNS).
  340. } catch (Exception $e) {
  341. throw new PropelException("Error populating CcPlayoutHistory object", $e);
  342. }
  343. }
  344. /**
  345. * Checks and repairs the internal consistency of the object.
  346. *
  347. * This method is executed after an already-instantiated object is re-hydrated
  348. * from the database. It exists to check any foreign keys to make sure that
  349. * the objects related to the current object are correct based on foreign key.
  350. *
  351. * You can override this method in the stub class, but you should always invoke
  352. * the base method from the overridden method (i.e. parent::ensureConsistency()),
  353. * in case your model changes.
  354. *
  355. * @throws PropelException
  356. */
  357. public function ensureConsistency()
  358. {
  359. if ($this->aCcFiles !== null && $this->file_id !== $this->aCcFiles->getDbId()) {
  360. $this->aCcFiles = null;
  361. }
  362. if ($this->aCcShowInstances !== null && $this->instance_id !== $this->aCcShowInstances->getDbId()) {
  363. $this->aCcShowInstances = null;
  364. }
  365. } // ensureConsistency
  366. /**
  367. * Reloads this object from datastore based on primary key and (optionally) resets all associated objects.
  368. *
  369. * This will only work if the object has been saved and has a valid primary key set.
  370. *
  371. * @param boolean $deep (optional) Whether to also de-associated any related objects.
  372. * @param PropelPDO $con (optional) The PropelPDO connection to use.
  373. * @return void
  374. * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db
  375. */
  376. public function reload($deep = false, PropelPDO $con = null)
  377. {
  378. if ($this->isDeleted()) {
  379. throw new PropelException("Cannot reload a deleted object.");
  380. }
  381. if ($this->isNew()) {
  382. throw new PropelException("Cannot reload an unsaved object.");
  383. }
  384. if ($con === null) {
  385. $con = Propel::getConnection(CcPlayoutHistoryPeer::DATABASE_NAME, Propel::CONNECTION_READ);
  386. }
  387. // We don't need to alter the object instance pool; we're just modifying this instance
  388. // already in the pool.
  389. $stmt = CcPlayoutHistoryPeer::doSelectStmt($this->buildPkeyCriteria(), $con);
  390. $row = $stmt->fetch(PDO::FETCH_NUM);
  391. $stmt->closeCursor();
  392. if (!$row) {
  393. throw new PropelException('Cannot find matching row in the database to reload object values.');
  394. }
  395. $this->hydrate($row, 0, true); // rehydrate
  396. if ($deep) { // also de-associate any related objects?
  397. $this->aCcFiles = null;
  398. $this->aCcShowInstances = null;
  399. $this->collCcPlayoutHistoryMetaDatas = null;
  400. } // if (deep)
  401. }
  402. /**
  403. * Removes this object from datastore and sets delete attribute.
  404. *
  405. * @param PropelPDO $con
  406. * @return void
  407. * @throws PropelException
  408. * @see BaseObject::setDeleted()
  409. * @see BaseObject::isDeleted()
  410. */
  411. public function delete(PropelPDO $con = null)
  412. {
  413. if ($this->isDeleted()) {
  414. throw new PropelException("This object has already been deleted.");
  415. }
  416. if ($con === null) {
  417. $con = Propel::getConnection(CcPlayoutHistoryPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
  418. }
  419. $con->beginTransaction();
  420. try {
  421. $ret = $this->preDelete($con);
  422. if ($ret) {
  423. CcPlayoutHistoryQuery::create()
  424. ->filterByPrimaryKey($this->getPrimaryKey())
  425. ->delete($con);
  426. $this->postDelete($con);
  427. $con->commit();
  428. $this->setDeleted(true);
  429. } else {
  430. $con->commit();
  431. }
  432. } catch (PropelException $e) {
  433. $con->rollBack();
  434. throw $e;
  435. }
  436. }
  437. /**
  438. * Persists this object to the database.
  439. *
  440. * If the object is new, it inserts it; otherwise an update is performed.
  441. * All modified related objects will also be persisted in the doSave()
  442. * method. This method wraps all precipitate database operations in a
  443. * single transaction.
  444. *
  445. * @param PropelPDO $con
  446. * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
  447. * @throws PropelException
  448. * @see doSave()
  449. */
  450. public function save(PropelPDO $con = null)
  451. {
  452. if ($this->isDeleted()) {
  453. throw new PropelException("You cannot save an object that has been deleted.");
  454. }
  455. if ($con === null) {
  456. $con = Propel::getConnection(CcPlayoutHistoryPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
  457. }
  458. $con->beginTransaction();
  459. $isInsert = $this->isNew();
  460. try {
  461. $ret = $this->preSave($con);
  462. if ($isInsert) {
  463. $ret = $ret && $this->preInsert($con);
  464. } else {
  465. $ret = $ret && $this->preUpdate($con);
  466. }
  467. if ($ret) {
  468. $affectedRows = $this->doSave($con);
  469. if ($isInsert) {
  470. $this->postInsert($con);
  471. } else {
  472. $this->postUpdate($con);
  473. }
  474. $this->postSave($con);
  475. CcPlayoutHistoryPeer::addInstanceToPool($this);
  476. } else {
  477. $affectedRows = 0;
  478. }
  479. $con->commit();
  480. return $affectedRows;
  481. } catch (PropelException $e) {
  482. $con->rollBack();
  483. throw $e;
  484. }
  485. }
  486. /**
  487. * Performs the work of inserting or updating the row in the database.
  488. *
  489. * If the object is new, it inserts it; otherwise an update is performed.
  490. * All related objects are also updated in this method.
  491. *
  492. * @param PropelPDO $con
  493. * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
  494. * @throws PropelException
  495. * @see save()
  496. */
  497. protected function doSave(PropelPDO $con)
  498. {
  499. $affectedRows = 0; // initialize var to track total num of affected rows
  500. if (!$this->alreadyInSave) {
  501. $this->alreadyInSave = true;
  502. // We call the save method on the following object(s) if they
  503. // were passed to this object by their coresponding set
  504. // method. This object relates to these object(s) by a
  505. // foreign key reference.
  506. if ($this->aCcFiles !== null) {
  507. if ($this->aCcFiles->isModified() || $this->aCcFiles->isNew()) {
  508. $affectedRows += $this->aCcFiles->save($con);
  509. }
  510. $this->setCcFiles($this->aCcFiles);
  511. }
  512. if ($this->aCcShowInstances !== null) {
  513. if ($this->aCcShowInstances->isModified() || $this->aCcShowInstances->isNew()) {
  514. $affectedRows += $this->aCcShowInstances->save($con);
  515. }
  516. $this->setCcShowInstances($this->aCcShowInstances);
  517. }
  518. if ($this->isNew() ) {
  519. $this->modifiedColumns[] = CcPlayoutHistoryPeer::ID;
  520. }
  521. // If this object has been modified, then save it to the database.
  522. if ($this->isModified()) {
  523. if ($this->isNew()) {
  524. $criteria = $this->buildCriteria();
  525. if ($criteria->keyContainsValue(CcPlayoutHistoryPeer::ID) ) {
  526. throw new PropelException('Cannot insert a value for auto-increment primary key ('.CcPlayoutHistoryPeer::ID.')');
  527. }
  528. $pk = BasePeer::doInsert($criteria, $con);
  529. $affectedRows += 1;
  530. $this->setDbId($pk); //[IMV] update autoincrement primary key
  531. $this->setNew(false);
  532. } else {
  533. $affectedRows += CcPlayoutHistoryPeer::doUpdate($this, $con);
  534. }
  535. $this->resetModified(); // [HL] After being saved an object is no longer 'modified'
  536. }
  537. if ($this->collCcPlayoutHistoryMetaDatas !== null) {
  538. foreach ($this->collCcPlayoutHistoryMetaDatas as $referrerFK) {
  539. if (!$referrerFK->isDeleted()) {
  540. $affectedRows += $referrerFK->save($con);
  541. }
  542. }
  543. }
  544. $this->alreadyInSave = false;
  545. }
  546. return $affectedRows;
  547. } // doSave()
  548. /**
  549. * Array of ValidationFailed objects.
  550. * @var array ValidationFailed[]
  551. */
  552. protected $validationFailures = array();
  553. /**
  554. * Gets any ValidationFailed objects that resulted from last call to validate().
  555. *
  556. *
  557. * @return array ValidationFailed[]
  558. * @see validate()
  559. */
  560. public function getValidationFailures()
  561. {
  562. return $this->validationFailures;
  563. }
  564. /**
  565. * Validates the objects modified field values and all objects related to this table.
  566. *
  567. * If $columns is either a column name or an array of column names
  568. * only those columns are validated.
  569. *
  570. * @param mixed $columns Column name or an array of column names.
  571. * @return boolean Whether all columns pass validation.
  572. * @see doValidate()
  573. * @see getValidationFailures()
  574. */
  575. public function validate($columns = null)
  576. {
  577. $res = $this->doValidate($columns);
  578. if ($res === true) {
  579. $this->validationFailures = array();
  580. return true;
  581. } else {
  582. $this->validationFailures = $res;
  583. return false;
  584. }
  585. }
  586. /**
  587. * This function performs the validation work for complex object models.
  588. *
  589. * In addition to checking the current object, all related objects will
  590. * also be validated. If all pass then <code>true</code> is returned; otherwise
  591. * an aggreagated array of ValidationFailed objects will be returned.
  592. *
  593. * @param array $columns Array of column names to validate.
  594. * @return mixed <code>true</code> if all validations pass; array of <code>ValidationFailed</code> objets otherwise.
  595. */
  596. protected function doValidate($columns = null)
  597. {
  598. if (!$this->alreadyInValidation) {
  599. $this->alreadyInValidation = true;
  600. $retval = null;
  601. $failureMap = array();
  602. // We call the validate method on the following object(s) if they
  603. // were passed to this object by their coresponding set
  604. // method. This object relates to these object(s) by a
  605. // foreign key reference.
  606. if ($this->aCcFiles !== null) {
  607. if (!$this->aCcFiles->validate($columns)) {
  608. $failureMap = array_merge($failureMap, $this->aCcFiles->getValidationFailures());
  609. }
  610. }
  611. if ($this->aCcShowInstances !== null) {
  612. if (!$this->aCcShowInstances->validate($columns)) {
  613. $failureMap = array_merge($failureMap, $this->aCcShowInstances->getValidationFailures());
  614. }
  615. }
  616. if (($retval = CcPlayoutHistoryPeer::doValidate($this, $columns)) !== true) {
  617. $failureMap = array_merge($failureMap, $retval);
  618. }
  619. if ($this->collCcPlayoutHistoryMetaDatas !== null) {
  620. foreach ($this->collCcPlayoutHistoryMetaDatas as $referrerFK) {
  621. if (!$referrerFK->validate($columns)) {
  622. $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
  623. }
  624. }
  625. }
  626. $this->alreadyInValidation = false;
  627. }
  628. return (!empty($failureMap) ? $failureMap : true);
  629. }
  630. /**
  631. * Retrieves a field from the object by name passed in as a string.
  632. *
  633. * @param string $name name
  634. * @param string $type The type of fieldname the $name is of:
  635. * one of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
  636. * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM
  637. * @return mixed Value of field.
  638. */
  639. public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
  640. {
  641. $pos = CcPlayoutHistoryPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
  642. $field = $this->getByPosition($pos);
  643. return $field;
  644. }
  645. /**
  646. * Retrieves a field from the object by Position as specified in the xml schema.
  647. * Zero-based.
  648. *
  649. * @param int $pos position in xml schema
  650. * @return mixed Value of field at $pos
  651. */
  652. public function getByPosition($pos)
  653. {
  654. switch($pos) {
  655. case 0:
  656. return $this->getDbId();
  657. break;
  658. case 1:
  659. return $this->getDbFileId();
  660. break;
  661. case 2:
  662. return $this->getDbStarts();
  663. break;
  664. case 3:
  665. return $this->getDbEnds();
  666. break;
  667. case 4:
  668. return $this->getDbInstanceId();
  669. break;
  670. default:
  671. return null;
  672. break;
  673. } // switch()
  674. }
  675. /**
  676. * Exports the object as an array.
  677. *
  678. * You can specify the key type of the array by passing one of the class
  679. * type constants.
  680. *
  681. * @param string $keyType (optional) One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
  682. * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
  683. * Defaults to BasePeer::TYPE_PHPNAME.
  684. * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE.
  685. * @param boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE.
  686. *
  687. * @return array an associative array containing the field names (as keys) and field values
  688. */
  689. public function toArray($keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true, $includeForeignObjects = false)
  690. {
  691. $keys = CcPlayoutHistoryPeer::getFieldNames($keyType);
  692. $result = array(
  693. $keys[0] => $this->getDbId(),
  694. $keys[1] => $this->getDbFileId(),
  695. $keys[2] => $this->getDbStarts(),
  696. $keys[3] => $this->getDbEnds(),
  697. $keys[4] => $this->getDbInstanceId(),
  698. );
  699. if ($includeForeignObjects) {
  700. if (null !== $this->aCcFiles) {
  701. $result['CcFiles'] = $this->aCcFiles->toArray($keyType, $includeLazyLoadColumns, true);
  702. }
  703. if (null !== $this->aCcShowInstances) {
  704. $result['CcShowInstances'] = $this->aCcShowInstances->toArray($keyType, $includeLazyLoadColumns, true);
  705. }
  706. }
  707. return $result;
  708. }
  709. /**
  710. * Sets a field from the object by name passed in as a string.
  711. *
  712. * @param string $name peer name
  713. * @param mixed $value field value
  714. * @param string $type The type of fieldname the $name is of:
  715. * one of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
  716. * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM
  717. * @return void
  718. */
  719. public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
  720. {
  721. $pos = CcPlayoutHistoryPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
  722. return $this->setByPosition($pos, $value);
  723. }
  724. /**
  725. * Sets a field from the object by Position as specified in the xml schema.
  726. * Zero-based.
  727. *
  728. * @param int $pos position in xml schema
  729. * @param mixed $value field value
  730. * @return void
  731. */
  732. public function setByPosition($pos, $value)
  733. {
  734. switch($pos) {
  735. case 0:
  736. $this->setDbId($value);
  737. break;
  738. case 1:
  739. $this->setDbFileId($value);
  740. break;
  741. case 2:
  742. $this->setDbStarts($value);
  743. break;
  744. case 3:
  745. $this->setDbEnds($value);
  746. break;
  747. case 4:
  748. $this->setDbInstanceId($value);
  749. break;
  750. } // switch()
  751. }
  752. /**
  753. * Populates the object using an array.
  754. *
  755. * This is particularly useful when populating an object from one of the
  756. * request arrays (e.g. $_POST). This method goes through the column
  757. * names, checking to see whether a matching key exists in populated
  758. * array. If so the setByName() method is called for that column.
  759. *
  760. * You can specify the key type of the array by additionally passing one
  761. * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
  762. * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
  763. * The default key type is the column's phpname (e.g. 'AuthorId')
  764. *
  765. * @param array $arr An array to populate the object from.
  766. * @param string $keyType The type of keys the array uses.
  767. * @return void
  768. */
  769. public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
  770. {
  771. $keys = CcPlayoutHistoryPeer::getFieldNames($keyType);
  772. if (array_key_exists($keys[0], $arr)) $this->setDbId($arr[$keys[0]]);
  773. if (array_key_exists($keys[1], $arr)) $this->setDbFileId($arr[$keys[1]]);
  774. if (array_key_exists($keys[2], $arr)) $this->setDbStarts($arr[$keys[2]]);
  775. if (array_key_exists($keys[3], $arr)) $this->setDbEnds($arr[$keys[3]]);
  776. if (array_key_exists($keys[4], $arr)) $this->setDbInstanceId($arr[$keys[4]]);
  777. }
  778. /**
  779. * Build a Criteria object containing the values of all modified columns in this object.
  780. *
  781. * @return Criteria The Criteria object containing all modified values.
  782. */
  783. public function buildCriteria()
  784. {
  785. $criteria = new Criteria(CcPlayoutHistoryPeer::DATABASE_NAME);
  786. if ($this->isColumnModified(CcPlayoutHistoryPeer::ID)) $criteria->add(CcPlayoutHistoryPeer::ID, $this->id);
  787. if ($this->isColumnModified(CcPlayoutHistoryPeer::FILE_ID)) $criteria->add(CcPlayoutHistoryPeer::FILE_ID, $this->file_id);
  788. if ($this->isColumnModified(CcPlayoutHistoryPeer::STARTS)) $criteria->add(CcPlayoutHistoryPeer::STARTS, $this->starts);
  789. if ($this->isColumnModified(CcPlayoutHistoryPeer::ENDS)) $criteria->add(CcPlayoutHistoryPeer::ENDS, $this->ends);
  790. if ($this->isColumnModified(CcPlayoutHistoryPeer::INSTANCE_ID)) $criteria->add(CcPlayoutHistoryPeer::INSTANCE_ID, $this->instance_id);
  791. return $criteria;
  792. }
  793. /**
  794. * Builds a Criteria object containing the primary key for this object.
  795. *
  796. * Unlike buildCriteria() this method includes the primary key values regardless
  797. * of whether or not they have been modified.
  798. *
  799. * @return Criteria The Criteria object containing value(s) for primary key(s).
  800. */
  801. public function buildPkeyCriteria()
  802. {
  803. $criteria = new Criteria(CcPlayoutHistoryPeer::DATABASE_NAME);
  804. $criteria->add(CcPlayoutHistoryPeer::ID, $this->id);
  805. return $criteria;
  806. }
  807. /**
  808. * Returns the primary key for this object (row).
  809. * @return int
  810. */
  811. public function getPrimaryKey()
  812. {
  813. return $this->getDbId();
  814. }
  815. /**
  816. * Generic method to set the primary key (id column).
  817. *
  818. * @param int $key Primary key.
  819. * @return void
  820. */
  821. public function setPrimaryKey($key)
  822. {
  823. $this->setDbId($key);
  824. }
  825. /**
  826. * Returns true if the primary key for this object is null.
  827. * @return boolean
  828. */
  829. public function isPrimaryKeyNull()
  830. {
  831. return null === $this->getDbId();
  832. }
  833. /**
  834. * Sets contents of passed object to values from current object.
  835. *
  836. * If desired, this method can also make copies of all associated (fkey referrers)
  837. * objects.
  838. *
  839. * @param object $copyObj An object of CcPlayoutHistory (or compatible) type.
  840. * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
  841. * @throws PropelException
  842. */
  843. public function copyInto($copyObj, $deepCopy = false)
  844. {
  845. $copyObj->setDbFileId($this->file_id);
  846. $copyObj->setDbStarts($this->starts);
  847. $copyObj->setDbEnds($this->ends);
  848. $copyObj->setDbInstanceId($this->instance_id);
  849. if ($deepCopy) {
  850. // important: temporarily setNew(false) because this affects the behavior of
  851. // the getter/setter methods for fkey referrer objects.
  852. $copyObj->setNew(false);
  853. foreach ($this->getCcPlayoutHistoryMetaDatas() as $relObj) {
  854. if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves
  855. $copyObj->addCcPlayoutHistoryMetaData($relObj->copy($deepCopy));
  856. }
  857. }
  858. } // if ($deepCopy)
  859. $copyObj->setNew(true);
  860. $copyObj->setDbId(NULL); // this is a auto-increment column, so set to default value
  861. }
  862. /**
  863. * Makes a copy of this object that will be inserted as a new row in table when saved.
  864. * It creates a new object filling in the simple attributes, but skipping any primary
  865. * keys that are defined for the table.
  866. *
  867. * If desired, this method can also make copies of all associated (fkey referrers)
  868. * objects.
  869. *
  870. * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
  871. * @return CcPlayoutHistory Clone of current object.
  872. * @throws PropelException
  873. */
  874. public function copy($deepCopy = false)
  875. {
  876. // we use get_class(), because this might be a subclass
  877. $clazz = get_class($this);
  878. $copyObj = new $clazz();
  879. $this->copyInto($copyObj, $deepCopy);
  880. return $copyObj;
  881. }
  882. /**
  883. * Returns a peer instance associated with this om.
  884. *
  885. * Since Peer classes are not to have any instance attributes, this method returns the
  886. * same instance for all member of this class. The method could therefore
  887. * be static, but this would prevent one from overriding the behavior.
  888. *
  889. * @return CcPlayoutHistoryPeer
  890. */
  891. public function getPeer()
  892. {
  893. if (self::$peer === null) {
  894. self::$peer = new CcPlayoutHistoryPeer();
  895. }
  896. return self::$peer;
  897. }
  898. /**
  899. * Declares an association between this object and a CcFiles object.
  900. *
  901. * @param CcFiles $v
  902. * @return CcPlayoutHistory The current object (for fluent API support)
  903. * @throws PropelException
  904. */
  905. public function setCcFiles(CcFiles $v = null)
  906. {
  907. if ($v === null) {
  908. $this->setDbFileId(NULL);
  909. } else {
  910. $this->setDbFileId($v->getDbId());
  911. }
  912. $this->aCcFiles = $v;
  913. // Add binding for other direction of this n:n relationship.
  914. // If this object has already been added to the CcFiles object, it will not be re-added.
  915. if ($v !== null) {
  916. $v->addCcPlayoutHistory($this);
  917. }
  918. return $this;
  919. }
  920. /**
  921. * Get the associated CcFiles object
  922. *
  923. * @param PropelPDO Optional Connection object.
  924. * @return CcFiles The associated CcFiles object.
  925. * @throws PropelException
  926. */
  927. public function getCcFiles(PropelPDO $con = null)
  928. {
  929. if ($this->aCcFiles === null && ($this->file_id !== null)) {
  930. $this->aCcFiles = CcFilesQuery::create()->findPk($this->file_id, $con);
  931. /* The following can be used additionally to
  932. guarantee the related object contains a reference
  933. to this object. This level of coupling may, however, be
  934. undesirable since it could result in an only partially populated collection
  935. in the referenced object.
  936. $this->aCcFiles->addCcPlayoutHistorys($this);
  937. */
  938. }
  939. return $this->aCcFiles;
  940. }
  941. /**
  942. * Declares an association between this object and a CcShowInstances object.
  943. *
  944. * @param CcShowInstances $v
  945. * @return CcPlayoutHistory The current object (for fluent API support)
  946. * @throws PropelException
  947. */
  948. public function setCcShowInstances(CcShowInstances $v = null)
  949. {
  950. if ($v === null) {
  951. $this->setDbInstanceId(NULL);
  952. } else {
  953. $this->setDbInstanceId($v->getDbId());
  954. }
  955. $this->aCcShowInstances = $v;
  956. // Add binding for other direction of this n:n relationship.
  957. // If this object has already been added to the CcShowInstances object, it will not be re-added.
  958. if ($v !== null) {
  959. $v->addCcPlayoutHistory($this);
  960. }
  961. return $this;
  962. }
  963. /**
  964. * Get the associated CcShowInstances object
  965. *
  966. * @param PropelPDO Optional Connection object.
  967. * @return CcShowInstances The associated CcShowInstances object.
  968. * @throws PropelException
  969. */
  970. public function getCcShowInstances(PropelPDO $con = null)
  971. {
  972. if ($this->aCcShowInstances === null && ($this->instance_id !== null)) {
  973. $this->aCcShowInstances = CcShowInstancesQuery::create()->findPk($this->instance_id, $con);
  974. /* The following can be used additionally to
  975. guarantee the related object contains a reference
  976. to this object. This level of coupling may, however, be
  977. undesirable since it could result in an only partially populated collection
  978. in the referenced object.
  979. $this->aCcShowInstances->addCcPlayoutHistorys($this);
  980. */
  981. }
  982. return $this->aCcShowInstances;
  983. }
  984. /**
  985. * Clears out the collCcPlayoutHistoryMetaDatas collection
  986. *
  987. * This does not modify the database; however, it will remove any associated objects, causing
  988. * them to be refetched by subsequent calls to accessor method.
  989. *
  990. * @return void
  991. * @see addCcPlayoutHistoryMetaDatas()
  992. */
  993. public function clearCcPlayoutHistoryMetaDatas()
  994. {
  995. $this->collCcPlayoutHistoryMetaDatas = null; // important to set this to NULL since that means it is uninitialized
  996. }
  997. /**
  998. * Initializes the collCcPlayoutHistoryMetaDatas collection.
  999. *
  1000. * By default this just sets the collCcPlayoutHistoryMetaDatas collection to an empty array (like clearcollCcPlayoutHistoryMetaDatas());
  1001. * however, you may wish to override this method in your stub class to provide setting appropriate
  1002. * to your application -- for example, setting the initial array to the values stored in database.
  1003. *
  1004. * @return void
  1005. */
  1006. public function initCcPlayoutHistoryMetaDatas()
  1007. {
  1008. $this->collCcPlayoutHistoryMetaDatas = new PropelObjectCollection();
  1009. $this->collCcPlayoutHistoryMetaDatas->setModel('CcPlayoutHistoryMetaData');
  1010. }
  1011. /**
  1012. * Gets an array of CcPlayoutHistoryMetaData objects which contain a foreign key that references this object.
  1013. *
  1014. * If the $criteria is not null, it is used to always fetch the results from the database.
  1015. * Otherwise the results are fetched from the database the first time, then cached.
  1016. * Next time the same method is called without $criteria, the cached collection is returned.
  1017. * If this CcPlayoutHistory is new, it will return
  1018. * an empty collection or the current collection; the criteria is ignored on a new object.
  1019. *
  1020. * @param Criteria $criteria optional Criteria object to narrow the query
  1021. * @param PropelPDO $con optional connection object
  1022. * @return PropelCollection|array CcPlayoutHistoryMetaData[] List of CcPlayoutHistoryMetaData objects
  1023. * @throws PropelException
  1024. */
  1025. public function getCcPlayoutHistoryMetaDatas($criteria = null, PropelPDO $con = null)
  1026. {
  1027. if(null === $this->collCcPlayoutHistoryMetaDatas || null !== $criteria) {
  1028. if ($this->isNew() && null === $this->collCcPlayoutHistoryMetaDatas) {
  1029. // return empty collection
  1030. $this->initCcPlayoutHistoryMetaDatas();
  1031. } else {
  1032. $collCcPlayoutHistoryMetaDatas = CcPlayoutHistoryMetaDataQuery::create(null, $criteria)
  1033. ->filterByCcPlayoutHistory($this)
  1034. ->find($con);
  1035. if (null !== $criteria) {
  1036. return $collCcPlayoutHistoryMetaDatas;
  1037. }
  1038. $this->collCcPlayoutHistoryMetaDatas = $collCcPlayoutHistoryMetaDatas;
  1039. }
  1040. }
  1041. return $this->collCcPlayoutHistoryMetaDatas;
  1042. }
  1043. /**
  1044. * Returns the number of related CcPlayoutHistoryMetaData objects.
  1045. *
  1046. * @param Criteria $criteria
  1047. * @param boolean $distinct
  1048. * @param PropelPDO $con
  1049. * @return int Count of related CcPlayoutHistoryMetaData objects.
  1050. * @throws PropelException
  1051. */
  1052. public function countCcPlayoutHistoryMetaDatas(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
  1053. {
  1054. if(null === $this->collCcPlayoutHistoryMetaDatas || null !== $criteria) {
  1055. if ($this->isNew() && null === $this->collCcPlayoutHistoryMetaDatas) {
  1056. return 0;
  1057. } else {
  1058. $query = CcPlayoutHistoryMetaDataQuery::create(null, $criteria);
  1059. if($distinct) {
  1060. $query->distinct();
  1061. }
  1062. return $query
  1063. ->filterByCcPlayoutHistory($this)
  1064. ->count($con);
  1065. }
  1066. } else {
  1067. return count($this->collCcPlayoutHistoryMetaDatas);
  1068. }
  1069. }
  1070. /**
  1071. * Method called to associate a CcPlayoutHistoryMetaData object to this object
  1072. * through the CcPlayoutHistoryMetaData foreign key attribute.
  1073. *
  1074. * @param CcPlayoutHistoryMetaData $l CcPlayoutHistoryMetaData
  1075. * @return void
  1076. * @throws PropelException
  1077. */
  1078. public function addCcPlayoutHistoryMetaData(CcPlayoutHistoryMetaData $l)
  1079. {
  1080. if ($this->collCcPlayoutHistoryMetaDatas === null) {
  1081. $this->initCcPlayoutHistoryMetaDatas();
  1082. }
  1083. if (!$this->collCcPlayoutHistoryMetaDatas->contains($l)) { // only add it if the **same** object is not already associated
  1084. $this->collCcPlayoutHistoryMetaDatas[]= $l;
  1085. $l->setCcPlayoutHistory($this);
  1086. }
  1087. }
  1088. /**
  1089. * Clears the current object and sets all attributes to their default values
  1090. */
  1091. public function clear()
  1092. {
  1093. $this->id = null;
  1094. $this->file_id = null;
  1095. $this->starts = null;
  1096. $this->ends = null;
  1097. $this->instance_id = null;
  1098. $this->alreadyInSave = false;
  1099. $this->alreadyInValidation = false;
  1100. $this->clearAllReferences();
  1101. $this->resetModified();
  1102. $this->setNew(true);
  1103. $this->setDeleted(false);
  1104. }
  1105. /**
  1106. * Resets all collections of referencing foreign keys.
  1107. *
  1108. * This method is a user-space workaround for PHP's inability to garbage collect objects
  1109. * with circular references. This is currently necessary when using Propel in certain
  1110. * daemon or large-volumne/high-memory operations.
  1111. *
  1112. * @param boolean $deep Whether to also clear the references on all associated objects.
  1113. */
  1114. public function clearAllReferences($deep = false)
  1115. {
  1116. if ($deep) {
  1117. if ($this->collCcPlayoutHistoryMetaDatas) {
  1118. foreach ((array) $this->collCcPlayoutHistoryMetaDatas as $o) {
  1119. $o->clearAllReferences($deep);
  1120. }
  1121. }
  1122. } // if ($deep)
  1123. $this->collCcPlayoutHistoryMetaDatas = null;
  1124. $this->aCcFiles = null;
  1125. $this->aCcShowInstances = null;
  1126. }
  1127. /**
  1128. * Catches calls to virtual methods
  1129. */
  1130. public function __call($name, $params)
  1131. {
  1132. if (preg_match('/get(\w+)/', $name, $matches)) {
  1133. $virtualColumn = $matches[1];
  1134. if ($this->hasVirtualColumn($virtualColumn)) {
  1135. return $this->getVirtualColumn($virtualColumn);
  1136. }
  1137. // no lcfirst in php<5.3...
  1138. $virtualColumn[0] = strtolower($virtualColumn[0]);
  1139. if ($this->hasVirtualColumn($virtualColumn)) {
  1140. return $this->getVirtualColumn($virtualColumn);
  1141. }
  1142. }
  1143. throw new PropelException('Call to undefined method: ' . $name);
  1144. }
  1145. } // BaseCcPlayoutHistory