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.

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