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.

406 lines
20 KiB

  1. <?php
  2. /**
  3. * This is a MetaControl class, providing a QForm or QPanel access to event handlers
  4. * and QControls to perform the Create, Edit, and Delete functionality
  5. * of the ShoppingCartItem class. This code-generated class
  6. * contains all the basic elements to help a QPanel or QForm display an HTML form that can
  7. * manipulate a single ShoppingCartItem object.
  8. *
  9. * To take advantage of some (or all) of these control objects, you
  10. * must create a new QForm or QPanel which instantiates a ShoppingCartItemMetaControl
  11. * class.
  12. *
  13. * Any and all changes to this file will be overwritten with any subsequent
  14. * code re-generation.
  15. *
  16. * @package Quinta CMS
  17. * @subpackage MetaControls
  18. * property-read ShoppingCartItem $ShoppingCartItem the actual ShoppingCartItem data class being edited
  19. * property QListBox $ShoppingCartIdControl
  20. * property-read QLabel $ShoppingCartIdLabel
  21. * property QListBox $ProductIdControl
  22. * property-read QLabel $ProductIdLabel
  23. * property QIntegerTextBox $QuantityControl
  24. * property-read QLabel $QuantityLabel
  25. * property-read string $TitleVerb a verb indicating whether or not this is being edited or created
  26. * property-read boolean $EditMode a boolean indicating whether or not this is being edited or created
  27. */
  28. class ShoppingCartItemMetaControlGen extends QBaseClass {
  29. // General Variables
  30. protected $objShoppingCartItem;
  31. protected $objParentObject;
  32. protected $strTitleVerb;
  33. protected $blnEditMode;
  34. // Controls that allow the editing of ShoppingCartItem's individual data fields
  35. protected $lstShoppingCart;
  36. protected $lstProduct;
  37. protected $txtQuantity;
  38. // Controls that allow the viewing of ShoppingCartItem's individual data fields
  39. protected $lblShoppingCartId;
  40. protected $lblProductId;
  41. protected $lblQuantity;
  42. // QListBox Controls (if applicable) to edit Unique ReverseReferences and ManyToMany References
  43. // QLabel Controls (if applicable) to view Unique ReverseReferences and ManyToMany References
  44. /**
  45. * Main constructor. Constructor OR static create methods are designed to be called in either
  46. * a parent QPanel or the main QForm when wanting to create a
  47. * ShoppingCartItemMetaControl to edit a single ShoppingCartItem object within the
  48. * QPanel or QForm.
  49. *
  50. * This constructor takes in a single ShoppingCartItem object, while any of the static
  51. * create methods below can be used to construct based off of individual PK ID(s).
  52. *
  53. * @param mixed $objParentObject QForm or QPanel which will be using this ShoppingCartItemMetaControl
  54. * @param ShoppingCartItem $objShoppingCartItem new or existing ShoppingCartItem object
  55. */
  56. public function __construct($objParentObject, ShoppingCartItem $objShoppingCartItem) {
  57. // Setup Parent Object (e.g. QForm or QPanel which will be using this ShoppingCartItemMetaControl)
  58. $this->objParentObject = $objParentObject;
  59. // Setup linked ShoppingCartItem object
  60. $this->objShoppingCartItem = $objShoppingCartItem;
  61. // Figure out if we're Editing or Creating New
  62. if ($this->objShoppingCartItem->__Restored) {
  63. $this->strTitleVerb = QApplication::Translate('Edit');
  64. $this->blnEditMode = true;
  65. } else {
  66. $this->strTitleVerb = QApplication::Translate('Create');
  67. $this->blnEditMode = false;
  68. }
  69. }
  70. /**
  71. * Static Helper Method to Create using PK arguments
  72. * You must pass in the PK arguments on an object to load, or leave it blank to create a new one.
  73. * If you want to load via QueryString or PathInfo, use the CreateFromQueryString or CreateFromPathInfo
  74. * static helper methods. Finally, specify a CreateType to define whether or not we are only allowed to
  75. * edit, or if we are also allowed to create a new one, etc.
  76. *
  77. * @param mixed $objParentObject QForm or QPanel which will be using this ShoppingCartItemMetaControl
  78. * @param integer $intShoppingCartId primary key value
  79. * @param integer $intProductId primary key value
  80. * @param QMetaControlCreateType $intCreateType rules governing ShoppingCartItem object creation - defaults to CreateOrEdit
  81. * @return ShoppingCartItemMetaControl
  82. */
  83. public static function Create($objParentObject, $intShoppingCartId = null, $intProductId = null, $intCreateType = QMetaControlCreateType::CreateOrEdit) {
  84. // Attempt to Load from PK Arguments
  85. if (strlen($intShoppingCartId) && strlen($intProductId)) {
  86. $objShoppingCartItem = ShoppingCartItem::Load($intShoppingCartId, $intProductId);
  87. // ShoppingCartItem was found -- return it!
  88. if ($objShoppingCartItem)
  89. return new ShoppingCartItemMetaControl($objParentObject, $objShoppingCartItem);
  90. // If CreateOnRecordNotFound not specified, throw an exception
  91. else if ($intCreateType != QMetaControlCreateType::CreateOnRecordNotFound)
  92. throw new QCallerException('Could not find a ShoppingCartItem object with PK arguments: ' . $intShoppingCartId . ', ' . $intProductId);
  93. // If EditOnly is specified, throw an exception
  94. } else if ($intCreateType == QMetaControlCreateType::EditOnly)
  95. throw new QCallerException('No PK arguments specified');
  96. // If we are here, then we need to create a new record
  97. return new ShoppingCartItemMetaControl($objParentObject, new ShoppingCartItem());
  98. }
  99. /**
  100. * Static Helper Method to Create using PathInfo arguments
  101. *
  102. * @param mixed $objParentObject QForm or QPanel which will be using this ShoppingCartItemMetaControl
  103. * @param QMetaControlCreateType $intCreateType rules governing ShoppingCartItem object creation - defaults to CreateOrEdit
  104. * @return ShoppingCartItemMetaControl
  105. */
  106. public static function CreateFromPathInfo($objParentObject, $intCreateType = QMetaControlCreateType::CreateOrEdit) {
  107. $intShoppingCartId = QApplication::PathInfo(0);
  108. $intProductId = QApplication::PathInfo(1);
  109. return ShoppingCartItemMetaControl::Create($objParentObject, $intShoppingCartId, $intProductId, $intCreateType);
  110. }
  111. /**
  112. * Static Helper Method to Create using QueryString arguments
  113. *
  114. * @param mixed $objParentObject QForm or QPanel which will be using this ShoppingCartItemMetaControl
  115. * @param QMetaControlCreateType $intCreateType rules governing ShoppingCartItem object creation - defaults to CreateOrEdit
  116. * @return ShoppingCartItemMetaControl
  117. */
  118. public static function CreateFromQueryString($objParentObject, $intCreateType = QMetaControlCreateType::CreateOrEdit) {
  119. $intShoppingCartId = QApplication::QueryString('intShoppingCartId');
  120. $intProductId = QApplication::QueryString('intProductId');
  121. return ShoppingCartItemMetaControl::Create($objParentObject, $intShoppingCartId, $intProductId, $intCreateType);
  122. }
  123. ///////////////////////////////////////////////
  124. // PUBLIC CREATE and REFRESH METHODS
  125. ///////////////////////////////////////////////
  126. /**
  127. * Create and setup QListBox lstShoppingCart
  128. * @param string $strControlId optional ControlId to use
  129. * @return QListBox
  130. */
  131. public function lstShoppingCart_Create($strControlId = null) {
  132. $this->lstShoppingCart = new QListBox($this->objParentObject, $strControlId);
  133. $this->lstShoppingCart->Name = QApplication::Translate('Shopping Cart');
  134. $this->lstShoppingCart->Required = true;
  135. if (!$this->blnEditMode)
  136. $this->lstShoppingCart->AddItem(QApplication::Translate('- Select One -'), null);
  137. $objShoppingCartArray = ShoppingCart::LoadAll();
  138. if ($objShoppingCartArray) foreach ($objShoppingCartArray as $objShoppingCart) {
  139. $objListItem = new QListItem($objShoppingCart->__toString(), $objShoppingCart->Id);
  140. if (($this->objShoppingCartItem->ShoppingCart) && ($this->objShoppingCartItem->ShoppingCart->Id == $objShoppingCart->Id))
  141. $objListItem->Selected = true;
  142. $this->lstShoppingCart->AddItem($objListItem);
  143. }
  144. return $this->lstShoppingCart;
  145. }
  146. /**
  147. * Create and setup QLabel lblShoppingCartId
  148. * @param string $strControlId optional ControlId to use
  149. * @return QLabel
  150. */
  151. public function lblShoppingCartId_Create($strControlId = null) {
  152. $this->lblShoppingCartId = new QLabel($this->objParentObject, $strControlId);
  153. $this->lblShoppingCartId->Name = QApplication::Translate('Shopping Cart');
  154. $this->lblShoppingCartId->Text = ($this->objShoppingCartItem->ShoppingCart) ? $this->objShoppingCartItem->ShoppingCart->__toString() : null;
  155. $this->lblShoppingCartId->Required = true;
  156. return $this->lblShoppingCartId;
  157. }
  158. /**
  159. * Create and setup QListBox lstProduct
  160. * @param string $strControlId optional ControlId to use
  161. * @return QListBox
  162. */
  163. public function lstProduct_Create($strControlId = null) {
  164. $this->lstProduct = new QListBox($this->objParentObject, $strControlId);
  165. $this->lstProduct->Name = QApplication::Translate('Product');
  166. $this->lstProduct->Required = true;
  167. if (!$this->blnEditMode)
  168. $this->lstProduct->AddItem(QApplication::Translate('- Select One -'), null);
  169. $objProductArray = Product::LoadAll();
  170. if ($objProductArray) foreach ($objProductArray as $objProduct) {
  171. $objListItem = new QListItem($objProduct->__toString(), $objProduct->Id);
  172. if (($this->objShoppingCartItem->Product) && ($this->objShoppingCartItem->Product->Id == $objProduct->Id))
  173. $objListItem->Selected = true;
  174. $this->lstProduct->AddItem($objListItem);
  175. }
  176. return $this->lstProduct;
  177. }
  178. /**
  179. * Create and setup QLabel lblProductId
  180. * @param string $strControlId optional ControlId to use
  181. * @return QLabel
  182. */
  183. public function lblProductId_Create($strControlId = null) {
  184. $this->lblProductId = new QLabel($this->objParentObject, $strControlId);
  185. $this->lblProductId->Name = QApplication::Translate('Product');
  186. $this->lblProductId->Text = ($this->objShoppingCartItem->Product) ? $this->objShoppingCartItem->Product->__toString() : null;
  187. $this->lblProductId->Required = true;
  188. return $this->lblProductId;
  189. }
  190. /**
  191. * Create and setup QIntegerTextBox txtQuantity
  192. * @param string $strControlId optional ControlId to use
  193. * @return QIntegerTextBox
  194. */
  195. public function txtQuantity_Create($strControlId = null) {
  196. $this->txtQuantity = new QIntegerTextBox($this->objParentObject, $strControlId);
  197. $this->txtQuantity->Name = QApplication::Translate('Quantity');
  198. $this->txtQuantity->Text = $this->objShoppingCartItem->Quantity;
  199. $this->txtQuantity->Required = true;
  200. return $this->txtQuantity;
  201. }
  202. /**
  203. * Create and setup QLabel lblQuantity
  204. * @param string $strControlId optional ControlId to use
  205. * @param string $strFormat optional sprintf format to use
  206. * @return QLabel
  207. */
  208. public function lblQuantity_Create($strControlId = null, $strFormat = null) {
  209. $this->lblQuantity = new QLabel($this->objParentObject, $strControlId);
  210. $this->lblQuantity->Name = QApplication::Translate('Quantity');
  211. $this->lblQuantity->Text = $this->objShoppingCartItem->Quantity;
  212. $this->lblQuantity->Required = true;
  213. $this->lblQuantity->Format = $strFormat;
  214. return $this->lblQuantity;
  215. }
  216. /**
  217. * Refresh this MetaControl with Data from the local ShoppingCartItem object.
  218. * @param boolean $blnReload reload ShoppingCartItem from the database
  219. * @return void
  220. */
  221. public function Refresh($blnReload = false) {
  222. if ($blnReload)
  223. $this->objShoppingCartItem->Reload();
  224. if ($this->lstShoppingCart) {
  225. $this->lstShoppingCart->RemoveAllItems();
  226. if (!$this->blnEditMode)
  227. $this->lstShoppingCart->AddItem(QApplication::Translate('- Select One -'), null);
  228. $objShoppingCartArray = ShoppingCart::LoadAll();
  229. if ($objShoppingCartArray) foreach ($objShoppingCartArray as $objShoppingCart) {
  230. $objListItem = new QListItem($objShoppingCart->__toString(), $objShoppingCart->Id);
  231. if (($this->objShoppingCartItem->ShoppingCart) && ($this->objShoppingCartItem->ShoppingCart->Id == $objShoppingCart->Id))
  232. $objListItem->Selected = true;
  233. $this->lstShoppingCart->AddItem($objListItem);
  234. }
  235. }
  236. if ($this->lblShoppingCartId) $this->lblShoppingCartId->Text = ($this->objShoppingCartItem->ShoppingCart) ? $this->objShoppingCartItem->ShoppingCart->__toString() : null;
  237. if ($this->lstProduct) {
  238. $this->lstProduct->RemoveAllItems();
  239. if (!$this->blnEditMode)
  240. $this->lstProduct->AddItem(QApplication::Translate('- Select One -'), null);
  241. $objProductArray = Product::LoadAll();
  242. if ($objProductArray) foreach ($objProductArray as $objProduct) {
  243. $objListItem = new QListItem($objProduct->__toString(), $objProduct->Id);
  244. if (($this->objShoppingCartItem->Product) && ($this->objShoppingCartItem->Product->Id == $objProduct->Id))
  245. $objListItem->Selected = true;
  246. $this->lstProduct->AddItem($objListItem);
  247. }
  248. }
  249. if ($this->lblProductId) $this->lblProductId->Text = ($this->objShoppingCartItem->Product) ? $this->objShoppingCartItem->Product->__toString() : null;
  250. if ($this->txtQuantity) $this->txtQuantity->Text = $this->objShoppingCartItem->Quantity;
  251. if ($this->lblQuantity) $this->lblQuantity->Text = $this->objShoppingCartItem->Quantity;
  252. }
  253. ///////////////////////////////////////////////
  254. // PROTECTED UPDATE METHODS for ManyToManyReferences (if any)
  255. ///////////////////////////////////////////////
  256. ///////////////////////////////////////////////
  257. // PUBLIC SHOPPINGCARTITEM OBJECT MANIPULATORS
  258. ///////////////////////////////////////////////
  259. /**
  260. * This will save this object's ShoppingCartItem instance,
  261. * updating only the fields which have had a control created for it.
  262. */
  263. public function SaveShoppingCartItem() {
  264. try {
  265. // Update any fields for controls that have been created
  266. if ($this->lstShoppingCart) $this->objShoppingCartItem->ShoppingCartId = $this->lstShoppingCart->SelectedValue;
  267. if ($this->lstProduct) $this->objShoppingCartItem->ProductId = $this->lstProduct->SelectedValue;
  268. if ($this->txtQuantity) $this->objShoppingCartItem->Quantity = $this->txtQuantity->Text;
  269. // Update any UniqueReverseReferences (if any) for controls that have been created for it
  270. // Save the ShoppingCartItem object
  271. $this->objShoppingCartItem->Save();
  272. // Finally, update any ManyToManyReferences (if any)
  273. } catch (QCallerException $objExc) {
  274. $objExc->IncrementOffset();
  275. throw $objExc;
  276. }
  277. }
  278. /**
  279. * This will DELETE this object's ShoppingCartItem instance from the database.
  280. * It will also unassociate itself from any ManyToManyReferences.
  281. */
  282. public function DeleteShoppingCartItem() {
  283. $this->objShoppingCartItem->Delete();
  284. }
  285. ///////////////////////////////////////////////
  286. // PUBLIC GETTERS and SETTERS
  287. ///////////////////////////////////////////////
  288. /**
  289. * Override method to perform a property "Get"
  290. * This will get the value of $strName
  291. *
  292. * @param string $strName Name of the property to get
  293. * @return mixed
  294. */
  295. public function __get($strName) {
  296. switch ($strName) {
  297. // General MetaControlVariables
  298. case 'ShoppingCartItem': return $this->objShoppingCartItem;
  299. case 'TitleVerb': return $this->strTitleVerb;
  300. case 'EditMode': return $this->blnEditMode;
  301. // Controls that point to ShoppingCartItem fields -- will be created dynamically if not yet created
  302. case 'ShoppingCartIdControl':
  303. if (!$this->lstShoppingCart) return $this->lstShoppingCart_Create();
  304. return $this->lstShoppingCart;
  305. case 'ShoppingCartIdLabel':
  306. if (!$this->lblShoppingCartId) return $this->lblShoppingCartId_Create();
  307. return $this->lblShoppingCartId;
  308. case 'ProductIdControl':
  309. if (!$this->lstProduct) return $this->lstProduct_Create();
  310. return $this->lstProduct;
  311. case 'ProductIdLabel':
  312. if (!$this->lblProductId) return $this->lblProductId_Create();
  313. return $this->lblProductId;
  314. case 'QuantityControl':
  315. if (!$this->txtQuantity) return $this->txtQuantity_Create();
  316. return $this->txtQuantity;
  317. case 'QuantityLabel':
  318. if (!$this->lblQuantity) return $this->lblQuantity_Create();
  319. return $this->lblQuantity;
  320. default:
  321. try {
  322. return parent::__get($strName);
  323. } catch (QCallerException $objExc) {
  324. $objExc->IncrementOffset();
  325. throw $objExc;
  326. }
  327. }
  328. }
  329. /**
  330. * Override method to perform a property "Set"
  331. * This will set the property $strName to be $mixValue
  332. *
  333. * @param string $strName Name of the property to set
  334. * @param string $mixValue New value of the property
  335. * @return mixed
  336. */
  337. public function __set($strName, $mixValue) {
  338. try {
  339. switch ($strName) {
  340. // Controls that point to ShoppingCartItem fields
  341. case 'ShoppingCartIdControl':
  342. return ($this->lstShoppingCart = QType::Cast($mixValue, 'QControl'));
  343. case 'ProductIdControl':
  344. return ($this->lstProduct = QType::Cast($mixValue, 'QControl'));
  345. case 'QuantityControl':
  346. return ($this->txtQuantity = QType::Cast($mixValue, 'QControl'));
  347. default:
  348. return parent::__set($strName, $mixValue);
  349. }
  350. } catch (QCallerException $objExc) {
  351. $objExc->IncrementOffset();
  352. throw $objExc;
  353. }
  354. }
  355. }
  356. ?>