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.

1473 lines
61 KiB

  1. <?php
  2. /**
  3. * The abstract AddressGen 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 Address subclass which
  8. * extends this AddressGen 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 Address class.
  15. *
  16. * @package Quinta CMS
  17. * @subpackage GeneratedDataObjects
  18. * @property-read integer $Id the value for intId (Read-Only PK)
  19. * @property string $Title the value for strTitle
  20. * @property integer $PersonId the value for intPersonId (Not Null)
  21. * @property string $Street1 the value for strStreet1
  22. * @property string $Street2 the value for strStreet2
  23. * @property string $Suburb the value for strSuburb
  24. * @property string $City the value for strCity
  25. * @property string $County the value for strCounty
  26. * @property integer $ZoneId the value for intZoneId (Not Null)
  27. * @property integer $CountryId the value for intCountryId (Not Null)
  28. * @property string $PostalCode the value for strPostalCode
  29. * @property boolean $IsCurrent the value for blnIsCurrent (Not Null)
  30. * @property integer $TypeId the value for intTypeId (Not Null)
  31. * @property-read string $CreationDate the value for strCreationDate (Read-Only Timestamp)
  32. * @property-read string $LastModification the value for strLastModification (Read-Only Timestamp)
  33. * @property Person $Person the value for the Person object referenced by intPersonId (Not Null)
  34. * @property-read boolean $__Restored whether or not this object was restored from the database (as opposed to created new)
  35. */
  36. class AddressGen extends QBaseClass
  37. {
  38. ///////////////////////////////////////////////////////////////////////
  39. // PROTECTED MEMBER VARIABLES and TEXT FIELD MAXLENGTHS (if applicable)
  40. ///////////////////////////////////////////////////////////////////////
  41. /////////// Object properties ////////////
  42. /**
  43. * Protected member variable that maps to the database PK Identity column address.id
  44. * @var integer intId
  45. *
  46. */
  47. protected $intId = null;
  48. /**
  49. * Protected member variable that maps to the database column address.title
  50. * @var string strTitle
  51. *
  52. */
  53. protected $strTitle = null;
  54. const TitleMaxLength = 256;
  55. /**
  56. * Protected member variable that maps to the database column address.person_id
  57. * @var integer intPersonId
  58. *
  59. */
  60. protected $intPersonId = null;
  61. /**
  62. * Protected member variable that maps to the database column address.street_1
  63. * @var string strStreet1
  64. *
  65. */
  66. protected $strStreet1 = null;
  67. const Street1MaxLength = 256;
  68. /**
  69. * Protected member variable that maps to the database column address.street_2
  70. * @var string strStreet2
  71. *
  72. */
  73. protected $strStreet2 = null;
  74. const Street2MaxLength = 256;
  75. /**
  76. * Protected member variable that maps to the database column address.suburb
  77. * @var string strSuburb
  78. *
  79. */
  80. protected $strSuburb = null;
  81. const SuburbMaxLength = 256;
  82. /**
  83. * Protected member variable that maps to the database column address.city
  84. * @var string strCity
  85. *
  86. */
  87. protected $strCity = null;
  88. const CityMaxLength = 256;
  89. /**
  90. * Protected member variable that maps to the database column address.county
  91. * @var string strCounty
  92. *
  93. */
  94. protected $strCounty = null;
  95. const CountyMaxLength = 256;
  96. /**
  97. * Protected member variable that maps to the database column address.zone_id
  98. * @var integer intZoneId
  99. *
  100. */
  101. protected $intZoneId = null;
  102. /**
  103. * Protected member variable that maps to the database column address.country_id
  104. * @var integer intCountryId
  105. *
  106. */
  107. protected $intCountryId = null;
  108. /**
  109. * Protected member variable that maps to the database column address.postal_code
  110. * @var string strPostalCode
  111. *
  112. */
  113. protected $strPostalCode = null;
  114. const PostalCodeMaxLength = 32;
  115. /**
  116. * Protected member variable that maps to the database column address.is_current
  117. * @var boolean blnIsCurrent
  118. *
  119. */
  120. protected $blnIsCurrent = null;
  121. /**
  122. * Protected member variable that maps to the database column address.type_id
  123. * @var integer intTypeId
  124. *
  125. */
  126. protected $intTypeId = null;
  127. /**
  128. * Protected member variable that maps to the database column address.creation_date
  129. * @var string strCreationDate
  130. *
  131. */
  132. protected $strCreationDate = null;
  133. /**
  134. * Protected member variable that maps to the database column address.last_modification
  135. * @var string strLastModification
  136. *
  137. */
  138. protected $strLastModification = null;
  139. /**
  140. * Protected array of virtual attributes for this object (e.g. extra/other calculated and/or non-object bound
  141. * columns from the run-time database query result for this object). Used by InstantiateDbRow and
  142. * GetVirtualAttribute.
  143. * @var string[] $__strVirtualAttributeArray
  144. */
  145. protected $__strVirtualAttributeArray = array();
  146. /**
  147. * Protected internal member variable that specifies whether or not this object is Restored from the database.
  148. * Used by Save() to determine if Save() should perform a db UPDATE or INSERT.
  149. * @var bool __blnRestored;
  150. */
  151. protected $__blnRestored;
  152. ///////////////////////////////
  153. // PROTECTED MEMBER OBJECTS
  154. ///////////////////////////////
  155. /**
  156. * Protected member variable that contains the object pointed by the reference
  157. * in the database column address.person_id.
  158. *
  159. * NOTE: Always use the Person property getter to correctly retrieve this Person object.
  160. * (Because this class implements late binding, this variable reference MAY be null.)
  161. * @var Person objPerson
  162. */
  163. protected $objPerson;
  164. ///////////////////////////////
  165. // CLASS-WIDE LOAD AND COUNT METHODS
  166. ///////////////////////////////
  167. /**
  168. * Static method to retrieve the Database object that owns this class.
  169. * @return QDatabaseBase reference to the Database object that can query this class
  170. */
  171. public static function GetDatabase() {
  172. return QApplication::$Database[1];
  173. }
  174. /**
  175. * Load a Address from PK Info
  176. * @param integer $intId
  177. * @return Address
  178. */
  179. public static function Load($intId) {
  180. // Use QuerySingle to Perform the Query
  181. return Address::QuerySingle(
  182. QQ::Equal(QQN::Address()->Id, $intId)
  183. );
  184. }
  185. /**
  186. * Load all Addresses
  187. * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  188. * @return Address[]
  189. */
  190. public static function LoadAll($objOptionalClauses = null) {
  191. // Call Address::QueryArray to perform the LoadAll query
  192. try {
  193. return Address::QueryArray(QQ::All(), $objOptionalClauses);
  194. } catch (QCallerException $objExc) {
  195. $objExc->IncrementOffset();
  196. throw $objExc;
  197. }
  198. }
  199. /**
  200. * Count all Addresses
  201. * @return int
  202. */
  203. public static function CountAll() {
  204. // Call Address::QueryCount to perform the CountAll query
  205. return Address::QueryCount(QQ::All());
  206. }
  207. ///////////////////////////////
  208. // QCODO QUERY-RELATED METHODS
  209. ///////////////////////////////
  210. /**
  211. * Internally called method to assist with calling Qcodo Query for this class
  212. * on load methods.
  213. * @param QQueryBuilder &$objQueryBuilder the QueryBuilder object that will be created
  214. * @param QQCondition $objConditions any conditions on the query, itself
  215. * @param QQClause[] $objOptionalClausees additional optional QQClause object or array of QQClause objects for this query
  216. * @param mixed[] $mixParameterArray a array of name-value pairs to perform PrepareStatement with (sending in null will skip the PrepareStatement step)
  217. * @param boolean $blnCountOnly only select a rowcount
  218. * @return string the query statement
  219. */
  220. protected static function BuildQueryStatement(&$objQueryBuilder, QQCondition $objConditions, $objOptionalClauses, $mixParameterArray, $blnCountOnly) {
  221. // Get the Database Object for this Class
  222. $objDatabase = Address::GetDatabase();
  223. // Create/Build out the QueryBuilder object with Address-specific SELET and FROM fields
  224. $objQueryBuilder = new QQueryBuilder($objDatabase, 'address');
  225. Address::GetSelectFields($objQueryBuilder);
  226. $objQueryBuilder->AddFromItem('address');
  227. // Set "CountOnly" option (if applicable)
  228. if ($blnCountOnly)
  229. $objQueryBuilder->SetCountOnlyFlag();
  230. // Apply Any Conditions
  231. if ($objConditions)
  232. try {
  233. $objConditions->UpdateQueryBuilder($objQueryBuilder);
  234. } catch (QCallerException $objExc) {
  235. $objExc->IncrementOffset();
  236. throw $objExc;
  237. }
  238. // Iterate through all the Optional Clauses (if any) and perform accordingly
  239. if ($objOptionalClauses) {
  240. if ($objOptionalClauses instanceof QQClause)
  241. $objOptionalClauses->UpdateQueryBuilder($objQueryBuilder);
  242. else if (is_array($objOptionalClauses))
  243. foreach ($objOptionalClauses as $objClause)
  244. $objClause->UpdateQueryBuilder($objQueryBuilder);
  245. else
  246. throw new QCallerException('Optional Clauses must be a QQClause object or an array of QQClause objects');
  247. }
  248. // Get the SQL Statement
  249. $strQuery = $objQueryBuilder->GetStatement();
  250. // Prepare the Statement with the Query Parameters (if applicable)
  251. if ($mixParameterArray) {
  252. if (is_array($mixParameterArray)) {
  253. if (count($mixParameterArray))
  254. $strQuery = $objDatabase->PrepareStatement($strQuery, $mixParameterArray);
  255. // Ensure that there are no other Unresolved Named Parameters
  256. if (strpos($strQuery, chr(QQNamedValue::DelimiterCode) . '{') !== false)
  257. throw new QCallerException('Unresolved named parameters in the query');
  258. } else
  259. throw new QCallerException('Parameter Array must be an array of name-value parameter pairs');
  260. }
  261. // Return the Objects
  262. return $strQuery;
  263. }
  264. /**
  265. * Static Qcodo Query method to query for a single Address object.
  266. * Uses BuildQueryStatment to perform most of the work.
  267. * @param QQCondition $objConditions any conditions on the query, itself
  268. * @param QQClause[] $objOptionalClausees additional optional QQClause objects for this query
  269. * @param mixed[] $mixParameterArray a array of name-value pairs to perform PrepareStatement with
  270. * @return Address the queried object
  271. */
  272. public static function QuerySingle(QQCondition $objConditions, $objOptionalClauses = null, $mixParameterArray = null) {
  273. // Get the Query Statement
  274. try {
  275. $strQuery = Address::BuildQueryStatement($objQueryBuilder, $objConditions, $objOptionalClauses, $mixParameterArray, false);
  276. } catch (QCallerException $objExc) {
  277. $objExc->IncrementOffset();
  278. throw $objExc;
  279. }
  280. // Perform the Query, Get the First Row, and Instantiate a new Address object
  281. $objDbResult = $objQueryBuilder->Database->Query($strQuery);
  282. return Address::InstantiateDbRow($objDbResult->GetNextRow(), null, null, null, $objQueryBuilder->ColumnAliasArray);
  283. }
  284. /**
  285. * Static Qcodo Query method to query for an array of Address objects.
  286. * Uses BuildQueryStatment to perform most of the work.
  287. * @param QQCondition $objConditions any conditions on the query, itself
  288. * @param QQClause[] $objOptionalClausees additional optional QQClause objects for this query
  289. * @param mixed[] $mixParameterArray a array of name-value pairs to perform PrepareStatement with
  290. * @return Address[] the queried objects as an array
  291. */
  292. public static function QueryArray(QQCondition $objConditions, $objOptionalClauses = null, $mixParameterArray = null) {
  293. // Get the Query Statement
  294. try {
  295. $strQuery = Address::BuildQueryStatement($objQueryBuilder, $objConditions, $objOptionalClauses, $mixParameterArray, false);
  296. } catch (QCallerException $objExc) {
  297. $objExc->IncrementOffset();
  298. throw $objExc;
  299. }
  300. // Perform the Query and Instantiate the Array Result
  301. $objDbResult = $objQueryBuilder->Database->Query($strQuery);
  302. return Address::InstantiateDbResult($objDbResult, $objQueryBuilder->ExpandAsArrayNodes, $objQueryBuilder->ColumnAliasArray);
  303. }
  304. /**
  305. * Static Qcodo Query method to query for a count of Address objects.
  306. * Uses BuildQueryStatment to perform most of the work.
  307. * @param QQCondition $objConditions any conditions on the query, itself
  308. * @param QQClause[] $objOptionalClausees additional optional QQClause objects for this query
  309. * @param mixed[] $mixParameterArray a array of name-value pairs to perform PrepareStatement with
  310. * @return integer the count of queried objects as an integer
  311. */
  312. public static function QueryCount(QQCondition $objConditions, $objOptionalClauses = null, $mixParameterArray = null) {
  313. // Get the Query Statement
  314. try {
  315. $strQuery = Address::BuildQueryStatement($objQueryBuilder, $objConditions, $objOptionalClauses, $mixParameterArray, true);
  316. } catch (QCallerException $objExc) {
  317. $objExc->IncrementOffset();
  318. throw $objExc;
  319. }
  320. // Perform the Query and return the row_count
  321. $objDbResult = $objQueryBuilder->Database->Query($strQuery);
  322. // Figure out if the query is using GroupBy
  323. $blnGrouped = false;
  324. if ($objOptionalClauses) foreach ($objOptionalClauses as $objClause) {
  325. if ($objClause instanceof QQGroupBy) {
  326. $blnGrouped = true;
  327. break;
  328. }
  329. }
  330. if ($blnGrouped)
  331. // Groups in this query - return the count of Groups (which is the count of all rows)
  332. return $objDbResult->CountRows();
  333. else {
  334. // No Groups - return the sql-calculated count(*) value
  335. $strDbRow = $objDbResult->FetchRow();
  336. return QType::Cast($strDbRow[0], QType::Integer);
  337. }
  338. }
  339. /* public static function QueryArrayCached($strConditions, $mixParameterArray = null) {
  340. // Get the Database Object for this Class
  341. $objDatabase = Address::GetDatabase();
  342. // Lookup the QCache for This Query Statement
  343. $objCache = new QCache('query', 'address_' . serialize($strConditions));
  344. if (!($strQuery = $objCache->GetData())) {
  345. // Not Found -- Go ahead and Create/Build out a new QueryBuilder object with Address-specific fields
  346. $objQueryBuilder = new QQueryBuilder($objDatabase);
  347. Address::GetSelectFields($objQueryBuilder);
  348. Address::GetFromFields($objQueryBuilder);
  349. // Ensure the Passed-in Conditions is a string
  350. try {
  351. $strConditions = QType::Cast($strConditions, QType::String);
  352. } catch (QCallerException $objExc) {
  353. $objExc->IncrementOffset();
  354. throw $objExc;
  355. }
  356. // Create the Conditions object, and apply it
  357. $objConditions = eval('return ' . $strConditions . ';');
  358. // Apply Any Conditions
  359. if ($objConditions)
  360. $objConditions->UpdateQueryBuilder($objQueryBuilder);
  361. // Get the SQL Statement
  362. $strQuery = $objQueryBuilder->GetStatement();
  363. // Save the SQL Statement in the Cache
  364. $objCache->SaveData($strQuery);
  365. }
  366. // Prepare the Statement with the Parameters
  367. if ($mixParameterArray)
  368. $strQuery = $objDatabase->PrepareStatement($strQuery, $mixParameterArray);
  369. // Perform the Query and Instantiate the Array Result
  370. $objDbResult = $objDatabase->Query($strQuery);
  371. return Address::InstantiateDbResult($objDbResult);
  372. }*/
  373. /**
  374. * Updates a QQueryBuilder with the SELECT fields for this Address
  375. * @param QQueryBuilder $objBuilder the Query Builder object to update
  376. * @param string $strPrefix optional prefix to add to the SELECT fields
  377. */
  378. public static function GetSelectFields(QQueryBuilder $objBuilder, $strPrefix = null) {
  379. if ($strPrefix) {
  380. $strTableName = $strPrefix;
  381. $strAliasPrefix = $strPrefix . '__';
  382. } else {
  383. $strTableName = 'address';
  384. $strAliasPrefix = '';
  385. }
  386. $objBuilder->AddSelectItem($strTableName, 'id', $strAliasPrefix . 'id');
  387. $objBuilder->AddSelectItem($strTableName, 'title', $strAliasPrefix . 'title');
  388. $objBuilder->AddSelectItem($strTableName, 'person_id', $strAliasPrefix . 'person_id');
  389. $objBuilder->AddSelectItem($strTableName, 'street_1', $strAliasPrefix . 'street_1');
  390. $objBuilder->AddSelectItem($strTableName, 'street_2', $strAliasPrefix . 'street_2');
  391. $objBuilder->AddSelectItem($strTableName, 'suburb', $strAliasPrefix . 'suburb');
  392. $objBuilder->AddSelectItem($strTableName, 'city', $strAliasPrefix . 'city');
  393. $objBuilder->AddSelectItem($strTableName, 'county', $strAliasPrefix . 'county');
  394. $objBuilder->AddSelectItem($strTableName, 'zone_id', $strAliasPrefix . 'zone_id');
  395. $objBuilder->AddSelectItem($strTableName, 'country_id', $strAliasPrefix . 'country_id');
  396. $objBuilder->AddSelectItem($strTableName, 'postal_code', $strAliasPrefix . 'postal_code');
  397. $objBuilder->AddSelectItem($strTableName, 'is_current', $strAliasPrefix . 'is_current');
  398. $objBuilder->AddSelectItem($strTableName, 'type_id', $strAliasPrefix . 'type_id');
  399. $objBuilder->AddSelectItem($strTableName, 'creation_date', $strAliasPrefix . 'creation_date');
  400. $objBuilder->AddSelectItem($strTableName, 'last_modification', $strAliasPrefix . 'last_modification');
  401. }
  402. ///////////////////////////////
  403. // INSTANTIATION-RELATED METHODS
  404. ///////////////////////////////
  405. /**
  406. * Instantiate a Address from a Database Row.
  407. * Takes in an optional strAliasPrefix, used in case another Object::InstantiateDbRow
  408. * is calling this Address::InstantiateDbRow in order to perform
  409. * early binding on referenced objects.
  410. * @param DatabaseRowBase $objDbRow
  411. * @param string $strAliasPrefix
  412. * @param string $strExpandAsArrayNodes
  413. * @param QBaseClass $objPreviousItem
  414. * @param string[] $strColumnAliasArray
  415. * @return Address
  416. */
  417. public static function InstantiateDbRow($objDbRow, $strAliasPrefix = null, $strExpandAsArrayNodes = null, $objPreviousItem = null, $strColumnAliasArray = array()) {
  418. // If blank row, return null
  419. if (!$objDbRow)
  420. return null;
  421. // Create a new instance of the Address object
  422. $objToReturn = new Address();
  423. $objToReturn->__blnRestored = true;
  424. $strAliasName = array_key_exists($strAliasPrefix . 'id', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'id'] : $strAliasPrefix . 'id';
  425. $objToReturn->intId = $objDbRow->GetColumn($strAliasName, 'Integer');
  426. $strAliasName = array_key_exists($strAliasPrefix . 'title', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'title'] : $strAliasPrefix . 'title';
  427. $objToReturn->strTitle = $objDbRow->GetColumn($strAliasName, 'VarChar');
  428. $strAliasName = array_key_exists($strAliasPrefix . 'person_id', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'person_id'] : $strAliasPrefix . 'person_id';
  429. $objToReturn->intPersonId = $objDbRow->GetColumn($strAliasName, 'Integer');
  430. $strAliasName = array_key_exists($strAliasPrefix . 'street_1', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'street_1'] : $strAliasPrefix . 'street_1';
  431. $objToReturn->strStreet1 = $objDbRow->GetColumn($strAliasName, 'VarChar');
  432. $strAliasName = array_key_exists($strAliasPrefix . 'street_2', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'street_2'] : $strAliasPrefix . 'street_2';
  433. $objToReturn->strStreet2 = $objDbRow->GetColumn($strAliasName, 'VarChar');
  434. $strAliasName = array_key_exists($strAliasPrefix . 'suburb', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'suburb'] : $strAliasPrefix . 'suburb';
  435. $objToReturn->strSuburb = $objDbRow->GetColumn($strAliasName, 'VarChar');
  436. $strAliasName = array_key_exists($strAliasPrefix . 'city', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'city'] : $strAliasPrefix . 'city';
  437. $objToReturn->strCity = $objDbRow->GetColumn($strAliasName, 'VarChar');
  438. $strAliasName = array_key_exists($strAliasPrefix . 'county', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'county'] : $strAliasPrefix . 'county';
  439. $objToReturn->strCounty = $objDbRow->GetColumn($strAliasName, 'VarChar');
  440. $strAliasName = array_key_exists($strAliasPrefix . 'zone_id', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'zone_id'] : $strAliasPrefix . 'zone_id';
  441. $objToReturn->intZoneId = $objDbRow->GetColumn($strAliasName, 'Integer');
  442. $strAliasName = array_key_exists($strAliasPrefix . 'country_id', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'country_id'] : $strAliasPrefix . 'country_id';
  443. $objToReturn->intCountryId = $objDbRow->GetColumn($strAliasName, 'Integer');
  444. $strAliasName = array_key_exists($strAliasPrefix . 'postal_code', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'postal_code'] : $strAliasPrefix . 'postal_code';
  445. $objToReturn->strPostalCode = $objDbRow->GetColumn($strAliasName, 'VarChar');
  446. $strAliasName = array_key_exists($strAliasPrefix . 'is_current', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'is_current'] : $strAliasPrefix . 'is_current';
  447. $objToReturn->blnIsCurrent = $objDbRow->GetColumn($strAliasName, 'Bit');
  448. $strAliasName = array_key_exists($strAliasPrefix . 'type_id', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'type_id'] : $strAliasPrefix . 'type_id';
  449. $objToReturn->intTypeId = $objDbRow->GetColumn($strAliasName, 'Integer');
  450. $strAliasName = array_key_exists($strAliasPrefix . 'creation_date', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'creation_date'] : $strAliasPrefix . 'creation_date';
  451. $objToReturn->strCreationDate = $objDbRow->GetColumn($strAliasName, 'VarChar');
  452. $strAliasName = array_key_exists($strAliasPrefix . 'last_modification', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'last_modification'] : $strAliasPrefix . 'last_modification';
  453. $objToReturn->strLastModification = $objDbRow->GetColumn($strAliasName, 'VarChar');
  454. // Instantiate Virtual Attributes
  455. foreach ($objDbRow->GetColumnNameArray() as $strColumnName => $mixValue) {
  456. $strVirtualPrefix = $strAliasPrefix . '__';
  457. $strVirtualPrefixLength = strlen($strVirtualPrefix);
  458. if (substr($strColumnName, 0, $strVirtualPrefixLength) == $strVirtualPrefix)
  459. $objToReturn->__strVirtualAttributeArray[substr($strColumnName, $strVirtualPrefixLength)] = $mixValue;
  460. }
  461. // Prepare to Check for Early/Virtual Binding
  462. if (!$strAliasPrefix)
  463. $strAliasPrefix = 'address__';
  464. // Check for Person Early Binding
  465. $strAlias = $strAliasPrefix . 'person_id__id';
  466. $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
  467. if (!is_null($objDbRow->GetColumn($strAliasName)))
  468. $objToReturn->objPerson = Person::InstantiateDbRow($objDbRow, $strAliasPrefix . 'person_id__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  469. return $objToReturn;
  470. }
  471. /**
  472. * Instantiate an array of Addresses from a Database Result
  473. * @param DatabaseResultBase $objDbResult
  474. * @param string $strExpandAsArrayNodes
  475. * @param string[] $strColumnAliasArray
  476. * @return Address[]
  477. */
  478. public static function InstantiateDbResult(QDatabaseResultBase $objDbResult, $strExpandAsArrayNodes = null, $strColumnAliasArray = null) {
  479. $objToReturn = array();
  480. if (!$strColumnAliasArray)
  481. $strColumnAliasArray = array();
  482. // If blank resultset, then return empty array
  483. if (!$objDbResult)
  484. return $objToReturn;
  485. // Load up the return array with each row
  486. if ($strExpandAsArrayNodes) {
  487. $objLastRowItem = null;
  488. while ($objDbRow = $objDbResult->GetNextRow()) {
  489. $objItem = Address::InstantiateDbRow($objDbRow, null, $strExpandAsArrayNodes, $objLastRowItem, $strColumnAliasArray);
  490. if ($objItem) {
  491. $objToReturn[] = $objItem;
  492. $objLastRowItem = $objItem;
  493. }
  494. }
  495. } else {
  496. while ($objDbRow = $objDbResult->GetNextRow())
  497. $objToReturn[] = Address::InstantiateDbRow($objDbRow, null, null, null, $strColumnAliasArray);
  498. }
  499. return $objToReturn;
  500. }
  501. ///////////////////////////////////////////////////
  502. // INDEX-BASED LOAD METHODS (Single Load and Array)
  503. ///////////////////////////////////////////////////
  504. /**
  505. * Load a single Address object,
  506. * by Id Index(es)
  507. * @param integer $intId
  508. * @return Address
  509. */
  510. public static function LoadById($intId) {
  511. return Address::QuerySingle(
  512. QQ::Equal(QQN::Address()->Id, $intId)
  513. );
  514. }
  515. /**
  516. * Load an array of Address objects,
  517. * by TypeId Index(es)
  518. * @param integer $intTypeId
  519. * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  520. * @return Address[]
  521. */
  522. public static function LoadArrayByTypeId($intTypeId, $objOptionalClauses = null) {
  523. // Call Address::QueryArray to perform the LoadArrayByTypeId query
  524. try {
  525. return Address::QueryArray(
  526. QQ::Equal(QQN::Address()->TypeId, $intTypeId),
  527. $objOptionalClauses);
  528. } catch (QCallerException $objExc) {
  529. $objExc->IncrementOffset();
  530. throw $objExc;
  531. }
  532. }
  533. /**
  534. * Count Addresses
  535. * by TypeId Index(es)
  536. * @param integer $intTypeId
  537. * @return int
  538. */
  539. public static function CountByTypeId($intTypeId) {
  540. // Call Address::QueryCount to perform the CountByTypeId query
  541. return Address::QueryCount(
  542. QQ::Equal(QQN::Address()->TypeId, $intTypeId)
  543. );
  544. }
  545. /**
  546. * Load an array of Address objects,
  547. * by ZoneId Index(es)
  548. * @param integer $intZoneId
  549. * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  550. * @return Address[]
  551. */
  552. public static function LoadArrayByZoneId($intZoneId, $objOptionalClauses = null) {
  553. // Call Address::QueryArray to perform the LoadArrayByZoneId query
  554. try {
  555. return Address::QueryArray(
  556. QQ::Equal(QQN::Address()->ZoneId, $intZoneId),
  557. $objOptionalClauses);
  558. } catch (QCallerException $objExc) {
  559. $objExc->IncrementOffset();
  560. throw $objExc;
  561. }
  562. }
  563. /**
  564. * Count Addresses
  565. * by ZoneId Index(es)
  566. * @param integer $intZoneId
  567. * @return int
  568. */
  569. public static function CountByZoneId($intZoneId) {
  570. // Call Address::QueryCount to perform the CountByZoneId query
  571. return Address::QueryCount(
  572. QQ::Equal(QQN::Address()->ZoneId, $intZoneId)
  573. );
  574. }
  575. /**
  576. * Load an array of Address objects,
  577. * by CountryId Index(es)
  578. * @param integer $intCountryId
  579. * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  580. * @return Address[]
  581. */
  582. public static function LoadArrayByCountryId($intCountryId, $objOptionalClauses = null) {
  583. // Call Address::QueryArray to perform the LoadArrayByCountryId query
  584. try {
  585. return Address::QueryArray(
  586. QQ::Equal(QQN::Address()->CountryId, $intCountryId),
  587. $objOptionalClauses);
  588. } catch (QCallerException $objExc) {
  589. $objExc->IncrementOffset();
  590. throw $objExc;
  591. }
  592. }
  593. /**
  594. * Count Addresses
  595. * by CountryId Index(es)
  596. * @param integer $intCountryId
  597. * @return int
  598. */
  599. public static function CountByCountryId($intCountryId) {
  600. // Call Address::QueryCount to perform the CountByCountryId query
  601. return Address::QueryCount(
  602. QQ::Equal(QQN::Address()->CountryId, $intCountryId)
  603. );
  604. }
  605. /**
  606. * Load an array of Address objects,
  607. * by PersonId Index(es)
  608. * @param integer $intPersonId
  609. * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  610. * @return Address[]
  611. */
  612. public static function LoadArrayByPersonId($intPersonId, $objOptionalClauses = null) {
  613. // Call Address::QueryArray to perform the LoadArrayByPersonId query
  614. try {
  615. return Address::QueryArray(
  616. QQ::Equal(QQN::Address()->PersonId, $intPersonId),
  617. $objOptionalClauses);
  618. } catch (QCallerException $objExc) {
  619. $objExc->IncrementOffset();
  620. throw $objExc;
  621. }
  622. }
  623. /**
  624. * Count Addresses
  625. * by PersonId Index(es)
  626. * @param integer $intPersonId
  627. * @return int
  628. */
  629. public static function CountByPersonId($intPersonId) {
  630. // Call Address::QueryCount to perform the CountByPersonId query
  631. return Address::QueryCount(
  632. QQ::Equal(QQN::Address()->PersonId, $intPersonId)
  633. );
  634. }
  635. ////////////////////////////////////////////////////
  636. // INDEX-BASED LOAD METHODS (Array via Many to Many)
  637. ////////////////////////////////////////////////////
  638. //////////////////////////
  639. // SAVE, DELETE AND RELOAD
  640. //////////////////////////
  641. /**
  642. * Save this Address
  643. * @param bool $blnForceInsert
  644. * @param bool $blnForceUpdate
  645. * @return int
  646. */
  647. public function Save($blnForceInsert = false, $blnForceUpdate = false) {
  648. // Get the Database Object for this Class
  649. $objDatabase = Address::GetDatabase();
  650. $mixToReturn = null;
  651. try {
  652. if ((!$this->__blnRestored) || ($blnForceInsert)) {
  653. // Perform an INSERT query
  654. $objDatabase->NonQuery('
  655. INSERT INTO `address` (
  656. `title`,
  657. `person_id`,
  658. `street_1`,
  659. `street_2`,
  660. `suburb`,
  661. `city`,
  662. `county`,
  663. `zone_id`,
  664. `country_id`,
  665. `postal_code`,
  666. `is_current`,
  667. `type_id`
  668. ) VALUES (
  669. ' . $objDatabase->SqlVariable($this->strTitle) . ',
  670. ' . $objDatabase->SqlVariable($this->intPersonId) . ',
  671. ' . $objDatabase->SqlVariable($this->strStreet1) . ',
  672. ' . $objDatabase->SqlVariable($this->strStreet2) . ',
  673. ' . $objDatabase->SqlVariable($this->strSuburb) . ',
  674. ' . $objDatabase->SqlVariable($this->strCity) . ',
  675. ' . $objDatabase->SqlVariable($this->strCounty) . ',
  676. ' . $objDatabase->SqlVariable($this->intZoneId) . ',
  677. ' . $objDatabase->SqlVariable($this->intCountryId) . ',
  678. ' . $objDatabase->SqlVariable($this->strPostalCode) . ',
  679. ' . $objDatabase->SqlVariable($this->blnIsCurrent) . ',
  680. ' . $objDatabase->SqlVariable($this->intTypeId) . '
  681. )
  682. ');
  683. // Update Identity column and return its value
  684. $mixToReturn = $this->intId = $objDatabase->InsertId('address', 'id');
  685. } else {
  686. // Perform an UPDATE query
  687. // First checking for Optimistic Locking constraints (if applicable)
  688. if (!$blnForceUpdate) {
  689. // Perform the Optimistic Locking check
  690. $objResult = $objDatabase->Query('
  691. SELECT
  692. `creation_date`
  693. FROM
  694. `address`
  695. WHERE
  696. `id` = ' . $objDatabase->SqlVariable($this->intId) . '
  697. ');
  698. $objRow = $objResult->FetchArray();
  699. if ($objRow[0] != $this->strCreationDate)
  700. throw new QOptimisticLockingException('Address');
  701. }
  702. if (!$blnForceUpdate) {
  703. // Perform the Optimistic Locking check
  704. $objResult = $objDatabase->Query('
  705. SELECT
  706. `last_modification`
  707. FROM
  708. `address`
  709. WHERE
  710. `id` = ' . $objDatabase->SqlVariable($this->intId) . '
  711. ');
  712. $objRow = $objResult->FetchArray();
  713. if ($objRow[0] != $this->strLastModification)
  714. throw new QOptimisticLockingException('Address');
  715. }
  716. // Perform the UPDATE query
  717. $objDatabase->NonQuery('
  718. UPDATE
  719. `address`
  720. SET
  721. `title` = ' . $objDatabase->SqlVariable($this->strTitle) . ',
  722. `person_id` = ' . $objDatabase->SqlVariable($this->intPersonId) . ',
  723. `street_1` = ' . $objDatabase->SqlVariable($this->strStreet1) . ',
  724. `street_2` = ' . $objDatabase->SqlVariable($this->strStreet2) . ',
  725. `suburb` = ' . $objDatabase->SqlVariable($this->strSuburb) . ',
  726. `city` = ' . $objDatabase->SqlVariable($this->strCity) . ',
  727. `county` = ' . $objDatabase->SqlVariable($this->strCounty) . ',
  728. `zone_id` = ' . $objDatabase->SqlVariable($this->intZoneId) . ',
  729. `country_id` = ' . $objDatabase->SqlVariable($this->intCountryId) . ',
  730. `postal_code` = ' . $objDatabase->SqlVariable($this->strPostalCode) . ',
  731. `is_current` = ' . $objDatabase->SqlVariable($this->blnIsCurrent) . ',
  732. `type_id` = ' . $objDatabase->SqlVariable($this->intTypeId) . '
  733. WHERE
  734. `id` = ' . $objDatabase->SqlVariable($this->intId) . '
  735. ');
  736. }
  737. } catch (QCallerException $objExc) {
  738. $objExc->IncrementOffset();
  739. throw $objExc;
  740. }
  741. // Update __blnRestored and any Non-Identity PK Columns (if applicable)
  742. $this->__blnRestored = true;
  743. // Update Local Timestamp
  744. $objResult = $objDatabase->Query('
  745. SELECT
  746. `creation_date`
  747. FROM
  748. `address`
  749. WHERE
  750. `id` = ' . $objDatabase->SqlVariable($this->intId) . '
  751. ');
  752. $objRow = $objResult->FetchArray();
  753. $this->strCreationDate = $objRow[0];
  754. // Update Local Timestamp
  755. $objResult = $objDatabase->Query('
  756. SELECT
  757. `last_modification`
  758. FROM
  759. `address`
  760. WHERE
  761. `id` = ' . $objDatabase->SqlVariable($this->intId) . '
  762. ');
  763. $objRow = $objResult->FetchArray();
  764. $this->strLastModification = $objRow[0];
  765. // Return
  766. return $mixToReturn;
  767. }
  768. /**
  769. * Delete this Address
  770. * @return void
  771. */
  772. public function Delete() {
  773. if ((is_null($this->intId)))
  774. throw new QUndefinedPrimaryKeyException('Cannot delete this Address with an unset primary key.');
  775. // Get the Database Object for this Class
  776. $objDatabase = Address::GetDatabase();
  777. // Perform the SQL Query
  778. $objDatabase->NonQuery('
  779. DELETE FROM
  780. `address`
  781. WHERE
  782. `id` = ' . $objDatabase->SqlVariable($this->intId) . '');
  783. }
  784. /**
  785. * Delete all Addresses
  786. * @return void
  787. */
  788. public static function DeleteAll() {
  789. // Get the Database Object for this Class
  790. $objDatabase = Address::GetDatabase();
  791. // Perform the Query
  792. $objDatabase->NonQuery('
  793. DELETE FROM
  794. `address`');
  795. }
  796. /**
  797. * Truncate address table
  798. * @return void
  799. */
  800. public static function Truncate() {
  801. // Get the Database Object for this Class
  802. $objDatabase = Address::GetDatabase();
  803. // Perform the Query
  804. $objDatabase->NonQuery('
  805. TRUNCATE `address`');
  806. }
  807. /**
  808. * Reload this Address from the database.
  809. * @return void
  810. */
  811. public function Reload() {
  812. // Make sure we are actually Restored from the database
  813. if (!$this->__blnRestored)
  814. throw new QCallerException('Cannot call Reload() on a new, unsaved Address object.');
  815. // Reload the Object
  816. $objReloaded = Address::Load($this->intId);
  817. // Update $this's local variables to match
  818. $this->strTitle = $objReloaded->strTitle;
  819. $this->PersonId = $objReloaded->PersonId;
  820. $this->strStreet1 = $objReloaded->strStreet1;
  821. $this->strStreet2 = $objReloaded->strStreet2;
  822. $this->strSuburb = $objReloaded->strSuburb;
  823. $this->strCity = $objReloaded->strCity;
  824. $this->strCounty = $objReloaded->strCounty;
  825. $this->ZoneId = $objReloaded->ZoneId;
  826. $this->CountryId = $objReloaded->CountryId;
  827. $this->strPostalCode = $objReloaded->strPostalCode;
  828. $this->blnIsCurrent = $objReloaded->blnIsCurrent;
  829. $this->TypeId = $objReloaded->TypeId;
  830. $this->strCreationDate = $objReloaded->strCreationDate;
  831. $this->strLastModification = $objReloaded->strLastModification;
  832. }
  833. ////////////////////
  834. // GETTORS AND SETTORS
  835. ////////////////////
  836. /**
  837. * Lookup a VirtualAttribute value (if applicable). Returns NULL if none found.
  838. * @param string $strName
  839. * @return string
  840. */
  841. public function GetVirtualAttribute($strName)
  842. {
  843. if (array_key_exists($strName, $this->__strVirtualAttributeArray))
  844. return $this->__strVirtualAttributeArray[$strName];
  845. return null;
  846. }
  847. /**
  848. * Override method to perform a property "Get"
  849. * This will get the value of $strName
  850. *
  851. * @param string $strName Name of the property to get
  852. * @return mixed
  853. */
  854. public function __get($strName)
  855. {
  856. switch ($strName)
  857. {
  858. ///////////////////
  859. // Member Variables
  860. ///////////////////
  861. case 'Id':
  862. /**
  863. * Gets the value for intId (Read-Only PK)
  864. * @return integer
  865. */
  866. return $this->intId;
  867. case 'Title':
  868. /**
  869. * Gets the value for strTitle
  870. * @return string
  871. */
  872. return $this->strTitle;
  873. case 'PersonId':
  874. /**
  875. * Gets the value for intPersonId (Not Null)
  876. * @return integer
  877. */
  878. return $this->intPersonId;
  879. case 'Street1':
  880. /**
  881. * Gets the value for strStreet1
  882. * @return string
  883. */
  884. return $this->strStreet1;
  885. case 'Street2':
  886. /**
  887. * Gets the value for strStreet2
  888. * @return string
  889. */
  890. return $this->strStreet2;
  891. case 'Suburb':
  892. /**
  893. * Gets the value for strSuburb
  894. * @return string
  895. */
  896. return $this->strSuburb;
  897. case 'City':
  898. /**
  899. * Gets the value for strCity
  900. * @return string
  901. */
  902. return $this->strCity;
  903. case 'County':
  904. /**
  905. * Gets the value for strCounty
  906. * @return string
  907. */
  908. return $this->strCounty;
  909. case 'ZoneId':
  910. /**
  911. * Gets the value for intZoneId (Not Null)
  912. * @return integer
  913. */
  914. return $this->intZoneId;
  915. case 'CountryId':
  916. /**
  917. * Gets the value for intCountryId (Not Null)
  918. * @return integer
  919. */
  920. return $this->intCountryId;
  921. case 'PostalCode':
  922. /**
  923. * Gets the value for strPostalCode
  924. * @return string
  925. */
  926. return $this->strPostalCode;
  927. case 'IsCurrent':
  928. /**
  929. * Gets the value for blnIsCurrent (Not Null)
  930. * @return boolean
  931. */
  932. return $this->blnIsCurrent;
  933. case 'TypeId':
  934. /**
  935. * Gets the value for intTypeId (Not Null)
  936. * @return integer
  937. */
  938. return $this->intTypeId;
  939. case 'CreationDate':
  940. /**
  941. * Gets the value for strCreationDate (Read-Only Timestamp)
  942. * @return string
  943. */
  944. return $this->strCreationDate;
  945. case 'LastModification':
  946. /**
  947. * Gets the value for strLastModification (Read-Only Timestamp)
  948. * @return string
  949. */
  950. return $this->strLastModification;
  951. ///////////////////
  952. // Member Objects
  953. ///////////////////
  954. case 'Person':
  955. /**
  956. * Gets the value for the Person object referenced by intPersonId (Not Null)
  957. * @return Person
  958. */
  959. try {
  960. if ((!$this->objPerson) && (!is_null($this->intPersonId)))
  961. $this->objPerson = Person::Load($this->intPersonId);
  962. return $this->objPerson;
  963. } catch (QCallerException $objExc) {
  964. $objExc->IncrementOffset();
  965. throw $objExc;
  966. }
  967. ////////////////////////////
  968. // Virtual Object References (Many to Many and Reverse References)
  969. // (If restored via a "Many-to" expansion)
  970. ////////////////////////////
  971. case '__Restored':
  972. return $this->__blnRestored;
  973. default:
  974. try {
  975. return parent::__get($strName);
  976. } catch (QCallerException $objExc) {
  977. $objExc->IncrementOffset();
  978. throw $objExc;
  979. }
  980. }
  981. }
  982. /**
  983. * Override method to perform a property "Set"
  984. * This will set the property $strName to be $mixValue
  985. *
  986. * @param string $strName Name of the property to set
  987. * @param string $mixValue New value of the property
  988. * @return mixed
  989. */
  990. public function __set($strName, $mixValue) {
  991. switch ($strName) {
  992. ///////////////////
  993. // Member Variables
  994. ///////////////////
  995. case 'Title':
  996. /**
  997. * Sets the value for strTitle
  998. * @param string $mixValue
  999. * @return string
  1000. */
  1001. try {
  1002. return ($this->strTitle = QType::Cast($mixValue, QType::String));
  1003. } catch (QCallerException $objExc) {
  1004. $objExc->IncrementOffset();
  1005. throw $objExc;
  1006. }
  1007. case 'PersonId':
  1008. /**
  1009. * Sets the value for intPersonId (Not Null)
  1010. * @param integer $mixValue
  1011. * @return integer
  1012. */
  1013. try {
  1014. $this->objPerson = null;
  1015. return ($this->intPersonId = QType::Cast($mixValue, QType::Integer));
  1016. } catch (QCallerException $objExc) {
  1017. $objExc->IncrementOffset();
  1018. throw $objExc;
  1019. }
  1020. case 'Street1':
  1021. /**
  1022. * Sets the value for strStreet1
  1023. * @param string $mixValue
  1024. * @return string
  1025. */
  1026. try {
  1027. return ($this->strStreet1 = QType::Cast($mixValue, QType::String));
  1028. } catch (QCallerException $objExc) {
  1029. $objExc->IncrementOffset();
  1030. throw $objExc;
  1031. }
  1032. case 'Street2':
  1033. /**
  1034. * Sets the value for strStreet2
  1035. * @param string $mixValue
  1036. * @return string
  1037. */
  1038. try {
  1039. return ($this->strStreet2 = QType::Cast($mixValue, QType::String));
  1040. } catch (QCallerException $objExc) {
  1041. $objExc->IncrementOffset();
  1042. throw $objExc;
  1043. }
  1044. case 'Suburb':
  1045. /**
  1046. * Sets the value for strSuburb
  1047. * @param string $mixValue
  1048. * @return string
  1049. */
  1050. try {
  1051. return ($this->strSuburb = QType::Cast($mixValue, QType::String));
  1052. } catch (QCallerException $objExc) {
  1053. $objExc->IncrementOffset();
  1054. throw $objExc;
  1055. }
  1056. case 'City':
  1057. /**
  1058. * Sets the value for strCity
  1059. * @param string $mixValue
  1060. * @return string
  1061. */
  1062. try {
  1063. return ($this->strCity = QType::Cast($mixValue, QType::String));
  1064. } catch (QCallerException $objExc) {
  1065. $objExc->IncrementOffset();
  1066. throw $objExc;
  1067. }
  1068. case 'County':
  1069. /**
  1070. * Sets the value for strCounty
  1071. * @param string $mixValue
  1072. * @return string
  1073. */
  1074. try {
  1075. return ($this->strCounty = QType::Cast($mixValue, QType::String));
  1076. } catch (QCallerException $objExc) {
  1077. $objExc->IncrementOffset();
  1078. throw $objExc;
  1079. }
  1080. case 'ZoneId':
  1081. /**
  1082. * Sets the value for intZoneId (Not Null)
  1083. * @param integer $mixValue
  1084. * @return integer
  1085. */
  1086. try {
  1087. return ($this->intZoneId = QType::Cast($mixValue, QType::Integer));
  1088. } catch (QCallerException $objExc) {
  1089. $objExc->IncrementOffset();
  1090. throw $objExc;
  1091. }
  1092. case 'CountryId':
  1093. /**
  1094. * Sets the value for intCountryId (Not Null)
  1095. * @param integer $mixValue
  1096. * @return integer
  1097. */
  1098. try {
  1099. return ($this->intCountryId = QType::Cast($mixValue, QType::Integer));
  1100. } catch (QCallerException $objExc) {
  1101. $objExc->IncrementOffset();
  1102. throw $objExc;
  1103. }
  1104. case 'PostalCode':
  1105. /**
  1106. * Sets the value for strPostalCode
  1107. * @param string $mixValue
  1108. * @return string
  1109. */
  1110. try {
  1111. return ($this->strPostalCode = QType::Cast($mixValue, QType::String));
  1112. } catch (QCallerException $objExc) {
  1113. $objExc->IncrementOffset();
  1114. throw $objExc;
  1115. }
  1116. case 'IsCurrent':
  1117. /**
  1118. * Sets the value for blnIsCurrent (Not Null)
  1119. * @param boolean $mixValue
  1120. * @return boolean
  1121. */
  1122. try {
  1123. return ($this->blnIsCurrent = QType::Cast($mixValue, QType::Boolean));
  1124. } catch (QCallerException $objExc) {
  1125. $objExc->IncrementOffset();
  1126. throw $objExc;
  1127. }
  1128. case 'TypeId':
  1129. /**
  1130. * Sets the value for intTypeId (Not Null)
  1131. * @param integer $mixValue
  1132. * @return integer
  1133. */
  1134. try {
  1135. return ($this->intTypeId = QType::Cast($mixValue, QType::Integer));
  1136. } catch (QCallerException $objExc) {
  1137. $objExc->IncrementOffset();
  1138. throw $objExc;
  1139. }
  1140. ///////////////////
  1141. // Member Objects
  1142. ///////////////////
  1143. case 'Person':
  1144. /**
  1145. * Sets the value for the Person object referenced by intPersonId (Not Null)
  1146. * @param Person $mixValue
  1147. * @return Person
  1148. */
  1149. if (is_null($mixValue)) {
  1150. $this->intPersonId = null;
  1151. $this->objPerson = null;
  1152. return null;
  1153. } else {
  1154. // Make sure $mixValue actually is a Person object
  1155. try {
  1156. $mixValue = QType::Cast($mixValue, 'Person');
  1157. } catch (QInvalidCastException $objExc) {
  1158. $objExc->IncrementOffset();
  1159. throw $objExc;
  1160. }
  1161. // Make sure $mixValue is a SAVED Person object
  1162. if (is_null($mixValue->Id))
  1163. throw new QCallerException('Unable to set an unsaved Person for this Address');
  1164. // Update Local Member Variables
  1165. $this->objPerson = $mixValue;
  1166. $this->intPersonId = $mixValue->Id;
  1167. // Return $mixValue
  1168. return $mixValue;
  1169. }
  1170. break;
  1171. default:
  1172. try {
  1173. return parent::__set($strName, $mixValue);
  1174. } catch (QCallerException $objExc) {
  1175. $objExc->IncrementOffset();
  1176. throw $objExc;
  1177. }
  1178. }
  1179. }
  1180. ///////////////////////////////
  1181. // ASSOCIATED OBJECTS' METHODS
  1182. ///////////////////////////////
  1183. }
  1184. /////////////////////////////////////
  1185. // ADDITIONAL CLASSES for QCODO QUERY
  1186. /////////////////////////////////////
  1187. class QQNodeAddress extends QQNode {
  1188. protected $strTableName = 'address';
  1189. protected $strPrimaryKey = 'id';
  1190. protected $strClassName = 'Address';
  1191. public function __get($strName) {
  1192. switch ($strName) {
  1193. case 'Id':
  1194. return new QQNode('id', 'Id', 'integer', $this);
  1195. case 'Title':
  1196. return new QQNode('title', 'Title', 'string', $this);
  1197. case 'PersonId':
  1198. return new QQNode('person_id', 'PersonId', 'integer', $this);
  1199. case 'Person':
  1200. return new QQNodePerson('person_id', 'Person', 'integer', $this);
  1201. case 'Street1':
  1202. return new QQNode('street_1', 'Street1', 'string', $this);
  1203. case 'Street2':
  1204. return new QQNode('street_2', 'Street2', 'string', $this);
  1205. case 'Suburb':
  1206. return new QQNode('suburb', 'Suburb', 'string', $this);
  1207. case 'City':
  1208. return new QQNode('city', 'City', 'string', $this);
  1209. case 'County':
  1210. return new QQNode('county', 'County', 'string', $this);
  1211. case 'ZoneId':
  1212. return new QQNode('zone_id', 'ZoneId', 'integer', $this);
  1213. case 'CountryId':
  1214. return new QQNode('country_id', 'CountryId', 'integer', $this);
  1215. case 'PostalCode':
  1216. return new QQNode('postal_code', 'PostalCode', 'string', $this);
  1217. case 'IsCurrent':
  1218. return new QQNode('is_current', 'IsCurrent', 'boolean', $this);
  1219. case 'TypeId':
  1220. return new QQNode('type_id', 'TypeId', 'integer', $this);
  1221. case 'CreationDate':
  1222. return new QQNode('creation_date', 'CreationDate', 'string', $this);
  1223. case 'LastModification':
  1224. return new QQNode('last_modification', 'LastModification', 'string', $this);
  1225. case '_PrimaryKeyNode':
  1226. return new QQNode('id', 'Id', 'integer', $this);
  1227. default:
  1228. try {
  1229. return parent::__get($strName);
  1230. } catch (QCallerException $objExc) {
  1231. $objExc->IncrementOffset();
  1232. throw $objExc;
  1233. }
  1234. }
  1235. }
  1236. }
  1237. class QQReverseReferenceNodeAddress extends QQReverseReferenceNode {
  1238. protected $strTableName = 'address';
  1239. protected $strPrimaryKey = 'id';
  1240. protected $strClassName = 'Address';
  1241. public function __get($strName) {
  1242. switch ($strName) {
  1243. case 'Id':
  1244. return new QQNode('id', 'Id', 'integer', $this);
  1245. case 'Title':
  1246. return new QQNode('title', 'Title', 'string', $this);
  1247. case 'PersonId':
  1248. return new QQNode('person_id', 'PersonId', 'integer', $this);
  1249. case 'Person':
  1250. return new QQNodePerson('person_id', 'Person', 'integer', $this);
  1251. case 'Street1':
  1252. return new QQNode('street_1', 'Street1', 'string', $this);
  1253. case 'Street2':
  1254. return new QQNode('street_2', 'Street2', 'string', $this);
  1255. case 'Suburb':
  1256. return new QQNode('suburb', 'Suburb', 'string', $this);
  1257. case 'City':
  1258. return new QQNode('city', 'City', 'string', $this);
  1259. case 'County':
  1260. return new QQNode('county', 'County', 'string', $this);
  1261. case 'ZoneId':
  1262. return new QQNode('zone_id', 'ZoneId', 'integer', $this);
  1263. case 'CountryId':
  1264. return new QQNode('country_id', 'CountryId', 'integer', $this);
  1265. case 'PostalCode':
  1266. return new QQNode('postal_code', 'PostalCode', 'string', $this);
  1267. case 'IsCurrent':
  1268. return new QQNode('is_current', 'IsCurrent', 'boolean', $this);
  1269. case 'TypeId':
  1270. return new QQNode('type_id', 'TypeId', 'integer', $this);
  1271. case 'CreationDate':
  1272. return new QQNode('creation_date', 'CreationDate', 'string', $this);
  1273. case 'LastModification':
  1274. return new QQNode('last_modification', 'LastModification', 'string', $this);
  1275. case '_PrimaryKeyNode':
  1276. return new QQNode('id', 'Id', 'integer', $this);
  1277. default:
  1278. try {
  1279. return parent::__get($strName);
  1280. } catch (QCallerException $objExc) {
  1281. $objExc->IncrementOffset();
  1282. throw $objExc;
  1283. }
  1284. }
  1285. }
  1286. }
  1287. ?>