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.

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