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.

1039 lines
42 KiB

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