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.

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