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.

991 lines
40 KiB

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