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.

875 lines
35 KiB

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