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.

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