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.

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