BaseCcAccess.php 33 KB

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