A QCodo powered CMS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

909 lines
36 KiB

  1. <?php
  2. /**
  3. * The abstract EmailAddressGen class defined here is
  4. * code-generated and contains all the basic CRUD-type functionality as well as
  5. * basic methods to handle relationships and index-based loading.
  6. *
  7. * To use, you should use the EmailAddress subclass which
  8. * extends this EmailAddressGen class.
  9. *
  10. * Because subsequent re-code generations will overwrite any changes to this
  11. * file, you should leave this file unaltered to prevent yourself from losing
  12. * any information or code changes. All customizations should be done by
  13. * overriding existing or implementing new methods, properties and variables
  14. * in the EmailAddress class.
  15. *
  16. * @package Quinta CMS
  17. * @subpackage GeneratedDataObjects
  18. * @property-read integer $Id the value for intId (Read-Only PK)
  19. * @property string $Url the value for strUrl (Not Null)
  20. * @property integer $PersonId the value for intPersonId (Not Null)
  21. * @property integer $IsPrimary the value for intIsPrimary
  22. * @property Person $Person the value for the Person object referenced by intPersonId (Not Null)
  23. * @property-read boolean $__Restored whether or not this object was restored from the database (as opposed to created new)
  24. */
  25. class EmailAddressGen extends QBaseClass
  26. {
  27. ///////////////////////////////////////////////////////////////////////
  28. // PROTECTED MEMBER VARIABLES and TEXT FIELD MAXLENGTHS (if applicable)
  29. ///////////////////////////////////////////////////////////////////////
  30. /////////// Object properties ////////////
  31. /**
  32. * Protected member variable that maps to the database PK Identity column email_address.id
  33. * @var integer intId
  34. *
  35. */
  36. protected $intId = null;
  37. /**
  38. * Protected member variable that maps to the database column email_address.url
  39. * @var string strUrl
  40. *
  41. */
  42. protected $strUrl = null;
  43. const UrlMaxLength = 128;
  44. /**
  45. * Protected member variable that maps to the database column email_address.person_id
  46. * @var integer intPersonId
  47. *
  48. */
  49. protected $intPersonId = null;
  50. /**
  51. * Protected member variable that maps to the database column email_address.is_primary
  52. * @var integer intIsPrimary
  53. *
  54. */
  55. protected $intIsPrimary = null;
  56. /**
  57. * Protected array of virtual attributes for this object (e.g. extra/other calculated and/or non-object bound
  58. * columns from the run-time database query result for this object). Used by InstantiateDbRow and
  59. * GetVirtualAttribute.
  60. * @var string[] $__strVirtualAttributeArray
  61. */
  62. protected $__strVirtualAttributeArray = array();
  63. /**
  64. * Protected internal member variable that specifies whether or not this object is Restored from the database.
  65. * Used by Save() to determine if Save() should perform a db UPDATE or INSERT.
  66. * @var bool __blnRestored;
  67. */
  68. protected $__blnRestored;
  69. ///////////////////////////////
  70. // PROTECTED MEMBER OBJECTS
  71. ///////////////////////////////
  72. /**
  73. * Protected member variable that contains the object pointed by the reference
  74. * in the database column email_address.person_id.
  75. *
  76. * NOTE: Always use the Person property getter to correctly retrieve this Person object.
  77. * (Because this class implements late binding, this variable reference MAY be null.)
  78. * @var Person objPerson
  79. */
  80. protected $objPerson;
  81. ///////////////////////////////
  82. // CLASS-WIDE LOAD AND COUNT METHODS
  83. ///////////////////////////////
  84. /**
  85. * Static method to retrieve the Database object that owns this class.
  86. * @return QDatabaseBase reference to the Database object that can query this class
  87. */
  88. public static function GetDatabase() {
  89. return QApplication::$Database[1];
  90. }
  91. /**
  92. * Load a EmailAddress from PK Info
  93. * @param integer $intId
  94. * @return EmailAddress
  95. */
  96. public static function Load($intId) {
  97. // Use QuerySingle to Perform the Query
  98. return EmailAddress::QuerySingle(
  99. QQ::Equal(QQN::EmailAddress()->Id, $intId)
  100. );
  101. }
  102. /**
  103. * Load all EmailAddresses
  104. * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  105. * @return EmailAddress[]
  106. */
  107. public static function LoadAll($objOptionalClauses = null) {
  108. // Call EmailAddress::QueryArray to perform the LoadAll query
  109. try {
  110. return EmailAddress::QueryArray(QQ::All(), $objOptionalClauses);
  111. } catch (QCallerException $objExc) {
  112. $objExc->IncrementOffset();
  113. throw $objExc;
  114. }
  115. }
  116. /**
  117. * Count all EmailAddresses
  118. * @return int
  119. */
  120. public static function CountAll() {
  121. // Call EmailAddress::QueryCount to perform the CountAll query
  122. return EmailAddress::QueryCount(QQ::All());
  123. }
  124. ///////////////////////////////
  125. // QCODO QUERY-RELATED METHODS
  126. ///////////////////////////////
  127. /**
  128. * Internally called method to assist with calling Qcodo Query for this class
  129. * on load methods.
  130. * @param QQueryBuilder &$objQueryBuilder the QueryBuilder object that will be created
  131. * @param QQCondition $objConditions any conditions on the query, itself
  132. * @param QQClause[] $objOptionalClausees additional optional QQClause object or array of QQClause objects for this query
  133. * @param mixed[] $mixParameterArray a array of name-value pairs to perform PrepareStatement with (sending in null will skip the PrepareStatement step)
  134. * @param boolean $blnCountOnly only select a rowcount
  135. * @return string the query statement
  136. */
  137. protected static function BuildQueryStatement(&$objQueryBuilder, QQCondition $objConditions, $objOptionalClauses, $mixParameterArray, $blnCountOnly) {
  138. // Get the Database Object for this Class
  139. $objDatabase = EmailAddress::GetDatabase();
  140. // Create/Build out the QueryBuilder object with EmailAddress-specific SELET and FROM fields
  141. $objQueryBuilder = new QQueryBuilder($objDatabase, 'email_address');
  142. EmailAddress::GetSelectFields($objQueryBuilder);
  143. $objQueryBuilder->AddFromItem('email_address');
  144. // Set "CountOnly" option (if applicable)
  145. if ($blnCountOnly)
  146. $objQueryBuilder->SetCountOnlyFlag();
  147. // Apply Any Conditions
  148. if ($objConditions)
  149. try {
  150. $objConditions->UpdateQueryBuilder($objQueryBuilder);
  151. } catch (QCallerException $objExc) {
  152. $objExc->IncrementOffset();
  153. throw $objExc;
  154. }
  155. // Iterate through all the Optional Clauses (if any) and perform accordingly
  156. if ($objOptionalClauses) {
  157. if ($objOptionalClauses instanceof QQClause)
  158. $objOptionalClauses->UpdateQueryBuilder($objQueryBuilder);
  159. else if (is_array($objOptionalClauses))
  160. foreach ($objOptionalClauses as $objClause)
  161. $objClause->UpdateQueryBuilder($objQueryBuilder);
  162. else
  163. throw new QCallerException('Optional Clauses must be a QQClause object or an array of QQClause objects');
  164. }
  165. // Get the SQL Statement
  166. $strQuery = $objQueryBuilder->GetStatement();
  167. // Prepare the Statement with the Query Parameters (if applicable)
  168. if ($mixParameterArray) {
  169. if (is_array($mixParameterArray)) {
  170. if (count($mixParameterArray))
  171. $strQuery = $objDatabase->PrepareStatement($strQuery, $mixParameterArray);
  172. // Ensure that there are no other Unresolved Named Parameters
  173. if (strpos($strQuery, chr(QQNamedValue::DelimiterCode) . '{') !== false)
  174. throw new QCallerException('Unresolved named parameters in the query');
  175. } else
  176. throw new QCallerException('Parameter Array must be an array of name-value parameter pairs');
  177. }
  178. // Return the Objects
  179. return $strQuery;
  180. }
  181. /**
  182. * Static Qcodo Query method to query for a single EmailAddress object.
  183. * Uses BuildQueryStatment to perform most of the work.
  184. * @param QQCondition $objConditions any conditions on the query, itself
  185. * @param QQClause[] $objOptionalClausees additional optional QQClause objects for this query
  186. * @param mixed[] $mixParameterArray a array of name-value pairs to perform PrepareStatement with
  187. * @return EmailAddress the queried object
  188. */
  189. public static function QuerySingle(QQCondition $objConditions, $objOptionalClauses = null, $mixParameterArray = null) {
  190. // Get the Query Statement
  191. try {
  192. $strQuery = EmailAddress::BuildQueryStatement($objQueryBuilder, $objConditions, $objOptionalClauses, $mixParameterArray, false);
  193. } catch (QCallerException $objExc) {
  194. $objExc->IncrementOffset();
  195. throw $objExc;
  196. }
  197. // Perform the Query, Get the First Row, and Instantiate a new EmailAddress object
  198. $objDbResult = $objQueryBuilder->Database->Query($strQuery);
  199. return EmailAddress::InstantiateDbRow($objDbResult->GetNextRow(), null, null, null, $objQueryBuilder->ColumnAliasArray);
  200. }
  201. /**
  202. * Static Qcodo Query method to query for an array of EmailAddress objects.
  203. * Uses BuildQueryStatment to perform most of the work.
  204. * @param QQCondition $objConditions any conditions on the query, itself
  205. * @param QQClause[] $objOptionalClausees additional optional QQClause objects for this query
  206. * @param mixed[] $mixParameterArray a array of name-value pairs to perform PrepareStatement with
  207. * @return EmailAddress[] the queried objects as an array
  208. */
  209. public static function QueryArray(QQCondition $objConditions, $objOptionalClauses = null, $mixParameterArray = null) {
  210. // Get the Query Statement
  211. try {
  212. $strQuery = EmailAddress::BuildQueryStatement($objQueryBuilder, $objConditions, $objOptionalClauses, $mixParameterArray, false);
  213. } catch (QCallerException $objExc) {
  214. $objExc->IncrementOffset();
  215. throw $objExc;
  216. }
  217. // Perform the Query and Instantiate the Array Result
  218. $objDbResult = $objQueryBuilder->Database->Query($strQuery);
  219. return EmailAddress::InstantiateDbResult($objDbResult, $objQueryBuilder->ExpandAsArrayNodes, $objQueryBuilder->ColumnAliasArray);
  220. }
  221. /**
  222. * Static Qcodo Query method to query for a count of EmailAddress objects.
  223. * Uses BuildQueryStatment to perform most of the work.
  224. * @param QQCondition $objConditions any conditions on the query, itself
  225. * @param QQClause[] $objOptionalClausees additional optional QQClause objects for this query
  226. * @param mixed[] $mixParameterArray a array of name-value pairs to perform PrepareStatement with
  227. * @return integer the count of queried objects as an integer
  228. */
  229. public static function QueryCount(QQCondition $objConditions, $objOptionalClauses = null, $mixParameterArray = null) {
  230. // Get the Query Statement
  231. try {
  232. $strQuery = EmailAddress::BuildQueryStatement($objQueryBuilder, $objConditions, $objOptionalClauses, $mixParameterArray, true);
  233. } catch (QCallerException $objExc) {
  234. $objExc->IncrementOffset();
  235. throw $objExc;
  236. }
  237. // Perform the Query and return the row_count
  238. $objDbResult = $objQueryBuilder->Database->Query($strQuery);
  239. // Figure out if the query is using GroupBy
  240. $blnGrouped = false;
  241. if ($objOptionalClauses) foreach ($objOptionalClauses as $objClause) {
  242. if ($objClause instanceof QQGroupBy) {
  243. $blnGrouped = true;
  244. break;
  245. }
  246. }
  247. if ($blnGrouped)
  248. // Groups in this query - return the count of Groups (which is the count of all rows)
  249. return $objDbResult->CountRows();
  250. else {
  251. // No Groups - return the sql-calculated count(*) value
  252. $strDbRow = $objDbResult->FetchRow();
  253. return QType::Cast($strDbRow[0], QType::Integer);
  254. }
  255. }
  256. /* public static function QueryArrayCached($strConditions, $mixParameterArray = null) {
  257. // Get the Database Object for this Class
  258. $objDatabase = EmailAddress::GetDatabase();
  259. // Lookup the QCache for This Query Statement
  260. $objCache = new QCache('query', 'email_address_' . serialize($strConditions));
  261. if (!($strQuery = $objCache->GetData())) {
  262. // Not Found -- Go ahead and Create/Build out a new QueryBuilder object with EmailAddress-specific fields
  263. $objQueryBuilder = new QQueryBuilder($objDatabase);
  264. EmailAddress::GetSelectFields($objQueryBuilder);
  265. EmailAddress::GetFromFields($objQueryBuilder);
  266. // Ensure the Passed-in Conditions is a string
  267. try {
  268. $strConditions = QType::Cast($strConditions, QType::String);
  269. } catch (QCallerException $objExc) {
  270. $objExc->IncrementOffset();
  271. throw $objExc;
  272. }
  273. // Create the Conditions object, and apply it
  274. $objConditions = eval('return ' . $strConditions . ';');
  275. // Apply Any Conditions
  276. if ($objConditions)
  277. $objConditions->UpdateQueryBuilder($objQueryBuilder);
  278. // Get the SQL Statement
  279. $strQuery = $objQueryBuilder->GetStatement();
  280. // Save the SQL Statement in the Cache
  281. $objCache->SaveData($strQuery);
  282. }
  283. // Prepare the Statement with the Parameters
  284. if ($mixParameterArray)
  285. $strQuery = $objDatabase->PrepareStatement($strQuery, $mixParameterArray);
  286. // Perform the Query and Instantiate the Array Result
  287. $objDbResult = $objDatabase->Query($strQuery);
  288. return EmailAddress::InstantiateDbResult($objDbResult);
  289. }*/
  290. /**
  291. * Updates a QQueryBuilder with the SELECT fields for this EmailAddress
  292. * @param QQueryBuilder $objBuilder the Query Builder object to update
  293. * @param string $strPrefix optional prefix to add to the SELECT fields
  294. */
  295. public static function GetSelectFields(QQueryBuilder $objBuilder, $strPrefix = null) {
  296. if ($strPrefix) {
  297. $strTableName = $strPrefix;
  298. $strAliasPrefix = $strPrefix . '__';
  299. } else {
  300. $strTableName = 'email_address';
  301. $strAliasPrefix = '';
  302. }
  303. $objBuilder->AddSelectItem($strTableName, 'id', $strAliasPrefix . 'id');
  304. $objBuilder->AddSelectItem($strTableName, 'url', $strAliasPrefix . 'url');
  305. $objBuilder->AddSelectItem($strTableName, 'person_id', $strAliasPrefix . 'person_id');
  306. $objBuilder->AddSelectItem($strTableName, 'is_primary', $strAliasPrefix . 'is_primary');
  307. }
  308. ///////////////////////////////
  309. // INSTANTIATION-RELATED METHODS
  310. ///////////////////////////////
  311. /**
  312. * Instantiate a EmailAddress from a Database Row.
  313. * Takes in an optional strAliasPrefix, used in case another Object::InstantiateDbRow
  314. * is calling this EmailAddress::InstantiateDbRow in order to perform
  315. * early binding on referenced objects.
  316. * @param DatabaseRowBase $objDbRow
  317. * @param string $strAliasPrefix
  318. * @param string $strExpandAsArrayNodes
  319. * @param QBaseClass $objPreviousItem
  320. * @param string[] $strColumnAliasArray
  321. * @return EmailAddress
  322. */
  323. public static function InstantiateDbRow($objDbRow, $strAliasPrefix = null, $strExpandAsArrayNodes = null, $objPreviousItem = null, $strColumnAliasArray = array()) {
  324. // If blank row, return null
  325. if (!$objDbRow)
  326. return null;
  327. // Create a new instance of the EmailAddress object
  328. $objToReturn = new EmailAddress();
  329. $objToReturn->__blnRestored = true;
  330. $strAliasName = array_key_exists($strAliasPrefix . 'id', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'id'] : $strAliasPrefix . 'id';
  331. $objToReturn->intId = $objDbRow->GetColumn($strAliasName, 'Integer');
  332. $strAliasName = array_key_exists($strAliasPrefix . 'url', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'url'] : $strAliasPrefix . 'url';
  333. $objToReturn->strUrl = $objDbRow->GetColumn($strAliasName, 'VarChar');
  334. $strAliasName = array_key_exists($strAliasPrefix . 'person_id', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'person_id'] : $strAliasPrefix . 'person_id';
  335. $objToReturn->intPersonId = $objDbRow->GetColumn($strAliasName, 'Integer');
  336. $strAliasName = array_key_exists($strAliasPrefix . 'is_primary', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'is_primary'] : $strAliasPrefix . 'is_primary';
  337. $objToReturn->intIsPrimary = $objDbRow->GetColumn($strAliasName, 'Integer');
  338. // Instantiate Virtual Attributes
  339. foreach ($objDbRow->GetColumnNameArray() as $strColumnName => $mixValue) {
  340. $strVirtualPrefix = $strAliasPrefix . '__';
  341. $strVirtualPrefixLength = strlen($strVirtualPrefix);
  342. if (substr($strColumnName, 0, $strVirtualPrefixLength) == $strVirtualPrefix)
  343. $objToReturn->__strVirtualAttributeArray[substr($strColumnName, $strVirtualPrefixLength)] = $mixValue;
  344. }
  345. // Prepare to Check for Early/Virtual Binding
  346. if (!$strAliasPrefix)
  347. $strAliasPrefix = 'email_address__';
  348. // Check for Person Early Binding
  349. $strAlias = $strAliasPrefix . 'person_id__id';
  350. $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
  351. if (!is_null($objDbRow->GetColumn($strAliasName)))
  352. $objToReturn->objPerson = Person::InstantiateDbRow($objDbRow, $strAliasPrefix . 'person_id__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  353. return $objToReturn;
  354. }
  355. /**
  356. * Instantiate an array of EmailAddresses from a Database Result
  357. * @param DatabaseResultBase $objDbResult
  358. * @param string $strExpandAsArrayNodes
  359. * @param string[] $strColumnAliasArray
  360. * @return EmailAddress[]
  361. */
  362. public static function InstantiateDbResult(QDatabaseResultBase $objDbResult, $strExpandAsArrayNodes = null, $strColumnAliasArray = null) {
  363. $objToReturn = array();
  364. if (!$strColumnAliasArray)
  365. $strColumnAliasArray = array();
  366. // If blank resultset, then return empty array
  367. if (!$objDbResult)
  368. return $objToReturn;
  369. // Load up the return array with each row
  370. if ($strExpandAsArrayNodes) {
  371. $objLastRowItem = null;
  372. while ($objDbRow = $objDbResult->GetNextRow()) {
  373. $objItem = EmailAddress::InstantiateDbRow($objDbRow, null, $strExpandAsArrayNodes, $objLastRowItem, $strColumnAliasArray);
  374. if ($objItem) {
  375. $objToReturn[] = $objItem;
  376. $objLastRowItem = $objItem;
  377. }
  378. }
  379. } else {
  380. while ($objDbRow = $objDbResult->GetNextRow())
  381. $objToReturn[] = EmailAddress::InstantiateDbRow($objDbRow, null, null, null, $strColumnAliasArray);
  382. }
  383. return $objToReturn;
  384. }
  385. ///////////////////////////////////////////////////
  386. // INDEX-BASED LOAD METHODS (Single Load and Array)
  387. ///////////////////////////////////////////////////
  388. /**
  389. * Load a single EmailAddress object,
  390. * by Id Index(es)
  391. * @param integer $intId
  392. * @return EmailAddress
  393. */
  394. public static function LoadById($intId) {
  395. return EmailAddress::QuerySingle(
  396. QQ::Equal(QQN::EmailAddress()->Id, $intId)
  397. );
  398. }
  399. /**
  400. * Load an array of EmailAddress objects,
  401. * by PersonId Index(es)
  402. * @param integer $intPersonId
  403. * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  404. * @return EmailAddress[]
  405. */
  406. public static function LoadArrayByPersonId($intPersonId, $objOptionalClauses = null) {
  407. // Call EmailAddress::QueryArray to perform the LoadArrayByPersonId query
  408. try {
  409. return EmailAddress::QueryArray(
  410. QQ::Equal(QQN::EmailAddress()->PersonId, $intPersonId),
  411. $objOptionalClauses);
  412. } catch (QCallerException $objExc) {
  413. $objExc->IncrementOffset();
  414. throw $objExc;
  415. }
  416. }
  417. /**
  418. * Count EmailAddresses
  419. * by PersonId Index(es)
  420. * @param integer $intPersonId
  421. * @return int
  422. */
  423. public static function CountByPersonId($intPersonId) {
  424. // Call EmailAddress::QueryCount to perform the CountByPersonId query
  425. return EmailAddress::QueryCount(
  426. QQ::Equal(QQN::EmailAddress()->PersonId, $intPersonId)
  427. );
  428. }
  429. ////////////////////////////////////////////////////
  430. // INDEX-BASED LOAD METHODS (Array via Many to Many)
  431. ////////////////////////////////////////////////////
  432. //////////////////////////
  433. // SAVE, DELETE AND RELOAD
  434. //////////////////////////
  435. /**
  436. * Save this EmailAddress
  437. * @param bool $blnForceInsert
  438. * @param bool $blnForceUpdate
  439. * @return int
  440. */
  441. public function Save($blnForceInsert = false, $blnForceUpdate = false) {
  442. // Get the Database Object for this Class
  443. $objDatabase = EmailAddress::GetDatabase();
  444. $mixToReturn = null;
  445. try {
  446. if ((!$this->__blnRestored) || ($blnForceInsert)) {
  447. // Perform an INSERT query
  448. $objDatabase->NonQuery('
  449. INSERT INTO `email_address` (
  450. `url`,
  451. `person_id`,
  452. `is_primary`
  453. ) VALUES (
  454. ' . $objDatabase->SqlVariable($this->strUrl) . ',
  455. ' . $objDatabase->SqlVariable($this->intPersonId) . ',
  456. ' . $objDatabase->SqlVariable($this->intIsPrimary) . '
  457. )
  458. ');
  459. // Update Identity column and return its value
  460. $mixToReturn = $this->intId = $objDatabase->InsertId('email_address', 'id');
  461. } else {
  462. // Perform an UPDATE query
  463. // First checking for Optimistic Locking constraints (if applicable)
  464. // Perform the UPDATE query
  465. $objDatabase->NonQuery('
  466. UPDATE
  467. `email_address`
  468. SET
  469. `url` = ' . $objDatabase->SqlVariable($this->strUrl) . ',
  470. `person_id` = ' . $objDatabase->SqlVariable($this->intPersonId) . ',
  471. `is_primary` = ' . $objDatabase->SqlVariable($this->intIsPrimary) . '
  472. WHERE
  473. `id` = ' . $objDatabase->SqlVariable($this->intId) . '
  474. ');
  475. }
  476. } catch (QCallerException $objExc) {
  477. $objExc->IncrementOffset();
  478. throw $objExc;
  479. }
  480. // Update __blnRestored and any Non-Identity PK Columns (if applicable)
  481. $this->__blnRestored = true;
  482. // Return
  483. return $mixToReturn;
  484. }
  485. /**
  486. * Delete this EmailAddress
  487. * @return void
  488. */
  489. public function Delete() {
  490. if ((is_null($this->intId)))
  491. throw new QUndefinedPrimaryKeyException('Cannot delete this EmailAddress with an unset primary key.');
  492. // Get the Database Object for this Class
  493. $objDatabase = EmailAddress::GetDatabase();
  494. // Perform the SQL Query
  495. $objDatabase->NonQuery('
  496. DELETE FROM
  497. `email_address`
  498. WHERE
  499. `id` = ' . $objDatabase->SqlVariable($this->intId) . '');
  500. }
  501. /**
  502. * Delete all EmailAddresses
  503. * @return void
  504. */
  505. public static function DeleteAll() {
  506. // Get the Database Object for this Class
  507. $objDatabase = EmailAddress::GetDatabase();
  508. // Perform the Query
  509. $objDatabase->NonQuery('
  510. DELETE FROM
  511. `email_address`');
  512. }
  513. /**
  514. * Truncate email_address table
  515. * @return void
  516. */
  517. public static function Truncate() {
  518. // Get the Database Object for this Class
  519. $objDatabase = EmailAddress::GetDatabase();
  520. // Perform the Query
  521. $objDatabase->NonQuery('
  522. TRUNCATE `email_address`');
  523. }
  524. /**
  525. * Reload this EmailAddress from the database.
  526. * @return void
  527. */
  528. public function Reload() {
  529. // Make sure we are actually Restored from the database
  530. if (!$this->__blnRestored)
  531. throw new QCallerException('Cannot call Reload() on a new, unsaved EmailAddress object.');
  532. // Reload the Object
  533. $objReloaded = EmailAddress::Load($this->intId);
  534. // Update $this's local variables to match
  535. $this->strUrl = $objReloaded->strUrl;
  536. $this->PersonId = $objReloaded->PersonId;
  537. $this->intIsPrimary = $objReloaded->intIsPrimary;
  538. }
  539. ////////////////////
  540. // GETTORS AND SETTORS
  541. ////////////////////
  542. /**
  543. * Lookup a VirtualAttribute value (if applicable). Returns NULL if none found.
  544. * @param string $strName
  545. * @return string
  546. */
  547. public function GetVirtualAttribute($strName)
  548. {
  549. if (array_key_exists($strName, $this->__strVirtualAttributeArray))
  550. return $this->__strVirtualAttributeArray[$strName];
  551. return null;
  552. }
  553. /**
  554. * Override method to perform a property "Get"
  555. * This will get the value of $strName
  556. *
  557. * @param string $strName Name of the property to get
  558. * @return mixed
  559. */
  560. public function __get($strName)
  561. {
  562. switch ($strName)
  563. {
  564. ///////////////////
  565. // Member Variables
  566. ///////////////////
  567. case 'Id':
  568. /**
  569. * Gets the value for intId (Read-Only PK)
  570. * @return integer
  571. */
  572. return $this->intId;
  573. case 'Url':
  574. /**
  575. * Gets the value for strUrl (Not Null)
  576. * @return string
  577. */
  578. return $this->strUrl;
  579. case 'PersonId':
  580. /**
  581. * Gets the value for intPersonId (Not Null)
  582. * @return integer
  583. */
  584. return $this->intPersonId;
  585. case 'IsPrimary':
  586. /**
  587. * Gets the value for intIsPrimary
  588. * @return integer
  589. */
  590. return $this->intIsPrimary;
  591. ///////////////////
  592. // Member Objects
  593. ///////////////////
  594. case 'Person':
  595. /**
  596. * Gets the value for the Person object referenced by intPersonId (Not Null)
  597. * @return Person
  598. */
  599. try {
  600. if ((!$this->objPerson) && (!is_null($this->intPersonId)))
  601. $this->objPerson = Person::Load($this->intPersonId);
  602. return $this->objPerson;
  603. } catch (QCallerException $objExc) {
  604. $objExc->IncrementOffset();
  605. throw $objExc;
  606. }
  607. ////////////////////////////
  608. // Virtual Object References (Many to Many and Reverse References)
  609. // (If restored via a "Many-to" expansion)
  610. ////////////////////////////
  611. case '__Restored':
  612. return $this->__blnRestored;
  613. default:
  614. try {
  615. return parent::__get($strName);
  616. } catch (QCallerException $objExc) {
  617. $objExc->IncrementOffset();
  618. throw $objExc;
  619. }
  620. }
  621. }
  622. /**
  623. * Override method to perform a property "Set"
  624. * This will set the property $strName to be $mixValue
  625. *
  626. * @param string $strName Name of the property to set
  627. * @param string $mixValue New value of the property
  628. * @return mixed
  629. */
  630. public function __set($strName, $mixValue) {
  631. switch ($strName) {
  632. ///////////////////
  633. // Member Variables
  634. ///////////////////
  635. case 'Url':
  636. /**
  637. * Sets the value for strUrl (Not Null)
  638. * @param string $mixValue
  639. * @return string
  640. */
  641. try {
  642. return ($this->strUrl = QType::Cast($mixValue, QType::String));
  643. } catch (QCallerException $objExc) {
  644. $objExc->IncrementOffset();
  645. throw $objExc;
  646. }
  647. case 'PersonId':
  648. /**
  649. * Sets the value for intPersonId (Not Null)
  650. * @param integer $mixValue
  651. * @return integer
  652. */
  653. try {
  654. $this->objPerson = null;
  655. return ($this->intPersonId = QType::Cast($mixValue, QType::Integer));
  656. } catch (QCallerException $objExc) {
  657. $objExc->IncrementOffset();
  658. throw $objExc;
  659. }
  660. case 'IsPrimary':
  661. /**
  662. * Sets the value for intIsPrimary
  663. * @param integer $mixValue
  664. * @return integer
  665. */
  666. try {
  667. return ($this->intIsPrimary = QType::Cast($mixValue, QType::Integer));
  668. } catch (QCallerException $objExc) {
  669. $objExc->IncrementOffset();
  670. throw $objExc;
  671. }
  672. ///////////////////
  673. // Member Objects
  674. ///////////////////
  675. case 'Person':
  676. /**
  677. * Sets the value for the Person object referenced by intPersonId (Not Null)
  678. * @param Person $mixValue
  679. * @return Person
  680. */
  681. if (is_null($mixValue)) {
  682. $this->intPersonId = null;
  683. $this->objPerson = null;
  684. return null;
  685. } else {
  686. // Make sure $mixValue actually is a Person object
  687. try {
  688. $mixValue = QType::Cast($mixValue, 'Person');
  689. } catch (QInvalidCastException $objExc) {
  690. $objExc->IncrementOffset();
  691. throw $objExc;
  692. }
  693. // Make sure $mixValue is a SAVED Person object
  694. if (is_null($mixValue->Id))
  695. throw new QCallerException('Unable to set an unsaved Person for this EmailAddress');
  696. // Update Local Member Variables
  697. $this->objPerson = $mixValue;
  698. $this->intPersonId = $mixValue->Id;
  699. // Return $mixValue
  700. return $mixValue;
  701. }
  702. break;
  703. default:
  704. try {
  705. return parent::__set($strName, $mixValue);
  706. } catch (QCallerException $objExc) {
  707. $objExc->IncrementOffset();
  708. throw $objExc;
  709. }
  710. }
  711. }
  712. ///////////////////////////////
  713. // ASSOCIATED OBJECTS' METHODS
  714. ///////////////////////////////
  715. }
  716. /////////////////////////////////////
  717. // ADDITIONAL CLASSES for QCODO QUERY
  718. /////////////////////////////////////
  719. class QQNodeEmailAddress extends QQNode {
  720. protected $strTableName = 'email_address';
  721. protected $strPrimaryKey = 'id';
  722. protected $strClassName = 'EmailAddress';
  723. public function __get($strName) {
  724. switch ($strName) {
  725. case 'Id':
  726. return new QQNode('id', 'Id', 'integer', $this);
  727. case 'Url':
  728. return new QQNode('url', 'Url', 'string', $this);
  729. case 'PersonId':
  730. return new QQNode('person_id', 'PersonId', 'integer', $this);
  731. case 'Person':
  732. return new QQNodePerson('person_id', 'Person', 'integer', $this);
  733. case 'IsPrimary':
  734. return new QQNode('is_primary', 'IsPrimary', 'integer', $this);
  735. case '_PrimaryKeyNode':
  736. return new QQNode('id', 'Id', 'integer', $this);
  737. default:
  738. try {
  739. return parent::__get($strName);
  740. } catch (QCallerException $objExc) {
  741. $objExc->IncrementOffset();
  742. throw $objExc;
  743. }
  744. }
  745. }
  746. }
  747. class QQReverseReferenceNodeEmailAddress extends QQReverseReferenceNode {
  748. protected $strTableName = 'email_address';
  749. protected $strPrimaryKey = 'id';
  750. protected $strClassName = 'EmailAddress';
  751. public function __get($strName) {
  752. switch ($strName) {
  753. case 'Id':
  754. return new QQNode('id', 'Id', 'integer', $this);
  755. case 'Url':
  756. return new QQNode('url', 'Url', 'string', $this);
  757. case 'PersonId':
  758. return new QQNode('person_id', 'PersonId', 'integer', $this);
  759. case 'Person':
  760. return new QQNodePerson('person_id', 'Person', 'integer', $this);
  761. case 'IsPrimary':
  762. return new QQNode('is_primary', 'IsPrimary', 'integer', $this);
  763. case '_PrimaryKeyNode':
  764. return new QQNode('id', 'Id', 'integer', $this);
  765. default:
  766. try {
  767. return parent::__get($strName);
  768. } catch (QCallerException $objExc) {
  769. $objExc->IncrementOffset();
  770. throw $objExc;
  771. }
  772. }
  773. }
  774. }
  775. ?>