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.

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