A Qcodo based CMS/ecommerce framework
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.

203 lines
7.7 KiB

12 years ago
  1. <?php
  2. require(__DATAGEN_CLASSES__ . '/ProductGen.class.php');
  3. /**
  4. * The Product class defined here contains any
  5. * customized code for the Product class in the
  6. * Object Relational Model. It represents the "product" table
  7. * in the database, and extends from the code generated abstract ProductGen
  8. * class, which contains all the basic CRUD-type functionality as well as
  9. * basic methods to handle relationships and index-based loading.
  10. *
  11. * @package Quasi
  12. * @subpackage ORM
  13. *
  14. */
  15. class Product extends ProductGen {
  16. /**
  17. * Default "to string" handler
  18. * Allows pages to _p()/echo()/print() this object, and to define the default
  19. * way this object would be outputted.
  20. *
  21. * Can also be called directly via $objProduct->__toString().
  22. *
  23. * @return string a nicely formatted string representation of this object
  24. */
  25. public function __toString() {
  26. return sprintf('%s', $this->Model);
  27. }
  28. public function InsertWithId()
  29. {
  30. $objDatabase = Product::GetDatabase();
  31. $strQuery = 'INSERT INTO `product` (
  32. `id`,
  33. `manufacturer_id`,
  34. `supplier_id`,
  35. `name`,
  36. `model`,
  37. `short_description`,
  38. `long_description`,
  39. `msrp`,
  40. `wholesale_price`,
  41. `retail_price`,
  42. `cost`,
  43. `weight`,
  44. `height`,
  45. `width`,
  46. `depth`,
  47. `is_virtual`,
  48. `type_id`,
  49. `status_id`,
  50. `view_count`,
  51. `user_permissions_id`,
  52. `public_permissions_id`,
  53. `group_permissions_id`';
  54. if( '' != $this->strCreationDate )
  55. $strQuery .= ',`creation_date`';
  56. $strQuery .= ') VALUES (
  57. ' . $objDatabase->SqlVariable($this->intId) . ',
  58. ' . $objDatabase->SqlVariable($this->intManufacturerId) . ',
  59. ' . $objDatabase->SqlVariable($this->intSupplierId) . ',
  60. ' . $objDatabase->SqlVariable($this->strName) . ',
  61. ' . $objDatabase->SqlVariable($this->strModel) . ',
  62. ' . $objDatabase->SqlVariable($this->strShortDescription) . ',
  63. ' . $objDatabase->SqlVariable($this->strLongDescription) . ',
  64. ' . $objDatabase->SqlVariable($this->fltMsrp) . ',
  65. ' . $objDatabase->SqlVariable($this->fltWholesalePrice) . ',
  66. ' . $objDatabase->SqlVariable($this->fltRetailPrice) . ',
  67. ' . $objDatabase->SqlVariable($this->fltCost) . ',
  68. ' . $objDatabase->SqlVariable($this->fltWeight) . ',
  69. ' . $objDatabase->SqlVariable($this->fltHeight) . ',
  70. ' . $objDatabase->SqlVariable($this->fltWidth) . ',
  71. ' . $objDatabase->SqlVariable($this->fltDepth) . ',
  72. ' . $objDatabase->SqlVariable($this->blnIsVirtual) . ',
  73. ' . $objDatabase->SqlVariable($this->intTypeId) . ',
  74. ' . $objDatabase->SqlVariable($this->intStatusId) . ',
  75. ' . $objDatabase->SqlVariable($this->intViewCount) . ',
  76. ' . $objDatabase->SqlVariable($this->intUserPermissionsId) . ',
  77. ' . $objDatabase->SqlVariable($this->intPublicPermissionsId) . ',
  78. ' . $objDatabase->SqlVariable($this->intGroupPermissionsId) ;
  79. if( '' != $this->strCreationDate )
  80. $strQuery .= ', ' . $objDatabase->SqlVariable($this->strCreationDate);
  81. $strQuery .= ' )';
  82. try{
  83. $objDatabase->NonQuery($strQuery);
  84. } catch (QCallerException $objExc) {
  85. $objExc->IncrementOffset();
  86. throw $objExc;
  87. }
  88. $this->__blnRestored = true;
  89. }
  90. public function __get($strName)
  91. {
  92. switch ($strName)
  93. {
  94. case 'RetailPrice':
  95. return number_format($this->fltRetailPrice, 2);
  96. default:
  97. try {
  98. return parent::__get($strName);
  99. } catch (QCallerException $objExc) {
  100. $objExc->IncrementOffset();
  101. throw $objExc;
  102. }
  103. }
  104. }
  105. public function __set($strName, $mixValue)
  106. {
  107. switch ($strName)
  108. {
  109. case 'Id':
  110. try {
  111. return ($this->intId = QType::Cast($mixValue, QType::Integer));
  112. } catch (QInvalidCastException $objExc) {
  113. $objExc->IncrementOffset();
  114. throw $objExc;
  115. }
  116. case 'CreationDate':
  117. try {
  118. return ($this->strCreationDate = QType::Cast($mixValue, QType::String));
  119. } catch (QInvalidCastException $objExc) {
  120. $objExc->IncrementOffset();
  121. throw $objExc;
  122. }
  123. default:
  124. try {
  125. return (parent::__set($strName, $mixValue));
  126. } catch (QCallerException $objExc) {
  127. $objExc->IncrementOffset();
  128. throw $objExc;
  129. }
  130. }
  131. }
  132. // Override or Create New Load/Count methods
  133. // (For obvious reasons, these methods are commented out...
  134. // but feel free to use these as a starting point)
  135. /*
  136. public static function LoadArrayBySample($strParam1, $intParam2, $objOptionalClauses = null) {
  137. // This will return an array of Product objects
  138. return Product::QueryArray(
  139. QQ::AndCondition(
  140. QQ::Equal(QQN::Product()->Param1, $strParam1),
  141. QQ::GreaterThan(QQN::Product()->Param2, $intParam2)
  142. ),
  143. $objOptionalClauses
  144. );
  145. }
  146. public static function LoadBySample($strParam1, $intParam2, $objOptionalClauses = null) {
  147. // This will return a single Product object
  148. return Product::QuerySingle(
  149. QQ::AndCondition(
  150. QQ::Equal(QQN::Product()->Param1, $strParam1),
  151. QQ::GreaterThan(QQN::Product()->Param2, $intParam2)
  152. ),
  153. $objOptionalClauses
  154. );
  155. }
  156. public static function CountBySample($strParam1, $intParam2, $objOptionalClauses = null) {
  157. // This will return a count of Product objects
  158. return Product::QueryCount(
  159. QQ::AndCondition(
  160. QQ::Equal(QQN::Product()->Param1, $strParam1),
  161. QQ::Equal(QQN::Product()->Param2, $intParam2)
  162. ),
  163. $objOptionalClauses
  164. );
  165. }
  166. public static function LoadArrayBySample($strParam1, $intParam2, $objOptionalClauses) {
  167. // Performing the load manually (instead of using Qcodo Query)
  168. // Get the Database Object for this Class
  169. $objDatabase = Product::GetDatabase();
  170. // Properly Escape All Input Parameters using Database->SqlVariable()
  171. $strParam1 = $objDatabase->SqlVariable($strParam1);
  172. $intParam2 = $objDatabase->SqlVariable($intParam2);
  173. // Setup the SQL Query
  174. $strQuery = sprintf('
  175. SELECT
  176. `product`.*
  177. FROM
  178. `product` AS `product`
  179. WHERE
  180. param_1 = %s AND
  181. param_2 < %s',
  182. $strParam1, $intParam2);
  183. // Perform the Query and Instantiate the Result
  184. $objDbResult = $objDatabase->Query($strQuery);
  185. return Product::InstantiateDbResult($objDbResult);
  186. }
  187. */
  188. }
  189. ?>