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.

1102 lines
45 KiB

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