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.

1030 lines
43 KiB

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