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.

1163 lines
50 KiB

  1. <?php
  2. /**
  3. * The abstract ShoppingCartGen 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 ShoppingCart subclass which
  8. * extends this ShoppingCartGen 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 ShoppingCart 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 $CreationDate the value for strCreationDate (Read-Only Timestamp)
  20. * @property-read string $LastModification the value for strLastModification (Read-Only Timestamp)
  21. * @property integer $AccountId the value for intAccountId (Not Null)
  22. * @property Account $Account the value for the Account object referenced by intAccountId (Not Null)
  23. * @property-read ShoppingCartItem $_ShoppingCartItem the value for the private _objShoppingCartItem (Read-Only) if set due to an expansion on the shopping_cart_item.shopping_cart_id reverse relationship
  24. * @property-read ShoppingCartItem[] $_ShoppingCartItemArray the value for the private _objShoppingCartItemArray (Read-Only) if set due to an ExpandAsArray on the shopping_cart_item.shopping_cart_id reverse relationship
  25. * @property-read boolean $__Restored whether or not this object was restored from the database (as opposed to created new)
  26. */
  27. class ShoppingCartGen extends QBaseClass
  28. {
  29. ///////////////////////////////////////////////////////////////////////
  30. // PROTECTED MEMBER VARIABLES and TEXT FIELD MAXLENGTHS (if applicable)
  31. ///////////////////////////////////////////////////////////////////////
  32. /////////// Object properties ////////////
  33. /**
  34. * Protected member variable that maps to the database PK Identity column shopping_cart.id
  35. * @var integer intId
  36. *
  37. */
  38. protected $intId = null;
  39. /**
  40. * Protected member variable that maps to the database column shopping_cart.creation_date
  41. * @var string strCreationDate
  42. *
  43. */
  44. protected $strCreationDate = null;
  45. /**
  46. * Protected member variable that maps to the database column shopping_cart.last_modification
  47. * @var string strLastModification
  48. *
  49. */
  50. protected $strLastModification = null;
  51. /**
  52. * Protected member variable that maps to the database column shopping_cart.account_id
  53. * @var integer intAccountId
  54. *
  55. */
  56. protected $intAccountId = null;
  57. /**
  58. * Private member variable that stores a reference to a single ShoppingCartItem object
  59. * (of type ShoppingCartItem), if this ShoppingCart object was restored with
  60. * an expansion on the shopping_cart_item association table.
  61. * @var ShoppingCartItem _objShoppingCartItem;
  62. */
  63. private $_objShoppingCartItem;
  64. /**
  65. * Private member variable that stores a reference to an array of ShoppingCartItem objects
  66. * (of type ShoppingCartItem[]), if this ShoppingCart object was restored with
  67. * an ExpandAsArray on the shopping_cart_item association table.
  68. * @var ShoppingCartItem[] _objShoppingCartItemArray;
  69. */
  70. private $_objShoppingCartItemArray = array();
  71. /**
  72. * Protected array of virtual attributes for this object (e.g. extra/other calculated and/or non-object bound
  73. * columns from the run-time database query result for this object). Used by InstantiateDbRow and
  74. * GetVirtualAttribute.
  75. * @var string[] $__strVirtualAttributeArray
  76. */
  77. protected $__strVirtualAttributeArray = array();
  78. /**
  79. * Protected internal member variable that specifies whether or not this object is Restored from the database.
  80. * Used by Save() to determine if Save() should perform a db UPDATE or INSERT.
  81. * @var bool __blnRestored;
  82. */
  83. protected $__blnRestored;
  84. ///////////////////////////////
  85. // PROTECTED MEMBER OBJECTS
  86. ///////////////////////////////
  87. /**
  88. * Protected member variable that contains the object pointed by the reference
  89. * in the database column shopping_cart.account_id.
  90. *
  91. * NOTE: Always use the Account property getter to correctly retrieve this Account object.
  92. * (Because this class implements late binding, this variable reference MAY be null.)
  93. * @var Account objAccount
  94. */
  95. protected $objAccount;
  96. ///////////////////////////////
  97. // CLASS-WIDE LOAD AND COUNT METHODS
  98. ///////////////////////////////
  99. /**
  100. * Static method to retrieve the Database object that owns this class.
  101. * @return QDatabaseBase reference to the Database object that can query this class
  102. */
  103. public static function GetDatabase() {
  104. return QApplication::$Database[1];
  105. }
  106. /**
  107. * Load a ShoppingCart from PK Info
  108. * @param integer $intId
  109. * @return ShoppingCart
  110. */
  111. public static function Load($intId) {
  112. // Use QuerySingle to Perform the Query
  113. return ShoppingCart::QuerySingle(
  114. QQ::Equal(QQN::ShoppingCart()->Id, $intId)
  115. );
  116. }
  117. /**
  118. * Load all ShoppingCarts
  119. * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  120. * @return ShoppingCart[]
  121. */
  122. public static function LoadAll($objOptionalClauses = null) {
  123. // Call ShoppingCart::QueryArray to perform the LoadAll query
  124. try {
  125. return ShoppingCart::QueryArray(QQ::All(), $objOptionalClauses);
  126. } catch (QCallerException $objExc) {
  127. $objExc->IncrementOffset();
  128. throw $objExc;
  129. }
  130. }
  131. /**
  132. * Count all ShoppingCarts
  133. * @return int
  134. */
  135. public static function CountAll() {
  136. // Call ShoppingCart::QueryCount to perform the CountAll query
  137. return ShoppingCart::QueryCount(QQ::All());
  138. }
  139. ///////////////////////////////
  140. // QCODO QUERY-RELATED METHODS
  141. ///////////////////////////////
  142. /**
  143. * Internally called method to assist with calling Qcodo Query for this class
  144. * on load methods.
  145. * @param QQueryBuilder &$objQueryBuilder the QueryBuilder object that will be created
  146. * @param QQCondition $objConditions any conditions on the query, itself
  147. * @param QQClause[] $objOptionalClausees additional optional QQClause object or array of QQClause objects for this query
  148. * @param mixed[] $mixParameterArray a array of name-value pairs to perform PrepareStatement with (sending in null will skip the PrepareStatement step)
  149. * @param boolean $blnCountOnly only select a rowcount
  150. * @return string the query statement
  151. */
  152. protected static function BuildQueryStatement(&$objQueryBuilder, QQCondition $objConditions, $objOptionalClauses, $mixParameterArray, $blnCountOnly) {
  153. // Get the Database Object for this Class
  154. $objDatabase = ShoppingCart::GetDatabase();
  155. // Create/Build out the QueryBuilder object with ShoppingCart-specific SELET and FROM fields
  156. $objQueryBuilder = new QQueryBuilder($objDatabase, 'shopping_cart');
  157. ShoppingCart::GetSelectFields($objQueryBuilder);
  158. $objQueryBuilder->AddFromItem('shopping_cart');
  159. // Set "CountOnly" option (if applicable)
  160. if ($blnCountOnly)
  161. $objQueryBuilder->SetCountOnlyFlag();
  162. // Apply Any Conditions
  163. if ($objConditions)
  164. try {
  165. $objConditions->UpdateQueryBuilder($objQueryBuilder);
  166. } catch (QCallerException $objExc) {
  167. $objExc->IncrementOffset();
  168. throw $objExc;
  169. }
  170. // Iterate through all the Optional Clauses (if any) and perform accordingly
  171. if ($objOptionalClauses) {
  172. if ($objOptionalClauses instanceof QQClause)
  173. $objOptionalClauses->UpdateQueryBuilder($objQueryBuilder);
  174. else if (is_array($objOptionalClauses))
  175. foreach ($objOptionalClauses as $objClause)
  176. $objClause->UpdateQueryBuilder($objQueryBuilder);
  177. else
  178. throw new QCallerException('Optional Clauses must be a QQClause object or an array of QQClause objects');
  179. }
  180. // Get the SQL Statement
  181. $strQuery = $objQueryBuilder->GetStatement();
  182. // Prepare the Statement with the Query Parameters (if applicable)
  183. if ($mixParameterArray) {
  184. if (is_array($mixParameterArray)) {
  185. if (count($mixParameterArray))
  186. $strQuery = $objDatabase->PrepareStatement($strQuery, $mixParameterArray);
  187. // Ensure that there are no other Unresolved Named Parameters
  188. if (strpos($strQuery, chr(QQNamedValue::DelimiterCode) . '{') !== false)
  189. throw new QCallerException('Unresolved named parameters in the query');
  190. } else
  191. throw new QCallerException('Parameter Array must be an array of name-value parameter pairs');
  192. }
  193. // Return the Objects
  194. return $strQuery;
  195. }
  196. /**
  197. * Static Qcodo Query method to query for a single ShoppingCart object.
  198. * Uses BuildQueryStatment to perform most of the work.
  199. * @param QQCondition $objConditions any conditions on the query, itself
  200. * @param QQClause[] $objOptionalClausees additional optional QQClause objects for this query
  201. * @param mixed[] $mixParameterArray a array of name-value pairs to perform PrepareStatement with
  202. * @return ShoppingCart the queried object
  203. */
  204. public static function QuerySingle(QQCondition $objConditions, $objOptionalClauses = null, $mixParameterArray = null) {
  205. // Get the Query Statement
  206. try {
  207. $strQuery = ShoppingCart::BuildQueryStatement($objQueryBuilder, $objConditions, $objOptionalClauses, $mixParameterArray, false);
  208. } catch (QCallerException $objExc) {
  209. $objExc->IncrementOffset();
  210. throw $objExc;
  211. }
  212. // Perform the Query, Get the First Row, and Instantiate a new ShoppingCart object
  213. $objDbResult = $objQueryBuilder->Database->Query($strQuery);
  214. return ShoppingCart::InstantiateDbRow($objDbResult->GetNextRow(), null, null, null, $objQueryBuilder->ColumnAliasArray);
  215. }
  216. /**
  217. * Static Qcodo Query method to query for an array of ShoppingCart objects.
  218. * Uses BuildQueryStatment to perform most of the work.
  219. * @param QQCondition $objConditions any conditions on the query, itself
  220. * @param QQClause[] $objOptionalClausees additional optional QQClause objects for this query
  221. * @param mixed[] $mixParameterArray a array of name-value pairs to perform PrepareStatement with
  222. * @return ShoppingCart[] the queried objects as an array
  223. */
  224. public static function QueryArray(QQCondition $objConditions, $objOptionalClauses = null, $mixParameterArray = null) {
  225. // Get the Query Statement
  226. try {
  227. $strQuery = ShoppingCart::BuildQueryStatement($objQueryBuilder, $objConditions, $objOptionalClauses, $mixParameterArray, false);
  228. } catch (QCallerException $objExc) {
  229. $objExc->IncrementOffset();
  230. throw $objExc;
  231. }
  232. // Perform the Query and Instantiate the Array Result
  233. $objDbResult = $objQueryBuilder->Database->Query($strQuery);
  234. return ShoppingCart::InstantiateDbResult($objDbResult, $objQueryBuilder->ExpandAsArrayNodes, $objQueryBuilder->ColumnAliasArray);
  235. }
  236. /**
  237. * Static Qcodo Query method to query for a count of ShoppingCart objects.
  238. * Uses BuildQueryStatment to perform most of the work.
  239. * @param QQCondition $objConditions any conditions on the query, itself
  240. * @param QQClause[] $objOptionalClausees additional optional QQClause objects for this query
  241. * @param mixed[] $mixParameterArray a array of name-value pairs to perform PrepareStatement with
  242. * @return integer the count of queried objects as an integer
  243. */
  244. public static function QueryCount(QQCondition $objConditions, $objOptionalClauses = null, $mixParameterArray = null) {
  245. // Get the Query Statement
  246. try {
  247. $strQuery = ShoppingCart::BuildQueryStatement($objQueryBuilder, $objConditions, $objOptionalClauses, $mixParameterArray, true);
  248. } catch (QCallerException $objExc) {
  249. $objExc->IncrementOffset();
  250. throw $objExc;
  251. }
  252. // Perform the Query and return the row_count
  253. $objDbResult = $objQueryBuilder->Database->Query($strQuery);
  254. // Figure out if the query is using GroupBy
  255. $blnGrouped = false;
  256. if ($objOptionalClauses) foreach ($objOptionalClauses as $objClause) {
  257. if ($objClause instanceof QQGroupBy) {
  258. $blnGrouped = true;
  259. break;
  260. }
  261. }
  262. if ($blnGrouped)
  263. // Groups in this query - return the count of Groups (which is the count of all rows)
  264. return $objDbResult->CountRows();
  265. else {
  266. // No Groups - return the sql-calculated count(*) value
  267. $strDbRow = $objDbResult->FetchRow();
  268. return QType::Cast($strDbRow[0], QType::Integer);
  269. }
  270. }
  271. /* public static function QueryArrayCached($strConditions, $mixParameterArray = null) {
  272. // Get the Database Object for this Class
  273. $objDatabase = ShoppingCart::GetDatabase();
  274. // Lookup the QCache for This Query Statement
  275. $objCache = new QCache('query', 'shopping_cart_' . serialize($strConditions));
  276. if (!($strQuery = $objCache->GetData())) {
  277. // Not Found -- Go ahead and Create/Build out a new QueryBuilder object with ShoppingCart-specific fields
  278. $objQueryBuilder = new QQueryBuilder($objDatabase);
  279. ShoppingCart::GetSelectFields($objQueryBuilder);
  280. ShoppingCart::GetFromFields($objQueryBuilder);
  281. // Ensure the Passed-in Conditions is a string
  282. try {
  283. $strConditions = QType::Cast($strConditions, QType::String);
  284. } catch (QCallerException $objExc) {
  285. $objExc->IncrementOffset();
  286. throw $objExc;
  287. }
  288. // Create the Conditions object, and apply it
  289. $objConditions = eval('return ' . $strConditions . ';');
  290. // Apply Any Conditions
  291. if ($objConditions)
  292. $objConditions->UpdateQueryBuilder($objQueryBuilder);
  293. // Get the SQL Statement
  294. $strQuery = $objQueryBuilder->GetStatement();
  295. // Save the SQL Statement in the Cache
  296. $objCache->SaveData($strQuery);
  297. }
  298. // Prepare the Statement with the Parameters
  299. if ($mixParameterArray)
  300. $strQuery = $objDatabase->PrepareStatement($strQuery, $mixParameterArray);
  301. // Perform the Query and Instantiate the Array Result
  302. $objDbResult = $objDatabase->Query($strQuery);
  303. return ShoppingCart::InstantiateDbResult($objDbResult);
  304. }*/
  305. /**
  306. * Updates a QQueryBuilder with the SELECT fields for this ShoppingCart
  307. * @param QQueryBuilder $objBuilder the Query Builder object to update
  308. * @param string $strPrefix optional prefix to add to the SELECT fields
  309. */
  310. public static function GetSelectFields(QQueryBuilder $objBuilder, $strPrefix = null) {
  311. if ($strPrefix) {
  312. $strTableName = $strPrefix;
  313. $strAliasPrefix = $strPrefix . '__';
  314. } else {
  315. $strTableName = 'shopping_cart';
  316. $strAliasPrefix = '';
  317. }
  318. $objBuilder->AddSelectItem($strTableName, 'id', $strAliasPrefix . 'id');
  319. $objBuilder->AddSelectItem($strTableName, 'creation_date', $strAliasPrefix . 'creation_date');
  320. $objBuilder->AddSelectItem($strTableName, 'last_modification', $strAliasPrefix . 'last_modification');
  321. $objBuilder->AddSelectItem($strTableName, 'account_id', $strAliasPrefix . 'account_id');
  322. }
  323. ///////////////////////////////
  324. // INSTANTIATION-RELATED METHODS
  325. ///////////////////////////////
  326. /**
  327. * Instantiate a ShoppingCart from a Database Row.
  328. * Takes in an optional strAliasPrefix, used in case another Object::InstantiateDbRow
  329. * is calling this ShoppingCart::InstantiateDbRow in order to perform
  330. * early binding on referenced objects.
  331. * @param DatabaseRowBase $objDbRow
  332. * @param string $strAliasPrefix
  333. * @param string $strExpandAsArrayNodes
  334. * @param QBaseClass $objPreviousItem
  335. * @param string[] $strColumnAliasArray
  336. * @return ShoppingCart
  337. */
  338. public static function InstantiateDbRow($objDbRow, $strAliasPrefix = null, $strExpandAsArrayNodes = null, $objPreviousItem = null, $strColumnAliasArray = array()) {
  339. // If blank row, return null
  340. if (!$objDbRow)
  341. return null;
  342. // See if we're doing an array expansion on the previous item
  343. $strAlias = $strAliasPrefix . 'id';
  344. $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
  345. if (($strExpandAsArrayNodes) && ($objPreviousItem) &&
  346. ($objPreviousItem->intId == $objDbRow->GetColumn($strAliasName, 'Integer'))) {
  347. // We are. Now, prepare to check for ExpandAsArray clauses
  348. $blnExpandedViaArray = false;
  349. if (!$strAliasPrefix)
  350. $strAliasPrefix = 'shopping_cart__';
  351. $strAlias = $strAliasPrefix . 'shoppingcartitem__shopping_cart_id';
  352. $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
  353. if ((array_key_exists($strAlias, $strExpandAsArrayNodes)) &&
  354. (!is_null($objDbRow->GetColumn($strAliasName)))) {
  355. if ($intPreviousChildItemCount = count($objPreviousItem->_objShoppingCartItemArray)) {
  356. $objPreviousChildItem = $objPreviousItem->_objShoppingCartItemArray[$intPreviousChildItemCount - 1];
  357. $objChildItem = ShoppingCartItem::InstantiateDbRow($objDbRow, $strAliasPrefix . 'shoppingcartitem__', $strExpandAsArrayNodes, $objPreviousChildItem, $strColumnAliasArray);
  358. if ($objChildItem)
  359. $objPreviousItem->_objShoppingCartItemArray[] = $objChildItem;
  360. } else
  361. $objPreviousItem->_objShoppingCartItemArray[] = ShoppingCartItem::InstantiateDbRow($objDbRow, $strAliasPrefix . 'shoppingcartitem__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  362. $blnExpandedViaArray = true;
  363. }
  364. // Either return false to signal array expansion, or check-to-reset the Alias prefix and move on
  365. if ($blnExpandedViaArray)
  366. return false;
  367. else if ($strAliasPrefix == 'shopping_cart__')
  368. $strAliasPrefix = null;
  369. }
  370. // Create a new instance of the ShoppingCart object
  371. $objToReturn = new ShoppingCart();
  372. $objToReturn->__blnRestored = true;
  373. $strAliasName = array_key_exists($strAliasPrefix . 'id', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'id'] : $strAliasPrefix . 'id';
  374. $objToReturn->intId = $objDbRow->GetColumn($strAliasName, 'Integer');
  375. $strAliasName = array_key_exists($strAliasPrefix . 'creation_date', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'creation_date'] : $strAliasPrefix . 'creation_date';
  376. $objToReturn->strCreationDate = $objDbRow->GetColumn($strAliasName, 'VarChar');
  377. $strAliasName = array_key_exists($strAliasPrefix . 'last_modification', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'last_modification'] : $strAliasPrefix . 'last_modification';
  378. $objToReturn->strLastModification = $objDbRow->GetColumn($strAliasName, 'VarChar');
  379. $strAliasName = array_key_exists($strAliasPrefix . 'account_id', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'account_id'] : $strAliasPrefix . 'account_id';
  380. $objToReturn->intAccountId = $objDbRow->GetColumn($strAliasName, 'Integer');
  381. // Instantiate Virtual Attributes
  382. foreach ($objDbRow->GetColumnNameArray() as $strColumnName => $mixValue) {
  383. $strVirtualPrefix = $strAliasPrefix . '__';
  384. $strVirtualPrefixLength = strlen($strVirtualPrefix);
  385. if (substr($strColumnName, 0, $strVirtualPrefixLength) == $strVirtualPrefix)
  386. $objToReturn->__strVirtualAttributeArray[substr($strColumnName, $strVirtualPrefixLength)] = $mixValue;
  387. }
  388. // Prepare to Check for Early/Virtual Binding
  389. if (!$strAliasPrefix)
  390. $strAliasPrefix = 'shopping_cart__';
  391. // Check for Account Early Binding
  392. $strAlias = $strAliasPrefix . 'account_id__id';
  393. $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
  394. if (!is_null($objDbRow->GetColumn($strAliasName)))
  395. $objToReturn->objAccount = Account::InstantiateDbRow($objDbRow, $strAliasPrefix . 'account_id__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  396. // Check for ShoppingCartItem Virtual Binding
  397. $strAlias = $strAliasPrefix . 'shoppingcartitem__shopping_cart_id';
  398. $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
  399. if (!is_null($objDbRow->GetColumn($strAliasName))) {
  400. if (($strExpandAsArrayNodes) && (array_key_exists($strAlias, $strExpandAsArrayNodes)))
  401. $objToReturn->_objShoppingCartItemArray[] = ShoppingCartItem::InstantiateDbRow($objDbRow, $strAliasPrefix . 'shoppingcartitem__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  402. else
  403. $objToReturn->_objShoppingCartItem = ShoppingCartItem::InstantiateDbRow($objDbRow, $strAliasPrefix . 'shoppingcartitem__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  404. }
  405. return $objToReturn;
  406. }
  407. /**
  408. * Instantiate an array of ShoppingCarts from a Database Result
  409. * @param DatabaseResultBase $objDbResult
  410. * @param string $strExpandAsArrayNodes
  411. * @param string[] $strColumnAliasArray
  412. * @return ShoppingCart[]
  413. */
  414. public static function InstantiateDbResult(QDatabaseResultBase $objDbResult, $strExpandAsArrayNodes = null, $strColumnAliasArray = null) {
  415. $objToReturn = array();
  416. if (!$strColumnAliasArray)
  417. $strColumnAliasArray = array();
  418. // If blank resultset, then return empty array
  419. if (!$objDbResult)
  420. return $objToReturn;
  421. // Load up the return array with each row
  422. if ($strExpandAsArrayNodes) {
  423. $objLastRowItem = null;
  424. while ($objDbRow = $objDbResult->GetNextRow()) {
  425. $objItem = ShoppingCart::InstantiateDbRow($objDbRow, null, $strExpandAsArrayNodes, $objLastRowItem, $strColumnAliasArray);
  426. if ($objItem) {
  427. $objToReturn[] = $objItem;
  428. $objLastRowItem = $objItem;
  429. }
  430. }
  431. } else {
  432. while ($objDbRow = $objDbResult->GetNextRow())
  433. $objToReturn[] = ShoppingCart::InstantiateDbRow($objDbRow, null, null, null, $strColumnAliasArray);
  434. }
  435. return $objToReturn;
  436. }
  437. ///////////////////////////////////////////////////
  438. // INDEX-BASED LOAD METHODS (Single Load and Array)
  439. ///////////////////////////////////////////////////
  440. /**
  441. * Load a single ShoppingCart object,
  442. * by Id Index(es)
  443. * @param integer $intId
  444. * @return ShoppingCart
  445. */
  446. public static function LoadById($intId) {
  447. return ShoppingCart::QuerySingle(
  448. QQ::Equal(QQN::ShoppingCart()->Id, $intId)
  449. );
  450. }
  451. /**
  452. * Load an array of ShoppingCart objects,
  453. * by AccountId Index(es)
  454. * @param integer $intAccountId
  455. * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  456. * @return ShoppingCart[]
  457. */
  458. public static function LoadArrayByAccountId($intAccountId, $objOptionalClauses = null) {
  459. // Call ShoppingCart::QueryArray to perform the LoadArrayByAccountId query
  460. try {
  461. return ShoppingCart::QueryArray(
  462. QQ::Equal(QQN::ShoppingCart()->AccountId, $intAccountId),
  463. $objOptionalClauses);
  464. } catch (QCallerException $objExc) {
  465. $objExc->IncrementOffset();
  466. throw $objExc;
  467. }
  468. }
  469. /**
  470. * Count ShoppingCarts
  471. * by AccountId Index(es)
  472. * @param integer $intAccountId
  473. * @return int
  474. */
  475. public static function CountByAccountId($intAccountId) {
  476. // Call ShoppingCart::QueryCount to perform the CountByAccountId query
  477. return ShoppingCart::QueryCount(
  478. QQ::Equal(QQN::ShoppingCart()->AccountId, $intAccountId)
  479. );
  480. }
  481. ////////////////////////////////////////////////////
  482. // INDEX-BASED LOAD METHODS (Array via Many to Many)
  483. ////////////////////////////////////////////////////
  484. //////////////////////////
  485. // SAVE, DELETE AND RELOAD
  486. //////////////////////////
  487. /**
  488. * Save this ShoppingCart
  489. * @param bool $blnForceInsert
  490. * @param bool $blnForceUpdate
  491. * @return int
  492. */
  493. public function Save($blnForceInsert = false, $blnForceUpdate = false) {
  494. // Get the Database Object for this Class
  495. $objDatabase = ShoppingCart::GetDatabase();
  496. $mixToReturn = null;
  497. try {
  498. if ((!$this->__blnRestored) || ($blnForceInsert)) {
  499. // Perform an INSERT query
  500. $objDatabase->NonQuery('
  501. INSERT INTO `shopping_cart` (
  502. `account_id`
  503. ) VALUES (
  504. ' . $objDatabase->SqlVariable($this->intAccountId) . '
  505. )
  506. ');
  507. // Update Identity column and return its value
  508. $mixToReturn = $this->intId = $objDatabase->InsertId('shopping_cart', 'id');
  509. } else {
  510. // Perform an UPDATE query
  511. // First checking for Optimistic Locking constraints (if applicable)
  512. if (!$blnForceUpdate) {
  513. // Perform the Optimistic Locking check
  514. $objResult = $objDatabase->Query('
  515. SELECT
  516. `creation_date`
  517. FROM
  518. `shopping_cart`
  519. WHERE
  520. `id` = ' . $objDatabase->SqlVariable($this->intId) . '
  521. ');
  522. $objRow = $objResult->FetchArray();
  523. if ($objRow[0] != $this->strCreationDate)
  524. throw new QOptimisticLockingException('ShoppingCart');
  525. }
  526. if (!$blnForceUpdate) {
  527. // Perform the Optimistic Locking check
  528. $objResult = $objDatabase->Query('
  529. SELECT
  530. `last_modification`
  531. FROM
  532. `shopping_cart`
  533. WHERE
  534. `id` = ' . $objDatabase->SqlVariable($this->intId) . '
  535. ');
  536. $objRow = $objResult->FetchArray();
  537. if ($objRow[0] != $this->strLastModification)
  538. throw new QOptimisticLockingException('ShoppingCart');
  539. }
  540. // Perform the UPDATE query
  541. $objDatabase->NonQuery('
  542. UPDATE
  543. `shopping_cart`
  544. SET
  545. `account_id` = ' . $objDatabase->SqlVariable($this->intAccountId) . '
  546. WHERE
  547. `id` = ' . $objDatabase->SqlVariable($this->intId) . '
  548. ');
  549. }
  550. } catch (QCallerException $objExc) {
  551. $objExc->IncrementOffset();
  552. throw $objExc;
  553. }
  554. // Update __blnRestored and any Non-Identity PK Columns (if applicable)
  555. $this->__blnRestored = true;
  556. // Update Local Timestamp
  557. $objResult = $objDatabase->Query('
  558. SELECT
  559. `creation_date`
  560. FROM
  561. `shopping_cart`
  562. WHERE
  563. `id` = ' . $objDatabase->SqlVariable($this->intId) . '
  564. ');
  565. $objRow = $objResult->FetchArray();
  566. $this->strCreationDate = $objRow[0];
  567. // Update Local Timestamp
  568. $objResult = $objDatabase->Query('
  569. SELECT
  570. `last_modification`
  571. FROM
  572. `shopping_cart`
  573. WHERE
  574. `id` = ' . $objDatabase->SqlVariable($this->intId) . '
  575. ');
  576. $objRow = $objResult->FetchArray();
  577. $this->strLastModification = $objRow[0];
  578. // Return
  579. return $mixToReturn;
  580. }
  581. /**
  582. * Delete this ShoppingCart
  583. * @return void
  584. */
  585. public function Delete() {
  586. if ((is_null($this->intId)))
  587. throw new QUndefinedPrimaryKeyException('Cannot delete this ShoppingCart with an unset primary key.');
  588. // Get the Database Object for this Class
  589. $objDatabase = ShoppingCart::GetDatabase();
  590. // Perform the SQL Query
  591. $objDatabase->NonQuery('
  592. DELETE FROM
  593. `shopping_cart`
  594. WHERE
  595. `id` = ' . $objDatabase->SqlVariable($this->intId) . '');
  596. }
  597. /**
  598. * Delete all ShoppingCarts
  599. * @return void
  600. */
  601. public static function DeleteAll() {
  602. // Get the Database Object for this Class
  603. $objDatabase = ShoppingCart::GetDatabase();
  604. // Perform the Query
  605. $objDatabase->NonQuery('
  606. DELETE FROM
  607. `shopping_cart`');
  608. }
  609. /**
  610. * Truncate shopping_cart table
  611. * @return void
  612. */
  613. public static function Truncate() {
  614. // Get the Database Object for this Class
  615. $objDatabase = ShoppingCart::GetDatabase();
  616. // Perform the Query
  617. $objDatabase->NonQuery('
  618. TRUNCATE `shopping_cart`');
  619. }
  620. /**
  621. * Reload this ShoppingCart from the database.
  622. * @return void
  623. */
  624. public function Reload() {
  625. // Make sure we are actually Restored from the database
  626. if (!$this->__blnRestored)
  627. throw new QCallerException('Cannot call Reload() on a new, unsaved ShoppingCart object.');
  628. // Reload the Object
  629. $objReloaded = ShoppingCart::Load($this->intId);
  630. // Update $this's local variables to match
  631. $this->strCreationDate = $objReloaded->strCreationDate;
  632. $this->strLastModification = $objReloaded->strLastModification;
  633. $this->AccountId = $objReloaded->AccountId;
  634. }
  635. ////////////////////
  636. // GETTORS AND SETTORS
  637. ////////////////////
  638. /**
  639. * Lookup a VirtualAttribute value (if applicable). Returns NULL if none found.
  640. * @param string $strName
  641. * @return string
  642. */
  643. public function GetVirtualAttribute($strName)
  644. {
  645. if (array_key_exists($strName, $this->__strVirtualAttributeArray))
  646. return $this->__strVirtualAttributeArray[$strName];
  647. return null;
  648. }
  649. /**
  650. * Override method to perform a property "Get"
  651. * This will get the value of $strName
  652. *
  653. * @param string $strName Name of the property to get
  654. * @return mixed
  655. */
  656. public function __get($strName)
  657. {
  658. switch ($strName)
  659. {
  660. ///////////////////
  661. // Member Variables
  662. ///////////////////
  663. case 'Id':
  664. /**
  665. * Gets the value for intId (Read-Only PK)
  666. * @return integer
  667. */
  668. return $this->intId;
  669. case 'CreationDate':
  670. /**
  671. * Gets the value for strCreationDate (Read-Only Timestamp)
  672. * @return string
  673. */
  674. return $this->strCreationDate;
  675. case 'LastModification':
  676. /**
  677. * Gets the value for strLastModification (Read-Only Timestamp)
  678. * @return string
  679. */
  680. return $this->strLastModification;
  681. case 'AccountId':
  682. /**
  683. * Gets the value for intAccountId (Not Null)
  684. * @return integer
  685. */
  686. return $this->intAccountId;
  687. ///////////////////
  688. // Member Objects
  689. ///////////////////
  690. case 'Account':
  691. /**
  692. * Gets the value for the Account object referenced by intAccountId (Not Null)
  693. * @return Account
  694. */
  695. try {
  696. if ((!$this->objAccount) && (!is_null($this->intAccountId)))
  697. $this->objAccount = Account::Load($this->intAccountId);
  698. return $this->objAccount;
  699. } catch (QCallerException $objExc) {
  700. $objExc->IncrementOffset();
  701. throw $objExc;
  702. }
  703. ////////////////////////////
  704. // Virtual Object References (Many to Many and Reverse References)
  705. // (If restored via a "Many-to" expansion)
  706. ////////////////////////////
  707. case '_ShoppingCartItem':
  708. /**
  709. * Gets the value for the private _objShoppingCartItem (Read-Only)
  710. * if set due to an expansion on the shopping_cart_item.shopping_cart_id reverse relationship
  711. * @return ShoppingCartItem
  712. */
  713. return $this->_objShoppingCartItem;
  714. case '_ShoppingCartItemArray':
  715. /**
  716. * Gets the value for the private _objShoppingCartItemArray (Read-Only)
  717. * if set due to an ExpandAsArray on the shopping_cart_item.shopping_cart_id reverse relationship
  718. * @return ShoppingCartItem[]
  719. */
  720. return (array) $this->_objShoppingCartItemArray;
  721. case '__Restored':
  722. return $this->__blnRestored;
  723. default:
  724. try {
  725. return parent::__get($strName);
  726. } catch (QCallerException $objExc) {
  727. $objExc->IncrementOffset();
  728. throw $objExc;
  729. }
  730. }
  731. }
  732. /**
  733. * Override method to perform a property "Set"
  734. * This will set the property $strName to be $mixValue
  735. *
  736. * @param string $strName Name of the property to set
  737. * @param string $mixValue New value of the property
  738. * @return mixed
  739. */
  740. public function __set($strName, $mixValue) {
  741. switch ($strName) {
  742. ///////////////////
  743. // Member Variables
  744. ///////////////////
  745. case 'AccountId':
  746. /**
  747. * Sets the value for intAccountId (Not Null)
  748. * @param integer $mixValue
  749. * @return integer
  750. */
  751. try {
  752. $this->objAccount = null;
  753. return ($this->intAccountId = QType::Cast($mixValue, QType::Integer));
  754. } catch (QCallerException $objExc) {
  755. $objExc->IncrementOffset();
  756. throw $objExc;
  757. }
  758. ///////////////////
  759. // Member Objects
  760. ///////////////////
  761. case 'Account':
  762. /**
  763. * Sets the value for the Account object referenced by intAccountId (Not Null)
  764. * @param Account $mixValue
  765. * @return Account
  766. */
  767. if (is_null($mixValue)) {
  768. $this->intAccountId = null;
  769. $this->objAccount = null;
  770. return null;
  771. } else {
  772. // Make sure $mixValue actually is a Account object
  773. try {
  774. $mixValue = QType::Cast($mixValue, 'Account');
  775. } catch (QInvalidCastException $objExc) {
  776. $objExc->IncrementOffset();
  777. throw $objExc;
  778. }
  779. // Make sure $mixValue is a SAVED Account object
  780. if (is_null($mixValue->Id))
  781. throw new QCallerException('Unable to set an unsaved Account for this ShoppingCart');
  782. // Update Local Member Variables
  783. $this->objAccount = $mixValue;
  784. $this->intAccountId = $mixValue->Id;
  785. // Return $mixValue
  786. return $mixValue;
  787. }
  788. break;
  789. default:
  790. try {
  791. return parent::__set($strName, $mixValue);
  792. } catch (QCallerException $objExc) {
  793. $objExc->IncrementOffset();
  794. throw $objExc;
  795. }
  796. }
  797. }
  798. ///////////////////////////////
  799. // ASSOCIATED OBJECTS' METHODS
  800. ///////////////////////////////
  801. // Related Objects' Methods for ShoppingCartItem
  802. //-------------------------------------------------------------------
  803. /**
  804. * Gets all associated ShoppingCartItems as an array of ShoppingCartItem objects
  805. * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  806. * @return ShoppingCartItem[]
  807. */
  808. public function GetShoppingCartItemArray($objOptionalClauses = null) {
  809. if ((is_null($this->intId)))
  810. return array();
  811. try {
  812. return ShoppingCartItem::LoadArrayByShoppingCartId($this->intId, $objOptionalClauses);
  813. } catch (QCallerException $objExc) {
  814. $objExc->IncrementOffset();
  815. throw $objExc;
  816. }
  817. }
  818. /**
  819. * Counts all associated ShoppingCartItems
  820. * @return int
  821. */
  822. public function CountShoppingCartItems() {
  823. if ((is_null($this->intId)))
  824. return 0;
  825. return ShoppingCartItem::CountByShoppingCartId($this->intId);
  826. }
  827. /**
  828. * Associates a ShoppingCartItem
  829. * @param ShoppingCartItem $objShoppingCartItem
  830. * @return void
  831. */
  832. public function AssociateShoppingCartItem(ShoppingCartItem $objShoppingCartItem) {
  833. if ((is_null($this->intId)))
  834. throw new QUndefinedPrimaryKeyException('Unable to call AssociateShoppingCartItem on this unsaved ShoppingCart.');
  835. if ((is_null($objShoppingCartItem->ShoppingCartId)) || (is_null($objShoppingCartItem->ProductId)))
  836. throw new QUndefinedPrimaryKeyException('Unable to call AssociateShoppingCartItem on this ShoppingCart with an unsaved ShoppingCartItem.');
  837. // Get the Database Object for this Class
  838. $objDatabase = ShoppingCart::GetDatabase();
  839. // Perform the SQL Query
  840. $objDatabase->NonQuery('
  841. UPDATE
  842. `shopping_cart_item`
  843. SET
  844. `shopping_cart_id` = ' . $objDatabase->SqlVariable($this->intId) . '
  845. WHERE
  846. `shopping_cart_id` = ' . $objDatabase->SqlVariable($objShoppingCartItem->ShoppingCartId) . ' AND
  847. `product_id` = ' . $objDatabase->SqlVariable($objShoppingCartItem->ProductId) . '
  848. ');
  849. }
  850. /**
  851. * Unassociates a ShoppingCartItem
  852. * @param ShoppingCartItem $objShoppingCartItem
  853. * @return void
  854. */
  855. public function UnassociateShoppingCartItem(ShoppingCartItem $objShoppingCartItem) {
  856. if ((is_null($this->intId)))
  857. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateShoppingCartItem on this unsaved ShoppingCart.');
  858. if ((is_null($objShoppingCartItem->ShoppingCartId)) || (is_null($objShoppingCartItem->ProductId)))
  859. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateShoppingCartItem on this ShoppingCart with an unsaved ShoppingCartItem.');
  860. // Get the Database Object for this Class
  861. $objDatabase = ShoppingCart::GetDatabase();
  862. // Perform the SQL Query
  863. $objDatabase->NonQuery('
  864. UPDATE
  865. `shopping_cart_item`
  866. SET
  867. `shopping_cart_id` = null
  868. WHERE
  869. `shopping_cart_id` = ' . $objDatabase->SqlVariable($objShoppingCartItem->ShoppingCartId) . ' AND
  870. `product_id` = ' . $objDatabase->SqlVariable($objShoppingCartItem->ProductId) . ' AND
  871. `shopping_cart_id` = ' . $objDatabase->SqlVariable($this->intId) . '
  872. ');
  873. }
  874. /**
  875. * Unassociates all ShoppingCartItems
  876. * @return void
  877. */
  878. public function UnassociateAllShoppingCartItems() {
  879. if ((is_null($this->intId)))
  880. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateShoppingCartItem on this unsaved ShoppingCart.');
  881. // Get the Database Object for this Class
  882. $objDatabase = ShoppingCart::GetDatabase();
  883. // Perform the SQL Query
  884. $objDatabase->NonQuery('
  885. UPDATE
  886. `shopping_cart_item`
  887. SET
  888. `shopping_cart_id` = null
  889. WHERE
  890. `shopping_cart_id` = ' . $objDatabase->SqlVariable($this->intId) . '
  891. ');
  892. }
  893. /**
  894. * Deletes an associated ShoppingCartItem
  895. * @param ShoppingCartItem $objShoppingCartItem
  896. * @return void
  897. */
  898. public function DeleteAssociatedShoppingCartItem(ShoppingCartItem $objShoppingCartItem) {
  899. if ((is_null($this->intId)))
  900. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateShoppingCartItem on this unsaved ShoppingCart.');
  901. if ((is_null($objShoppingCartItem->ShoppingCartId)) || (is_null($objShoppingCartItem->ProductId)))
  902. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateShoppingCartItem on this ShoppingCart with an unsaved ShoppingCartItem.');
  903. // Get the Database Object for this Class
  904. $objDatabase = ShoppingCart::GetDatabase();
  905. // Perform the SQL Query
  906. $objDatabase->NonQuery('
  907. DELETE FROM
  908. `shopping_cart_item`
  909. WHERE
  910. `shopping_cart_id` = ' . $objDatabase->SqlVariable($objShoppingCartItem->ShoppingCartId) . ' AND
  911. `product_id` = ' . $objDatabase->SqlVariable($objShoppingCartItem->ProductId) . ' AND
  912. `shopping_cart_id` = ' . $objDatabase->SqlVariable($this->intId) . '
  913. ');
  914. }
  915. /**
  916. * Deletes all associated ShoppingCartItems
  917. * @return void
  918. */
  919. public function DeleteAllShoppingCartItems() {
  920. if ((is_null($this->intId)))
  921. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateShoppingCartItem on this unsaved ShoppingCart.');
  922. // Get the Database Object for this Class
  923. $objDatabase = ShoppingCart::GetDatabase();
  924. // Perform the SQL Query
  925. $objDatabase->NonQuery('
  926. DELETE FROM
  927. `shopping_cart_item`
  928. WHERE
  929. `shopping_cart_id` = ' . $objDatabase->SqlVariable($this->intId) . '
  930. ');
  931. }
  932. }
  933. /////////////////////////////////////
  934. // ADDITIONAL CLASSES for QCODO QUERY
  935. /////////////////////////////////////
  936. class QQNodeShoppingCart extends QQNode {
  937. protected $strTableName = 'shopping_cart';
  938. protected $strPrimaryKey = 'id';
  939. protected $strClassName = 'ShoppingCart';
  940. public function __get($strName) {
  941. switch ($strName) {
  942. case 'Id':
  943. return new QQNode('id', 'Id', 'integer', $this);
  944. case 'CreationDate':
  945. return new QQNode('creation_date', 'CreationDate', 'string', $this);
  946. case 'LastModification':
  947. return new QQNode('last_modification', 'LastModification', 'string', $this);
  948. case 'AccountId':
  949. return new QQNode('account_id', 'AccountId', 'integer', $this);
  950. case 'Account':
  951. return new QQNodeAccount('account_id', 'Account', 'integer', $this);
  952. case 'ShoppingCartItem':
  953. return new QQReverseReferenceNodeShoppingCartItem($this, 'shoppingcartitem', 'reverse_reference', 'shopping_cart_id');
  954. case '_PrimaryKeyNode':
  955. return new QQNode('id', 'Id', 'integer', $this);
  956. default:
  957. try {
  958. return parent::__get($strName);
  959. } catch (QCallerException $objExc) {
  960. $objExc->IncrementOffset();
  961. throw $objExc;
  962. }
  963. }
  964. }
  965. }
  966. class QQReverseReferenceNodeShoppingCart extends QQReverseReferenceNode {
  967. protected $strTableName = 'shopping_cart';
  968. protected $strPrimaryKey = 'id';
  969. protected $strClassName = 'ShoppingCart';
  970. public function __get($strName) {
  971. switch ($strName) {
  972. case 'Id':
  973. return new QQNode('id', 'Id', 'integer', $this);
  974. case 'CreationDate':
  975. return new QQNode('creation_date', 'CreationDate', 'string', $this);
  976. case 'LastModification':
  977. return new QQNode('last_modification', 'LastModification', 'string', $this);
  978. case 'AccountId':
  979. return new QQNode('account_id', 'AccountId', 'integer', $this);
  980. case 'Account':
  981. return new QQNodeAccount('account_id', 'Account', 'integer', $this);
  982. case 'ShoppingCartItem':
  983. return new QQReverseReferenceNodeShoppingCartItem($this, 'shoppingcartitem', 'reverse_reference', 'shopping_cart_id');
  984. case '_PrimaryKeyNode':
  985. return new QQNode('id', 'Id', 'integer', $this);
  986. default:
  987. try {
  988. return parent::__get($strName);
  989. } catch (QCallerException $objExc) {
  990. $objExc->IncrementOffset();
  991. throw $objExc;
  992. }
  993. }
  994. }
  995. }
  996. ?>