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.

3127 lines
137 KiB

  1. <?php
  2. /**
  3. * The abstract PersonGen 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 Person subclass which
  8. * extends this PersonGen 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 Person class.
  15. *
  16. * @package Quinta CMS
  17. * @subpackage GeneratedDataObjects
  18. * @property-read integer $Id the value for intId (Read-Only PK)
  19. * @property string $NamePrefix the value for strNamePrefix
  20. * @property string $FirstName the value for strFirstName (Not Null)
  21. * @property string $MiddleName the value for strMiddleName
  22. * @property string $LastName the value for strLastName (Not Null)
  23. * @property string $NameSuffix the value for strNameSuffix
  24. * @property string $NickName the value for strNickName
  25. * @property string $AvatarUri the value for strAvatarUri
  26. * @property string $CompanyName the value for strCompanyName
  27. * @property integer $OwnerPersonId the value for intOwnerPersonId
  28. * @property boolean $IsVirtual the value for blnIsVirtual
  29. * @property Person $OwnerPerson the value for the Person object referenced by intOwnerPersonId
  30. * @property Account $Account the value for the Account object that uniquely references this Person
  31. * @property-read Usergroup $_Usergroup the value for the private _objUsergroup (Read-Only) if set due to an expansion on the person_usergroup_assn association table
  32. * @property-read Usergroup[] $_UsergroupArray the value for the private _objUsergroupArray (Read-Only) if set due to an ExpandAsArray on the person_usergroup_assn association table
  33. * @property-read Address $_Address the value for the private _objAddress (Read-Only) if set due to an expansion on the address.person_id reverse relationship
  34. * @property-read Address[] $_AddressArray the value for the private _objAddressArray (Read-Only) if set due to an ExpandAsArray on the address.person_id reverse relationship
  35. * @property-read ContentItem $_ContentItemAsCreator the value for the private _objContentItemAsCreator (Read-Only) if set due to an expansion on the content_item.creator_id reverse relationship
  36. * @property-read ContentItem[] $_ContentItemAsCreatorArray the value for the private _objContentItemAsCreatorArray (Read-Only) if set due to an ExpandAsArray on the content_item.creator_id reverse relationship
  37. * @property-read EmailAddress $_EmailAddress the value for the private _objEmailAddress (Read-Only) if set due to an expansion on the email_address.person_id reverse relationship
  38. * @property-read EmailAddress[] $_EmailAddressArray the value for the private _objEmailAddressArray (Read-Only) if set due to an ExpandAsArray on the email_address.person_id reverse relationship
  39. * @property-read Person $_PersonAsOwner the value for the private _objPersonAsOwner (Read-Only) if set due to an expansion on the person.owner_person_id reverse relationship
  40. * @property-read Person[] $_PersonAsOwnerArray the value for the private _objPersonAsOwnerArray (Read-Only) if set due to an ExpandAsArray on the person.owner_person_id reverse relationship
  41. * @property-read PhoneNumber $_PhoneNumber the value for the private _objPhoneNumber (Read-Only) if set due to an expansion on the phone_number.person_id reverse relationship
  42. * @property-read PhoneNumber[] $_PhoneNumberArray the value for the private _objPhoneNumberArray (Read-Only) if set due to an ExpandAsArray on the phone_number.person_id reverse relationship
  43. * @property-read Product $_ProductAsManufacturer the value for the private _objProductAsManufacturer (Read-Only) if set due to an expansion on the product.manufacturer_id reverse relationship
  44. * @property-read Product[] $_ProductAsManufacturerArray the value for the private _objProductAsManufacturerArray (Read-Only) if set due to an ExpandAsArray on the product.manufacturer_id reverse relationship
  45. * @property-read Product $_ProductAsSupplier the value for the private _objProductAsSupplier (Read-Only) if set due to an expansion on the product.supplier_id reverse relationship
  46. * @property-read Product[] $_ProductAsSupplierArray the value for the private _objProductAsSupplierArray (Read-Only) if set due to an ExpandAsArray on the product.supplier_id reverse relationship
  47. * @property-read boolean $__Restored whether or not this object was restored from the database (as opposed to created new)
  48. */
  49. class PersonGen extends QBaseClass
  50. {
  51. ///////////////////////////////////////////////////////////////////////
  52. // PROTECTED MEMBER VARIABLES and TEXT FIELD MAXLENGTHS (if applicable)
  53. ///////////////////////////////////////////////////////////////////////
  54. /////////// Object properties ////////////
  55. /**
  56. * Protected member variable that maps to the database PK Identity column person.id
  57. * @var integer intId
  58. *
  59. */
  60. protected $intId = null;
  61. /**
  62. * Protected member variable that maps to the database column person.name_prefix
  63. * @var string strNamePrefix
  64. *
  65. */
  66. protected $strNamePrefix = null;
  67. const NamePrefixMaxLength = 32;
  68. /**
  69. * Protected member variable that maps to the database column person.first_name
  70. * @var string strFirstName
  71. *
  72. */
  73. protected $strFirstName = null;
  74. const FirstNameMaxLength = 256;
  75. /**
  76. * Protected member variable that maps to the database column person.middle_name
  77. * @var string strMiddleName
  78. *
  79. */
  80. protected $strMiddleName = null;
  81. const MiddleNameMaxLength = 128;
  82. /**
  83. * Protected member variable that maps to the database column person.last_name
  84. * @var string strLastName
  85. *
  86. */
  87. protected $strLastName = null;
  88. const LastNameMaxLength = 256;
  89. /**
  90. * Protected member variable that maps to the database column person.name_suffix
  91. * @var string strNameSuffix
  92. *
  93. */
  94. protected $strNameSuffix = null;
  95. const NameSuffixMaxLength = 32;
  96. /**
  97. * Protected member variable that maps to the database column person.nick_name
  98. * @var string strNickName
  99. *
  100. */
  101. protected $strNickName = null;
  102. const NickNameMaxLength = 128;
  103. /**
  104. * Protected member variable that maps to the database column person.avatar_uri
  105. * @var string strAvatarUri
  106. *
  107. */
  108. protected $strAvatarUri = null;
  109. const AvatarUriMaxLength = 256;
  110. /**
  111. * Protected member variable that maps to the database column person.company_name
  112. * @var string strCompanyName
  113. *
  114. */
  115. protected $strCompanyName = null;
  116. const CompanyNameMaxLength = 256;
  117. /**
  118. * Protected member variable that maps to the database column person.owner_person_id
  119. * @var integer intOwnerPersonId
  120. *
  121. */
  122. protected $intOwnerPersonId = null;
  123. /**
  124. * Protected member variable that maps to the database column person.is_virtual
  125. * @var boolean blnIsVirtual
  126. *
  127. */
  128. protected $blnIsVirtual = null;
  129. /**
  130. * Private member variable that stores a reference to a single Usergroup object
  131. * (of type Usergroup), if this Person object was restored with
  132. * an expansion on the person_usergroup_assn association table.
  133. * @var Usergroup _objUsergroup;
  134. */
  135. private $_objUsergroup;
  136. /**
  137. * Private member variable that stores a reference to an array of Usergroup objects
  138. * (of type Usergroup[]), if this Person object was restored with
  139. * an ExpandAsArray on the person_usergroup_assn association table.
  140. * @var Usergroup[] _objUsergroupArray;
  141. */
  142. private $_objUsergroupArray = array();
  143. /**
  144. * Private member variable that stores a reference to a single Address object
  145. * (of type Address), if this Person object was restored with
  146. * an expansion on the address association table.
  147. * @var Address _objAddress;
  148. */
  149. private $_objAddress;
  150. /**
  151. * Private member variable that stores a reference to an array of Address objects
  152. * (of type Address[]), if this Person object was restored with
  153. * an ExpandAsArray on the address association table.
  154. * @var Address[] _objAddressArray;
  155. */
  156. private $_objAddressArray = array();
  157. /**
  158. * Private member variable that stores a reference to a single ContentItemAsCreator object
  159. * (of type ContentItem), if this Person object was restored with
  160. * an expansion on the content_item association table.
  161. * @var ContentItem _objContentItemAsCreator;
  162. */
  163. private $_objContentItemAsCreator;
  164. /**
  165. * Private member variable that stores a reference to an array of ContentItemAsCreator objects
  166. * (of type ContentItem[]), if this Person object was restored with
  167. * an ExpandAsArray on the content_item association table.
  168. * @var ContentItem[] _objContentItemAsCreatorArray;
  169. */
  170. private $_objContentItemAsCreatorArray = array();
  171. /**
  172. * Private member variable that stores a reference to a single EmailAddress object
  173. * (of type EmailAddress), if this Person object was restored with
  174. * an expansion on the email_address association table.
  175. * @var EmailAddress _objEmailAddress;
  176. */
  177. private $_objEmailAddress;
  178. /**
  179. * Private member variable that stores a reference to an array of EmailAddress objects
  180. * (of type EmailAddress[]), if this Person object was restored with
  181. * an ExpandAsArray on the email_address association table.
  182. * @var EmailAddress[] _objEmailAddressArray;
  183. */
  184. private $_objEmailAddressArray = array();
  185. /**
  186. * Private member variable that stores a reference to a single PersonAsOwner object
  187. * (of type Person), if this Person object was restored with
  188. * an expansion on the person association table.
  189. * @var Person _objPersonAsOwner;
  190. */
  191. private $_objPersonAsOwner;
  192. /**
  193. * Private member variable that stores a reference to an array of PersonAsOwner objects
  194. * (of type Person[]), if this Person object was restored with
  195. * an ExpandAsArray on the person association table.
  196. * @var Person[] _objPersonAsOwnerArray;
  197. */
  198. private $_objPersonAsOwnerArray = array();
  199. /**
  200. * Private member variable that stores a reference to a single PhoneNumber object
  201. * (of type PhoneNumber), if this Person object was restored with
  202. * an expansion on the phone_number association table.
  203. * @var PhoneNumber _objPhoneNumber;
  204. */
  205. private $_objPhoneNumber;
  206. /**
  207. * Private member variable that stores a reference to an array of PhoneNumber objects
  208. * (of type PhoneNumber[]), if this Person object was restored with
  209. * an ExpandAsArray on the phone_number association table.
  210. * @var PhoneNumber[] _objPhoneNumberArray;
  211. */
  212. private $_objPhoneNumberArray = array();
  213. /**
  214. * Private member variable that stores a reference to a single ProductAsManufacturer object
  215. * (of type Product), if this Person object was restored with
  216. * an expansion on the product association table.
  217. * @var Product _objProductAsManufacturer;
  218. */
  219. private $_objProductAsManufacturer;
  220. /**
  221. * Private member variable that stores a reference to an array of ProductAsManufacturer objects
  222. * (of type Product[]), if this Person object was restored with
  223. * an ExpandAsArray on the product association table.
  224. * @var Product[] _objProductAsManufacturerArray;
  225. */
  226. private $_objProductAsManufacturerArray = array();
  227. /**
  228. * Private member variable that stores a reference to a single ProductAsSupplier object
  229. * (of type Product), if this Person object was restored with
  230. * an expansion on the product association table.
  231. * @var Product _objProductAsSupplier;
  232. */
  233. private $_objProductAsSupplier;
  234. /**
  235. * Private member variable that stores a reference to an array of ProductAsSupplier objects
  236. * (of type Product[]), if this Person object was restored with
  237. * an ExpandAsArray on the product association table.
  238. * @var Product[] _objProductAsSupplierArray;
  239. */
  240. private $_objProductAsSupplierArray = array();
  241. /**
  242. * Protected array of virtual attributes for this object (e.g. extra/other calculated and/or non-object bound
  243. * columns from the run-time database query result for this object). Used by InstantiateDbRow and
  244. * GetVirtualAttribute.
  245. * @var string[] $__strVirtualAttributeArray
  246. */
  247. protected $__strVirtualAttributeArray = array();
  248. /**
  249. * Protected internal member variable that specifies whether or not this object is Restored from the database.
  250. * Used by Save() to determine if Save() should perform a db UPDATE or INSERT.
  251. * @var bool __blnRestored;
  252. */
  253. protected $__blnRestored;
  254. ///////////////////////////////
  255. // PROTECTED MEMBER OBJECTS
  256. ///////////////////////////////
  257. /**
  258. * Protected member variable that contains the object pointed by the reference
  259. * in the database column person.owner_person_id.
  260. *
  261. * NOTE: Always use the OwnerPerson property getter to correctly retrieve this Person object.
  262. * (Because this class implements late binding, this variable reference MAY be null.)
  263. * @var Person objOwnerPerson
  264. */
  265. protected $objOwnerPerson;
  266. /**
  267. * Protected member variable that contains the object which points to
  268. * this object by the reference in the unique database column account.person_id.
  269. *
  270. * NOTE: Always use the Account property getter to correctly retrieve this Account object.
  271. * (Because this class implements late binding, this variable reference MAY be null.)
  272. * @var Account objAccount
  273. */
  274. protected $objAccount;
  275. /**
  276. * Used internally to manage whether the adjoined Account object
  277. * needs to be updated on save.
  278. *
  279. * NOTE: Do not manually update this value
  280. */
  281. protected $blnDirtyAccount;
  282. ///////////////////////////////
  283. // CLASS-WIDE LOAD AND COUNT METHODS
  284. ///////////////////////////////
  285. /**
  286. * Static method to retrieve the Database object that owns this class.
  287. * @return QDatabaseBase reference to the Database object that can query this class
  288. */
  289. public static function GetDatabase() {
  290. return QApplication::$Database[1];
  291. }
  292. /**
  293. * Load a Person from PK Info
  294. * @param integer $intId
  295. * @return Person
  296. */
  297. public static function Load($intId) {
  298. // Use QuerySingle to Perform the Query
  299. return Person::QuerySingle(
  300. QQ::Equal(QQN::Person()->Id, $intId)
  301. );
  302. }
  303. /**
  304. * Load all People
  305. * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  306. * @return Person[]
  307. */
  308. public static function LoadAll($objOptionalClauses = null) {
  309. // Call Person::QueryArray to perform the LoadAll query
  310. try {
  311. return Person::QueryArray(QQ::All(), $objOptionalClauses);
  312. } catch (QCallerException $objExc) {
  313. $objExc->IncrementOffset();
  314. throw $objExc;
  315. }
  316. }
  317. /**
  318. * Count all People
  319. * @return int
  320. */
  321. public static function CountAll() {
  322. // Call Person::QueryCount to perform the CountAll query
  323. return Person::QueryCount(QQ::All());
  324. }
  325. ///////////////////////////////
  326. // QCODO QUERY-RELATED METHODS
  327. ///////////////////////////////
  328. /**
  329. * Internally called method to assist with calling Qcodo Query for this class
  330. * on load methods.
  331. * @param QQueryBuilder &$objQueryBuilder the QueryBuilder object that will be created
  332. * @param QQCondition $objConditions any conditions on the query, itself
  333. * @param QQClause[] $objOptionalClausees additional optional QQClause object or array of QQClause objects for this query
  334. * @param mixed[] $mixParameterArray a array of name-value pairs to perform PrepareStatement with (sending in null will skip the PrepareStatement step)
  335. * @param boolean $blnCountOnly only select a rowcount
  336. * @return string the query statement
  337. */
  338. protected static function BuildQueryStatement(&$objQueryBuilder, QQCondition $objConditions, $objOptionalClauses, $mixParameterArray, $blnCountOnly) {
  339. // Get the Database Object for this Class
  340. $objDatabase = Person::GetDatabase();
  341. // Create/Build out the QueryBuilder object with Person-specific SELET and FROM fields
  342. $objQueryBuilder = new QQueryBuilder($objDatabase, 'person');
  343. Person::GetSelectFields($objQueryBuilder);
  344. $objQueryBuilder->AddFromItem('person');
  345. // Set "CountOnly" option (if applicable)
  346. if ($blnCountOnly)
  347. $objQueryBuilder->SetCountOnlyFlag();
  348. // Apply Any Conditions
  349. if ($objConditions)
  350. try {
  351. $objConditions->UpdateQueryBuilder($objQueryBuilder);
  352. } catch (QCallerException $objExc) {
  353. $objExc->IncrementOffset();
  354. throw $objExc;
  355. }
  356. // Iterate through all the Optional Clauses (if any) and perform accordingly
  357. if ($objOptionalClauses) {
  358. if ($objOptionalClauses instanceof QQClause)
  359. $objOptionalClauses->UpdateQueryBuilder($objQueryBuilder);
  360. else if (is_array($objOptionalClauses))
  361. foreach ($objOptionalClauses as $objClause)
  362. $objClause->UpdateQueryBuilder($objQueryBuilder);
  363. else
  364. throw new QCallerException('Optional Clauses must be a QQClause object or an array of QQClause objects');
  365. }
  366. // Get the SQL Statement
  367. $strQuery = $objQueryBuilder->GetStatement();
  368. // Prepare the Statement with the Query Parameters (if applicable)
  369. if ($mixParameterArray) {
  370. if (is_array($mixParameterArray)) {
  371. if (count($mixParameterArray))
  372. $strQuery = $objDatabase->PrepareStatement($strQuery, $mixParameterArray);
  373. // Ensure that there are no other Unresolved Named Parameters
  374. if (strpos($strQuery, chr(QQNamedValue::DelimiterCode) . '{') !== false)
  375. throw new QCallerException('Unresolved named parameters in the query');
  376. } else
  377. throw new QCallerException('Parameter Array must be an array of name-value parameter pairs');
  378. }
  379. // Return the Objects
  380. return $strQuery;
  381. }
  382. /**
  383. * Static Qcodo Query method to query for a single Person object.
  384. * Uses BuildQueryStatment to perform most of the work.
  385. * @param QQCondition $objConditions any conditions on the query, itself
  386. * @param QQClause[] $objOptionalClausees additional optional QQClause objects for this query
  387. * @param mixed[] $mixParameterArray a array of name-value pairs to perform PrepareStatement with
  388. * @return Person the queried object
  389. */
  390. public static function QuerySingle(QQCondition $objConditions, $objOptionalClauses = null, $mixParameterArray = null) {
  391. // Get the Query Statement
  392. try {
  393. $strQuery = Person::BuildQueryStatement($objQueryBuilder, $objConditions, $objOptionalClauses, $mixParameterArray, false);
  394. } catch (QCallerException $objExc) {
  395. $objExc->IncrementOffset();
  396. throw $objExc;
  397. }
  398. // Perform the Query, Get the First Row, and Instantiate a new Person object
  399. $objDbResult = $objQueryBuilder->Database->Query($strQuery);
  400. return Person::InstantiateDbRow($objDbResult->GetNextRow(), null, null, null, $objQueryBuilder->ColumnAliasArray);
  401. }
  402. /**
  403. * Static Qcodo Query method to query for an array of Person objects.
  404. * Uses BuildQueryStatment to perform most of the work.
  405. * @param QQCondition $objConditions any conditions on the query, itself
  406. * @param QQClause[] $objOptionalClausees additional optional QQClause objects for this query
  407. * @param mixed[] $mixParameterArray a array of name-value pairs to perform PrepareStatement with
  408. * @return Person[] the queried objects as an array
  409. */
  410. public static function QueryArray(QQCondition $objConditions, $objOptionalClauses = null, $mixParameterArray = null) {
  411. // Get the Query Statement
  412. try {
  413. $strQuery = Person::BuildQueryStatement($objQueryBuilder, $objConditions, $objOptionalClauses, $mixParameterArray, false);
  414. } catch (QCallerException $objExc) {
  415. $objExc->IncrementOffset();
  416. throw $objExc;
  417. }
  418. // Perform the Query and Instantiate the Array Result
  419. $objDbResult = $objQueryBuilder->Database->Query($strQuery);
  420. return Person::InstantiateDbResult($objDbResult, $objQueryBuilder->ExpandAsArrayNodes, $objQueryBuilder->ColumnAliasArray);
  421. }
  422. /**
  423. * Static Qcodo Query method to query for a count of Person objects.
  424. * Uses BuildQueryStatment to perform most of the work.
  425. * @param QQCondition $objConditions any conditions on the query, itself
  426. * @param QQClause[] $objOptionalClausees additional optional QQClause objects for this query
  427. * @param mixed[] $mixParameterArray a array of name-value pairs to perform PrepareStatement with
  428. * @return integer the count of queried objects as an integer
  429. */
  430. public static function QueryCount(QQCondition $objConditions, $objOptionalClauses = null, $mixParameterArray = null) {
  431. // Get the Query Statement
  432. try {
  433. $strQuery = Person::BuildQueryStatement($objQueryBuilder, $objConditions, $objOptionalClauses, $mixParameterArray, true);
  434. } catch (QCallerException $objExc) {
  435. $objExc->IncrementOffset();
  436. throw $objExc;
  437. }
  438. // Perform the Query and return the row_count
  439. $objDbResult = $objQueryBuilder->Database->Query($strQuery);
  440. // Figure out if the query is using GroupBy
  441. $blnGrouped = false;
  442. if ($objOptionalClauses) foreach ($objOptionalClauses as $objClause) {
  443. if ($objClause instanceof QQGroupBy) {
  444. $blnGrouped = true;
  445. break;
  446. }
  447. }
  448. if ($blnGrouped)
  449. // Groups in this query - return the count of Groups (which is the count of all rows)
  450. return $objDbResult->CountRows();
  451. else {
  452. // No Groups - return the sql-calculated count(*) value
  453. $strDbRow = $objDbResult->FetchRow();
  454. return QType::Cast($strDbRow[0], QType::Integer);
  455. }
  456. }
  457. /* public static function QueryArrayCached($strConditions, $mixParameterArray = null) {
  458. // Get the Database Object for this Class
  459. $objDatabase = Person::GetDatabase();
  460. // Lookup the QCache for This Query Statement
  461. $objCache = new QCache('query', 'person_' . serialize($strConditions));
  462. if (!($strQuery = $objCache->GetData())) {
  463. // Not Found -- Go ahead and Create/Build out a new QueryBuilder object with Person-specific fields
  464. $objQueryBuilder = new QQueryBuilder($objDatabase);
  465. Person::GetSelectFields($objQueryBuilder);
  466. Person::GetFromFields($objQueryBuilder);
  467. // Ensure the Passed-in Conditions is a string
  468. try {
  469. $strConditions = QType::Cast($strConditions, QType::String);
  470. } catch (QCallerException $objExc) {
  471. $objExc->IncrementOffset();
  472. throw $objExc;
  473. }
  474. // Create the Conditions object, and apply it
  475. $objConditions = eval('return ' . $strConditions . ';');
  476. // Apply Any Conditions
  477. if ($objConditions)
  478. $objConditions->UpdateQueryBuilder($objQueryBuilder);
  479. // Get the SQL Statement
  480. $strQuery = $objQueryBuilder->GetStatement();
  481. // Save the SQL Statement in the Cache
  482. $objCache->SaveData($strQuery);
  483. }
  484. // Prepare the Statement with the Parameters
  485. if ($mixParameterArray)
  486. $strQuery = $objDatabase->PrepareStatement($strQuery, $mixParameterArray);
  487. // Perform the Query and Instantiate the Array Result
  488. $objDbResult = $objDatabase->Query($strQuery);
  489. return Person::InstantiateDbResult($objDbResult);
  490. }*/
  491. /**
  492. * Updates a QQueryBuilder with the SELECT fields for this Person
  493. * @param QQueryBuilder $objBuilder the Query Builder object to update
  494. * @param string $strPrefix optional prefix to add to the SELECT fields
  495. */
  496. public static function GetSelectFields(QQueryBuilder $objBuilder, $strPrefix = null) {
  497. if ($strPrefix) {
  498. $strTableName = $strPrefix;
  499. $strAliasPrefix = $strPrefix . '__';
  500. } else {
  501. $strTableName = 'person';
  502. $strAliasPrefix = '';
  503. }
  504. $objBuilder->AddSelectItem($strTableName, 'id', $strAliasPrefix . 'id');
  505. $objBuilder->AddSelectItem($strTableName, 'name_prefix', $strAliasPrefix . 'name_prefix');
  506. $objBuilder->AddSelectItem($strTableName, 'first_name', $strAliasPrefix . 'first_name');
  507. $objBuilder->AddSelectItem($strTableName, 'middle_name', $strAliasPrefix . 'middle_name');
  508. $objBuilder->AddSelectItem($strTableName, 'last_name', $strAliasPrefix . 'last_name');
  509. $objBuilder->AddSelectItem($strTableName, 'name_suffix', $strAliasPrefix . 'name_suffix');
  510. $objBuilder->AddSelectItem($strTableName, 'nick_name', $strAliasPrefix . 'nick_name');
  511. $objBuilder->AddSelectItem($strTableName, 'avatar_uri', $strAliasPrefix . 'avatar_uri');
  512. $objBuilder->AddSelectItem($strTableName, 'company_name', $strAliasPrefix . 'company_name');
  513. $objBuilder->AddSelectItem($strTableName, 'owner_person_id', $strAliasPrefix . 'owner_person_id');
  514. $objBuilder->AddSelectItem($strTableName, 'is_virtual', $strAliasPrefix . 'is_virtual');
  515. }
  516. ///////////////////////////////
  517. // INSTANTIATION-RELATED METHODS
  518. ///////////////////////////////
  519. /**
  520. * Instantiate a Person from a Database Row.
  521. * Takes in an optional strAliasPrefix, used in case another Object::InstantiateDbRow
  522. * is calling this Person::InstantiateDbRow in order to perform
  523. * early binding on referenced objects.
  524. * @param DatabaseRowBase $objDbRow
  525. * @param string $strAliasPrefix
  526. * @param string $strExpandAsArrayNodes
  527. * @param QBaseClass $objPreviousItem
  528. * @param string[] $strColumnAliasArray
  529. * @return Person
  530. */
  531. public static function InstantiateDbRow($objDbRow, $strAliasPrefix = null, $strExpandAsArrayNodes = null, $objPreviousItem = null, $strColumnAliasArray = array()) {
  532. // If blank row, return null
  533. if (!$objDbRow)
  534. return null;
  535. // See if we're doing an array expansion on the previous item
  536. $strAlias = $strAliasPrefix . 'id';
  537. $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
  538. if (($strExpandAsArrayNodes) && ($objPreviousItem) &&
  539. ($objPreviousItem->intId == $objDbRow->GetColumn($strAliasName, 'Integer'))) {
  540. // We are. Now, prepare to check for ExpandAsArray clauses
  541. $blnExpandedViaArray = false;
  542. if (!$strAliasPrefix)
  543. $strAliasPrefix = 'person__';
  544. $strAlias = $strAliasPrefix . 'usergroup__usergroup_id__id';
  545. $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
  546. if ((array_key_exists($strAlias, $strExpandAsArrayNodes)) &&
  547. (!is_null($objDbRow->GetColumn($strAliasName)))) {
  548. if ($intPreviousChildItemCount = count($objPreviousItem->_objUsergroupArray)) {
  549. $objPreviousChildItem = $objPreviousItem->_objUsergroupArray[$intPreviousChildItemCount - 1];
  550. $objChildItem = Usergroup::InstantiateDbRow($objDbRow, $strAliasPrefix . 'usergroup__usergroup_id__', $strExpandAsArrayNodes, $objPreviousChildItem, $strColumnAliasArray);
  551. if ($objChildItem)
  552. $objPreviousItem->_objUsergroupArray[] = $objChildItem;
  553. } else
  554. $objPreviousItem->_objUsergroupArray[] = Usergroup::InstantiateDbRow($objDbRow, $strAliasPrefix . 'usergroup__usergroup_id__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  555. $blnExpandedViaArray = true;
  556. }
  557. $strAlias = $strAliasPrefix . 'address__id';
  558. $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
  559. if ((array_key_exists($strAlias, $strExpandAsArrayNodes)) &&
  560. (!is_null($objDbRow->GetColumn($strAliasName)))) {
  561. if ($intPreviousChildItemCount = count($objPreviousItem->_objAddressArray)) {
  562. $objPreviousChildItem = $objPreviousItem->_objAddressArray[$intPreviousChildItemCount - 1];
  563. $objChildItem = Address::InstantiateDbRow($objDbRow, $strAliasPrefix . 'address__', $strExpandAsArrayNodes, $objPreviousChildItem, $strColumnAliasArray);
  564. if ($objChildItem)
  565. $objPreviousItem->_objAddressArray[] = $objChildItem;
  566. } else
  567. $objPreviousItem->_objAddressArray[] = Address::InstantiateDbRow($objDbRow, $strAliasPrefix . 'address__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  568. $blnExpandedViaArray = true;
  569. }
  570. $strAlias = $strAliasPrefix . 'contentitemascreator__id';
  571. $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
  572. if ((array_key_exists($strAlias, $strExpandAsArrayNodes)) &&
  573. (!is_null($objDbRow->GetColumn($strAliasName)))) {
  574. if ($intPreviousChildItemCount = count($objPreviousItem->_objContentItemAsCreatorArray)) {
  575. $objPreviousChildItem = $objPreviousItem->_objContentItemAsCreatorArray[$intPreviousChildItemCount - 1];
  576. $objChildItem = ContentItem::InstantiateDbRow($objDbRow, $strAliasPrefix . 'contentitemascreator__', $strExpandAsArrayNodes, $objPreviousChildItem, $strColumnAliasArray);
  577. if ($objChildItem)
  578. $objPreviousItem->_objContentItemAsCreatorArray[] = $objChildItem;
  579. } else
  580. $objPreviousItem->_objContentItemAsCreatorArray[] = ContentItem::InstantiateDbRow($objDbRow, $strAliasPrefix . 'contentitemascreator__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  581. $blnExpandedViaArray = true;
  582. }
  583. $strAlias = $strAliasPrefix . 'emailaddress__id';
  584. $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
  585. if ((array_key_exists($strAlias, $strExpandAsArrayNodes)) &&
  586. (!is_null($objDbRow->GetColumn($strAliasName)))) {
  587. if ($intPreviousChildItemCount = count($objPreviousItem->_objEmailAddressArray)) {
  588. $objPreviousChildItem = $objPreviousItem->_objEmailAddressArray[$intPreviousChildItemCount - 1];
  589. $objChildItem = EmailAddress::InstantiateDbRow($objDbRow, $strAliasPrefix . 'emailaddress__', $strExpandAsArrayNodes, $objPreviousChildItem, $strColumnAliasArray);
  590. if ($objChildItem)
  591. $objPreviousItem->_objEmailAddressArray[] = $objChildItem;
  592. } else
  593. $objPreviousItem->_objEmailAddressArray[] = EmailAddress::InstantiateDbRow($objDbRow, $strAliasPrefix . 'emailaddress__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  594. $blnExpandedViaArray = true;
  595. }
  596. $strAlias = $strAliasPrefix . 'personasowner__id';
  597. $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
  598. if ((array_key_exists($strAlias, $strExpandAsArrayNodes)) &&
  599. (!is_null($objDbRow->GetColumn($strAliasName)))) {
  600. if ($intPreviousChildItemCount = count($objPreviousItem->_objPersonAsOwnerArray)) {
  601. $objPreviousChildItem = $objPreviousItem->_objPersonAsOwnerArray[$intPreviousChildItemCount - 1];
  602. $objChildItem = Person::InstantiateDbRow($objDbRow, $strAliasPrefix . 'personasowner__', $strExpandAsArrayNodes, $objPreviousChildItem, $strColumnAliasArray);
  603. if ($objChildItem)
  604. $objPreviousItem->_objPersonAsOwnerArray[] = $objChildItem;
  605. } else
  606. $objPreviousItem->_objPersonAsOwnerArray[] = Person::InstantiateDbRow($objDbRow, $strAliasPrefix . 'personasowner__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  607. $blnExpandedViaArray = true;
  608. }
  609. $strAlias = $strAliasPrefix . 'phonenumber__id';
  610. $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
  611. if ((array_key_exists($strAlias, $strExpandAsArrayNodes)) &&
  612. (!is_null($objDbRow->GetColumn($strAliasName)))) {
  613. if ($intPreviousChildItemCount = count($objPreviousItem->_objPhoneNumberArray)) {
  614. $objPreviousChildItem = $objPreviousItem->_objPhoneNumberArray[$intPreviousChildItemCount - 1];
  615. $objChildItem = PhoneNumber::InstantiateDbRow($objDbRow, $strAliasPrefix . 'phonenumber__', $strExpandAsArrayNodes, $objPreviousChildItem, $strColumnAliasArray);
  616. if ($objChildItem)
  617. $objPreviousItem->_objPhoneNumberArray[] = $objChildItem;
  618. } else
  619. $objPreviousItem->_objPhoneNumberArray[] = PhoneNumber::InstantiateDbRow($objDbRow, $strAliasPrefix . 'phonenumber__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  620. $blnExpandedViaArray = true;
  621. }
  622. $strAlias = $strAliasPrefix . 'productasmanufacturer__id';
  623. $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
  624. if ((array_key_exists($strAlias, $strExpandAsArrayNodes)) &&
  625. (!is_null($objDbRow->GetColumn($strAliasName)))) {
  626. if ($intPreviousChildItemCount = count($objPreviousItem->_objProductAsManufacturerArray)) {
  627. $objPreviousChildItem = $objPreviousItem->_objProductAsManufacturerArray[$intPreviousChildItemCount - 1];
  628. $objChildItem = Product::InstantiateDbRow($objDbRow, $strAliasPrefix . 'productasmanufacturer__', $strExpandAsArrayNodes, $objPreviousChildItem, $strColumnAliasArray);
  629. if ($objChildItem)
  630. $objPreviousItem->_objProductAsManufacturerArray[] = $objChildItem;
  631. } else
  632. $objPreviousItem->_objProductAsManufacturerArray[] = Product::InstantiateDbRow($objDbRow, $strAliasPrefix . 'productasmanufacturer__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  633. $blnExpandedViaArray = true;
  634. }
  635. $strAlias = $strAliasPrefix . 'productassupplier__id';
  636. $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
  637. if ((array_key_exists($strAlias, $strExpandAsArrayNodes)) &&
  638. (!is_null($objDbRow->GetColumn($strAliasName)))) {
  639. if ($intPreviousChildItemCount = count($objPreviousItem->_objProductAsSupplierArray)) {
  640. $objPreviousChildItem = $objPreviousItem->_objProductAsSupplierArray[$intPreviousChildItemCount - 1];
  641. $objChildItem = Product::InstantiateDbRow($objDbRow, $strAliasPrefix . 'productassupplier__', $strExpandAsArrayNodes, $objPreviousChildItem, $strColumnAliasArray);
  642. if ($objChildItem)
  643. $objPreviousItem->_objProductAsSupplierArray[] = $objChildItem;
  644. } else
  645. $objPreviousItem->_objProductAsSupplierArray[] = Product::InstantiateDbRow($objDbRow, $strAliasPrefix . 'productassupplier__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  646. $blnExpandedViaArray = true;
  647. }
  648. // Either return false to signal array expansion, or check-to-reset the Alias prefix and move on
  649. if ($blnExpandedViaArray)
  650. return false;
  651. else if ($strAliasPrefix == 'person__')
  652. $strAliasPrefix = null;
  653. }
  654. // Create a new instance of the Person object
  655. $objToReturn = new Person();
  656. $objToReturn->__blnRestored = true;
  657. $strAliasName = array_key_exists($strAliasPrefix . 'id', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'id'] : $strAliasPrefix . 'id';
  658. $objToReturn->intId = $objDbRow->GetColumn($strAliasName, 'Integer');
  659. $strAliasName = array_key_exists($strAliasPrefix . 'name_prefix', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'name_prefix'] : $strAliasPrefix . 'name_prefix';
  660. $objToReturn->strNamePrefix = $objDbRow->GetColumn($strAliasName, 'VarChar');
  661. $strAliasName = array_key_exists($strAliasPrefix . 'first_name', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'first_name'] : $strAliasPrefix . 'first_name';
  662. $objToReturn->strFirstName = $objDbRow->GetColumn($strAliasName, 'VarChar');
  663. $strAliasName = array_key_exists($strAliasPrefix . 'middle_name', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'middle_name'] : $strAliasPrefix . 'middle_name';
  664. $objToReturn->strMiddleName = $objDbRow->GetColumn($strAliasName, 'VarChar');
  665. $strAliasName = array_key_exists($strAliasPrefix . 'last_name', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'last_name'] : $strAliasPrefix . 'last_name';
  666. $objToReturn->strLastName = $objDbRow->GetColumn($strAliasName, 'VarChar');
  667. $strAliasName = array_key_exists($strAliasPrefix . 'name_suffix', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'name_suffix'] : $strAliasPrefix . 'name_suffix';
  668. $objToReturn->strNameSuffix = $objDbRow->GetColumn($strAliasName, 'VarChar');
  669. $strAliasName = array_key_exists($strAliasPrefix . 'nick_name', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'nick_name'] : $strAliasPrefix . 'nick_name';
  670. $objToReturn->strNickName = $objDbRow->GetColumn($strAliasName, 'VarChar');
  671. $strAliasName = array_key_exists($strAliasPrefix . 'avatar_uri', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'avatar_uri'] : $strAliasPrefix . 'avatar_uri';
  672. $objToReturn->strAvatarUri = $objDbRow->GetColumn($strAliasName, 'VarChar');
  673. $strAliasName = array_key_exists($strAliasPrefix . 'company_name', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'company_name'] : $strAliasPrefix . 'company_name';
  674. $objToReturn->strCompanyName = $objDbRow->GetColumn($strAliasName, 'VarChar');
  675. $strAliasName = array_key_exists($strAliasPrefix . 'owner_person_id', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'owner_person_id'] : $strAliasPrefix . 'owner_person_id';
  676. $objToReturn->intOwnerPersonId = $objDbRow->GetColumn($strAliasName, 'Integer');
  677. $strAliasName = array_key_exists($strAliasPrefix . 'is_virtual', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'is_virtual'] : $strAliasPrefix . 'is_virtual';
  678. $objToReturn->blnIsVirtual = $objDbRow->GetColumn($strAliasName, 'Bit');
  679. // Instantiate Virtual Attributes
  680. foreach ($objDbRow->GetColumnNameArray() as $strColumnName => $mixValue) {
  681. $strVirtualPrefix = $strAliasPrefix . '__';
  682. $strVirtualPrefixLength = strlen($strVirtualPrefix);
  683. if (substr($strColumnName, 0, $strVirtualPrefixLength) == $strVirtualPrefix)
  684. $objToReturn->__strVirtualAttributeArray[substr($strColumnName, $strVirtualPrefixLength)] = $mixValue;
  685. }
  686. // Prepare to Check for Early/Virtual Binding
  687. if (!$strAliasPrefix)
  688. $strAliasPrefix = 'person__';
  689. // Check for OwnerPerson Early Binding
  690. $strAlias = $strAliasPrefix . 'owner_person_id__id';
  691. $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
  692. if (!is_null($objDbRow->GetColumn($strAliasName)))
  693. $objToReturn->objOwnerPerson = Person::InstantiateDbRow($objDbRow, $strAliasPrefix . 'owner_person_id__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  694. // Check for Account Unique ReverseReference Binding
  695. $strAlias = $strAliasPrefix . 'account__id';
  696. $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
  697. if ($objDbRow->ColumnExists($strAliasName)) {
  698. if (!is_null($objDbRow->GetColumn($strAliasName)))
  699. $objToReturn->objAccount = Account::InstantiateDbRow($objDbRow, $strAliasPrefix . 'account__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  700. else
  701. // We ATTEMPTED to do an Early Bind but the Object Doesn't Exist
  702. // Let's set to FALSE so that the object knows not to try and re-query again
  703. $objToReturn->objAccount = false;
  704. }
  705. // Check for Usergroup Virtual Binding
  706. $strAlias = $strAliasPrefix . 'usergroup__usergroup_id__id';
  707. $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
  708. if (!is_null($objDbRow->GetColumn($strAliasName))) {
  709. if (($strExpandAsArrayNodes) && (array_key_exists($strAlias, $strExpandAsArrayNodes)))
  710. $objToReturn->_objUsergroupArray[] = Usergroup::InstantiateDbRow($objDbRow, $strAliasPrefix . 'usergroup__usergroup_id__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  711. else
  712. $objToReturn->_objUsergroup = Usergroup::InstantiateDbRow($objDbRow, $strAliasPrefix . 'usergroup__usergroup_id__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  713. }
  714. // Check for Address Virtual Binding
  715. $strAlias = $strAliasPrefix . 'address__id';
  716. $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
  717. if (!is_null($objDbRow->GetColumn($strAliasName))) {
  718. if (($strExpandAsArrayNodes) && (array_key_exists($strAlias, $strExpandAsArrayNodes)))
  719. $objToReturn->_objAddressArray[] = Address::InstantiateDbRow($objDbRow, $strAliasPrefix . 'address__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  720. else
  721. $objToReturn->_objAddress = Address::InstantiateDbRow($objDbRow, $strAliasPrefix . 'address__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  722. }
  723. // Check for ContentItemAsCreator Virtual Binding
  724. $strAlias = $strAliasPrefix . 'contentitemascreator__id';
  725. $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
  726. if (!is_null($objDbRow->GetColumn($strAliasName))) {
  727. if (($strExpandAsArrayNodes) && (array_key_exists($strAlias, $strExpandAsArrayNodes)))
  728. $objToReturn->_objContentItemAsCreatorArray[] = ContentItem::InstantiateDbRow($objDbRow, $strAliasPrefix . 'contentitemascreator__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  729. else
  730. $objToReturn->_objContentItemAsCreator = ContentItem::InstantiateDbRow($objDbRow, $strAliasPrefix . 'contentitemascreator__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  731. }
  732. // Check for EmailAddress Virtual Binding
  733. $strAlias = $strAliasPrefix . 'emailaddress__id';
  734. $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
  735. if (!is_null($objDbRow->GetColumn($strAliasName))) {
  736. if (($strExpandAsArrayNodes) && (array_key_exists($strAlias, $strExpandAsArrayNodes)))
  737. $objToReturn->_objEmailAddressArray[] = EmailAddress::InstantiateDbRow($objDbRow, $strAliasPrefix . 'emailaddress__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  738. else
  739. $objToReturn->_objEmailAddress = EmailAddress::InstantiateDbRow($objDbRow, $strAliasPrefix . 'emailaddress__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  740. }
  741. // Check for PersonAsOwner Virtual Binding
  742. $strAlias = $strAliasPrefix . 'personasowner__id';
  743. $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
  744. if (!is_null($objDbRow->GetColumn($strAliasName))) {
  745. if (($strExpandAsArrayNodes) && (array_key_exists($strAlias, $strExpandAsArrayNodes)))
  746. $objToReturn->_objPersonAsOwnerArray[] = Person::InstantiateDbRow($objDbRow, $strAliasPrefix . 'personasowner__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  747. else
  748. $objToReturn->_objPersonAsOwner = Person::InstantiateDbRow($objDbRow, $strAliasPrefix . 'personasowner__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  749. }
  750. // Check for PhoneNumber Virtual Binding
  751. $strAlias = $strAliasPrefix . 'phonenumber__id';
  752. $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
  753. if (!is_null($objDbRow->GetColumn($strAliasName))) {
  754. if (($strExpandAsArrayNodes) && (array_key_exists($strAlias, $strExpandAsArrayNodes)))
  755. $objToReturn->_objPhoneNumberArray[] = PhoneNumber::InstantiateDbRow($objDbRow, $strAliasPrefix . 'phonenumber__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  756. else
  757. $objToReturn->_objPhoneNumber = PhoneNumber::InstantiateDbRow($objDbRow, $strAliasPrefix . 'phonenumber__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  758. }
  759. // Check for ProductAsManufacturer Virtual Binding
  760. $strAlias = $strAliasPrefix . 'productasmanufacturer__id';
  761. $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
  762. if (!is_null($objDbRow->GetColumn($strAliasName))) {
  763. if (($strExpandAsArrayNodes) && (array_key_exists($strAlias, $strExpandAsArrayNodes)))
  764. $objToReturn->_objProductAsManufacturerArray[] = Product::InstantiateDbRow($objDbRow, $strAliasPrefix . 'productasmanufacturer__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  765. else
  766. $objToReturn->_objProductAsManufacturer = Product::InstantiateDbRow($objDbRow, $strAliasPrefix . 'productasmanufacturer__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  767. }
  768. // Check for ProductAsSupplier Virtual Binding
  769. $strAlias = $strAliasPrefix . 'productassupplier__id';
  770. $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
  771. if (!is_null($objDbRow->GetColumn($strAliasName))) {
  772. if (($strExpandAsArrayNodes) && (array_key_exists($strAlias, $strExpandAsArrayNodes)))
  773. $objToReturn->_objProductAsSupplierArray[] = Product::InstantiateDbRow($objDbRow, $strAliasPrefix . 'productassupplier__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  774. else
  775. $objToReturn->_objProductAsSupplier = Product::InstantiateDbRow($objDbRow, $strAliasPrefix . 'productassupplier__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  776. }
  777. return $objToReturn;
  778. }
  779. /**
  780. * Instantiate an array of People from a Database Result
  781. * @param DatabaseResultBase $objDbResult
  782. * @param string $strExpandAsArrayNodes
  783. * @param string[] $strColumnAliasArray
  784. * @return Person[]
  785. */
  786. public static function InstantiateDbResult(QDatabaseResultBase $objDbResult, $strExpandAsArrayNodes = null, $strColumnAliasArray = null) {
  787. $objToReturn = array();
  788. if (!$strColumnAliasArray)
  789. $strColumnAliasArray = array();
  790. // If blank resultset, then return empty array
  791. if (!$objDbResult)
  792. return $objToReturn;
  793. // Load up the return array with each row
  794. if ($strExpandAsArrayNodes) {
  795. $objLastRowItem = null;
  796. while ($objDbRow = $objDbResult->GetNextRow()) {
  797. $objItem = Person::InstantiateDbRow($objDbRow, null, $strExpandAsArrayNodes, $objLastRowItem, $strColumnAliasArray);
  798. if ($objItem) {
  799. $objToReturn[] = $objItem;
  800. $objLastRowItem = $objItem;
  801. }
  802. }
  803. } else {
  804. while ($objDbRow = $objDbResult->GetNextRow())
  805. $objToReturn[] = Person::InstantiateDbRow($objDbRow, null, null, null, $strColumnAliasArray);
  806. }
  807. return $objToReturn;
  808. }
  809. ///////////////////////////////////////////////////
  810. // INDEX-BASED LOAD METHODS (Single Load and Array)
  811. ///////////////////////////////////////////////////
  812. /**
  813. * Load a single Person object,
  814. * by Id Index(es)
  815. * @param integer $intId
  816. * @return Person
  817. */
  818. public static function LoadById($intId) {
  819. return Person::QuerySingle(
  820. QQ::Equal(QQN::Person()->Id, $intId)
  821. );
  822. }
  823. /**
  824. * Load an array of Person objects,
  825. * by FirstName Index(es)
  826. * @param string $strFirstName
  827. * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  828. * @return Person[]
  829. */
  830. public static function LoadArrayByFirstName($strFirstName, $objOptionalClauses = null) {
  831. // Call Person::QueryArray to perform the LoadArrayByFirstName query
  832. try {
  833. return Person::QueryArray(
  834. QQ::Equal(QQN::Person()->FirstName, $strFirstName),
  835. $objOptionalClauses);
  836. } catch (QCallerException $objExc) {
  837. $objExc->IncrementOffset();
  838. throw $objExc;
  839. }
  840. }
  841. /**
  842. * Count People
  843. * by FirstName Index(es)
  844. * @param string $strFirstName
  845. * @return int
  846. */
  847. public static function CountByFirstName($strFirstName) {
  848. // Call Person::QueryCount to perform the CountByFirstName query
  849. return Person::QueryCount(
  850. QQ::Equal(QQN::Person()->FirstName, $strFirstName)
  851. );
  852. }
  853. /**
  854. * Load an array of Person objects,
  855. * by LastName Index(es)
  856. * @param string $strLastName
  857. * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  858. * @return Person[]
  859. */
  860. public static function LoadArrayByLastName($strLastName, $objOptionalClauses = null) {
  861. // Call Person::QueryArray to perform the LoadArrayByLastName query
  862. try {
  863. return Person::QueryArray(
  864. QQ::Equal(QQN::Person()->LastName, $strLastName),
  865. $objOptionalClauses);
  866. } catch (QCallerException $objExc) {
  867. $objExc->IncrementOffset();
  868. throw $objExc;
  869. }
  870. }
  871. /**
  872. * Count People
  873. * by LastName Index(es)
  874. * @param string $strLastName
  875. * @return int
  876. */
  877. public static function CountByLastName($strLastName) {
  878. // Call Person::QueryCount to perform the CountByLastName query
  879. return Person::QueryCount(
  880. QQ::Equal(QQN::Person()->LastName, $strLastName)
  881. );
  882. }
  883. /**
  884. * Load an array of Person objects,
  885. * by OwnerPersonId Index(es)
  886. * @param integer $intOwnerPersonId
  887. * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  888. * @return Person[]
  889. */
  890. public static function LoadArrayByOwnerPersonId($intOwnerPersonId, $objOptionalClauses = null) {
  891. // Call Person::QueryArray to perform the LoadArrayByOwnerPersonId query
  892. try {
  893. return Person::QueryArray(
  894. QQ::Equal(QQN::Person()->OwnerPersonId, $intOwnerPersonId),
  895. $objOptionalClauses);
  896. } catch (QCallerException $objExc) {
  897. $objExc->IncrementOffset();
  898. throw $objExc;
  899. }
  900. }
  901. /**
  902. * Count People
  903. * by OwnerPersonId Index(es)
  904. * @param integer $intOwnerPersonId
  905. * @return int
  906. */
  907. public static function CountByOwnerPersonId($intOwnerPersonId) {
  908. // Call Person::QueryCount to perform the CountByOwnerPersonId query
  909. return Person::QueryCount(
  910. QQ::Equal(QQN::Person()->OwnerPersonId, $intOwnerPersonId)
  911. );
  912. }
  913. ////////////////////////////////////////////////////
  914. // INDEX-BASED LOAD METHODS (Array via Many to Many)
  915. ////////////////////////////////////////////////////
  916. /**
  917. * Load an array of Usergroup objects for a given Usergroup
  918. * via the person_usergroup_assn table
  919. * @param integer $intUsergroupId
  920. * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  921. * @return Person[]
  922. */
  923. public static function LoadArrayByUsergroup($intUsergroupId, $objOptionalClauses = null) {
  924. // Call Person::QueryArray to perform the LoadArrayByUsergroup query
  925. try {
  926. return Person::QueryArray(
  927. QQ::Equal(QQN::Person()->Usergroup->UsergroupId, $intUsergroupId),
  928. $objOptionalClauses
  929. );
  930. } catch (QCallerException $objExc) {
  931. $objExc->IncrementOffset();
  932. throw $objExc;
  933. }
  934. }
  935. /**
  936. * Count People for a given Usergroup
  937. * via the person_usergroup_assn table
  938. * @param integer $intUsergroupId
  939. * @return int
  940. */
  941. public static function CountByUsergroup($intUsergroupId) {
  942. return Person::QueryCount(
  943. QQ::Equal(QQN::Person()->Usergroup->UsergroupId, $intUsergroupId)
  944. );
  945. }
  946. //////////////////////////
  947. // SAVE, DELETE AND RELOAD
  948. //////////////////////////
  949. /**
  950. * Save this Person
  951. * @param bool $blnForceInsert
  952. * @param bool $blnForceUpdate
  953. * @return int
  954. */
  955. public function Save($blnForceInsert = false, $blnForceUpdate = false) {
  956. // Get the Database Object for this Class
  957. $objDatabase = Person::GetDatabase();
  958. $mixToReturn = null;
  959. try {
  960. if ((!$this->__blnRestored) || ($blnForceInsert)) {
  961. // Perform an INSERT query
  962. $objDatabase->NonQuery('
  963. INSERT INTO `person` (
  964. `name_prefix`,
  965. `first_name`,
  966. `middle_name`,
  967. `last_name`,
  968. `name_suffix`,
  969. `nick_name`,
  970. `avatar_uri`,
  971. `company_name`,
  972. `owner_person_id`,
  973. `is_virtual`
  974. ) VALUES (
  975. ' . $objDatabase->SqlVariable($this->strNamePrefix) . ',
  976. ' . $objDatabase->SqlVariable($this->strFirstName) . ',
  977. ' . $objDatabase->SqlVariable($this->strMiddleName) . ',
  978. ' . $objDatabase->SqlVariable($this->strLastName) . ',
  979. ' . $objDatabase->SqlVariable($this->strNameSuffix) . ',
  980. ' . $objDatabase->SqlVariable($this->strNickName) . ',
  981. ' . $objDatabase->SqlVariable($this->strAvatarUri) . ',
  982. ' . $objDatabase->SqlVariable($this->strCompanyName) . ',
  983. ' . $objDatabase->SqlVariable($this->intOwnerPersonId) . ',
  984. ' . $objDatabase->SqlVariable($this->blnIsVirtual) . '
  985. )
  986. ');
  987. // Update Identity column and return its value
  988. $mixToReturn = $this->intId = $objDatabase->InsertId('person', 'id');
  989. } else {
  990. // Perform an UPDATE query
  991. // First checking for Optimistic Locking constraints (if applicable)
  992. // Perform the UPDATE query
  993. $objDatabase->NonQuery('
  994. UPDATE
  995. `person`
  996. SET
  997. `name_prefix` = ' . $objDatabase->SqlVariable($this->strNamePrefix) . ',
  998. `first_name` = ' . $objDatabase->SqlVariable($this->strFirstName) . ',
  999. `middle_name` = ' . $objDatabase->SqlVariable($this->strMiddleName) . ',
  1000. `last_name` = ' . $objDatabase->SqlVariable($this->strLastName) . ',
  1001. `name_suffix` = ' . $objDatabase->SqlVariable($this->strNameSuffix) . ',
  1002. `nick_name` = ' . $objDatabase->SqlVariable($this->strNickName) . ',
  1003. `avatar_uri` = ' . $objDatabase->SqlVariable($this->strAvatarUri) . ',
  1004. `company_name` = ' . $objDatabase->SqlVariable($this->strCompanyName) . ',
  1005. `owner_person_id` = ' . $objDatabase->SqlVariable($this->intOwnerPersonId) . ',
  1006. `is_virtual` = ' . $objDatabase->SqlVariable($this->blnIsVirtual) . '
  1007. WHERE
  1008. `id` = ' . $objDatabase->SqlVariable($this->intId) . '
  1009. ');
  1010. }
  1011. // Update the adjoined Account object (if applicable)
  1012. // TODO: Make this into hard-coded SQL queries
  1013. if ($this->blnDirtyAccount) {
  1014. // Unassociate the old one (if applicable)
  1015. if ($objAssociated = Account::LoadByPersonId($this->intId)) {
  1016. $objAssociated->PersonId = null;
  1017. $objAssociated->Save();
  1018. }
  1019. // Associate the new one (if applicable)
  1020. if ($this->objAccount) {
  1021. $this->objAccount->PersonId = $this->intId;
  1022. $this->objAccount->Save();
  1023. }
  1024. // Reset the "Dirty" flag
  1025. $this->blnDirtyAccount = false;
  1026. }
  1027. } catch (QCallerException $objExc) {
  1028. $objExc->IncrementOffset();
  1029. throw $objExc;
  1030. }
  1031. // Update __blnRestored and any Non-Identity PK Columns (if applicable)
  1032. $this->__blnRestored = true;
  1033. // Return
  1034. return $mixToReturn;
  1035. }
  1036. /**
  1037. * Delete this Person
  1038. * @return void
  1039. */
  1040. public function Delete() {
  1041. if ((is_null($this->intId)))
  1042. throw new QUndefinedPrimaryKeyException('Cannot delete this Person with an unset primary key.');
  1043. // Get the Database Object for this Class
  1044. $objDatabase = Person::GetDatabase();
  1045. // Update the adjoined Account object (if applicable) and perform a delete
  1046. // Optional -- if you **KNOW** that you do not want to EVER run any level of business logic on the disassocation,
  1047. // you *could* override Delete() so that this step can be a single hard coded query to optimize performance.
  1048. if ($objAssociated = Account::LoadByPersonId($this->intId)) {
  1049. $objAssociated->Delete();
  1050. }
  1051. // Perform the SQL Query
  1052. $objDatabase->NonQuery('
  1053. DELETE FROM
  1054. `person`
  1055. WHERE
  1056. `id` = ' . $objDatabase->SqlVariable($this->intId) . '');
  1057. }
  1058. /**
  1059. * Delete all People
  1060. * @return void
  1061. */
  1062. public static function DeleteAll() {
  1063. // Get the Database Object for this Class
  1064. $objDatabase = Person::GetDatabase();
  1065. // Perform the Query
  1066. $objDatabase->NonQuery('
  1067. DELETE FROM
  1068. `person`');
  1069. }
  1070. /**
  1071. * Truncate person table
  1072. * @return void
  1073. */
  1074. public static function Truncate() {
  1075. // Get the Database Object for this Class
  1076. $objDatabase = Person::GetDatabase();
  1077. // Perform the Query
  1078. $objDatabase->NonQuery('
  1079. TRUNCATE `person`');
  1080. }
  1081. /**
  1082. * Reload this Person from the database.
  1083. * @return void
  1084. */
  1085. public function Reload() {
  1086. // Make sure we are actually Restored from the database
  1087. if (!$this->__blnRestored)
  1088. throw new QCallerException('Cannot call Reload() on a new, unsaved Person object.');
  1089. // Reload the Object
  1090. $objReloaded = Person::Load($this->intId);
  1091. // Update $this's local variables to match
  1092. $this->strNamePrefix = $objReloaded->strNamePrefix;
  1093. $this->strFirstName = $objReloaded->strFirstName;
  1094. $this->strMiddleName = $objReloaded->strMiddleName;
  1095. $this->strLastName = $objReloaded->strLastName;
  1096. $this->strNameSuffix = $objReloaded->strNameSuffix;
  1097. $this->strNickName = $objReloaded->strNickName;
  1098. $this->strAvatarUri = $objReloaded->strAvatarUri;
  1099. $this->strCompanyName = $objReloaded->strCompanyName;
  1100. $this->OwnerPersonId = $objReloaded->OwnerPersonId;
  1101. $this->blnIsVirtual = $objReloaded->blnIsVirtual;
  1102. }
  1103. ////////////////////
  1104. // GETTORS AND SETTORS
  1105. ////////////////////
  1106. /**
  1107. * Lookup a VirtualAttribute value (if applicable). Returns NULL if none found.
  1108. * @param string $strName
  1109. * @return string
  1110. */
  1111. public function GetVirtualAttribute($strName)
  1112. {
  1113. if (array_key_exists($strName, $this->__strVirtualAttributeArray))
  1114. return $this->__strVirtualAttributeArray[$strName];
  1115. return null;
  1116. }
  1117. /**
  1118. * Override method to perform a property "Get"
  1119. * This will get the value of $strName
  1120. *
  1121. * @param string $strName Name of the property to get
  1122. * @return mixed
  1123. */
  1124. public function __get($strName)
  1125. {
  1126. switch ($strName)
  1127. {
  1128. ///////////////////
  1129. // Member Variables
  1130. ///////////////////
  1131. case 'Id':
  1132. /**
  1133. * Gets the value for intId (Read-Only PK)
  1134. * @return integer
  1135. */
  1136. return $this->intId;
  1137. case 'NamePrefix':
  1138. /**
  1139. * Gets the value for strNamePrefix
  1140. * @return string
  1141. */
  1142. return $this->strNamePrefix;
  1143. case 'FirstName':
  1144. /**
  1145. * Gets the value for strFirstName (Not Null)
  1146. * @return string
  1147. */
  1148. return $this->strFirstName;
  1149. case 'MiddleName':
  1150. /**
  1151. * Gets the value for strMiddleName
  1152. * @return string
  1153. */
  1154. return $this->strMiddleName;
  1155. case 'LastName':
  1156. /**
  1157. * Gets the value for strLastName (Not Null)
  1158. * @return string
  1159. */
  1160. return $this->strLastName;
  1161. case 'NameSuffix':
  1162. /**
  1163. * Gets the value for strNameSuffix
  1164. * @return string
  1165. */
  1166. return $this->strNameSuffix;
  1167. case 'NickName':
  1168. /**
  1169. * Gets the value for strNickName
  1170. * @return string
  1171. */
  1172. return $this->strNickName;
  1173. case 'AvatarUri':
  1174. /**
  1175. * Gets the value for strAvatarUri
  1176. * @return string
  1177. */
  1178. return $this->strAvatarUri;
  1179. case 'CompanyName':
  1180. /**
  1181. * Gets the value for strCompanyName
  1182. * @return string
  1183. */
  1184. return $this->strCompanyName;
  1185. case 'OwnerPersonId':
  1186. /**
  1187. * Gets the value for intOwnerPersonId
  1188. * @return integer
  1189. */
  1190. return $this->intOwnerPersonId;
  1191. case 'IsVirtual':
  1192. /**
  1193. * Gets the value for blnIsVirtual
  1194. * @return boolean
  1195. */
  1196. return $this->blnIsVirtual;
  1197. ///////////////////
  1198. // Member Objects
  1199. ///////////////////
  1200. case 'OwnerPerson':
  1201. /**
  1202. * Gets the value for the Person object referenced by intOwnerPersonId
  1203. * @return Person
  1204. */
  1205. try {
  1206. if ((!$this->objOwnerPerson) && (!is_null($this->intOwnerPersonId)))
  1207. $this->objOwnerPerson = Person::Load($this->intOwnerPersonId);
  1208. return $this->objOwnerPerson;
  1209. } catch (QCallerException $objExc) {
  1210. $objExc->IncrementOffset();
  1211. throw $objExc;
  1212. }
  1213. case 'Account':
  1214. /**
  1215. * Gets the value for the Account object that uniquely references this Person
  1216. * by objAccount (Unique)
  1217. * @return Account
  1218. */
  1219. try {
  1220. if ($this->objAccount === false)
  1221. // We've attempted early binding -- and the reverse reference object does not exist
  1222. return null;
  1223. if (!$this->objAccount)
  1224. $this->objAccount = Account::LoadByPersonId($this->intId);
  1225. return $this->objAccount;
  1226. } catch (QCallerException $objExc) {
  1227. $objExc->IncrementOffset();
  1228. throw $objExc;
  1229. }
  1230. ////////////////////////////
  1231. // Virtual Object References (Many to Many and Reverse References)
  1232. // (If restored via a "Many-to" expansion)
  1233. ////////////////////////////
  1234. case '_Usergroup':
  1235. /**
  1236. * Gets the value for the private _objUsergroup (Read-Only)
  1237. * if set due to an expansion on the person_usergroup_assn association table
  1238. * @return Usergroup
  1239. */
  1240. return $this->_objUsergroup;
  1241. case '_UsergroupArray':
  1242. /**
  1243. * Gets the value for the private _objUsergroupArray (Read-Only)
  1244. * if set due to an ExpandAsArray on the person_usergroup_assn association table
  1245. * @return Usergroup[]
  1246. */
  1247. return (array) $this->_objUsergroupArray;
  1248. case '_Address':
  1249. /**
  1250. * Gets the value for the private _objAddress (Read-Only)
  1251. * if set due to an expansion on the address.person_id reverse relationship
  1252. * @return Address
  1253. */
  1254. return $this->_objAddress;
  1255. case '_AddressArray':
  1256. /**
  1257. * Gets the value for the private _objAddressArray (Read-Only)
  1258. * if set due to an ExpandAsArray on the address.person_id reverse relationship
  1259. * @return Address[]
  1260. */
  1261. return (array) $this->_objAddressArray;
  1262. case '_ContentItemAsCreator':
  1263. /**
  1264. * Gets the value for the private _objContentItemAsCreator (Read-Only)
  1265. * if set due to an expansion on the content_item.creator_id reverse relationship
  1266. * @return ContentItem
  1267. */
  1268. return $this->_objContentItemAsCreator;
  1269. case '_ContentItemAsCreatorArray':
  1270. /**
  1271. * Gets the value for the private _objContentItemAsCreatorArray (Read-Only)
  1272. * if set due to an ExpandAsArray on the content_item.creator_id reverse relationship
  1273. * @return ContentItem[]
  1274. */
  1275. return (array) $this->_objContentItemAsCreatorArray;
  1276. case '_EmailAddress':
  1277. /**
  1278. * Gets the value for the private _objEmailAddress (Read-Only)
  1279. * if set due to an expansion on the email_address.person_id reverse relationship
  1280. * @return EmailAddress
  1281. */
  1282. return $this->_objEmailAddress;
  1283. case '_EmailAddressArray':
  1284. /**
  1285. * Gets the value for the private _objEmailAddressArray (Read-Only)
  1286. * if set due to an ExpandAsArray on the email_address.person_id reverse relationship
  1287. * @return EmailAddress[]
  1288. */
  1289. return (array) $this->_objEmailAddressArray;
  1290. case '_PersonAsOwner':
  1291. /**
  1292. * Gets the value for the private _objPersonAsOwner (Read-Only)
  1293. * if set due to an expansion on the person.owner_person_id reverse relationship
  1294. * @return Person
  1295. */
  1296. return $this->_objPersonAsOwner;
  1297. case '_PersonAsOwnerArray':
  1298. /**
  1299. * Gets the value for the private _objPersonAsOwnerArray (Read-Only)
  1300. * if set due to an ExpandAsArray on the person.owner_person_id reverse relationship
  1301. * @return Person[]
  1302. */
  1303. return (array) $this->_objPersonAsOwnerArray;
  1304. case '_PhoneNumber':
  1305. /**
  1306. * Gets the value for the private _objPhoneNumber (Read-Only)
  1307. * if set due to an expansion on the phone_number.person_id reverse relationship
  1308. * @return PhoneNumber
  1309. */
  1310. return $this->_objPhoneNumber;
  1311. case '_PhoneNumberArray':
  1312. /**
  1313. * Gets the value for the private _objPhoneNumberArray (Read-Only)
  1314. * if set due to an ExpandAsArray on the phone_number.person_id reverse relationship
  1315. * @return PhoneNumber[]
  1316. */
  1317. return (array) $this->_objPhoneNumberArray;
  1318. case '_ProductAsManufacturer':
  1319. /**
  1320. * Gets the value for the private _objProductAsManufacturer (Read-Only)
  1321. * if set due to an expansion on the product.manufacturer_id reverse relationship
  1322. * @return Product
  1323. */
  1324. return $this->_objProductAsManufacturer;
  1325. case '_ProductAsManufacturerArray':
  1326. /**
  1327. * Gets the value for the private _objProductAsManufacturerArray (Read-Only)
  1328. * if set due to an ExpandAsArray on the product.manufacturer_id reverse relationship
  1329. * @return Product[]
  1330. */
  1331. return (array) $this->_objProductAsManufacturerArray;
  1332. case '_ProductAsSupplier':
  1333. /**
  1334. * Gets the value for the private _objProductAsSupplier (Read-Only)
  1335. * if set due to an expansion on the product.supplier_id reverse relationship
  1336. * @return Product
  1337. */
  1338. return $this->_objProductAsSupplier;
  1339. case '_ProductAsSupplierArray':
  1340. /**
  1341. * Gets the value for the private _objProductAsSupplierArray (Read-Only)
  1342. * if set due to an ExpandAsArray on the product.supplier_id reverse relationship
  1343. * @return Product[]
  1344. */
  1345. return (array) $this->_objProductAsSupplierArray;
  1346. case '__Restored':
  1347. return $this->__blnRestored;
  1348. default:
  1349. try {
  1350. return parent::__get($strName);
  1351. } catch (QCallerException $objExc) {
  1352. $objExc->IncrementOffset();
  1353. throw $objExc;
  1354. }
  1355. }
  1356. }
  1357. /**
  1358. * Override method to perform a property "Set"
  1359. * This will set the property $strName to be $mixValue
  1360. *
  1361. * @param string $strName Name of the property to set
  1362. * @param string $mixValue New value of the property
  1363. * @return mixed
  1364. */
  1365. public function __set($strName, $mixValue) {
  1366. switch ($strName) {
  1367. ///////////////////
  1368. // Member Variables
  1369. ///////////////////
  1370. case 'NamePrefix':
  1371. /**
  1372. * Sets the value for strNamePrefix
  1373. * @param string $mixValue
  1374. * @return string
  1375. */
  1376. try {
  1377. return ($this->strNamePrefix = QType::Cast($mixValue, QType::String));
  1378. } catch (QCallerException $objExc) {
  1379. $objExc->IncrementOffset();
  1380. throw $objExc;
  1381. }
  1382. case 'FirstName':
  1383. /**
  1384. * Sets the value for strFirstName (Not Null)
  1385. * @param string $mixValue
  1386. * @return string
  1387. */
  1388. try {
  1389. return ($this->strFirstName = QType::Cast($mixValue, QType::String));
  1390. } catch (QCallerException $objExc) {
  1391. $objExc->IncrementOffset();
  1392. throw $objExc;
  1393. }
  1394. case 'MiddleName':
  1395. /**
  1396. * Sets the value for strMiddleName
  1397. * @param string $mixValue
  1398. * @return string
  1399. */
  1400. try {
  1401. return ($this->strMiddleName = QType::Cast($mixValue, QType::String));
  1402. } catch (QCallerException $objExc) {
  1403. $objExc->IncrementOffset();
  1404. throw $objExc;
  1405. }
  1406. case 'LastName':
  1407. /**
  1408. * Sets the value for strLastName (Not Null)
  1409. * @param string $mixValue
  1410. * @return string
  1411. */
  1412. try {
  1413. return ($this->strLastName = QType::Cast($mixValue, QType::String));
  1414. } catch (QCallerException $objExc) {
  1415. $objExc->IncrementOffset();
  1416. throw $objExc;
  1417. }
  1418. case 'NameSuffix':
  1419. /**
  1420. * Sets the value for strNameSuffix
  1421. * @param string $mixValue
  1422. * @return string
  1423. */
  1424. try {
  1425. return ($this->strNameSuffix = QType::Cast($mixValue, QType::String));
  1426. } catch (QCallerException $objExc) {
  1427. $objExc->IncrementOffset();
  1428. throw $objExc;
  1429. }
  1430. case 'NickName':
  1431. /**
  1432. * Sets the value for strNickName
  1433. * @param string $mixValue
  1434. * @return string
  1435. */
  1436. try {
  1437. return ($this->strNickName = QType::Cast($mixValue, QType::String));
  1438. } catch (QCallerException $objExc) {
  1439. $objExc->IncrementOffset();
  1440. throw $objExc;
  1441. }
  1442. case 'AvatarUri':
  1443. /**
  1444. * Sets the value for strAvatarUri
  1445. * @param string $mixValue
  1446. * @return string
  1447. */
  1448. try {
  1449. return ($this->strAvatarUri = QType::Cast($mixValue, QType::String));
  1450. } catch (QCallerException $objExc) {
  1451. $objExc->IncrementOffset();
  1452. throw $objExc;
  1453. }
  1454. case 'CompanyName':
  1455. /**
  1456. * Sets the value for strCompanyName
  1457. * @param string $mixValue
  1458. * @return string
  1459. */
  1460. try {
  1461. return ($this->strCompanyName = QType::Cast($mixValue, QType::String));
  1462. } catch (QCallerException $objExc) {
  1463. $objExc->IncrementOffset();
  1464. throw $objExc;
  1465. }
  1466. case 'OwnerPersonId':
  1467. /**
  1468. * Sets the value for intOwnerPersonId
  1469. * @param integer $mixValue
  1470. * @return integer
  1471. */
  1472. try {
  1473. $this->objOwnerPerson = null;
  1474. return ($this->intOwnerPersonId = QType::Cast($mixValue, QType::Integer));
  1475. } catch (QCallerException $objExc) {
  1476. $objExc->IncrementOffset();
  1477. throw $objExc;
  1478. }
  1479. case 'IsVirtual':
  1480. /**
  1481. * Sets the value for blnIsVirtual
  1482. * @param boolean $mixValue
  1483. * @return boolean
  1484. */
  1485. try {
  1486. return ($this->blnIsVirtual = QType::Cast($mixValue, QType::Boolean));
  1487. } catch (QCallerException $objExc) {
  1488. $objExc->IncrementOffset();
  1489. throw $objExc;
  1490. }
  1491. ///////////////////
  1492. // Member Objects
  1493. ///////////////////
  1494. case 'OwnerPerson':
  1495. /**
  1496. * Sets the value for the Person object referenced by intOwnerPersonId
  1497. * @param Person $mixValue
  1498. * @return Person
  1499. */
  1500. if (is_null($mixValue)) {
  1501. $this->intOwnerPersonId = null;
  1502. $this->objOwnerPerson = null;
  1503. return null;
  1504. } else {
  1505. // Make sure $mixValue actually is a Person object
  1506. try {
  1507. $mixValue = QType::Cast($mixValue, 'Person');
  1508. } catch (QInvalidCastException $objExc) {
  1509. $objExc->IncrementOffset();
  1510. throw $objExc;
  1511. }
  1512. // Make sure $mixValue is a SAVED Person object
  1513. if (is_null($mixValue->Id))
  1514. throw new QCallerException('Unable to set an unsaved OwnerPerson for this Person');
  1515. // Update Local Member Variables
  1516. $this->objOwnerPerson = $mixValue;
  1517. $this->intOwnerPersonId = $mixValue->Id;
  1518. // Return $mixValue
  1519. return $mixValue;
  1520. }
  1521. break;
  1522. case 'Account':
  1523. /**
  1524. * Sets the value for the Account object referenced by objAccount (Unique)
  1525. * @param Account $mixValue
  1526. * @return Account
  1527. */
  1528. if (is_null($mixValue)) {
  1529. $this->objAccount = null;
  1530. // Make sure we update the adjoined Account object the next time we call Save()
  1531. $this->blnDirtyAccount = true;
  1532. return null;
  1533. } else {
  1534. // Make sure $mixValue actually is a Account object
  1535. try {
  1536. $mixValue = QType::Cast($mixValue, 'Account');
  1537. } catch (QInvalidCastException $objExc) {
  1538. $objExc->IncrementOffset();
  1539. throw $objExc;
  1540. }
  1541. // Are we setting objAccount to a DIFFERENT $mixValue?
  1542. if ((!$this->Account) || ($this->Account->Id != $mixValue->Id)) {
  1543. // Yes -- therefore, set the "Dirty" flag to true
  1544. // to make sure we update the adjoined Account object the next time we call Save()
  1545. $this->blnDirtyAccount = true;
  1546. // Update Local Member Variable
  1547. $this->objAccount = $mixValue;
  1548. } else {
  1549. // Nope -- therefore, make no changes
  1550. }
  1551. // Return $mixValue
  1552. return $mixValue;
  1553. }
  1554. break;
  1555. default:
  1556. try {
  1557. return parent::__set($strName, $mixValue);
  1558. } catch (QCallerException $objExc) {
  1559. $objExc->IncrementOffset();
  1560. throw $objExc;
  1561. }
  1562. }
  1563. }
  1564. ///////////////////////////////
  1565. // ASSOCIATED OBJECTS' METHODS
  1566. ///////////////////////////////
  1567. // Related Objects' Methods for Address
  1568. //-------------------------------------------------------------------
  1569. /**
  1570. * Gets all associated Addresses as an array of Address objects
  1571. * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  1572. * @return Address[]
  1573. */
  1574. public function GetAddressArray($objOptionalClauses = null) {
  1575. if ((is_null($this->intId)))
  1576. return array();
  1577. try {
  1578. return Address::LoadArrayByPersonId($this->intId, $objOptionalClauses);
  1579. } catch (QCallerException $objExc) {
  1580. $objExc->IncrementOffset();
  1581. throw $objExc;
  1582. }
  1583. }
  1584. /**
  1585. * Counts all associated Addresses
  1586. * @return int
  1587. */
  1588. public function CountAddresses() {
  1589. if ((is_null($this->intId)))
  1590. return 0;
  1591. return Address::CountByPersonId($this->intId);
  1592. }
  1593. /**
  1594. * Associates a Address
  1595. * @param Address $objAddress
  1596. * @return void
  1597. */
  1598. public function AssociateAddress(Address $objAddress) {
  1599. if ((is_null($this->intId)))
  1600. throw new QUndefinedPrimaryKeyException('Unable to call AssociateAddress on this unsaved Person.');
  1601. if ((is_null($objAddress->Id)))
  1602. throw new QUndefinedPrimaryKeyException('Unable to call AssociateAddress on this Person with an unsaved Address.');
  1603. // Get the Database Object for this Class
  1604. $objDatabase = Person::GetDatabase();
  1605. // Perform the SQL Query
  1606. $objDatabase->NonQuery('
  1607. UPDATE
  1608. `address`
  1609. SET
  1610. `person_id` = ' . $objDatabase->SqlVariable($this->intId) . '
  1611. WHERE
  1612. `id` = ' . $objDatabase->SqlVariable($objAddress->Id) . '
  1613. ');
  1614. }
  1615. /**
  1616. * Unassociates a Address
  1617. * @param Address $objAddress
  1618. * @return void
  1619. */
  1620. public function UnassociateAddress(Address $objAddress) {
  1621. if ((is_null($this->intId)))
  1622. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateAddress on this unsaved Person.');
  1623. if ((is_null($objAddress->Id)))
  1624. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateAddress on this Person with an unsaved Address.');
  1625. // Get the Database Object for this Class
  1626. $objDatabase = Person::GetDatabase();
  1627. // Perform the SQL Query
  1628. $objDatabase->NonQuery('
  1629. UPDATE
  1630. `address`
  1631. SET
  1632. `person_id` = null
  1633. WHERE
  1634. `id` = ' . $objDatabase->SqlVariable($objAddress->Id) . ' AND
  1635. `person_id` = ' . $objDatabase->SqlVariable($this->intId) . '
  1636. ');
  1637. }
  1638. /**
  1639. * Unassociates all Addresses
  1640. * @return void
  1641. */
  1642. public function UnassociateAllAddresses() {
  1643. if ((is_null($this->intId)))
  1644. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateAddress on this unsaved Person.');
  1645. // Get the Database Object for this Class
  1646. $objDatabase = Person::GetDatabase();
  1647. // Perform the SQL Query
  1648. $objDatabase->NonQuery('
  1649. UPDATE
  1650. `address`
  1651. SET
  1652. `person_id` = null
  1653. WHERE
  1654. `person_id` = ' . $objDatabase->SqlVariable($this->intId) . '
  1655. ');
  1656. }
  1657. /**
  1658. * Deletes an associated Address
  1659. * @param Address $objAddress
  1660. * @return void
  1661. */
  1662. public function DeleteAssociatedAddress(Address $objAddress) {
  1663. if ((is_null($this->intId)))
  1664. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateAddress on this unsaved Person.');
  1665. if ((is_null($objAddress->Id)))
  1666. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateAddress on this Person with an unsaved Address.');
  1667. // Get the Database Object for this Class
  1668. $objDatabase = Person::GetDatabase();
  1669. // Perform the SQL Query
  1670. $objDatabase->NonQuery('
  1671. DELETE FROM
  1672. `address`
  1673. WHERE
  1674. `id` = ' . $objDatabase->SqlVariable($objAddress->Id) . ' AND
  1675. `person_id` = ' . $objDatabase->SqlVariable($this->intId) . '
  1676. ');
  1677. }
  1678. /**
  1679. * Deletes all associated Addresses
  1680. * @return void
  1681. */
  1682. public function DeleteAllAddresses() {
  1683. if ((is_null($this->intId)))
  1684. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateAddress on this unsaved Person.');
  1685. // Get the Database Object for this Class
  1686. $objDatabase = Person::GetDatabase();
  1687. // Perform the SQL Query
  1688. $objDatabase->NonQuery('
  1689. DELETE FROM
  1690. `address`
  1691. WHERE
  1692. `person_id` = ' . $objDatabase->SqlVariable($this->intId) . '
  1693. ');
  1694. }
  1695. // Related Objects' Methods for ContentItemAsCreator
  1696. //-------------------------------------------------------------------
  1697. /**
  1698. * Gets all associated ContentItemsAsCreator as an array of ContentItem objects
  1699. * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  1700. * @return ContentItem[]
  1701. */
  1702. public function GetContentItemAsCreatorArray($objOptionalClauses = null) {
  1703. if ((is_null($this->intId)))
  1704. return array();
  1705. try {
  1706. return ContentItem::LoadArrayByCreatorId($this->intId, $objOptionalClauses);
  1707. } catch (QCallerException $objExc) {
  1708. $objExc->IncrementOffset();
  1709. throw $objExc;
  1710. }
  1711. }
  1712. /**
  1713. * Counts all associated ContentItemsAsCreator
  1714. * @return int
  1715. */
  1716. public function CountContentItemsAsCreator() {
  1717. if ((is_null($this->intId)))
  1718. return 0;
  1719. return ContentItem::CountByCreatorId($this->intId);
  1720. }
  1721. /**
  1722. * Associates a ContentItemAsCreator
  1723. * @param ContentItem $objContentItem
  1724. * @return void
  1725. */
  1726. public function AssociateContentItemAsCreator(ContentItem $objContentItem) {
  1727. if ((is_null($this->intId)))
  1728. throw new QUndefinedPrimaryKeyException('Unable to call AssociateContentItemAsCreator on this unsaved Person.');
  1729. if ((is_null($objContentItem->Id)))
  1730. throw new QUndefinedPrimaryKeyException('Unable to call AssociateContentItemAsCreator on this Person with an unsaved ContentItem.');
  1731. // Get the Database Object for this Class
  1732. $objDatabase = Person::GetDatabase();
  1733. // Perform the SQL Query
  1734. $objDatabase->NonQuery('
  1735. UPDATE
  1736. `content_item`
  1737. SET
  1738. `creator_id` = ' . $objDatabase->SqlVariable($this->intId) . '
  1739. WHERE
  1740. `id` = ' . $objDatabase->SqlVariable($objContentItem->Id) . '
  1741. ');
  1742. }
  1743. /**
  1744. * Unassociates a ContentItemAsCreator
  1745. * @param ContentItem $objContentItem
  1746. * @return void
  1747. */
  1748. public function UnassociateContentItemAsCreator(ContentItem $objContentItem) {
  1749. if ((is_null($this->intId)))
  1750. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateContentItemAsCreator on this unsaved Person.');
  1751. if ((is_null($objContentItem->Id)))
  1752. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateContentItemAsCreator on this Person with an unsaved ContentItem.');
  1753. // Get the Database Object for this Class
  1754. $objDatabase = Person::GetDatabase();
  1755. // Perform the SQL Query
  1756. $objDatabase->NonQuery('
  1757. UPDATE
  1758. `content_item`
  1759. SET
  1760. `creator_id` = null
  1761. WHERE
  1762. `id` = ' . $objDatabase->SqlVariable($objContentItem->Id) . ' AND
  1763. `creator_id` = ' . $objDatabase->SqlVariable($this->intId) . '
  1764. ');
  1765. }
  1766. /**
  1767. * Unassociates all ContentItemsAsCreator
  1768. * @return void
  1769. */
  1770. public function UnassociateAllContentItemsAsCreator() {
  1771. if ((is_null($this->intId)))
  1772. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateContentItemAsCreator on this unsaved Person.');
  1773. // Get the Database Object for this Class
  1774. $objDatabase = Person::GetDatabase();
  1775. // Perform the SQL Query
  1776. $objDatabase->NonQuery('
  1777. UPDATE
  1778. `content_item`
  1779. SET
  1780. `creator_id` = null
  1781. WHERE
  1782. `creator_id` = ' . $objDatabase->SqlVariable($this->intId) . '
  1783. ');
  1784. }
  1785. /**
  1786. * Deletes an associated ContentItemAsCreator
  1787. * @param ContentItem $objContentItem
  1788. * @return void
  1789. */
  1790. public function DeleteAssociatedContentItemAsCreator(ContentItem $objContentItem) {
  1791. if ((is_null($this->intId)))
  1792. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateContentItemAsCreator on this unsaved Person.');
  1793. if ((is_null($objContentItem->Id)))
  1794. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateContentItemAsCreator on this Person with an unsaved ContentItem.');
  1795. // Get the Database Object for this Class
  1796. $objDatabase = Person::GetDatabase();
  1797. // Perform the SQL Query
  1798. $objDatabase->NonQuery('
  1799. DELETE FROM
  1800. `content_item`
  1801. WHERE
  1802. `id` = ' . $objDatabase->SqlVariable($objContentItem->Id) . ' AND
  1803. `creator_id` = ' . $objDatabase->SqlVariable($this->intId) . '
  1804. ');
  1805. }
  1806. /**
  1807. * Deletes all associated ContentItemsAsCreator
  1808. * @return void
  1809. */
  1810. public function DeleteAllContentItemsAsCreator() {
  1811. if ((is_null($this->intId)))
  1812. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateContentItemAsCreator on this unsaved Person.');
  1813. // Get the Database Object for this Class
  1814. $objDatabase = Person::GetDatabase();
  1815. // Perform the SQL Query
  1816. $objDatabase->NonQuery('
  1817. DELETE FROM
  1818. `content_item`
  1819. WHERE
  1820. `creator_id` = ' . $objDatabase->SqlVariable($this->intId) . '
  1821. ');
  1822. }
  1823. // Related Objects' Methods for EmailAddress
  1824. //-------------------------------------------------------------------
  1825. /**
  1826. * Gets all associated EmailAddresses as an array of EmailAddress objects
  1827. * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  1828. * @return EmailAddress[]
  1829. */
  1830. public function GetEmailAddressArray($objOptionalClauses = null) {
  1831. if ((is_null($this->intId)))
  1832. return array();
  1833. try {
  1834. return EmailAddress::LoadArrayByPersonId($this->intId, $objOptionalClauses);
  1835. } catch (QCallerException $objExc) {
  1836. $objExc->IncrementOffset();
  1837. throw $objExc;
  1838. }
  1839. }
  1840. /**
  1841. * Counts all associated EmailAddresses
  1842. * @return int
  1843. */
  1844. public function CountEmailAddresses() {
  1845. if ((is_null($this->intId)))
  1846. return 0;
  1847. return EmailAddress::CountByPersonId($this->intId);
  1848. }
  1849. /**
  1850. * Associates a EmailAddress
  1851. * @param EmailAddress $objEmailAddress
  1852. * @return void
  1853. */
  1854. public function AssociateEmailAddress(EmailAddress $objEmailAddress) {
  1855. if ((is_null($this->intId)))
  1856. throw new QUndefinedPrimaryKeyException('Unable to call AssociateEmailAddress on this unsaved Person.');
  1857. if ((is_null($objEmailAddress->Id)))
  1858. throw new QUndefinedPrimaryKeyException('Unable to call AssociateEmailAddress on this Person with an unsaved EmailAddress.');
  1859. // Get the Database Object for this Class
  1860. $objDatabase = Person::GetDatabase();
  1861. // Perform the SQL Query
  1862. $objDatabase->NonQuery('
  1863. UPDATE
  1864. `email_address`
  1865. SET
  1866. `person_id` = ' . $objDatabase->SqlVariable($this->intId) . '
  1867. WHERE
  1868. `id` = ' . $objDatabase->SqlVariable($objEmailAddress->Id) . '
  1869. ');
  1870. }
  1871. /**
  1872. * Unassociates a EmailAddress
  1873. * @param EmailAddress $objEmailAddress
  1874. * @return void
  1875. */
  1876. public function UnassociateEmailAddress(EmailAddress $objEmailAddress) {
  1877. if ((is_null($this->intId)))
  1878. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateEmailAddress on this unsaved Person.');
  1879. if ((is_null($objEmailAddress->Id)))
  1880. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateEmailAddress on this Person with an unsaved EmailAddress.');
  1881. // Get the Database Object for this Class
  1882. $objDatabase = Person::GetDatabase();
  1883. // Perform the SQL Query
  1884. $objDatabase->NonQuery('
  1885. UPDATE
  1886. `email_address`
  1887. SET
  1888. `person_id` = null
  1889. WHERE
  1890. `id` = ' . $objDatabase->SqlVariable($objEmailAddress->Id) . ' AND
  1891. `person_id` = ' . $objDatabase->SqlVariable($this->intId) . '
  1892. ');
  1893. }
  1894. /**
  1895. * Unassociates all EmailAddresses
  1896. * @return void
  1897. */
  1898. public function UnassociateAllEmailAddresses() {
  1899. if ((is_null($this->intId)))
  1900. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateEmailAddress on this unsaved Person.');
  1901. // Get the Database Object for this Class
  1902. $objDatabase = Person::GetDatabase();
  1903. // Perform the SQL Query
  1904. $objDatabase->NonQuery('
  1905. UPDATE
  1906. `email_address`
  1907. SET
  1908. `person_id` = null
  1909. WHERE
  1910. `person_id` = ' . $objDatabase->SqlVariable($this->intId) . '
  1911. ');
  1912. }
  1913. /**
  1914. * Deletes an associated EmailAddress
  1915. * @param EmailAddress $objEmailAddress
  1916. * @return void
  1917. */
  1918. public function DeleteAssociatedEmailAddress(EmailAddress $objEmailAddress) {
  1919. if ((is_null($this->intId)))
  1920. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateEmailAddress on this unsaved Person.');
  1921. if ((is_null($objEmailAddress->Id)))
  1922. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateEmailAddress on this Person with an unsaved EmailAddress.');
  1923. // Get the Database Object for this Class
  1924. $objDatabase = Person::GetDatabase();
  1925. // Perform the SQL Query
  1926. $objDatabase->NonQuery('
  1927. DELETE FROM
  1928. `email_address`
  1929. WHERE
  1930. `id` = ' . $objDatabase->SqlVariable($objEmailAddress->Id) . ' AND
  1931. `person_id` = ' . $objDatabase->SqlVariable($this->intId) . '
  1932. ');
  1933. }
  1934. /**
  1935. * Deletes all associated EmailAddresses
  1936. * @return void
  1937. */
  1938. public function DeleteAllEmailAddresses() {
  1939. if ((is_null($this->intId)))
  1940. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateEmailAddress on this unsaved Person.');
  1941. // Get the Database Object for this Class
  1942. $objDatabase = Person::GetDatabase();
  1943. // Perform the SQL Query
  1944. $objDatabase->NonQuery('
  1945. DELETE FROM
  1946. `email_address`
  1947. WHERE
  1948. `person_id` = ' . $objDatabase->SqlVariable($this->intId) . '
  1949. ');
  1950. }
  1951. // Related Objects' Methods for PersonAsOwner
  1952. //-------------------------------------------------------------------
  1953. /**
  1954. * Gets all associated PeopleAsOwner as an array of Person objects
  1955. * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  1956. * @return Person[]
  1957. */
  1958. public function GetPersonAsOwnerArray($objOptionalClauses = null) {
  1959. if ((is_null($this->intId)))
  1960. return array();
  1961. try {
  1962. return Person::LoadArrayByOwnerPersonId($this->intId, $objOptionalClauses);
  1963. } catch (QCallerException $objExc) {
  1964. $objExc->IncrementOffset();
  1965. throw $objExc;
  1966. }
  1967. }
  1968. /**
  1969. * Counts all associated PeopleAsOwner
  1970. * @return int
  1971. */
  1972. public function CountPeopleAsOwner() {
  1973. if ((is_null($this->intId)))
  1974. return 0;
  1975. return Person::CountByOwnerPersonId($this->intId);
  1976. }
  1977. /**
  1978. * Associates a PersonAsOwner
  1979. * @param Person $objPerson
  1980. * @return void
  1981. */
  1982. public function AssociatePersonAsOwner(Person $objPerson) {
  1983. if ((is_null($this->intId)))
  1984. throw new QUndefinedPrimaryKeyException('Unable to call AssociatePersonAsOwner on this unsaved Person.');
  1985. if ((is_null($objPerson->Id)))
  1986. throw new QUndefinedPrimaryKeyException('Unable to call AssociatePersonAsOwner on this Person with an unsaved Person.');
  1987. // Get the Database Object for this Class
  1988. $objDatabase = Person::GetDatabase();
  1989. // Perform the SQL Query
  1990. $objDatabase->NonQuery('
  1991. UPDATE
  1992. `person`
  1993. SET
  1994. `owner_person_id` = ' . $objDatabase->SqlVariable($this->intId) . '
  1995. WHERE
  1996. `id` = ' . $objDatabase->SqlVariable($objPerson->Id) . '
  1997. ');
  1998. }
  1999. /**
  2000. * Unassociates a PersonAsOwner
  2001. * @param Person $objPerson
  2002. * @return void
  2003. */
  2004. public function UnassociatePersonAsOwner(Person $objPerson) {
  2005. if ((is_null($this->intId)))
  2006. throw new QUndefinedPrimaryKeyException('Unable to call UnassociatePersonAsOwner on this unsaved Person.');
  2007. if ((is_null($objPerson->Id)))
  2008. throw new QUndefinedPrimaryKeyException('Unable to call UnassociatePersonAsOwner on this Person with an unsaved Person.');
  2009. // Get the Database Object for this Class
  2010. $objDatabase = Person::GetDatabase();
  2011. // Perform the SQL Query
  2012. $objDatabase->NonQuery('
  2013. UPDATE
  2014. `person`
  2015. SET
  2016. `owner_person_id` = null
  2017. WHERE
  2018. `id` = ' . $objDatabase->SqlVariable($objPerson->Id) . ' AND
  2019. `owner_person_id` = ' . $objDatabase->SqlVariable($this->intId) . '
  2020. ');
  2021. }
  2022. /**
  2023. * Unassociates all PeopleAsOwner
  2024. * @return void
  2025. */
  2026. public function UnassociateAllPeopleAsOwner() {
  2027. if ((is_null($this->intId)))
  2028. throw new QUndefinedPrimaryKeyException('Unable to call UnassociatePersonAsOwner on this unsaved Person.');
  2029. // Get the Database Object for this Class
  2030. $objDatabase = Person::GetDatabase();
  2031. // Perform the SQL Query
  2032. $objDatabase->NonQuery('
  2033. UPDATE
  2034. `person`
  2035. SET
  2036. `owner_person_id` = null
  2037. WHERE
  2038. `owner_person_id` = ' . $objDatabase->SqlVariable($this->intId) . '
  2039. ');
  2040. }
  2041. /**
  2042. * Deletes an associated PersonAsOwner
  2043. * @param Person $objPerson
  2044. * @return void
  2045. */
  2046. public function DeleteAssociatedPersonAsOwner(Person $objPerson) {
  2047. if ((is_null($this->intId)))
  2048. throw new QUndefinedPrimaryKeyException('Unable to call UnassociatePersonAsOwner on this unsaved Person.');
  2049. if ((is_null($objPerson->Id)))
  2050. throw new QUndefinedPrimaryKeyException('Unable to call UnassociatePersonAsOwner on this Person with an unsaved Person.');
  2051. // Get the Database Object for this Class
  2052. $objDatabase = Person::GetDatabase();
  2053. // Perform the SQL Query
  2054. $objDatabase->NonQuery('
  2055. DELETE FROM
  2056. `person`
  2057. WHERE
  2058. `id` = ' . $objDatabase->SqlVariable($objPerson->Id) . ' AND
  2059. `owner_person_id` = ' . $objDatabase->SqlVariable($this->intId) . '
  2060. ');
  2061. }
  2062. /**
  2063. * Deletes all associated PeopleAsOwner
  2064. * @return void
  2065. */
  2066. public function DeleteAllPeopleAsOwner() {
  2067. if ((is_null($this->intId)))
  2068. throw new QUndefinedPrimaryKeyException('Unable to call UnassociatePersonAsOwner on this unsaved Person.');
  2069. // Get the Database Object for this Class
  2070. $objDatabase = Person::GetDatabase();
  2071. // Perform the SQL Query
  2072. $objDatabase->NonQuery('
  2073. DELETE FROM
  2074. `person`
  2075. WHERE
  2076. `owner_person_id` = ' . $objDatabase->SqlVariable($this->intId) . '
  2077. ');
  2078. }
  2079. // Related Objects' Methods for PhoneNumber
  2080. //-------------------------------------------------------------------
  2081. /**
  2082. * Gets all associated PhoneNumbers as an array of PhoneNumber objects
  2083. * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  2084. * @return PhoneNumber[]
  2085. */
  2086. public function GetPhoneNumberArray($objOptionalClauses = null) {
  2087. if ((is_null($this->intId)))
  2088. return array();
  2089. try {
  2090. return PhoneNumber::LoadArrayByPersonId($this->intId, $objOptionalClauses);
  2091. } catch (QCallerException $objExc) {
  2092. $objExc->IncrementOffset();
  2093. throw $objExc;
  2094. }
  2095. }
  2096. /**
  2097. * Counts all associated PhoneNumbers
  2098. * @return int
  2099. */
  2100. public function CountPhoneNumbers() {
  2101. if ((is_null($this->intId)))
  2102. return 0;
  2103. return PhoneNumber::CountByPersonId($this->intId);
  2104. }
  2105. /**
  2106. * Associates a PhoneNumber
  2107. * @param PhoneNumber $objPhoneNumber
  2108. * @return void
  2109. */
  2110. public function AssociatePhoneNumber(PhoneNumber $objPhoneNumber) {
  2111. if ((is_null($this->intId)))
  2112. throw new QUndefinedPrimaryKeyException('Unable to call AssociatePhoneNumber on this unsaved Person.');
  2113. if ((is_null($objPhoneNumber->Id)))
  2114. throw new QUndefinedPrimaryKeyException('Unable to call AssociatePhoneNumber on this Person with an unsaved PhoneNumber.');
  2115. // Get the Database Object for this Class
  2116. $objDatabase = Person::GetDatabase();
  2117. // Perform the SQL Query
  2118. $objDatabase->NonQuery('
  2119. UPDATE
  2120. `phone_number`
  2121. SET
  2122. `person_id` = ' . $objDatabase->SqlVariable($this->intId) . '
  2123. WHERE
  2124. `id` = ' . $objDatabase->SqlVariable($objPhoneNumber->Id) . '
  2125. ');
  2126. }
  2127. /**
  2128. * Unassociates a PhoneNumber
  2129. * @param PhoneNumber $objPhoneNumber
  2130. * @return void
  2131. */
  2132. public function UnassociatePhoneNumber(PhoneNumber $objPhoneNumber) {
  2133. if ((is_null($this->intId)))
  2134. throw new QUndefinedPrimaryKeyException('Unable to call UnassociatePhoneNumber on this unsaved Person.');
  2135. if ((is_null($objPhoneNumber->Id)))
  2136. throw new QUndefinedPrimaryKeyException('Unable to call UnassociatePhoneNumber on this Person with an unsaved PhoneNumber.');
  2137. // Get the Database Object for this Class
  2138. $objDatabase = Person::GetDatabase();
  2139. // Perform the SQL Query
  2140. $objDatabase->NonQuery('
  2141. UPDATE
  2142. `phone_number`
  2143. SET
  2144. `person_id` = null
  2145. WHERE
  2146. `id` = ' . $objDatabase->SqlVariable($objPhoneNumber->Id) . ' AND
  2147. `person_id` = ' . $objDatabase->SqlVariable($this->intId) . '
  2148. ');
  2149. }
  2150. /**
  2151. * Unassociates all PhoneNumbers
  2152. * @return void
  2153. */
  2154. public function UnassociateAllPhoneNumbers() {
  2155. if ((is_null($this->intId)))
  2156. throw new QUndefinedPrimaryKeyException('Unable to call UnassociatePhoneNumber on this unsaved Person.');
  2157. // Get the Database Object for this Class
  2158. $objDatabase = Person::GetDatabase();
  2159. // Perform the SQL Query
  2160. $objDatabase->NonQuery('
  2161. UPDATE
  2162. `phone_number`
  2163. SET
  2164. `person_id` = null
  2165. WHERE
  2166. `person_id` = ' . $objDatabase->SqlVariable($this->intId) . '
  2167. ');
  2168. }
  2169. /**
  2170. * Deletes an associated PhoneNumber
  2171. * @param PhoneNumber $objPhoneNumber
  2172. * @return void
  2173. */
  2174. public function DeleteAssociatedPhoneNumber(PhoneNumber $objPhoneNumber) {
  2175. if ((is_null($this->intId)))
  2176. throw new QUndefinedPrimaryKeyException('Unable to call UnassociatePhoneNumber on this unsaved Person.');
  2177. if ((is_null($objPhoneNumber->Id)))
  2178. throw new QUndefinedPrimaryKeyException('Unable to call UnassociatePhoneNumber on this Person with an unsaved PhoneNumber.');
  2179. // Get the Database Object for this Class
  2180. $objDatabase = Person::GetDatabase();
  2181. // Perform the SQL Query
  2182. $objDatabase->NonQuery('
  2183. DELETE FROM
  2184. `phone_number`
  2185. WHERE
  2186. `id` = ' . $objDatabase->SqlVariable($objPhoneNumber->Id) . ' AND
  2187. `person_id` = ' . $objDatabase->SqlVariable($this->intId) . '
  2188. ');
  2189. }
  2190. /**
  2191. * Deletes all associated PhoneNumbers
  2192. * @return void
  2193. */
  2194. public function DeleteAllPhoneNumbers() {
  2195. if ((is_null($this->intId)))
  2196. throw new QUndefinedPrimaryKeyException('Unable to call UnassociatePhoneNumber on this unsaved Person.');
  2197. // Get the Database Object for this Class
  2198. $objDatabase = Person::GetDatabase();
  2199. // Perform the SQL Query
  2200. $objDatabase->NonQuery('
  2201. DELETE FROM
  2202. `phone_number`
  2203. WHERE
  2204. `person_id` = ' . $objDatabase->SqlVariable($this->intId) . '
  2205. ');
  2206. }
  2207. // Related Objects' Methods for ProductAsManufacturer
  2208. //-------------------------------------------------------------------
  2209. /**
  2210. * Gets all associated ProductsAsManufacturer as an array of Product objects
  2211. * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  2212. * @return Product[]
  2213. */
  2214. public function GetProductAsManufacturerArray($objOptionalClauses = null) {
  2215. if ((is_null($this->intId)))
  2216. return array();
  2217. try {
  2218. return Product::LoadArrayByManufacturerId($this->intId, $objOptionalClauses);
  2219. } catch (QCallerException $objExc) {
  2220. $objExc->IncrementOffset();
  2221. throw $objExc;
  2222. }
  2223. }
  2224. /**
  2225. * Counts all associated ProductsAsManufacturer
  2226. * @return int
  2227. */
  2228. public function CountProductsAsManufacturer() {
  2229. if ((is_null($this->intId)))
  2230. return 0;
  2231. return Product::CountByManufacturerId($this->intId);
  2232. }
  2233. /**
  2234. * Associates a ProductAsManufacturer
  2235. * @param Product $objProduct
  2236. * @return void
  2237. */
  2238. public function AssociateProductAsManufacturer(Product $objProduct) {
  2239. if ((is_null($this->intId)))
  2240. throw new QUndefinedPrimaryKeyException('Unable to call AssociateProductAsManufacturer on this unsaved Person.');
  2241. if ((is_null($objProduct->Id)))
  2242. throw new QUndefinedPrimaryKeyException('Unable to call AssociateProductAsManufacturer on this Person with an unsaved Product.');
  2243. // Get the Database Object for this Class
  2244. $objDatabase = Person::GetDatabase();
  2245. // Perform the SQL Query
  2246. $objDatabase->NonQuery('
  2247. UPDATE
  2248. `product`
  2249. SET
  2250. `manufacturer_id` = ' . $objDatabase->SqlVariable($this->intId) . '
  2251. WHERE
  2252. `id` = ' . $objDatabase->SqlVariable($objProduct->Id) . '
  2253. ');
  2254. }
  2255. /**
  2256. * Unassociates a ProductAsManufacturer
  2257. * @param Product $objProduct
  2258. * @return void
  2259. */
  2260. public function UnassociateProductAsManufacturer(Product $objProduct) {
  2261. if ((is_null($this->intId)))
  2262. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateProductAsManufacturer on this unsaved Person.');
  2263. if ((is_null($objProduct->Id)))
  2264. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateProductAsManufacturer on this Person with an unsaved Product.');
  2265. // Get the Database Object for this Class
  2266. $objDatabase = Person::GetDatabase();
  2267. // Perform the SQL Query
  2268. $objDatabase->NonQuery('
  2269. UPDATE
  2270. `product`
  2271. SET
  2272. `manufacturer_id` = null
  2273. WHERE
  2274. `id` = ' . $objDatabase->SqlVariable($objProduct->Id) . ' AND
  2275. `manufacturer_id` = ' . $objDatabase->SqlVariable($this->intId) . '
  2276. ');
  2277. }
  2278. /**
  2279. * Unassociates all ProductsAsManufacturer
  2280. * @return void
  2281. */
  2282. public function UnassociateAllProductsAsManufacturer() {
  2283. if ((is_null($this->intId)))
  2284. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateProductAsManufacturer on this unsaved Person.');
  2285. // Get the Database Object for this Class
  2286. $objDatabase = Person::GetDatabase();
  2287. // Perform the SQL Query
  2288. $objDatabase->NonQuery('
  2289. UPDATE
  2290. `product`
  2291. SET
  2292. `manufacturer_id` = null
  2293. WHERE
  2294. `manufacturer_id` = ' . $objDatabase->SqlVariable($this->intId) . '
  2295. ');
  2296. }
  2297. /**
  2298. * Deletes an associated ProductAsManufacturer
  2299. * @param Product $objProduct
  2300. * @return void
  2301. */
  2302. public function DeleteAssociatedProductAsManufacturer(Product $objProduct) {
  2303. if ((is_null($this->intId)))
  2304. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateProductAsManufacturer on this unsaved Person.');
  2305. if ((is_null($objProduct->Id)))
  2306. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateProductAsManufacturer on this Person with an unsaved Product.');
  2307. // Get the Database Object for this Class
  2308. $objDatabase = Person::GetDatabase();
  2309. // Perform the SQL Query
  2310. $objDatabase->NonQuery('
  2311. DELETE FROM
  2312. `product`
  2313. WHERE
  2314. `id` = ' . $objDatabase->SqlVariable($objProduct->Id) . ' AND
  2315. `manufacturer_id` = ' . $objDatabase->SqlVariable($this->intId) . '
  2316. ');
  2317. }
  2318. /**
  2319. * Deletes all associated ProductsAsManufacturer
  2320. * @return void
  2321. */
  2322. public function DeleteAllProductsAsManufacturer() {
  2323. if ((is_null($this->intId)))
  2324. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateProductAsManufacturer on this unsaved Person.');
  2325. // Get the Database Object for this Class
  2326. $objDatabase = Person::GetDatabase();
  2327. // Perform the SQL Query
  2328. $objDatabase->NonQuery('
  2329. DELETE FROM
  2330. `product`
  2331. WHERE
  2332. `manufacturer_id` = ' . $objDatabase->SqlVariable($this->intId) . '
  2333. ');
  2334. }
  2335. // Related Objects' Methods for ProductAsSupplier
  2336. //-------------------------------------------------------------------
  2337. /**
  2338. * Gets all associated ProductsAsSupplier as an array of Product objects
  2339. * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  2340. * @return Product[]
  2341. */
  2342. public function GetProductAsSupplierArray($objOptionalClauses = null) {
  2343. if ((is_null($this->intId)))
  2344. return array();
  2345. try {
  2346. return Product::LoadArrayBySupplierId($this->intId, $objOptionalClauses);
  2347. } catch (QCallerException $objExc) {
  2348. $objExc->IncrementOffset();
  2349. throw $objExc;
  2350. }
  2351. }
  2352. /**
  2353. * Counts all associated ProductsAsSupplier
  2354. * @return int
  2355. */
  2356. public function CountProductsAsSupplier() {
  2357. if ((is_null($this->intId)))
  2358. return 0;
  2359. return Product::CountBySupplierId($this->intId);
  2360. }
  2361. /**
  2362. * Associates a ProductAsSupplier
  2363. * @param Product $objProduct
  2364. * @return void
  2365. */
  2366. public function AssociateProductAsSupplier(Product $objProduct) {
  2367. if ((is_null($this->intId)))
  2368. throw new QUndefinedPrimaryKeyException('Unable to call AssociateProductAsSupplier on this unsaved Person.');
  2369. if ((is_null($objProduct->Id)))
  2370. throw new QUndefinedPrimaryKeyException('Unable to call AssociateProductAsSupplier on this Person with an unsaved Product.');
  2371. // Get the Database Object for this Class
  2372. $objDatabase = Person::GetDatabase();
  2373. // Perform the SQL Query
  2374. $objDatabase->NonQuery('
  2375. UPDATE
  2376. `product`
  2377. SET
  2378. `supplier_id` = ' . $objDatabase->SqlVariable($this->intId) . '
  2379. WHERE
  2380. `id` = ' . $objDatabase->SqlVariable($objProduct->Id) . '
  2381. ');
  2382. }
  2383. /**
  2384. * Unassociates a ProductAsSupplier
  2385. * @param Product $objProduct
  2386. * @return void
  2387. */
  2388. public function UnassociateProductAsSupplier(Product $objProduct) {
  2389. if ((is_null($this->intId)))
  2390. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateProductAsSupplier on this unsaved Person.');
  2391. if ((is_null($objProduct->Id)))
  2392. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateProductAsSupplier on this Person with an unsaved Product.');
  2393. // Get the Database Object for this Class
  2394. $objDatabase = Person::GetDatabase();
  2395. // Perform the SQL Query
  2396. $objDatabase->NonQuery('
  2397. UPDATE
  2398. `product`
  2399. SET
  2400. `supplier_id` = null
  2401. WHERE
  2402. `id` = ' . $objDatabase->SqlVariable($objProduct->Id) . ' AND
  2403. `supplier_id` = ' . $objDatabase->SqlVariable($this->intId) . '
  2404. ');
  2405. }
  2406. /**
  2407. * Unassociates all ProductsAsSupplier
  2408. * @return void
  2409. */
  2410. public function UnassociateAllProductsAsSupplier() {
  2411. if ((is_null($this->intId)))
  2412. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateProductAsSupplier on this unsaved Person.');
  2413. // Get the Database Object for this Class
  2414. $objDatabase = Person::GetDatabase();
  2415. // Perform the SQL Query
  2416. $objDatabase->NonQuery('
  2417. UPDATE
  2418. `product`
  2419. SET
  2420. `supplier_id` = null
  2421. WHERE
  2422. `supplier_id` = ' . $objDatabase->SqlVariable($this->intId) . '
  2423. ');
  2424. }
  2425. /**
  2426. * Deletes an associated ProductAsSupplier
  2427. * @param Product $objProduct
  2428. * @return void
  2429. */
  2430. public function DeleteAssociatedProductAsSupplier(Product $objProduct) {
  2431. if ((is_null($this->intId)))
  2432. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateProductAsSupplier on this unsaved Person.');
  2433. if ((is_null($objProduct->Id)))
  2434. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateProductAsSupplier on this Person with an unsaved Product.');
  2435. // Get the Database Object for this Class
  2436. $objDatabase = Person::GetDatabase();
  2437. // Perform the SQL Query
  2438. $objDatabase->NonQuery('
  2439. DELETE FROM
  2440. `product`
  2441. WHERE
  2442. `id` = ' . $objDatabase->SqlVariable($objProduct->Id) . ' AND
  2443. `supplier_id` = ' . $objDatabase->SqlVariable($this->intId) . '
  2444. ');
  2445. }
  2446. /**
  2447. * Deletes all associated ProductsAsSupplier
  2448. * @return void
  2449. */
  2450. public function DeleteAllProductsAsSupplier() {
  2451. if ((is_null($this->intId)))
  2452. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateProductAsSupplier on this unsaved Person.');
  2453. // Get the Database Object for this Class
  2454. $objDatabase = Person::GetDatabase();
  2455. // Perform the SQL Query
  2456. $objDatabase->NonQuery('
  2457. DELETE FROM
  2458. `product`
  2459. WHERE
  2460. `supplier_id` = ' . $objDatabase->SqlVariable($this->intId) . '
  2461. ');
  2462. }
  2463. // Related Many-to-Many Objects' Methods for Usergroup
  2464. //-------------------------------------------------------------------
  2465. /**
  2466. * Gets all many-to-many associated Usergroups as an array of Usergroup objects
  2467. * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  2468. * @return Usergroup[]
  2469. */
  2470. public function GetUsergroupArray($objOptionalClauses = null) {
  2471. if ((is_null($this->intId)))
  2472. return array();
  2473. try {
  2474. return Usergroup::LoadArrayByPerson($this->intId, $objOptionalClauses);
  2475. } catch (QCallerException $objExc) {
  2476. $objExc->IncrementOffset();
  2477. throw $objExc;
  2478. }
  2479. }
  2480. /**
  2481. * Counts all many-to-many associated Usergroups
  2482. * @return int
  2483. */
  2484. public function CountUsergroups() {
  2485. if ((is_null($this->intId)))
  2486. return 0;
  2487. return Usergroup::CountByPerson($this->intId);
  2488. }
  2489. /**
  2490. * Checks to see if an association exists with a specific Usergroup
  2491. * @param Usergroup $objUsergroup
  2492. * @return bool
  2493. */
  2494. public function IsUsergroupAssociated(Usergroup $objUsergroup) {
  2495. if ((is_null($this->intId)))
  2496. throw new QUndefinedPrimaryKeyException('Unable to call IsUsergroupAssociated on this unsaved Person.');
  2497. if ((is_null($objUsergroup->Id)))
  2498. throw new QUndefinedPrimaryKeyException('Unable to call IsUsergroupAssociated on this Person with an unsaved Usergroup.');
  2499. $intRowCount = Person::QueryCount(
  2500. QQ::AndCondition(
  2501. QQ::Equal(QQN::Person()->Id, $this->intId),
  2502. QQ::Equal(QQN::Person()->Usergroup->UsergroupId, $objUsergroup->Id)
  2503. )
  2504. );
  2505. return ($intRowCount > 0);
  2506. }
  2507. /**
  2508. * Associates a Usergroup
  2509. * @param Usergroup $objUsergroup
  2510. * @return void
  2511. */
  2512. public function AssociateUsergroup(Usergroup $objUsergroup) {
  2513. if ((is_null($this->intId)))
  2514. throw new QUndefinedPrimaryKeyException('Unable to call AssociateUsergroup on this unsaved Person.');
  2515. if ((is_null($objUsergroup->Id)))
  2516. throw new QUndefinedPrimaryKeyException('Unable to call AssociateUsergroup on this Person with an unsaved Usergroup.');
  2517. // Get the Database Object for this Class
  2518. $objDatabase = Person::GetDatabase();
  2519. // Perform the SQL Query
  2520. $objDatabase->NonQuery('
  2521. INSERT INTO `person_usergroup_assn` (
  2522. `person_id`,
  2523. `usergroup_id`
  2524. ) VALUES (
  2525. ' . $objDatabase->SqlVariable($this->intId) . ',
  2526. ' . $objDatabase->SqlVariable($objUsergroup->Id) . '
  2527. )
  2528. ');
  2529. }
  2530. /**
  2531. * Unassociates a Usergroup
  2532. * @param Usergroup $objUsergroup
  2533. * @return void
  2534. */
  2535. public function UnassociateUsergroup(Usergroup $objUsergroup) {
  2536. if ((is_null($this->intId)))
  2537. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateUsergroup on this unsaved Person.');
  2538. if ((is_null($objUsergroup->Id)))
  2539. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateUsergroup on this Person with an unsaved Usergroup.');
  2540. // Get the Database Object for this Class
  2541. $objDatabase = Person::GetDatabase();
  2542. // Perform the SQL Query
  2543. $objDatabase->NonQuery('
  2544. DELETE FROM
  2545. `person_usergroup_assn`
  2546. WHERE
  2547. `person_id` = ' . $objDatabase->SqlVariable($this->intId) . ' AND
  2548. `usergroup_id` = ' . $objDatabase->SqlVariable($objUsergroup->Id) . '
  2549. ');
  2550. }
  2551. /**
  2552. * Unassociates all Usergroups
  2553. * @return void
  2554. */
  2555. public function UnassociateAllUsergroups() {
  2556. if ((is_null($this->intId)))
  2557. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateAllUsergroupArray on this unsaved Person.');
  2558. // Get the Database Object for this Class
  2559. $objDatabase = Person::GetDatabase();
  2560. // Perform the SQL Query
  2561. $objDatabase->NonQuery('
  2562. DELETE FROM
  2563. `person_usergroup_assn`
  2564. WHERE
  2565. `person_id` = ' . $objDatabase->SqlVariable($this->intId) . '
  2566. ');
  2567. }
  2568. }
  2569. /////////////////////////////////////
  2570. // ADDITIONAL CLASSES for QCODO QUERY
  2571. /////////////////////////////////////
  2572. class QQNodePersonUsergroup extends QQAssociationNode {
  2573. protected $strType = 'association';
  2574. protected $strName = 'usergroup';
  2575. protected $strTableName = 'person_usergroup_assn';
  2576. protected $strPrimaryKey = 'person_id';
  2577. protected $strClassName = 'Usergroup';
  2578. public function __get($strName) {
  2579. switch ($strName) {
  2580. case 'UsergroupId':
  2581. return new QQNode('usergroup_id', 'UsergroupId', 'integer', $this);
  2582. case 'Usergroup':
  2583. return new QQNodeUsergroup('usergroup_id', 'UsergroupId', 'integer', $this);
  2584. case '_ChildTableNode':
  2585. return new QQNodeUsergroup('usergroup_id', 'UsergroupId', 'integer', $this);
  2586. default:
  2587. try {
  2588. return parent::__get($strName);
  2589. } catch (QCallerException $objExc) {
  2590. $objExc->IncrementOffset();
  2591. throw $objExc;
  2592. }
  2593. }
  2594. }
  2595. }
  2596. class QQNodePerson extends QQNode {
  2597. protected $strTableName = 'person';
  2598. protected $strPrimaryKey = 'id';
  2599. protected $strClassName = 'Person';
  2600. public function __get($strName) {
  2601. switch ($strName) {
  2602. case 'Id':
  2603. return new QQNode('id', 'Id', 'integer', $this);
  2604. case 'NamePrefix':
  2605. return new QQNode('name_prefix', 'NamePrefix', 'string', $this);
  2606. case 'FirstName':
  2607. return new QQNode('first_name', 'FirstName', 'string', $this);
  2608. case 'MiddleName':
  2609. return new QQNode('middle_name', 'MiddleName', 'string', $this);
  2610. case 'LastName':
  2611. return new QQNode('last_name', 'LastName', 'string', $this);
  2612. case 'NameSuffix':
  2613. return new QQNode('name_suffix', 'NameSuffix', 'string', $this);
  2614. case 'NickName':
  2615. return new QQNode('nick_name', 'NickName', 'string', $this);
  2616. case 'AvatarUri':
  2617. return new QQNode('avatar_uri', 'AvatarUri', 'string', $this);
  2618. case 'CompanyName':
  2619. return new QQNode('company_name', 'CompanyName', 'string', $this);
  2620. case 'OwnerPersonId':
  2621. return new QQNode('owner_person_id', 'OwnerPersonId', 'integer', $this);
  2622. case 'OwnerPerson':
  2623. return new QQNodePerson('owner_person_id', 'OwnerPerson', 'integer', $this);
  2624. case 'IsVirtual':
  2625. return new QQNode('is_virtual', 'IsVirtual', 'boolean', $this);
  2626. case 'Usergroup':
  2627. return new QQNodePersonUsergroup($this);
  2628. case 'Account':
  2629. return new QQReverseReferenceNodeAccount($this, 'account', 'reverse_reference', 'person_id', 'Account');
  2630. case 'Address':
  2631. return new QQReverseReferenceNodeAddress($this, 'address', 'reverse_reference', 'person_id');
  2632. case 'ContentItemAsCreator':
  2633. return new QQReverseReferenceNodeContentItem($this, 'contentitemascreator', 'reverse_reference', 'creator_id');
  2634. case 'EmailAddress':
  2635. return new QQReverseReferenceNodeEmailAddress($this, 'emailaddress', 'reverse_reference', 'person_id');
  2636. case 'PersonAsOwner':
  2637. return new QQReverseReferenceNodePerson($this, 'personasowner', 'reverse_reference', 'owner_person_id');
  2638. case 'PhoneNumber':
  2639. return new QQReverseReferenceNodePhoneNumber($this, 'phonenumber', 'reverse_reference', 'person_id');
  2640. case 'ProductAsManufacturer':
  2641. return new QQReverseReferenceNodeProduct($this, 'productasmanufacturer', 'reverse_reference', 'manufacturer_id');
  2642. case 'ProductAsSupplier':
  2643. return new QQReverseReferenceNodeProduct($this, 'productassupplier', 'reverse_reference', 'supplier_id');
  2644. case '_PrimaryKeyNode':
  2645. return new QQNode('id', 'Id', 'integer', $this);
  2646. default:
  2647. try {
  2648. return parent::__get($strName);
  2649. } catch (QCallerException $objExc) {
  2650. $objExc->IncrementOffset();
  2651. throw $objExc;
  2652. }
  2653. }
  2654. }
  2655. }
  2656. class QQReverseReferenceNodePerson extends QQReverseReferenceNode {
  2657. protected $strTableName = 'person';
  2658. protected $strPrimaryKey = 'id';
  2659. protected $strClassName = 'Person';
  2660. public function __get($strName) {
  2661. switch ($strName) {
  2662. case 'Id':
  2663. return new QQNode('id', 'Id', 'integer', $this);
  2664. case 'NamePrefix':
  2665. return new QQNode('name_prefix', 'NamePrefix', 'string', $this);
  2666. case 'FirstName':
  2667. return new QQNode('first_name', 'FirstName', 'string', $this);
  2668. case 'MiddleName':
  2669. return new QQNode('middle_name', 'MiddleName', 'string', $this);
  2670. case 'LastName':
  2671. return new QQNode('last_name', 'LastName', 'string', $this);
  2672. case 'NameSuffix':
  2673. return new QQNode('name_suffix', 'NameSuffix', 'string', $this);
  2674. case 'NickName':
  2675. return new QQNode('nick_name', 'NickName', 'string', $this);
  2676. case 'AvatarUri':
  2677. return new QQNode('avatar_uri', 'AvatarUri', 'string', $this);
  2678. case 'CompanyName':
  2679. return new QQNode('company_name', 'CompanyName', 'string', $this);
  2680. case 'OwnerPersonId':
  2681. return new QQNode('owner_person_id', 'OwnerPersonId', 'integer', $this);
  2682. case 'OwnerPerson':
  2683. return new QQNodePerson('owner_person_id', 'OwnerPerson', 'integer', $this);
  2684. case 'IsVirtual':
  2685. return new QQNode('is_virtual', 'IsVirtual', 'boolean', $this);
  2686. case 'Usergroup':
  2687. return new QQNodePersonUsergroup($this);
  2688. case 'Account':
  2689. return new QQReverseReferenceNodeAccount($this, 'account', 'reverse_reference', 'person_id', 'Account');
  2690. case 'Address':
  2691. return new QQReverseReferenceNodeAddress($this, 'address', 'reverse_reference', 'person_id');
  2692. case 'ContentItemAsCreator':
  2693. return new QQReverseReferenceNodeContentItem($this, 'contentitemascreator', 'reverse_reference', 'creator_id');
  2694. case 'EmailAddress':
  2695. return new QQReverseReferenceNodeEmailAddress($this, 'emailaddress', 'reverse_reference', 'person_id');
  2696. case 'PersonAsOwner':
  2697. return new QQReverseReferenceNodePerson($this, 'personasowner', 'reverse_reference', 'owner_person_id');
  2698. case 'PhoneNumber':
  2699. return new QQReverseReferenceNodePhoneNumber($this, 'phonenumber', 'reverse_reference', 'person_id');
  2700. case 'ProductAsManufacturer':
  2701. return new QQReverseReferenceNodeProduct($this, 'productasmanufacturer', 'reverse_reference', 'manufacturer_id');
  2702. case 'ProductAsSupplier':
  2703. return new QQReverseReferenceNodeProduct($this, 'productassupplier', 'reverse_reference', 'supplier_id');
  2704. case '_PrimaryKeyNode':
  2705. return new QQNode('id', 'Id', 'integer', $this);
  2706. default:
  2707. try {
  2708. return parent::__get($strName);
  2709. } catch (QCallerException $objExc) {
  2710. $objExc->IncrementOffset();
  2711. throw $objExc;
  2712. }
  2713. }
  2714. }
  2715. }
  2716. ?>