farmer-duck

CompanyPhone

May 23rd, 2013
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 43.07 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Axtion\CompanyBundle\Model\om;
  4.  
  5. use \BaseObject;
  6. use \BasePeer;
  7. use \Criteria;
  8. use \Exception;
  9. use \PDO;
  10. use \Persistent;
  11. use \Propel;
  12. use \PropelException;
  13. use \PropelPDO;
  14. use Axtion\CompanyBundle\Model\Company;
  15. use Axtion\CompanyBundle\Model\CompanyContact;
  16. use Axtion\CompanyBundle\Model\CompanyContactQuery;
  17. use Axtion\CompanyBundle\Model\CompanyPhone;
  18. use Axtion\CompanyBundle\Model\CompanyPhonePeer;
  19. use Axtion\CompanyBundle\Model\CompanyPhoneQuery;
  20. use Axtion\CompanyBundle\Model\CompanyPhoneType;
  21. use Axtion\CompanyBundle\Model\CompanyPhoneTypeQuery;
  22. use Axtion\CompanyBundle\Model\CompanyQuery;
  23.  
  24. abstract class BaseCompanyPhone extends BaseObject implements Persistent
  25. {
  26. /**
  27. * Peer class name
  28. */
  29. const PEER = 'Axtion\\CompanyBundle\\Model\\CompanyPhonePeer';
  30.  
  31. /**
  32. * The Peer class.
  33. * Instance provides a convenient way of calling static methods on a class
  34. * that calling code may not be able to identify.
  35. * @var CompanyPhonePeer
  36. */
  37. protected static $peer;
  38.  
  39. /**
  40. * The flag var to prevent infinit loop in deep copy
  41. * @var boolean
  42. */
  43. protected $startCopy = false;
  44.  
  45. /**
  46. * The value for the id field.
  47. * @var int
  48. */
  49. protected $id;
  50.  
  51. /**
  52. * The value for the company_phone_type_id field.
  53. * @var int
  54. */
  55. protected $company_phone_type_id;
  56.  
  57. /**
  58. * The value for the company_id field.
  59. * @var int
  60. */
  61. protected $company_id;
  62.  
  63. /**
  64. * The value for the company_contact_id field.
  65. * @var int
  66. */
  67. protected $company_contact_id;
  68.  
  69. /**
  70. * The value for the number field.
  71. * @var string
  72. */
  73. protected $number;
  74.  
  75. /**
  76. * @var Company
  77. */
  78. protected $aCompany;
  79.  
  80. /**
  81. * @var CompanyContact
  82. */
  83. protected $aCompanyContact;
  84.  
  85. /**
  86. * @var CompanyPhoneType
  87. */
  88. protected $aCompanyPhoneType;
  89.  
  90. /**
  91. * Flag to prevent endless save loop, if this object is referenced
  92. * by another object which falls in this transaction.
  93. * @var boolean
  94. */
  95. protected $alreadyInSave = false;
  96.  
  97. /**
  98. * Flag to prevent endless validation loop, if this object is referenced
  99. * by another object which falls in this transaction.
  100. * @var boolean
  101. */
  102. protected $alreadyInValidation = false;
  103.  
  104. /**
  105. * Flag to prevent endless clearAllReferences($deep=true) loop, if this object is referenced
  106. * @var boolean
  107. */
  108. protected $alreadyInClearAllReferencesDeep = false;
  109.  
  110. /**
  111. * Get the [id] column value.
  112. *
  113. * @return int
  114. */
  115. public function getId()
  116. {
  117. return $this->id;
  118. }
  119.  
  120. /**
  121. * Get the [company_phone_type_id] column value.
  122. *
  123. * @return int
  124. */
  125. public function getCompanyPhoneTypeId()
  126. {
  127. return $this->company_phone_type_id;
  128. }
  129.  
  130. /**
  131. * Get the [company_id] column value.
  132. *
  133. * @return int
  134. */
  135. public function getCompanyId()
  136. {
  137. return $this->company_id;
  138. }
  139.  
  140. /**
  141. * Get the [company_contact_id] column value.
  142. *
  143. * @return int
  144. */
  145. public function getCompanyContactId()
  146. {
  147. return $this->company_contact_id;
  148. }
  149.  
  150. /**
  151. * Get the [number] column value.
  152. *
  153. * @return string
  154. */
  155. public function getNumber()
  156. {
  157. return $this->number;
  158. }
  159.  
  160. /**
  161. * Set the value of [id] column.
  162. *
  163. * @param int $v new value
  164. * @return CompanyPhone The current object (for fluent API support)
  165. */
  166. public function setId($v)
  167. {
  168. if ($v !== null && is_numeric($v)) {
  169. $v = (int) $v;
  170. }
  171.  
  172. if ($this->id !== $v) {
  173. $this->id = $v;
  174. $this->modifiedColumns[] = CompanyPhonePeer::ID;
  175. }
  176.  
  177.  
  178. return $this;
  179. } // setId()
  180.  
  181. /**
  182. * Set the value of [company_phone_type_id] column.
  183. *
  184. * @param int $v new value
  185. * @return CompanyPhone The current object (for fluent API support)
  186. */
  187. public function setCompanyPhoneTypeId($v)
  188. {
  189. if ($v !== null && is_numeric($v)) {
  190. $v = (int) $v;
  191. }
  192.  
  193. if ($this->company_phone_type_id !== $v) {
  194. $this->company_phone_type_id = $v;
  195. $this->modifiedColumns[] = CompanyPhonePeer::COMPANY_PHONE_TYPE_ID;
  196. }
  197.  
  198. if ($this->aCompanyPhoneType !== null && $this->aCompanyPhoneType->getId() !== $v) {
  199. $this->aCompanyPhoneType = null;
  200. }
  201.  
  202.  
  203. return $this;
  204. } // setCompanyPhoneTypeId()
  205.  
  206. /**
  207. * Set the value of [company_id] column.
  208. *
  209. * @param int $v new value
  210. * @return CompanyPhone The current object (for fluent API support)
  211. */
  212. public function setCompanyId($v)
  213. {
  214. if ($v !== null && is_numeric($v)) {
  215. $v = (int) $v;
  216. }
  217.  
  218. if ($this->company_id !== $v) {
  219. $this->company_id = $v;
  220. $this->modifiedColumns[] = CompanyPhonePeer::COMPANY_ID;
  221. }
  222.  
  223. if ($this->aCompany !== null && $this->aCompany->getId() !== $v) {
  224. $this->aCompany = null;
  225. }
  226.  
  227.  
  228. return $this;
  229. } // setCompanyId()
  230.  
  231. /**
  232. * Set the value of [company_contact_id] column.
  233. *
  234. * @param int $v new value
  235. * @return CompanyPhone The current object (for fluent API support)
  236. */
  237. public function setCompanyContactId($v)
  238. {
  239. if ($v !== null && is_numeric($v)) {
  240. $v = (int) $v;
  241. }
  242.  
  243. if ($this->company_contact_id !== $v) {
  244. $this->company_contact_id = $v;
  245. $this->modifiedColumns[] = CompanyPhonePeer::COMPANY_CONTACT_ID;
  246. }
  247.  
  248. if ($this->aCompanyContact !== null && $this->aCompanyContact->getId() !== $v) {
  249. $this->aCompanyContact = null;
  250. }
  251.  
  252.  
  253. return $this;
  254. } // setCompanyContactId()
  255.  
  256. /**
  257. * Set the value of [number] column.
  258. *
  259. * @param string $v new value
  260. * @return CompanyPhone The current object (for fluent API support)
  261. */
  262. public function setNumber($v)
  263. {
  264. if ($v !== null && is_numeric($v)) {
  265. $v = (string) $v;
  266. }
  267.  
  268. if ($this->number !== $v) {
  269. $this->number = $v;
  270. $this->modifiedColumns[] = CompanyPhonePeer::NUMBER;
  271. }
  272.  
  273.  
  274. return $this;
  275. } // setNumber()
  276.  
  277. /**
  278. * Indicates whether the columns in this object are only set to default values.
  279. *
  280. * This method can be used in conjunction with isModified() to indicate whether an object is both
  281. * modified _and_ has some values set which are non-default.
  282. *
  283. * @return boolean Whether the columns in this object are only been set with default values.
  284. */
  285. public function hasOnlyDefaultValues()
  286. {
  287. // otherwise, everything was equal, so return true
  288. return true;
  289. } // hasOnlyDefaultValues()
  290.  
  291. /**
  292. * Hydrates (populates) the object variables with values from the database resultset.
  293. *
  294. * An offset (0-based "start column") is specified so that objects can be hydrated
  295. * with a subset of the columns in the resultset rows. This is needed, for example,
  296. * for results of JOIN queries where the resultset row includes columns from two or
  297. * more tables.
  298. *
  299. * @param array $row The row returned by PDOStatement->fetch(PDO::FETCH_NUM)
  300. * @param int $startcol 0-based offset column which indicates which restultset column to start with.
  301. * @param boolean $rehydrate Whether this object is being re-hydrated from the database.
  302. * @return int next starting column
  303. * @throws PropelException - Any caught Exception will be rewrapped as a PropelException.
  304. */
  305. public function hydrate($row, $startcol = 0, $rehydrate = false)
  306. {
  307. try {
  308.  
  309. $this->id = ($row[$startcol + 0] !== null) ? (int) $row[$startcol + 0] : null;
  310. $this->company_phone_type_id = ($row[$startcol + 1] !== null) ? (int) $row[$startcol + 1] : null;
  311. $this->company_id = ($row[$startcol + 2] !== null) ? (int) $row[$startcol + 2] : null;
  312. $this->company_contact_id = ($row[$startcol + 3] !== null) ? (int) $row[$startcol + 3] : null;
  313. $this->number = ($row[$startcol + 4] !== null) ? (string) $row[$startcol + 4] : null;
  314. $this->resetModified();
  315.  
  316. $this->setNew(false);
  317.  
  318. if ($rehydrate) {
  319. $this->ensureConsistency();
  320. }
  321. $this->postHydrate($row, $startcol, $rehydrate);
  322. return $startcol + 5; // 5 = CompanyPhonePeer::NUM_HYDRATE_COLUMNS.
  323.  
  324. } catch (Exception $e) {
  325. throw new PropelException("Error populating CompanyPhone object", $e);
  326. }
  327. }
  328.  
  329. /**
  330. * Checks and repairs the internal consistency of the object.
  331. *
  332. * This method is executed after an already-instantiated object is re-hydrated
  333. * from the database. It exists to check any foreign keys to make sure that
  334. * the objects related to the current object are correct based on foreign key.
  335. *
  336. * You can override this method in the stub class, but you should always invoke
  337. * the base method from the overridden method (i.e. parent::ensureConsistency()),
  338. * in case your model changes.
  339. *
  340. * @throws PropelException
  341. */
  342. public function ensureConsistency()
  343. {
  344.  
  345. if ($this->aCompanyPhoneType !== null && $this->company_phone_type_id !== $this->aCompanyPhoneType->getId()) {
  346. $this->aCompanyPhoneType = null;
  347. }
  348. if ($this->aCompany !== null && $this->company_id !== $this->aCompany->getId()) {
  349. $this->aCompany = null;
  350. }
  351. if ($this->aCompanyContact !== null && $this->company_contact_id !== $this->aCompanyContact->getId()) {
  352. $this->aCompanyContact = null;
  353. }
  354. } // ensureConsistency
  355.  
  356. /**
  357. * Reloads this object from datastore based on primary key and (optionally) resets all associated objects.
  358. *
  359. * This will only work if the object has been saved and has a valid primary key set.
  360. *
  361. * @param boolean $deep (optional) Whether to also de-associated any related objects.
  362. * @param PropelPDO $con (optional) The PropelPDO connection to use.
  363. * @return void
  364. * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db
  365. */
  366. public function reload($deep = false, PropelPDO $con = null)
  367. {
  368. if ($this->isDeleted()) {
  369. throw new PropelException("Cannot reload a deleted object.");
  370. }
  371.  
  372. if ($this->isNew()) {
  373. throw new PropelException("Cannot reload an unsaved object.");
  374. }
  375.  
  376. if ($con === null) {
  377. $con = Propel::getConnection(CompanyPhonePeer::DATABASE_NAME, Propel::CONNECTION_READ);
  378. }
  379.  
  380. // We don't need to alter the object instance pool; we're just modifying this instance
  381. // already in the pool.
  382.  
  383. $stmt = CompanyPhonePeer::doSelectStmt($this->buildPkeyCriteria(), $con);
  384. $row = $stmt->fetch(PDO::FETCH_NUM);
  385. $stmt->closeCursor();
  386. if (!$row) {
  387. throw new PropelException('Cannot find matching row in the database to reload object values.');
  388. }
  389. $this->hydrate($row, 0, true); // rehydrate
  390.  
  391. if ($deep) { // also de-associate any related objects?
  392.  
  393. $this->aCompany = null;
  394. $this->aCompanyContact = null;
  395. $this->aCompanyPhoneType = null;
  396. } // if (deep)
  397. }
  398.  
  399. /**
  400. * Removes this object from datastore and sets delete attribute.
  401. *
  402. * @param PropelPDO $con
  403. * @return void
  404. * @throws PropelException
  405. * @throws Exception
  406. * @see BaseObject::setDeleted()
  407. * @see BaseObject::isDeleted()
  408. */
  409. public function delete(PropelPDO $con = null)
  410. {
  411. if ($this->isDeleted()) {
  412. throw new PropelException("This object has already been deleted.");
  413. }
  414.  
  415. if ($con === null) {
  416. $con = Propel::getConnection(CompanyPhonePeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
  417. }
  418.  
  419. $con->beginTransaction();
  420. try {
  421. $deleteQuery = CompanyPhoneQuery::create()
  422. ->filterByPrimaryKey($this->getPrimaryKey());
  423. $ret = $this->preDelete($con);
  424. if ($ret) {
  425. $deleteQuery->delete($con);
  426. $this->postDelete($con);
  427. $con->commit();
  428. $this->setDeleted(true);
  429. } else {
  430. $con->commit();
  431. }
  432. } catch (Exception $e) {
  433. $con->rollBack();
  434. throw $e;
  435. }
  436. }
  437.  
  438. /**
  439. * Persists this object to the database.
  440. *
  441. * If the object is new, it inserts it; otherwise an update is performed.
  442. * All modified related objects will also be persisted in the doSave()
  443. * method. This method wraps all precipitate database operations in a
  444. * single transaction.
  445. *
  446. * @param PropelPDO $con
  447. * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
  448. * @throws PropelException
  449. * @throws Exception
  450. * @see doSave()
  451. */
  452. public function save(PropelPDO $con = null)
  453. {
  454. if ($this->isDeleted()) {
  455. throw new PropelException("You cannot save an object that has been deleted.");
  456. }
  457.  
  458. if ($con === null) {
  459. $con = Propel::getConnection(CompanyPhonePeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
  460. }
  461.  
  462. $con->beginTransaction();
  463. $isInsert = $this->isNew();
  464. try {
  465. $ret = $this->preSave($con);
  466. if ($isInsert) {
  467. $ret = $ret && $this->preInsert($con);
  468. } else {
  469. $ret = $ret && $this->preUpdate($con);
  470. }
  471. if ($ret) {
  472. $affectedRows = $this->doSave($con);
  473. if ($isInsert) {
  474. $this->postInsert($con);
  475. } else {
  476. $this->postUpdate($con);
  477. }
  478. $this->postSave($con);
  479. CompanyPhonePeer::addInstanceToPool($this);
  480. } else {
  481. $affectedRows = 0;
  482. }
  483. $con->commit();
  484.  
  485. return $affectedRows;
  486. } catch (Exception $e) {
  487. $con->rollBack();
  488. throw $e;
  489. }
  490. }
  491.  
  492. /**
  493. * Performs the work of inserting or updating the row in the database.
  494. *
  495. * If the object is new, it inserts it; otherwise an update is performed.
  496. * All related objects are also updated in this method.
  497. *
  498. * @param PropelPDO $con
  499. * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
  500. * @throws PropelException
  501. * @see save()
  502. */
  503. protected function doSave(PropelPDO $con)
  504. {
  505. $affectedRows = 0; // initialize var to track total num of affected rows
  506. if (!$this->alreadyInSave) {
  507. $this->alreadyInSave = true;
  508.  
  509. // We call the save method on the following object(s) if they
  510. // were passed to this object by their coresponding set
  511. // method. This object relates to these object(s) by a
  512. // foreign key reference.
  513.  
  514. if ($this->aCompany !== null) {
  515. if ($this->aCompany->isModified() || $this->aCompany->isNew()) {
  516. $affectedRows += $this->aCompany->save($con);
  517. }
  518. $this->setCompany($this->aCompany);
  519. }
  520.  
  521. if ($this->aCompanyContact !== null) {
  522. if ($this->aCompanyContact->isModified() || $this->aCompanyContact->isNew()) {
  523. $affectedRows += $this->aCompanyContact->save($con);
  524. }
  525. $this->setCompanyContact($this->aCompanyContact);
  526. }
  527.  
  528. if ($this->aCompanyPhoneType !== null) {
  529. if ($this->aCompanyPhoneType->isModified() || $this->aCompanyPhoneType->isNew()) {
  530. $affectedRows += $this->aCompanyPhoneType->save($con);
  531. }
  532. $this->setCompanyPhoneType($this->aCompanyPhoneType);
  533. }
  534.  
  535. if ($this->isNew() || $this->isModified()) {
  536. // persist changes
  537. if ($this->isNew()) {
  538. $this->doInsert($con);
  539. } else {
  540. $this->doUpdate($con);
  541. }
  542. $affectedRows += 1;
  543. $this->resetModified();
  544. }
  545.  
  546. $this->alreadyInSave = false;
  547.  
  548. }
  549.  
  550. return $affectedRows;
  551. } // doSave()
  552.  
  553. /**
  554. * Insert the row in the database.
  555. *
  556. * @param PropelPDO $con
  557. *
  558. * @throws PropelException
  559. * @see doSave()
  560. */
  561. protected function doInsert(PropelPDO $con)
  562. {
  563. $modifiedColumns = array();
  564. $index = 0;
  565.  
  566. $this->modifiedColumns[] = CompanyPhonePeer::ID;
  567. if (null !== $this->id) {
  568. throw new PropelException('Cannot insert a value for auto-increment primary key (' . CompanyPhonePeer::ID . ')');
  569. }
  570.  
  571. // check the columns in natural order for more readable SQL queries
  572. if ($this->isColumnModified(CompanyPhonePeer::ID)) {
  573. $modifiedColumns[':p' . $index++] = '`id`';
  574. }
  575. if ($this->isColumnModified(CompanyPhonePeer::COMPANY_PHONE_TYPE_ID)) {
  576. $modifiedColumns[':p' . $index++] = '`company_phone_type_id`';
  577. }
  578. if ($this->isColumnModified(CompanyPhonePeer::COMPANY_ID)) {
  579. $modifiedColumns[':p' . $index++] = '`company_id`';
  580. }
  581. if ($this->isColumnModified(CompanyPhonePeer::COMPANY_CONTACT_ID)) {
  582. $modifiedColumns[':p' . $index++] = '`company_contact_id`';
  583. }
  584. if ($this->isColumnModified(CompanyPhonePeer::NUMBER)) {
  585. $modifiedColumns[':p' . $index++] = '`number`';
  586. }
  587.  
  588. $sql = sprintf(
  589. 'INSERT INTO `company_phone` (%s) VALUES (%s)',
  590. implode(', ', $modifiedColumns),
  591. implode(', ', array_keys($modifiedColumns))
  592. );
  593.  
  594. try {
  595. $stmt = $con->prepare($sql);
  596. foreach ($modifiedColumns as $identifier => $columnName) {
  597. switch ($columnName) {
  598. case '`id`':
  599. $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT);
  600. break;
  601. case '`company_phone_type_id`':
  602. $stmt->bindValue($identifier, $this->company_phone_type_id, PDO::PARAM_INT);
  603. break;
  604. case '`company_id`':
  605. $stmt->bindValue($identifier, $this->company_id, PDO::PARAM_INT);
  606. break;
  607. case '`company_contact_id`':
  608. $stmt->bindValue($identifier, $this->company_contact_id, PDO::PARAM_INT);
  609. break;
  610. case '`number`':
  611. $stmt->bindValue($identifier, $this->number, PDO::PARAM_STR);
  612. break;
  613. }
  614. }
  615. $stmt->execute();
  616. } catch (Exception $e) {
  617. Propel::log($e->getMessage(), Propel::LOG_ERR);
  618. throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), $e);
  619. }
  620.  
  621. try {
  622. $pk = $con->lastInsertId();
  623. } catch (Exception $e) {
  624. throw new PropelException('Unable to get autoincrement id.', $e);
  625. }
  626. $this->setId($pk);
  627.  
  628. $this->setNew(false);
  629. }
  630.  
  631. /**
  632. * Update the row in the database.
  633. *
  634. * @param PropelPDO $con
  635. *
  636. * @see doSave()
  637. */
  638. protected function doUpdate(PropelPDO $con)
  639. {
  640. $selectCriteria = $this->buildPkeyCriteria();
  641. $valuesCriteria = $this->buildCriteria();
  642. BasePeer::doUpdate($selectCriteria, $valuesCriteria, $con);
  643. }
  644.  
  645. /**
  646. * Array of ValidationFailed objects.
  647. * @var array ValidationFailed[]
  648. */
  649. protected $validationFailures = array();
  650.  
  651. /**
  652. * Gets any ValidationFailed objects that resulted from last call to validate().
  653. *
  654. *
  655. * @return array ValidationFailed[]
  656. * @see validate()
  657. */
  658. public function getValidationFailures()
  659. {
  660. return $this->validationFailures;
  661. }
  662.  
  663. /**
  664. * Validates the objects modified field values and all objects related to this table.
  665. *
  666. * If $columns is either a column name or an array of column names
  667. * only those columns are validated.
  668. *
  669. * @param mixed $columns Column name or an array of column names.
  670. * @return boolean Whether all columns pass validation.
  671. * @see doValidate()
  672. * @see getValidationFailures()
  673. */
  674. public function validate($columns = null)
  675. {
  676. $res = $this->doValidate($columns);
  677. if ($res === true) {
  678. $this->validationFailures = array();
  679.  
  680. return true;
  681. }
  682.  
  683. $this->validationFailures = $res;
  684.  
  685. return false;
  686. }
  687.  
  688. /**
  689. * This function performs the validation work for complex object models.
  690. *
  691. * In addition to checking the current object, all related objects will
  692. * also be validated. If all pass then <code>true</code> is returned; otherwise
  693. * an aggreagated array of ValidationFailed objects will be returned.
  694. *
  695. * @param array $columns Array of column names to validate.
  696. * @return mixed <code>true</code> if all validations pass; array of <code>ValidationFailed</code> objets otherwise.
  697. */
  698. protected function doValidate($columns = null)
  699. {
  700. if (!$this->alreadyInValidation) {
  701. $this->alreadyInValidation = true;
  702. $retval = null;
  703.  
  704. $failureMap = array();
  705.  
  706.  
  707. // We call the validate method on the following object(s) if they
  708. // were passed to this object by their coresponding set
  709. // method. This object relates to these object(s) by a
  710. // foreign key reference.
  711.  
  712. if ($this->aCompany !== null) {
  713. if (!$this->aCompany->validate($columns)) {
  714. $failureMap = array_merge($failureMap, $this->aCompany->getValidationFailures());
  715. }
  716. }
  717.  
  718. if ($this->aCompanyContact !== null) {
  719. if (!$this->aCompanyContact->validate($columns)) {
  720. $failureMap = array_merge($failureMap, $this->aCompanyContact->getValidationFailures());
  721. }
  722. }
  723.  
  724. if ($this->aCompanyPhoneType !== null) {
  725. if (!$this->aCompanyPhoneType->validate($columns)) {
  726. $failureMap = array_merge($failureMap, $this->aCompanyPhoneType->getValidationFailures());
  727. }
  728. }
  729.  
  730.  
  731. if (($retval = CompanyPhonePeer::doValidate($this, $columns)) !== true) {
  732. $failureMap = array_merge($failureMap, $retval);
  733. }
  734.  
  735.  
  736.  
  737. $this->alreadyInValidation = false;
  738. }
  739.  
  740. return (!empty($failureMap) ? $failureMap : true);
  741. }
  742.  
  743. /**
  744. * Retrieves a field from the object by name passed in as a string.
  745. *
  746. * @param string $name name
  747. * @param string $type The type of fieldname the $name is of:
  748. * one of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
  749. * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
  750. * Defaults to BasePeer::TYPE_PHPNAME
  751. * @return mixed Value of field.
  752. */
  753. public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
  754. {
  755. $pos = CompanyPhonePeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
  756. $field = $this->getByPosition($pos);
  757.  
  758. return $field;
  759. }
  760.  
  761. /**
  762. * Retrieves a field from the object by Position as specified in the xml schema.
  763. * Zero-based.
  764. *
  765. * @param int $pos position in xml schema
  766. * @return mixed Value of field at $pos
  767. */
  768. public function getByPosition($pos)
  769. {
  770. switch ($pos) {
  771. case 0:
  772. return $this->getId();
  773. break;
  774. case 1:
  775. return $this->getCompanyPhoneTypeId();
  776. break;
  777. case 2:
  778. return $this->getCompanyId();
  779. break;
  780. case 3:
  781. return $this->getCompanyContactId();
  782. break;
  783. case 4:
  784. return $this->getNumber();
  785. break;
  786. default:
  787. return null;
  788. break;
  789. } // switch()
  790. }
  791.  
  792. /**
  793. * Exports the object as an array.
  794. *
  795. * You can specify the key type of the array by passing one of the class
  796. * type constants.
  797. *
  798. * @param string $keyType (optional) One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
  799. * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
  800. * Defaults to BasePeer::TYPE_PHPNAME.
  801. * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to true.
  802. * @param array $alreadyDumpedObjects List of objects to skip to avoid recursion
  803. * @param boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE.
  804. *
  805. * @return array an associative array containing the field names (as keys) and field values
  806. */
  807. public function toArray($keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false)
  808. {
  809. if (isset($alreadyDumpedObjects['CompanyPhone'][$this->getPrimaryKey()])) {
  810. return '*RECURSION*';
  811. }
  812. $alreadyDumpedObjects['CompanyPhone'][$this->getPrimaryKey()] = true;
  813. $keys = CompanyPhonePeer::getFieldNames($keyType);
  814. $result = array(
  815. $keys[0] => $this->getId(),
  816. $keys[1] => $this->getCompanyPhoneTypeId(),
  817. $keys[2] => $this->getCompanyId(),
  818. $keys[3] => $this->getCompanyContactId(),
  819. $keys[4] => $this->getNumber(),
  820. );
  821. if ($includeForeignObjects) {
  822. if (null !== $this->aCompany) {
  823. $result['Company'] = $this->aCompany->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true);
  824. }
  825. if (null !== $this->aCompanyContact) {
  826. $result['CompanyContact'] = $this->aCompanyContact->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true);
  827. }
  828. if (null !== $this->aCompanyPhoneType) {
  829. $result['CompanyPhoneType'] = $this->aCompanyPhoneType->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true);
  830. }
  831. }
  832.  
  833. return $result;
  834. }
  835.  
  836. /**
  837. * Sets a field from the object by name passed in as a string.
  838. *
  839. * @param string $name peer name
  840. * @param mixed $value field value
  841. * @param string $type The type of fieldname the $name is of:
  842. * one of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
  843. * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
  844. * Defaults to BasePeer::TYPE_PHPNAME
  845. * @return void
  846. */
  847. public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
  848. {
  849. $pos = CompanyPhonePeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
  850.  
  851. $this->setByPosition($pos, $value);
  852. }
  853.  
  854. /**
  855. * Sets a field from the object by Position as specified in the xml schema.
  856. * Zero-based.
  857. *
  858. * @param int $pos position in xml schema
  859. * @param mixed $value field value
  860. * @return void
  861. */
  862. public function setByPosition($pos, $value)
  863. {
  864. switch ($pos) {
  865. case 0:
  866. $this->setId($value);
  867. break;
  868. case 1:
  869. $this->setCompanyPhoneTypeId($value);
  870. break;
  871. case 2:
  872. $this->setCompanyId($value);
  873. break;
  874. case 3:
  875. $this->setCompanyContactId($value);
  876. break;
  877. case 4:
  878. $this->setNumber($value);
  879. break;
  880. } // switch()
  881. }
  882.  
  883. /**
  884. * Populates the object using an array.
  885. *
  886. * This is particularly useful when populating an object from one of the
  887. * request arrays (e.g. $_POST). This method goes through the column
  888. * names, checking to see whether a matching key exists in populated
  889. * array. If so the setByName() method is called for that column.
  890. *
  891. * You can specify the key type of the array by additionally passing one
  892. * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
  893. * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
  894. * The default key type is the column's BasePeer::TYPE_PHPNAME
  895. *
  896. * @param array $arr An array to populate the object from.
  897. * @param string $keyType The type of keys the array uses.
  898. * @return void
  899. */
  900. public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
  901. {
  902. $keys = CompanyPhonePeer::getFieldNames($keyType);
  903.  
  904. if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
  905. if (array_key_exists($keys[1], $arr)) $this->setCompanyPhoneTypeId($arr[$keys[1]]);
  906. if (array_key_exists($keys[2], $arr)) $this->setCompanyId($arr[$keys[2]]);
  907. if (array_key_exists($keys[3], $arr)) $this->setCompanyContactId($arr[$keys[3]]);
  908. if (array_key_exists($keys[4], $arr)) $this->setNumber($arr[$keys[4]]);
  909. }
  910.  
  911. /**
  912. * Build a Criteria object containing the values of all modified columns in this object.
  913. *
  914. * @return Criteria The Criteria object containing all modified values.
  915. */
  916. public function buildCriteria()
  917. {
  918. $criteria = new Criteria(CompanyPhonePeer::DATABASE_NAME);
  919.  
  920. if ($this->isColumnModified(CompanyPhonePeer::ID)) $criteria->add(CompanyPhonePeer::ID, $this->id);
  921. if ($this->isColumnModified(CompanyPhonePeer::COMPANY_PHONE_TYPE_ID)) $criteria->add(CompanyPhonePeer::COMPANY_PHONE_TYPE_ID, $this->company_phone_type_id);
  922. if ($this->isColumnModified(CompanyPhonePeer::COMPANY_ID)) $criteria->add(CompanyPhonePeer::COMPANY_ID, $this->company_id);
  923. if ($this->isColumnModified(CompanyPhonePeer::COMPANY_CONTACT_ID)) $criteria->add(CompanyPhonePeer::COMPANY_CONTACT_ID, $this->company_contact_id);
  924. if ($this->isColumnModified(CompanyPhonePeer::NUMBER)) $criteria->add(CompanyPhonePeer::NUMBER, $this->number);
  925.  
  926. return $criteria;
  927. }
  928.  
  929. /**
  930. * Builds a Criteria object containing the primary key for this object.
  931. *
  932. * Unlike buildCriteria() this method includes the primary key values regardless
  933. * of whether or not they have been modified.
  934. *
  935. * @return Criteria The Criteria object containing value(s) for primary key(s).
  936. */
  937. public function buildPkeyCriteria()
  938. {
  939. $criteria = new Criteria(CompanyPhonePeer::DATABASE_NAME);
  940. $criteria->add(CompanyPhonePeer::ID, $this->id);
  941.  
  942. return $criteria;
  943. }
  944.  
  945. /**
  946. * Returns the primary key for this object (row).
  947. * @return int
  948. */
  949. public function getPrimaryKey()
  950. {
  951. return $this->getId();
  952. }
  953.  
  954. /**
  955. * Generic method to set the primary key (id column).
  956. *
  957. * @param int $key Primary key.
  958. * @return void
  959. */
  960. public function setPrimaryKey($key)
  961. {
  962. $this->setId($key);
  963. }
  964.  
  965. /**
  966. * Returns true if the primary key for this object is null.
  967. * @return boolean
  968. */
  969. public function isPrimaryKeyNull()
  970. {
  971.  
  972. return null === $this->getId();
  973. }
  974.  
  975. /**
  976. * Sets contents of passed object to values from current object.
  977. *
  978. * If desired, this method can also make copies of all associated (fkey referrers)
  979. * objects.
  980. *
  981. * @param object $copyObj An object of CompanyPhone (or compatible) type.
  982. * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
  983. * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new.
  984. * @throws PropelException
  985. */
  986. public function copyInto($copyObj, $deepCopy = false, $makeNew = true)
  987. {
  988. $copyObj->setCompanyPhoneTypeId($this->getCompanyPhoneTypeId());
  989. $copyObj->setCompanyId($this->getCompanyId());
  990. $copyObj->setCompanyContactId($this->getCompanyContactId());
  991. $copyObj->setNumber($this->getNumber());
  992.  
  993. if ($deepCopy && !$this->startCopy) {
  994. // important: temporarily setNew(false) because this affects the behavior of
  995. // the getter/setter methods for fkey referrer objects.
  996. $copyObj->setNew(false);
  997. // store object hash to prevent cycle
  998. $this->startCopy = true;
  999.  
  1000. //unflag object copy
  1001. $this->startCopy = false;
  1002. } // if ($deepCopy)
  1003.  
  1004. if ($makeNew) {
  1005. $copyObj->setNew(true);
  1006. $copyObj->setId(NULL); // this is a auto-increment column, so set to default value
  1007. }
  1008. }
  1009.  
  1010. /**
  1011. * Makes a copy of this object that will be inserted as a new row in table when saved.
  1012. * It creates a new object filling in the simple attributes, but skipping any primary
  1013. * keys that are defined for the table.
  1014. *
  1015. * If desired, this method can also make copies of all associated (fkey referrers)
  1016. * objects.
  1017. *
  1018. * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
  1019. * @return CompanyPhone Clone of current object.
  1020. * @throws PropelException
  1021. */
  1022. public function copy($deepCopy = false)
  1023. {
  1024. // we use get_class(), because this might be a subclass
  1025. $clazz = get_class($this);
  1026. $copyObj = new $clazz();
  1027. $this->copyInto($copyObj, $deepCopy);
  1028.  
  1029. return $copyObj;
  1030. }
  1031.  
  1032. /**
  1033. * Returns a peer instance associated with this om.
  1034. *
  1035. * Since Peer classes are not to have any instance attributes, this method returns the
  1036. * same instance for all member of this class. The method could therefore
  1037. * be static, but this would prevent one from overriding the behavior.
  1038. *
  1039. * @return CompanyPhonePeer
  1040. */
  1041. public function getPeer()
  1042. {
  1043. if (self::$peer === null) {
  1044. self::$peer = new CompanyPhonePeer();
  1045. }
  1046.  
  1047. return self::$peer;
  1048. }
  1049.  
  1050. /**
  1051. * Declares an association between this object and a Company object.
  1052. *
  1053. * @param Company $v
  1054. * @return CompanyPhone The current object (for fluent API support)
  1055. * @throws PropelException
  1056. */
  1057. public function setCompany(Company $v = null)
  1058. {
  1059. if ($v === null) {
  1060. $this->setCompanyId(NULL);
  1061. } else {
  1062. $this->setCompanyId($v->getId());
  1063. }
  1064.  
  1065. $this->aCompany = $v;
  1066.  
  1067. // Add binding for other direction of this n:n relationship.
  1068. // If this object has already been added to the Company object, it will not be re-added.
  1069. if ($v !== null) {
  1070. $v->addCompanyPhone($this);
  1071. }
  1072.  
  1073.  
  1074. return $this;
  1075. }
  1076.  
  1077.  
  1078. /**
  1079. * Get the associated Company object
  1080. *
  1081. * @param PropelPDO $con Optional Connection object.
  1082. * @param $doQuery Executes a query to get the object if required
  1083. * @return Company The associated Company object.
  1084. * @throws PropelException
  1085. */
  1086. public function getCompany(PropelPDO $con = null, $doQuery = true)
  1087. {
  1088. if ($this->aCompany === null && ($this->company_id !== null) && $doQuery) {
  1089. $this->aCompany = CompanyQuery::create()->findPk($this->company_id, $con);
  1090. /* The following can be used additionally to
  1091. guarantee the related object contains a reference
  1092. to this object. This level of coupling may, however, be
  1093. undesirable since it could result in an only partially populated collection
  1094. in the referenced object.
  1095. $this->aCompany->addCompanyPhones($this);
  1096. */
  1097. }
  1098.  
  1099. return $this->aCompany;
  1100. }
  1101.  
  1102. /**
  1103. * Declares an association between this object and a CompanyContact object.
  1104. *
  1105. * @param CompanyContact $v
  1106. * @return CompanyPhone The current object (for fluent API support)
  1107. * @throws PropelException
  1108. */
  1109. public function setCompanyContact(CompanyContact $v = null)
  1110. {
  1111. if ($v === null) {
  1112. $this->setCompanyContactId(NULL);
  1113. } else {
  1114. $this->setCompanyContactId($v->getId());
  1115. }
  1116.  
  1117. $this->aCompanyContact = $v;
  1118.  
  1119. // Add binding for other direction of this n:n relationship.
  1120. // If this object has already been added to the CompanyContact object, it will not be re-added.
  1121. if ($v !== null) {
  1122. $v->addCompanyPhone($this);
  1123. }
  1124.  
  1125.  
  1126. return $this;
  1127. }
  1128.  
  1129.  
  1130. /**
  1131. * Get the associated CompanyContact object
  1132. *
  1133. * @param PropelPDO $con Optional Connection object.
  1134. * @param $doQuery Executes a query to get the object if required
  1135. * @return CompanyContact The associated CompanyContact object.
  1136. * @throws PropelException
  1137. */
  1138. public function getCompanyContact(PropelPDO $con = null, $doQuery = true)
  1139. {
  1140. if ($this->aCompanyContact === null && ($this->company_contact_id !== null) && $doQuery) {
  1141. $this->aCompanyContact = CompanyContactQuery::create()->findPk($this->company_contact_id, $con);
  1142. /* The following can be used additionally to
  1143. guarantee the related object contains a reference
  1144. to this object. This level of coupling may, however, be
  1145. undesirable since it could result in an only partially populated collection
  1146. in the referenced object.
  1147. $this->aCompanyContact->addCompanyPhones($this);
  1148. */
  1149. }
  1150.  
  1151. return $this->aCompanyContact;
  1152. }
  1153.  
  1154. /**
  1155. * Declares an association between this object and a CompanyPhoneType object.
  1156. *
  1157. * @param CompanyPhoneType $v
  1158. * @return CompanyPhone The current object (for fluent API support)
  1159. * @throws PropelException
  1160. */
  1161. public function setCompanyPhoneType(CompanyPhoneType $v = null)
  1162. {
  1163. if ($v === null) {
  1164. $this->setCompanyPhoneTypeId(NULL);
  1165. } else {
  1166. $this->setCompanyPhoneTypeId($v->getId());
  1167. }
  1168.  
  1169. $this->aCompanyPhoneType = $v;
  1170.  
  1171. // Add binding for other direction of this n:n relationship.
  1172. // If this object has already been added to the CompanyPhoneType object, it will not be re-added.
  1173. if ($v !== null) {
  1174. $v->addCompanyPhone($this);
  1175. }
  1176.  
  1177.  
  1178. return $this;
  1179. }
  1180.  
  1181.  
  1182. /**
  1183. * Get the associated CompanyPhoneType object
  1184. *
  1185. * @param PropelPDO $con Optional Connection object.
  1186. * @param $doQuery Executes a query to get the object if required
  1187. * @return CompanyPhoneType The associated CompanyPhoneType object.
  1188. * @throws PropelException
  1189. */
  1190. public function getCompanyPhoneType(PropelPDO $con = null, $doQuery = true)
  1191. {
  1192. if ($this->aCompanyPhoneType === null && ($this->company_phone_type_id !== null) && $doQuery) {
  1193. $this->aCompanyPhoneType = CompanyPhoneTypeQuery::create()->findPk($this->company_phone_type_id, $con);
  1194. /* The following can be used additionally to
  1195. guarantee the related object contains a reference
  1196. to this object. This level of coupling may, however, be
  1197. undesirable since it could result in an only partially populated collection
  1198. in the referenced object.
  1199. $this->aCompanyPhoneType->addCompanyPhones($this);
  1200. */
  1201. }
  1202.  
  1203. return $this->aCompanyPhoneType;
  1204. }
  1205.  
  1206. /**
  1207. * Clears the current object and sets all attributes to their default values
  1208. */
  1209. public function clear()
  1210. {
  1211. $this->id = null;
  1212. $this->company_phone_type_id = null;
  1213. $this->company_id = null;
  1214. $this->company_contact_id = null;
  1215. $this->number = null;
  1216. $this->alreadyInSave = false;
  1217. $this->alreadyInValidation = false;
  1218. $this->alreadyInClearAllReferencesDeep = false;
  1219. $this->clearAllReferences();
  1220. $this->resetModified();
  1221. $this->setNew(true);
  1222. $this->setDeleted(false);
  1223. }
  1224.  
  1225. /**
  1226. * Resets all references to other model objects or collections of model objects.
  1227. *
  1228. * This method is a user-space workaround for PHP's inability to garbage collect
  1229. * objects with circular references (even in PHP 5.3). This is currently necessary
  1230. * when using Propel in certain daemon or large-volumne/high-memory operations.
  1231. *
  1232. * @param boolean $deep Whether to also clear the references on all referrer objects.
  1233. */
  1234. public function clearAllReferences($deep = false)
  1235. {
  1236. if ($deep && !$this->alreadyInClearAllReferencesDeep) {
  1237. $this->alreadyInClearAllReferencesDeep = true;
  1238. if ($this->aCompany instanceof Persistent) {
  1239. $this->aCompany->clearAllReferences($deep);
  1240. }
  1241. if ($this->aCompanyContact instanceof Persistent) {
  1242. $this->aCompanyContact->clearAllReferences($deep);
  1243. }
  1244. if ($this->aCompanyPhoneType instanceof Persistent) {
  1245. $this->aCompanyPhoneType->clearAllReferences($deep);
  1246. }
  1247.  
  1248. $this->alreadyInClearAllReferencesDeep = false;
  1249. } // if ($deep)
  1250.  
  1251. $this->aCompany = null;
  1252. $this->aCompanyContact = null;
  1253. $this->aCompanyPhoneType = null;
  1254. }
  1255.  
  1256. /**
  1257. * return the string representation of this object
  1258. *
  1259. * @return string
  1260. */
  1261. public function __toString()
  1262. {
  1263. return (string) $this->exportTo(CompanyPhonePeer::DEFAULT_STRING_FORMAT);
  1264. }
  1265.  
  1266. /**
  1267. * return true is the object is in saving state
  1268. *
  1269. * @return boolean
  1270. */
  1271. public function isAlreadyInSave()
  1272. {
  1273. return $this->alreadyInSave;
  1274. }
  1275.  
  1276. }
Advertisement
Add Comment
Please, Sign In to add comment