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.

382 lines
17 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 ShoppingCart 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 ShoppingCart 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 ShoppingCartMetaControl
  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 ShoppingCart $ShoppingCart the actual ShoppingCart data class being edited
  19. * property QLabel $IdControl
  20. * property-read QLabel $IdLabel
  21. * property QLabel $CreationDateControl
  22. * property-read QLabel $CreationDateLabel
  23. * property QLabel $LastModificationControl
  24. * property-read QLabel $LastModificationLabel
  25. * property QListBox $AccountIdControl
  26. * property-read QLabel $AccountIdLabel
  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 ShoppingCartMetaControlGen extends QBaseClass {
  31. // General Variables
  32. protected $objShoppingCart;
  33. protected $objParentObject;
  34. protected $strTitleVerb;
  35. protected $blnEditMode;
  36. // Controls that allow the editing of ShoppingCart's individual data fields
  37. protected $lblId;
  38. protected $lblCreationDate;
  39. protected $lblLastModification;
  40. protected $lstAccount;
  41. // Controls that allow the viewing of ShoppingCart's individual data fields
  42. protected $lblAccountId;
  43. // QListBox Controls (if applicable) to edit Unique ReverseReferences and ManyToMany References
  44. // QLabel Controls (if applicable) to view Unique ReverseReferences and ManyToMany References
  45. /**
  46. * Main constructor. Constructor OR static create methods are designed to be called in either
  47. * a parent QPanel or the main QForm when wanting to create a
  48. * ShoppingCartMetaControl to edit a single ShoppingCart object within the
  49. * QPanel or QForm.
  50. *
  51. * This constructor takes in a single ShoppingCart object, while any of the static
  52. * create methods below can be used to construct based off of individual PK ID(s).
  53. *
  54. * @param mixed $objParentObject QForm or QPanel which will be using this ShoppingCartMetaControl
  55. * @param ShoppingCart $objShoppingCart new or existing ShoppingCart object
  56. */
  57. public function __construct($objParentObject, ShoppingCart $objShoppingCart) {
  58. // Setup Parent Object (e.g. QForm or QPanel which will be using this ShoppingCartMetaControl)
  59. $this->objParentObject = $objParentObject;
  60. // Setup linked ShoppingCart object
  61. $this->objShoppingCart = $objShoppingCart;
  62. // Figure out if we're Editing or Creating New
  63. if ($this->objShoppingCart->__Restored) {
  64. $this->strTitleVerb = QApplication::Translate('Edit');
  65. $this->blnEditMode = true;
  66. } else {
  67. $this->strTitleVerb = QApplication::Translate('Create');
  68. $this->blnEditMode = false;
  69. }
  70. }
  71. /**
  72. * Static Helper Method to Create using PK arguments
  73. * You must pass in the PK arguments on an object to load, or leave it blank to create a new one.
  74. * If you want to load via QueryString or PathInfo, use the CreateFromQueryString or CreateFromPathInfo
  75. * static helper methods. Finally, specify a CreateType to define whether or not we are only allowed to
  76. * edit, or if we are also allowed to create a new one, etc.
  77. *
  78. * @param mixed $objParentObject QForm or QPanel which will be using this ShoppingCartMetaControl
  79. * @param integer $intId primary key value
  80. * @param QMetaControlCreateType $intCreateType rules governing ShoppingCart object creation - defaults to CreateOrEdit
  81. * @return ShoppingCartMetaControl
  82. */
  83. public static function Create($objParentObject, $intId = null, $intCreateType = QMetaControlCreateType::CreateOrEdit) {
  84. // Attempt to Load from PK Arguments
  85. if (strlen($intId)) {
  86. $objShoppingCart = ShoppingCart::Load($intId);
  87. // ShoppingCart was found -- return it!
  88. if ($objShoppingCart)
  89. return new ShoppingCartMetaControl($objParentObject, $objShoppingCart);
  90. // If CreateOnRecordNotFound not specified, throw an exception
  91. else if ($intCreateType != QMetaControlCreateType::CreateOnRecordNotFound)
  92. throw new QCallerException('Could not find a ShoppingCart object with PK arguments: ' . $intId);
  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 ShoppingCartMetaControl($objParentObject, new ShoppingCart());
  98. }
  99. /**
  100. * Static Helper Method to Create using PathInfo arguments
  101. *
  102. * @param mixed $objParentObject QForm or QPanel which will be using this ShoppingCartMetaControl
  103. * @param QMetaControlCreateType $intCreateType rules governing ShoppingCart object creation - defaults to CreateOrEdit
  104. * @return ShoppingCartMetaControl
  105. */
  106. public static function CreateFromPathInfo($objParentObject, $intCreateType = QMetaControlCreateType::CreateOrEdit) {
  107. $intId = QApplication::PathInfo(0);
  108. return ShoppingCartMetaControl::Create($objParentObject, $intId, $intCreateType);
  109. }
  110. /**
  111. * Static Helper Method to Create using QueryString arguments
  112. *
  113. * @param mixed $objParentObject QForm or QPanel which will be using this ShoppingCartMetaControl
  114. * @param QMetaControlCreateType $intCreateType rules governing ShoppingCart object creation - defaults to CreateOrEdit
  115. * @return ShoppingCartMetaControl
  116. */
  117. public static function CreateFromQueryString($objParentObject, $intCreateType = QMetaControlCreateType::CreateOrEdit) {
  118. $intId = QApplication::QueryString('intId');
  119. return ShoppingCartMetaControl::Create($objParentObject, $intId, $intCreateType);
  120. }
  121. ///////////////////////////////////////////////
  122. // PUBLIC CREATE and REFRESH METHODS
  123. ///////////////////////////////////////////////
  124. /**
  125. * Create and setup QLabel lblId
  126. * @param string $strControlId optional ControlId to use
  127. * @return QLabel
  128. */
  129. public function lblId_Create($strControlId = null) {
  130. $this->lblId = new QLabel($this->objParentObject, $strControlId);
  131. $this->lblId->Name = QApplication::Translate('Id');
  132. if ($this->blnEditMode)
  133. $this->lblId->Text = $this->objShoppingCart->Id;
  134. else
  135. $this->lblId->Text = 'N/A';
  136. return $this->lblId;
  137. }
  138. /**
  139. * Create and setup QLabel lblCreationDate
  140. * @param string $strControlId optional ControlId to use
  141. * @return QLabel
  142. */
  143. public function lblCreationDate_Create($strControlId = null) {
  144. $this->lblCreationDate = new QLabel($this->objParentObject, $strControlId);
  145. $this->lblCreationDate->Name = QApplication::Translate('Creation Date');
  146. if ($this->blnEditMode)
  147. $this->lblCreationDate->Text = $this->objShoppingCart->CreationDate;
  148. else
  149. $this->lblCreationDate->Text = 'N/A';
  150. return $this->lblCreationDate;
  151. }
  152. /**
  153. * Create and setup QLabel lblLastModification
  154. * @param string $strControlId optional ControlId to use
  155. * @return QLabel
  156. */
  157. public function lblLastModification_Create($strControlId = null) {
  158. $this->lblLastModification = new QLabel($this->objParentObject, $strControlId);
  159. $this->lblLastModification->Name = QApplication::Translate('Last Modification');
  160. if ($this->blnEditMode)
  161. $this->lblLastModification->Text = $this->objShoppingCart->LastModification;
  162. else
  163. $this->lblLastModification->Text = 'N/A';
  164. return $this->lblLastModification;
  165. }
  166. /**
  167. * Create and setup QListBox lstAccount
  168. * @param string $strControlId optional ControlId to use
  169. * @return QListBox
  170. */
  171. public function lstAccount_Create($strControlId = null) {
  172. $this->lstAccount = new QListBox($this->objParentObject, $strControlId);
  173. $this->lstAccount->Name = QApplication::Translate('Account');
  174. $this->lstAccount->Required = true;
  175. if (!$this->blnEditMode)
  176. $this->lstAccount->AddItem(QApplication::Translate('- Select One -'), null);
  177. $objAccountArray = Account::LoadAll();
  178. if ($objAccountArray) foreach ($objAccountArray as $objAccount) {
  179. $objListItem = new QListItem($objAccount->__toString(), $objAccount->Id);
  180. if (($this->objShoppingCart->Account) && ($this->objShoppingCart->Account->Id == $objAccount->Id))
  181. $objListItem->Selected = true;
  182. $this->lstAccount->AddItem($objListItem);
  183. }
  184. return $this->lstAccount;
  185. }
  186. /**
  187. * Create and setup QLabel lblAccountId
  188. * @param string $strControlId optional ControlId to use
  189. * @return QLabel
  190. */
  191. public function lblAccountId_Create($strControlId = null) {
  192. $this->lblAccountId = new QLabel($this->objParentObject, $strControlId);
  193. $this->lblAccountId->Name = QApplication::Translate('Account');
  194. $this->lblAccountId->Text = ($this->objShoppingCart->Account) ? $this->objShoppingCart->Account->__toString() : null;
  195. $this->lblAccountId->Required = true;
  196. return $this->lblAccountId;
  197. }
  198. /**
  199. * Refresh this MetaControl with Data from the local ShoppingCart object.
  200. * @param boolean $blnReload reload ShoppingCart from the database
  201. * @return void
  202. */
  203. public function Refresh($blnReload = false) {
  204. if ($blnReload)
  205. $this->objShoppingCart->Reload();
  206. if ($this->lblId) if ($this->blnEditMode) $this->lblId->Text = $this->objShoppingCart->Id;
  207. if ($this->lblCreationDate) if ($this->blnEditMode) $this->lblCreationDate->Text = $this->objShoppingCart->CreationDate;
  208. if ($this->lblLastModification) if ($this->blnEditMode) $this->lblLastModification->Text = $this->objShoppingCart->LastModification;
  209. if ($this->lstAccount) {
  210. $this->lstAccount->RemoveAllItems();
  211. if (!$this->blnEditMode)
  212. $this->lstAccount->AddItem(QApplication::Translate('- Select One -'), null);
  213. $objAccountArray = Account::LoadAll();
  214. if ($objAccountArray) foreach ($objAccountArray as $objAccount) {
  215. $objListItem = new QListItem($objAccount->__toString(), $objAccount->Id);
  216. if (($this->objShoppingCart->Account) && ($this->objShoppingCart->Account->Id == $objAccount->Id))
  217. $objListItem->Selected = true;
  218. $this->lstAccount->AddItem($objListItem);
  219. }
  220. }
  221. if ($this->lblAccountId) $this->lblAccountId->Text = ($this->objShoppingCart->Account) ? $this->objShoppingCart->Account->__toString() : null;
  222. }
  223. ///////////////////////////////////////////////
  224. // PROTECTED UPDATE METHODS for ManyToManyReferences (if any)
  225. ///////////////////////////////////////////////
  226. ///////////////////////////////////////////////
  227. // PUBLIC SHOPPINGCART OBJECT MANIPULATORS
  228. ///////////////////////////////////////////////
  229. /**
  230. * This will save this object's ShoppingCart instance,
  231. * updating only the fields which have had a control created for it.
  232. */
  233. public function SaveShoppingCart() {
  234. try {
  235. // Update any fields for controls that have been created
  236. if ($this->lstAccount) $this->objShoppingCart->AccountId = $this->lstAccount->SelectedValue;
  237. // Update any UniqueReverseReferences (if any) for controls that have been created for it
  238. // Save the ShoppingCart object
  239. $this->objShoppingCart->Save();
  240. // Finally, update any ManyToManyReferences (if any)
  241. } catch (QCallerException $objExc) {
  242. $objExc->IncrementOffset();
  243. throw $objExc;
  244. }
  245. }
  246. /**
  247. * This will DELETE this object's ShoppingCart instance from the database.
  248. * It will also unassociate itself from any ManyToManyReferences.
  249. */
  250. public function DeleteShoppingCart() {
  251. $this->objShoppingCart->Delete();
  252. }
  253. ///////////////////////////////////////////////
  254. // PUBLIC GETTERS and SETTERS
  255. ///////////////////////////////////////////////
  256. /**
  257. * Override method to perform a property "Get"
  258. * This will get the value of $strName
  259. *
  260. * @param string $strName Name of the property to get
  261. * @return mixed
  262. */
  263. public function __get($strName) {
  264. switch ($strName) {
  265. // General MetaControlVariables
  266. case 'ShoppingCart': return $this->objShoppingCart;
  267. case 'TitleVerb': return $this->strTitleVerb;
  268. case 'EditMode': return $this->blnEditMode;
  269. // Controls that point to ShoppingCart fields -- will be created dynamically if not yet created
  270. case 'IdControl':
  271. if (!$this->lblId) return $this->lblId_Create();
  272. return $this->lblId;
  273. case 'IdLabel':
  274. if (!$this->lblId) return $this->lblId_Create();
  275. return $this->lblId;
  276. case 'CreationDateControl':
  277. if (!$this->lblCreationDate) return $this->lblCreationDate_Create();
  278. return $this->lblCreationDate;
  279. case 'CreationDateLabel':
  280. if (!$this->lblCreationDate) return $this->lblCreationDate_Create();
  281. return $this->lblCreationDate;
  282. case 'LastModificationControl':
  283. if (!$this->lblLastModification) return $this->lblLastModification_Create();
  284. return $this->lblLastModification;
  285. case 'LastModificationLabel':
  286. if (!$this->lblLastModification) return $this->lblLastModification_Create();
  287. return $this->lblLastModification;
  288. case 'AccountIdControl':
  289. if (!$this->lstAccount) return $this->lstAccount_Create();
  290. return $this->lstAccount;
  291. case 'AccountIdLabel':
  292. if (!$this->lblAccountId) return $this->lblAccountId_Create();
  293. return $this->lblAccountId;
  294. default:
  295. try {
  296. return parent::__get($strName);
  297. } catch (QCallerException $objExc) {
  298. $objExc->IncrementOffset();
  299. throw $objExc;
  300. }
  301. }
  302. }
  303. /**
  304. * Override method to perform a property "Set"
  305. * This will set the property $strName to be $mixValue
  306. *
  307. * @param string $strName Name of the property to set
  308. * @param string $mixValue New value of the property
  309. * @return mixed
  310. */
  311. public function __set($strName, $mixValue) {
  312. try {
  313. switch ($strName) {
  314. // Controls that point to ShoppingCart fields
  315. case 'IdControl':
  316. return ($this->lblId = QType::Cast($mixValue, 'QControl'));
  317. case 'CreationDateControl':
  318. return ($this->lblCreationDate = QType::Cast($mixValue, 'QControl'));
  319. case 'LastModificationControl':
  320. return ($this->lblLastModification = QType::Cast($mixValue, 'QControl'));
  321. case 'AccountIdControl':
  322. return ($this->lstAccount = QType::Cast($mixValue, 'QControl'));
  323. default:
  324. return parent::__set($strName, $mixValue);
  325. }
  326. } catch (QCallerException $objExc) {
  327. $objExc->IncrementOffset();
  328. throw $objExc;
  329. }
  330. }
  331. }
  332. ?>