BaseCcCountry.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  1. <?php
  2. /**
  3. * Base class that represents a row from the 'cc_country' table.
  4. *
  5. *
  6. *
  7. * @package propel.generator.airtime.om
  8. */
  9. abstract class BaseCcCountry extends BaseObject implements Persistent
  10. {
  11. /**
  12. * Peer class name
  13. */
  14. const PEER = 'CcCountryPeer';
  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 CcCountryPeer
  20. */
  21. protected static $peer;
  22. /**
  23. * The value for the isocode field.
  24. * @var string
  25. */
  26. protected $isocode;
  27. /**
  28. * The value for the name field.
  29. * @var string
  30. */
  31. protected $name;
  32. /**
  33. * Flag to prevent endless save loop, if this object is referenced
  34. * by another object which falls in this transaction.
  35. * @var boolean
  36. */
  37. protected $alreadyInSave = false;
  38. /**
  39. * Flag to prevent endless validation loop, if this object is referenced
  40. * by another object which falls in this transaction.
  41. * @var boolean
  42. */
  43. protected $alreadyInValidation = false;
  44. /**
  45. * Get the [isocode] column value.
  46. *
  47. * @return string
  48. */
  49. public function getDbIsoCode()
  50. {
  51. return $this->isocode;
  52. }
  53. /**
  54. * Get the [name] column value.
  55. *
  56. * @return string
  57. */
  58. public function getDbName()
  59. {
  60. return $this->name;
  61. }
  62. /**
  63. * Set the value of [isocode] column.
  64. *
  65. * @param string $v new value
  66. * @return CcCountry The current object (for fluent API support)
  67. */
  68. public function setDbIsoCode($v)
  69. {
  70. if ($v !== null) {
  71. $v = (string) $v;
  72. }
  73. if ($this->isocode !== $v) {
  74. $this->isocode = $v;
  75. $this->modifiedColumns[] = CcCountryPeer::ISOCODE;
  76. }
  77. return $this;
  78. } // setDbIsoCode()
  79. /**
  80. * Set the value of [name] column.
  81. *
  82. * @param string $v new value
  83. * @return CcCountry The current object (for fluent API support)
  84. */
  85. public function setDbName($v)
  86. {
  87. if ($v !== null) {
  88. $v = (string) $v;
  89. }
  90. if ($this->name !== $v) {
  91. $this->name = $v;
  92. $this->modifiedColumns[] = CcCountryPeer::NAME;
  93. }
  94. return $this;
  95. } // setDbName()
  96. /**
  97. * Indicates whether the columns in this object are only set to default values.
  98. *
  99. * This method can be used in conjunction with isModified() to indicate whether an object is both
  100. * modified _and_ has some values set which are non-default.
  101. *
  102. * @return boolean Whether the columns in this object are only been set with default values.
  103. */
  104. public function hasOnlyDefaultValues()
  105. {
  106. // otherwise, everything was equal, so return TRUE
  107. return true;
  108. } // hasOnlyDefaultValues()
  109. /**
  110. * Hydrates (populates) the object variables with values from the database resultset.
  111. *
  112. * An offset (0-based "start column") is specified so that objects can be hydrated
  113. * with a subset of the columns in the resultset rows. This is needed, for example,
  114. * for results of JOIN queries where the resultset row includes columns from two or
  115. * more tables.
  116. *
  117. * @param array $row The row returned by PDOStatement->fetch(PDO::FETCH_NUM)
  118. * @param int $startcol 0-based offset column which indicates which restultset column to start with.
  119. * @param boolean $rehydrate Whether this object is being re-hydrated from the database.
  120. * @return int next starting column
  121. * @throws PropelException - Any caught Exception will be rewrapped as a PropelException.
  122. */
  123. public function hydrate($row, $startcol = 0, $rehydrate = false)
  124. {
  125. try {
  126. $this->isocode = ($row[$startcol + 0] !== null) ? (string) $row[$startcol + 0] : null;
  127. $this->name = ($row[$startcol + 1] !== null) ? (string) $row[$startcol + 1] : null;
  128. $this->resetModified();
  129. $this->setNew(false);
  130. if ($rehydrate) {
  131. $this->ensureConsistency();
  132. }
  133. return $startcol + 2; // 2 = CcCountryPeer::NUM_COLUMNS - CcCountryPeer::NUM_LAZY_LOAD_COLUMNS).
  134. } catch (Exception $e) {
  135. throw new PropelException("Error populating CcCountry object", $e);
  136. }
  137. }
  138. /**
  139. * Checks and repairs the internal consistency of the object.
  140. *
  141. * This method is executed after an already-instantiated object is re-hydrated
  142. * from the database. It exists to check any foreign keys to make sure that
  143. * the objects related to the current object are correct based on foreign key.
  144. *
  145. * You can override this method in the stub class, but you should always invoke
  146. * the base method from the overridden method (i.e. parent::ensureConsistency()),
  147. * in case your model changes.
  148. *
  149. * @throws PropelException
  150. */
  151. public function ensureConsistency()
  152. {
  153. } // ensureConsistency
  154. /**
  155. * Reloads this object from datastore based on primary key and (optionally) resets all associated objects.
  156. *
  157. * This will only work if the object has been saved and has a valid primary key set.
  158. *
  159. * @param boolean $deep (optional) Whether to also de-associated any related objects.
  160. * @param PropelPDO $con (optional) The PropelPDO connection to use.
  161. * @return void
  162. * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db
  163. */
  164. public function reload($deep = false, PropelPDO $con = null)
  165. {
  166. if ($this->isDeleted()) {
  167. throw new PropelException("Cannot reload a deleted object.");
  168. }
  169. if ($this->isNew()) {
  170. throw new PropelException("Cannot reload an unsaved object.");
  171. }
  172. if ($con === null) {
  173. $con = Propel::getConnection(CcCountryPeer::DATABASE_NAME, Propel::CONNECTION_READ);
  174. }
  175. // We don't need to alter the object instance pool; we're just modifying this instance
  176. // already in the pool.
  177. $stmt = CcCountryPeer::doSelectStmt($this->buildPkeyCriteria(), $con);
  178. $row = $stmt->fetch(PDO::FETCH_NUM);
  179. $stmt->closeCursor();
  180. if (!$row) {
  181. throw new PropelException('Cannot find matching row in the database to reload object values.');
  182. }
  183. $this->hydrate($row, 0, true); // rehydrate
  184. if ($deep) { // also de-associate any related objects?
  185. } // if (deep)
  186. }
  187. /**
  188. * Removes this object from datastore and sets delete attribute.
  189. *
  190. * @param PropelPDO $con
  191. * @return void
  192. * @throws PropelException
  193. * @see BaseObject::setDeleted()
  194. * @see BaseObject::isDeleted()
  195. */
  196. public function delete(PropelPDO $con = null)
  197. {
  198. if ($this->isDeleted()) {
  199. throw new PropelException("This object has already been deleted.");
  200. }
  201. if ($con === null) {
  202. $con = Propel::getConnection(CcCountryPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
  203. }
  204. $con->beginTransaction();
  205. try {
  206. $ret = $this->preDelete($con);
  207. if ($ret) {
  208. CcCountryQuery::create()
  209. ->filterByPrimaryKey($this->getPrimaryKey())
  210. ->delete($con);
  211. $this->postDelete($con);
  212. $con->commit();
  213. $this->setDeleted(true);
  214. } else {
  215. $con->commit();
  216. }
  217. } catch (PropelException $e) {
  218. $con->rollBack();
  219. throw $e;
  220. }
  221. }
  222. /**
  223. * Persists this object to the database.
  224. *
  225. * If the object is new, it inserts it; otherwise an update is performed.
  226. * All modified related objects will also be persisted in the doSave()
  227. * method. This method wraps all precipitate database operations in a
  228. * single transaction.
  229. *
  230. * @param PropelPDO $con
  231. * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
  232. * @throws PropelException
  233. * @see doSave()
  234. */
  235. public function save(PropelPDO $con = null)
  236. {
  237. if ($this->isDeleted()) {
  238. throw new PropelException("You cannot save an object that has been deleted.");
  239. }
  240. if ($con === null) {
  241. $con = Propel::getConnection(CcCountryPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
  242. }
  243. $con->beginTransaction();
  244. $isInsert = $this->isNew();
  245. try {
  246. $ret = $this->preSave($con);
  247. if ($isInsert) {
  248. $ret = $ret && $this->preInsert($con);
  249. } else {
  250. $ret = $ret && $this->preUpdate($con);
  251. }
  252. if ($ret) {
  253. $affectedRows = $this->doSave($con);
  254. if ($isInsert) {
  255. $this->postInsert($con);
  256. } else {
  257. $this->postUpdate($con);
  258. }
  259. $this->postSave($con);
  260. CcCountryPeer::addInstanceToPool($this);
  261. } else {
  262. $affectedRows = 0;
  263. }
  264. $con->commit();
  265. return $affectedRows;
  266. } catch (PropelException $e) {
  267. $con->rollBack();
  268. throw $e;
  269. }
  270. }
  271. /**
  272. * Performs the work of inserting or updating the row in the database.
  273. *
  274. * If the object is new, it inserts it; otherwise an update is performed.
  275. * All related objects are also updated in this method.
  276. *
  277. * @param PropelPDO $con
  278. * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
  279. * @throws PropelException
  280. * @see save()
  281. */
  282. protected function doSave(PropelPDO $con)
  283. {
  284. $affectedRows = 0; // initialize var to track total num of affected rows
  285. if (!$this->alreadyInSave) {
  286. $this->alreadyInSave = true;
  287. // If this object has been modified, then save it to the database.
  288. if ($this->isModified()) {
  289. if ($this->isNew()) {
  290. $criteria = $this->buildCriteria();
  291. $pk = BasePeer::doInsert($criteria, $con);
  292. $affectedRows = 1;
  293. $this->setNew(false);
  294. } else {
  295. $affectedRows = CcCountryPeer::doUpdate($this, $con);
  296. }
  297. $this->resetModified(); // [HL] After being saved an object is no longer 'modified'
  298. }
  299. $this->alreadyInSave = false;
  300. }
  301. return $affectedRows;
  302. } // doSave()
  303. /**
  304. * Array of ValidationFailed objects.
  305. * @var array ValidationFailed[]
  306. */
  307. protected $validationFailures = array();
  308. /**
  309. * Gets any ValidationFailed objects that resulted from last call to validate().
  310. *
  311. *
  312. * @return array ValidationFailed[]
  313. * @see validate()
  314. */
  315. public function getValidationFailures()
  316. {
  317. return $this->validationFailures;
  318. }
  319. /**
  320. * Validates the objects modified field values and all objects related to this table.
  321. *
  322. * If $columns is either a column name or an array of column names
  323. * only those columns are validated.
  324. *
  325. * @param mixed $columns Column name or an array of column names.
  326. * @return boolean Whether all columns pass validation.
  327. * @see doValidate()
  328. * @see getValidationFailures()
  329. */
  330. public function validate($columns = null)
  331. {
  332. $res = $this->doValidate($columns);
  333. if ($res === true) {
  334. $this->validationFailures = array();
  335. return true;
  336. } else {
  337. $this->validationFailures = $res;
  338. return false;
  339. }
  340. }
  341. /**
  342. * This function performs the validation work for complex object models.
  343. *
  344. * In addition to checking the current object, all related objects will
  345. * also be validated. If all pass then <code>true</code> is returned; otherwise
  346. * an aggreagated array of ValidationFailed objects will be returned.
  347. *
  348. * @param array $columns Array of column names to validate.
  349. * @return mixed <code>true</code> if all validations pass; array of <code>ValidationFailed</code> objets otherwise.
  350. */
  351. protected function doValidate($columns = null)
  352. {
  353. if (!$this->alreadyInValidation) {
  354. $this->alreadyInValidation = true;
  355. $retval = null;
  356. $failureMap = array();
  357. if (($retval = CcCountryPeer::doValidate($this, $columns)) !== true) {
  358. $failureMap = array_merge($failureMap, $retval);
  359. }
  360. $this->alreadyInValidation = false;
  361. }
  362. return (!empty($failureMap) ? $failureMap : true);
  363. }
  364. /**
  365. * Retrieves a field from the object by name passed in as a string.
  366. *
  367. * @param string $name name
  368. * @param string $type The type of fieldname the $name is of:
  369. * one of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
  370. * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM
  371. * @return mixed Value of field.
  372. */
  373. public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
  374. {
  375. $pos = CcCountryPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
  376. $field = $this->getByPosition($pos);
  377. return $field;
  378. }
  379. /**
  380. * Retrieves a field from the object by Position as specified in the xml schema.
  381. * Zero-based.
  382. *
  383. * @param int $pos position in xml schema
  384. * @return mixed Value of field at $pos
  385. */
  386. public function getByPosition($pos)
  387. {
  388. switch($pos) {
  389. case 0:
  390. return $this->getDbIsoCode();
  391. break;
  392. case 1:
  393. return $this->getDbName();
  394. break;
  395. default:
  396. return null;
  397. break;
  398. } // switch()
  399. }
  400. /**
  401. * Exports the object as an array.
  402. *
  403. * You can specify the key type of the array by passing one of the class
  404. * type constants.
  405. *
  406. * @param string $keyType (optional) One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
  407. * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
  408. * Defaults to BasePeer::TYPE_PHPNAME.
  409. * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE.
  410. *
  411. * @return array an associative array containing the field names (as keys) and field values
  412. */
  413. public function toArray($keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true)
  414. {
  415. $keys = CcCountryPeer::getFieldNames($keyType);
  416. $result = array(
  417. $keys[0] => $this->getDbIsoCode(),
  418. $keys[1] => $this->getDbName(),
  419. );
  420. return $result;
  421. }
  422. /**
  423. * Sets a field from the object by name passed in as a string.
  424. *
  425. * @param string $name peer name
  426. * @param mixed $value field value
  427. * @param string $type The type of fieldname the $name is of:
  428. * one of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
  429. * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM
  430. * @return void
  431. */
  432. public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
  433. {
  434. $pos = CcCountryPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
  435. return $this->setByPosition($pos, $value);
  436. }
  437. /**
  438. * Sets a field from the object by Position as specified in the xml schema.
  439. * Zero-based.
  440. *
  441. * @param int $pos position in xml schema
  442. * @param mixed $value field value
  443. * @return void
  444. */
  445. public function setByPosition($pos, $value)
  446. {
  447. switch($pos) {
  448. case 0:
  449. $this->setDbIsoCode($value);
  450. break;
  451. case 1:
  452. $this->setDbName($value);
  453. break;
  454. } // switch()
  455. }
  456. /**
  457. * Populates the object using an array.
  458. *
  459. * This is particularly useful when populating an object from one of the
  460. * request arrays (e.g. $_POST). This method goes through the column
  461. * names, checking to see whether a matching key exists in populated
  462. * array. If so the setByName() method is called for that column.
  463. *
  464. * You can specify the key type of the array by additionally passing one
  465. * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
  466. * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
  467. * The default key type is the column's phpname (e.g. 'AuthorId')
  468. *
  469. * @param array $arr An array to populate the object from.
  470. * @param string $keyType The type of keys the array uses.
  471. * @return void
  472. */
  473. public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
  474. {
  475. $keys = CcCountryPeer::getFieldNames($keyType);
  476. if (array_key_exists($keys[0], $arr)) $this->setDbIsoCode($arr[$keys[0]]);
  477. if (array_key_exists($keys[1], $arr)) $this->setDbName($arr[$keys[1]]);
  478. }
  479. /**
  480. * Build a Criteria object containing the values of all modified columns in this object.
  481. *
  482. * @return Criteria The Criteria object containing all modified values.
  483. */
  484. public function buildCriteria()
  485. {
  486. $criteria = new Criteria(CcCountryPeer::DATABASE_NAME);
  487. if ($this->isColumnModified(CcCountryPeer::ISOCODE)) $criteria->add(CcCountryPeer::ISOCODE, $this->isocode);
  488. if ($this->isColumnModified(CcCountryPeer::NAME)) $criteria->add(CcCountryPeer::NAME, $this->name);
  489. return $criteria;
  490. }
  491. /**
  492. * Builds a Criteria object containing the primary key for this object.
  493. *
  494. * Unlike buildCriteria() this method includes the primary key values regardless
  495. * of whether or not they have been modified.
  496. *
  497. * @return Criteria The Criteria object containing value(s) for primary key(s).
  498. */
  499. public function buildPkeyCriteria()
  500. {
  501. $criteria = new Criteria(CcCountryPeer::DATABASE_NAME);
  502. $criteria->add(CcCountryPeer::ISOCODE, $this->isocode);
  503. return $criteria;
  504. }
  505. /**
  506. * Returns the primary key for this object (row).
  507. * @return string
  508. */
  509. public function getPrimaryKey()
  510. {
  511. return $this->getDbIsoCode();
  512. }
  513. /**
  514. * Generic method to set the primary key (isocode column).
  515. *
  516. * @param string $key Primary key.
  517. * @return void
  518. */
  519. public function setPrimaryKey($key)
  520. {
  521. $this->setDbIsoCode($key);
  522. }
  523. /**
  524. * Returns true if the primary key for this object is null.
  525. * @return boolean
  526. */
  527. public function isPrimaryKeyNull()
  528. {
  529. return null === $this->getDbIsoCode();
  530. }
  531. /**
  532. * Sets contents of passed object to values from current object.
  533. *
  534. * If desired, this method can also make copies of all associated (fkey referrers)
  535. * objects.
  536. *
  537. * @param object $copyObj An object of CcCountry (or compatible) type.
  538. * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
  539. * @throws PropelException
  540. */
  541. public function copyInto($copyObj, $deepCopy = false)
  542. {
  543. $copyObj->setDbIsoCode($this->isocode);
  544. $copyObj->setDbName($this->name);
  545. $copyObj->setNew(true);
  546. }
  547. /**
  548. * Makes a copy of this object that will be inserted as a new row in table when saved.
  549. * It creates a new object filling in the simple attributes, but skipping any primary
  550. * keys that are defined for the table.
  551. *
  552. * If desired, this method can also make copies of all associated (fkey referrers)
  553. * objects.
  554. *
  555. * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
  556. * @return CcCountry Clone of current object.
  557. * @throws PropelException
  558. */
  559. public function copy($deepCopy = false)
  560. {
  561. // we use get_class(), because this might be a subclass
  562. $clazz = get_class($this);
  563. $copyObj = new $clazz();
  564. $this->copyInto($copyObj, $deepCopy);
  565. return $copyObj;
  566. }
  567. /**
  568. * Returns a peer instance associated with this om.
  569. *
  570. * Since Peer classes are not to have any instance attributes, this method returns the
  571. * same instance for all member of this class. The method could therefore
  572. * be static, but this would prevent one from overriding the behavior.
  573. *
  574. * @return CcCountryPeer
  575. */
  576. public function getPeer()
  577. {
  578. if (self::$peer === null) {
  579. self::$peer = new CcCountryPeer();
  580. }
  581. return self::$peer;
  582. }
  583. /**
  584. * Clears the current object and sets all attributes to their default values
  585. */
  586. public function clear()
  587. {
  588. $this->isocode = null;
  589. $this->name = null;
  590. $this->alreadyInSave = false;
  591. $this->alreadyInValidation = false;
  592. $this->clearAllReferences();
  593. $this->resetModified();
  594. $this->setNew(true);
  595. $this->setDeleted(false);
  596. }
  597. /**
  598. * Resets all collections of referencing foreign keys.
  599. *
  600. * This method is a user-space workaround for PHP's inability to garbage collect objects
  601. * with circular references. This is currently necessary when using Propel in certain
  602. * daemon or large-volumne/high-memory operations.
  603. *
  604. * @param boolean $deep Whether to also clear the references on all associated objects.
  605. */
  606. public function clearAllReferences($deep = false)
  607. {
  608. if ($deep) {
  609. } // if ($deep)
  610. }
  611. /**
  612. * Catches calls to virtual methods
  613. */
  614. public function __call($name, $params)
  615. {
  616. if (preg_match('/get(\w+)/', $name, $matches)) {
  617. $virtualColumn = $matches[1];
  618. if ($this->hasVirtualColumn($virtualColumn)) {
  619. return $this->getVirtualColumn($virtualColumn);
  620. }
  621. // no lcfirst in php<5.3...
  622. $virtualColumn[0] = strtolower($virtualColumn[0]);
  623. if ($this->hasVirtualColumn($virtualColumn)) {
  624. return $this->getVirtualColumn($virtualColumn);
  625. }
  626. }
  627. throw new PropelException('Call to undefined method: ' . $name);
  628. }
  629. } // BaseCcCountry