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.

1790 lines
75 KiB

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