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.

785 lines
36 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 Menu 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 Menu 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 MenuMetaControl
  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 Menu $Menu the actual Menu 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 $TitleControl
  24. * property-read QLabel $TitleLabel
  25. * property QTextBox $CssClassControl
  26. * property-read QLabel $CssClassLabel
  27. * property QIntegerTextBox $SortOrderControl
  28. * property-read QLabel $SortOrderLabel
  29. * property QCheckBox $ShowTitleControl
  30. * property-read QLabel $ShowTitleLabel
  31. * property QListBox $ParentMenuItemIdControl
  32. * property-read QLabel $ParentMenuItemIdLabel
  33. * property QListBox $StatusIdControl
  34. * property-read QLabel $StatusIdLabel
  35. * property QListBox $TypeIdControl
  36. * property-read QLabel $TypeIdLabel
  37. * property QListBox $ContentBlockControl
  38. * property-read QLabel $ContentBlockLabel
  39. * property QListBox $MenuItemControl
  40. * property-read QLabel $MenuItemLabel
  41. * property-read string $TitleVerb a verb indicating whether or not this is being edited or created
  42. * property-read boolean $EditMode a boolean indicating whether or not this is being edited or created
  43. */
  44. class MenuMetaControlGen extends QBaseClass {
  45. // General Variables
  46. protected $objMenu;
  47. protected $objParentObject;
  48. protected $strTitleVerb;
  49. protected $blnEditMode;
  50. // Controls that allow the editing of Menu's individual data fields
  51. protected $lblId;
  52. protected $txtName;
  53. protected $txtTitle;
  54. protected $txtCssClass;
  55. protected $txtSortOrder;
  56. protected $chkShowTitle;
  57. protected $lstParentMenuItem;
  58. protected $lstStatus;
  59. protected $lstType;
  60. // Controls that allow the viewing of Menu's individual data fields
  61. protected $lblName;
  62. protected $lblTitle;
  63. protected $lblCssClass;
  64. protected $lblSortOrder;
  65. protected $lblShowTitle;
  66. protected $lblParentMenuItemId;
  67. protected $lblStatusId;
  68. protected $lblTypeId;
  69. // QListBox Controls (if applicable) to edit Unique ReverseReferences and ManyToMany References
  70. protected $lstContentBlocks;
  71. protected $lstMenuItems;
  72. // QLabel Controls (if applicable) to view Unique ReverseReferences and ManyToMany References
  73. protected $lblContentBlocks;
  74. protected $lblMenuItems;
  75. /**
  76. * Main constructor. Constructor OR static create methods are designed to be called in either
  77. * a parent QPanel or the main QForm when wanting to create a
  78. * MenuMetaControl to edit a single Menu object within the
  79. * QPanel or QForm.
  80. *
  81. * This constructor takes in a single Menu object, while any of the static
  82. * create methods below can be used to construct based off of individual PK ID(s).
  83. *
  84. * @param mixed $objParentObject QForm or QPanel which will be using this MenuMetaControl
  85. * @param Menu $objMenu new or existing Menu object
  86. */
  87. public function __construct($objParentObject, Menu $objMenu) {
  88. // Setup Parent Object (e.g. QForm or QPanel which will be using this MenuMetaControl)
  89. $this->objParentObject = $objParentObject;
  90. // Setup linked Menu object
  91. $this->objMenu = $objMenu;
  92. // Figure out if we're Editing or Creating New
  93. if ($this->objMenu->__Restored) {
  94. $this->strTitleVerb = QApplication::Translate('Edit');
  95. $this->blnEditMode = true;
  96. } else {
  97. $this->strTitleVerb = QApplication::Translate('Create');
  98. $this->blnEditMode = false;
  99. }
  100. }
  101. /**
  102. * Static Helper Method to Create using PK arguments
  103. * You must pass in the PK arguments on an object to load, or leave it blank to create a new one.
  104. * If you want to load via QueryString or PathInfo, use the CreateFromQueryString or CreateFromPathInfo
  105. * static helper methods. Finally, specify a CreateType to define whether or not we are only allowed to
  106. * edit, or if we are also allowed to create a new one, etc.
  107. *
  108. * @param mixed $objParentObject QForm or QPanel which will be using this MenuMetaControl
  109. * @param integer $intId primary key value
  110. * @param QMetaControlCreateType $intCreateType rules governing Menu object creation - defaults to CreateOrEdit
  111. * @return MenuMetaControl
  112. */
  113. public static function Create($objParentObject, $intId = null, $intCreateType = QMetaControlCreateType::CreateOrEdit) {
  114. // Attempt to Load from PK Arguments
  115. if (strlen($intId)) {
  116. $objMenu = Menu::Load($intId);
  117. // Menu was found -- return it!
  118. if ($objMenu)
  119. return new MenuMetaControl($objParentObject, $objMenu);
  120. // If CreateOnRecordNotFound not specified, throw an exception
  121. else if ($intCreateType != QMetaControlCreateType::CreateOnRecordNotFound)
  122. throw new QCallerException('Could not find a Menu object with PK arguments: ' . $intId);
  123. // If EditOnly is specified, throw an exception
  124. } else if ($intCreateType == QMetaControlCreateType::EditOnly)
  125. throw new QCallerException('No PK arguments specified');
  126. // If we are here, then we need to create a new record
  127. return new MenuMetaControl($objParentObject, new Menu());
  128. }
  129. /**
  130. * Static Helper Method to Create using PathInfo arguments
  131. *
  132. * @param mixed $objParentObject QForm or QPanel which will be using this MenuMetaControl
  133. * @param QMetaControlCreateType $intCreateType rules governing Menu object creation - defaults to CreateOrEdit
  134. * @return MenuMetaControl
  135. */
  136. public static function CreateFromPathInfo($objParentObject, $intCreateType = QMetaControlCreateType::CreateOrEdit) {
  137. $intId = QApplication::PathInfo(0);
  138. return MenuMetaControl::Create($objParentObject, $intId, $intCreateType);
  139. }
  140. /**
  141. * Static Helper Method to Create using QueryString arguments
  142. *
  143. * @param mixed $objParentObject QForm or QPanel which will be using this MenuMetaControl
  144. * @param QMetaControlCreateType $intCreateType rules governing Menu object creation - defaults to CreateOrEdit
  145. * @return MenuMetaControl
  146. */
  147. public static function CreateFromQueryString($objParentObject, $intCreateType = QMetaControlCreateType::CreateOrEdit) {
  148. $intId = QApplication::QueryString('intId');
  149. return MenuMetaControl::Create($objParentObject, $intId, $intCreateType);
  150. }
  151. ///////////////////////////////////////////////
  152. // PUBLIC CREATE and REFRESH METHODS
  153. ///////////////////////////////////////////////
  154. /**
  155. * Create and setup QLabel lblId
  156. * @param string $strControlId optional ControlId to use
  157. * @return QLabel
  158. */
  159. public function lblId_Create($strControlId = null) {
  160. $this->lblId = new QLabel($this->objParentObject, $strControlId);
  161. $this->lblId->Name = QApplication::Translate('Id');
  162. if ($this->blnEditMode)
  163. $this->lblId->Text = $this->objMenu->Id;
  164. else
  165. $this->lblId->Text = 'N/A';
  166. return $this->lblId;
  167. }
  168. /**
  169. * Create and setup QTextBox txtName
  170. * @param string $strControlId optional ControlId to use
  171. * @return QTextBox
  172. */
  173. public function txtName_Create($strControlId = null) {
  174. $this->txtName = new QTextBox($this->objParentObject, $strControlId);
  175. $this->txtName->Name = QApplication::Translate('Name');
  176. $this->txtName->Text = $this->objMenu->Name;
  177. $this->txtName->Required = true;
  178. $this->txtName->MaxLength = Menu::NameMaxLength;
  179. return $this->txtName;
  180. }
  181. /**
  182. * Create and setup QLabel lblName
  183. * @param string $strControlId optional ControlId to use
  184. * @return QLabel
  185. */
  186. public function lblName_Create($strControlId = null) {
  187. $this->lblName = new QLabel($this->objParentObject, $strControlId);
  188. $this->lblName->Name = QApplication::Translate('Name');
  189. $this->lblName->Text = $this->objMenu->Name;
  190. $this->lblName->Required = true;
  191. return $this->lblName;
  192. }
  193. /**
  194. * Create and setup QTextBox txtTitle
  195. * @param string $strControlId optional ControlId to use
  196. * @return QTextBox
  197. */
  198. public function txtTitle_Create($strControlId = null) {
  199. $this->txtTitle = new QTextBox($this->objParentObject, $strControlId);
  200. $this->txtTitle->Name = QApplication::Translate('Title');
  201. $this->txtTitle->Text = $this->objMenu->Title;
  202. $this->txtTitle->MaxLength = Menu::TitleMaxLength;
  203. return $this->txtTitle;
  204. }
  205. /**
  206. * Create and setup QLabel lblTitle
  207. * @param string $strControlId optional ControlId to use
  208. * @return QLabel
  209. */
  210. public function lblTitle_Create($strControlId = null) {
  211. $this->lblTitle = new QLabel($this->objParentObject, $strControlId);
  212. $this->lblTitle->Name = QApplication::Translate('Title');
  213. $this->lblTitle->Text = $this->objMenu->Title;
  214. return $this->lblTitle;
  215. }
  216. /**
  217. * Create and setup QTextBox txtCssClass
  218. * @param string $strControlId optional ControlId to use
  219. * @return QTextBox
  220. */
  221. public function txtCssClass_Create($strControlId = null) {
  222. $this->txtCssClass = new QTextBox($this->objParentObject, $strControlId);
  223. $this->txtCssClass->Name = QApplication::Translate('Css Class');
  224. $this->txtCssClass->Text = $this->objMenu->CssClass;
  225. $this->txtCssClass->MaxLength = Menu::CssClassMaxLength;
  226. return $this->txtCssClass;
  227. }
  228. /**
  229. * Create and setup QLabel lblCssClass
  230. * @param string $strControlId optional ControlId to use
  231. * @return QLabel
  232. */
  233. public function lblCssClass_Create($strControlId = null) {
  234. $this->lblCssClass = new QLabel($this->objParentObject, $strControlId);
  235. $this->lblCssClass->Name = QApplication::Translate('Css Class');
  236. $this->lblCssClass->Text = $this->objMenu->CssClass;
  237. return $this->lblCssClass;
  238. }
  239. /**
  240. * Create and setup QIntegerTextBox txtSortOrder
  241. * @param string $strControlId optional ControlId to use
  242. * @return QIntegerTextBox
  243. */
  244. public function txtSortOrder_Create($strControlId = null) {
  245. $this->txtSortOrder = new QIntegerTextBox($this->objParentObject, $strControlId);
  246. $this->txtSortOrder->Name = QApplication::Translate('Sort Order');
  247. $this->txtSortOrder->Text = $this->objMenu->SortOrder;
  248. return $this->txtSortOrder;
  249. }
  250. /**
  251. * Create and setup QLabel lblSortOrder
  252. * @param string $strControlId optional ControlId to use
  253. * @param string $strFormat optional sprintf format to use
  254. * @return QLabel
  255. */
  256. public function lblSortOrder_Create($strControlId = null, $strFormat = null) {
  257. $this->lblSortOrder = new QLabel($this->objParentObject, $strControlId);
  258. $this->lblSortOrder->Name = QApplication::Translate('Sort Order');
  259. $this->lblSortOrder->Text = $this->objMenu->SortOrder;
  260. $this->lblSortOrder->Format = $strFormat;
  261. return $this->lblSortOrder;
  262. }
  263. /**
  264. * Create and setup QCheckBox chkShowTitle
  265. * @param string $strControlId optional ControlId to use
  266. * @return QCheckBox
  267. */
  268. public function chkShowTitle_Create($strControlId = null) {
  269. $this->chkShowTitle = new QCheckBox($this->objParentObject, $strControlId);
  270. $this->chkShowTitle->Name = QApplication::Translate('Show Title');
  271. $this->chkShowTitle->Checked = $this->objMenu->ShowTitle;
  272. return $this->chkShowTitle;
  273. }
  274. /**
  275. * Create and setup QLabel lblShowTitle
  276. * @param string $strControlId optional ControlId to use
  277. * @return QLabel
  278. */
  279. public function lblShowTitle_Create($strControlId = null) {
  280. $this->lblShowTitle = new QLabel($this->objParentObject, $strControlId);
  281. $this->lblShowTitle->Name = QApplication::Translate('Show Title');
  282. $this->lblShowTitle->Text = ($this->objMenu->ShowTitle) ? QApplication::Translate('Yes') : QApplication::Translate('No');
  283. return $this->lblShowTitle;
  284. }
  285. /**
  286. * Create and setup QListBox lstParentMenuItem
  287. * @param string $strControlId optional ControlId to use
  288. * @return QListBox
  289. */
  290. public function lstParentMenuItem_Create($strControlId = null) {
  291. $this->lstParentMenuItem = new QListBox($this->objParentObject, $strControlId);
  292. $this->lstParentMenuItem->Name = QApplication::Translate('Parent Menu Item');
  293. $this->lstParentMenuItem->AddItem(QApplication::Translate('- Select One -'), null);
  294. $objParentMenuItemArray = MenuItem::LoadAll();
  295. if ($objParentMenuItemArray) foreach ($objParentMenuItemArray as $objParentMenuItem) {
  296. $objListItem = new QListItem($objParentMenuItem->__toString(), $objParentMenuItem->Id);
  297. if (($this->objMenu->ParentMenuItem) && ($this->objMenu->ParentMenuItem->Id == $objParentMenuItem->Id))
  298. $objListItem->Selected = true;
  299. $this->lstParentMenuItem->AddItem($objListItem);
  300. }
  301. return $this->lstParentMenuItem;
  302. }
  303. /**
  304. * Create and setup QLabel lblParentMenuItemId
  305. * @param string $strControlId optional ControlId to use
  306. * @return QLabel
  307. */
  308. public function lblParentMenuItemId_Create($strControlId = null) {
  309. $this->lblParentMenuItemId = new QLabel($this->objParentObject, $strControlId);
  310. $this->lblParentMenuItemId->Name = QApplication::Translate('Parent Menu Item');
  311. $this->lblParentMenuItemId->Text = ($this->objMenu->ParentMenuItem) ? $this->objMenu->ParentMenuItem->__toString() : null;
  312. return $this->lblParentMenuItemId;
  313. }
  314. /**
  315. * Create and setup QListBox lstStatus
  316. * @param string $strControlId optional ControlId to use
  317. * @return QListBox
  318. */
  319. public function lstStatus_Create($strControlId = null) {
  320. $this->lstStatus = new QListBox($this->objParentObject, $strControlId);
  321. $this->lstStatus->Name = QApplication::Translate('Status');
  322. $this->lstStatus->Required = true;
  323. foreach (MenuStatusType::$NameArray as $intId => $strValue)
  324. $this->lstStatus->AddItem(new QListItem($strValue, $intId, $this->objMenu->StatusId == $intId));
  325. return $this->lstStatus;
  326. }
  327. /**
  328. * Create and setup QLabel lblStatusId
  329. * @param string $strControlId optional ControlId to use
  330. * @return QLabel
  331. */
  332. public function lblStatusId_Create($strControlId = null) {
  333. $this->lblStatusId = new QLabel($this->objParentObject, $strControlId);
  334. $this->lblStatusId->Name = QApplication::Translate('Status');
  335. $this->lblStatusId->Text = ($this->objMenu->StatusId) ? MenuStatusType::$NameArray[$this->objMenu->StatusId] : null;
  336. $this->lblStatusId->Required = true;
  337. return $this->lblStatusId;
  338. }
  339. /**
  340. * Create and setup QListBox lstType
  341. * @param string $strControlId optional ControlId to use
  342. * @return QListBox
  343. */
  344. public function lstType_Create($strControlId = null) {
  345. $this->lstType = new QListBox($this->objParentObject, $strControlId);
  346. $this->lstType->Name = QApplication::Translate('Type');
  347. $this->lstType->Required = true;
  348. foreach (MenuType::$NameArray as $intId => $strValue)
  349. $this->lstType->AddItem(new QListItem($strValue, $intId, $this->objMenu->TypeId == $intId));
  350. return $this->lstType;
  351. }
  352. /**
  353. * Create and setup QLabel lblTypeId
  354. * @param string $strControlId optional ControlId to use
  355. * @return QLabel
  356. */
  357. public function lblTypeId_Create($strControlId = null) {
  358. $this->lblTypeId = new QLabel($this->objParentObject, $strControlId);
  359. $this->lblTypeId->Name = QApplication::Translate('Type');
  360. $this->lblTypeId->Text = ($this->objMenu->TypeId) ? MenuType::$NameArray[$this->objMenu->TypeId] : null;
  361. $this->lblTypeId->Required = true;
  362. return $this->lblTypeId;
  363. }
  364. /**
  365. * Create and setup QListBox lstContentBlocks
  366. * @param string $strControlId optional ControlId to use
  367. * @return QListBox
  368. */
  369. public function lstContentBlocks_Create($strControlId = null) {
  370. $this->lstContentBlocks = new QListBox($this->objParentObject, $strControlId);
  371. $this->lstContentBlocks->Name = QApplication::Translate('Content Blocks');
  372. $this->lstContentBlocks->SelectionMode = QSelectionMode::Multiple;
  373. $objAssociatedArray = $this->objMenu->GetContentBlockArray();
  374. $objContentBlockArray = ContentBlock::LoadAll();
  375. if ($objContentBlockArray) foreach ($objContentBlockArray as $objContentBlock) {
  376. $objListItem = new QListItem($objContentBlock->__toString(), $objContentBlock->Id);
  377. foreach ($objAssociatedArray as $objAssociated) {
  378. if ($objAssociated->Id == $objContentBlock->Id)
  379. $objListItem->Selected = true;
  380. }
  381. $this->lstContentBlocks->AddItem($objListItem);
  382. }
  383. return $this->lstContentBlocks;
  384. }
  385. /**
  386. * Create and setup QLabel lblContentBlocks
  387. * @param string $strControlId optional ControlId to use
  388. * @param string $strGlue glue to display in between each associated object
  389. * @return QLabel
  390. */
  391. public function lblContentBlocks_Create($strControlId = null, $strGlue = ', ') {
  392. $this->lblContentBlocks = new QLabel($this->objParentObject, $strControlId);
  393. $this->lblContentBlocks->Name = QApplication::Translate('Content Blocks');
  394. $objAssociatedArray = $this->objMenu->GetContentBlockArray();
  395. $strItems = array();
  396. foreach ($objAssociatedArray as $objAssociated)
  397. $strItems[] = $objAssociated->__toString();
  398. $this->lblContentBlocks->Text = implode($strGlue, $strItems);
  399. return $this->lblContentBlocks;
  400. }
  401. /**
  402. * Create and setup QListBox lstMenuItems
  403. * @param string $strControlId optional ControlId to use
  404. * @return QListBox
  405. */
  406. public function lstMenuItems_Create($strControlId = null) {
  407. $this->lstMenuItems = new QListBox($this->objParentObject, $strControlId);
  408. $this->lstMenuItems->Name = QApplication::Translate('Menu Items');
  409. $this->lstMenuItems->SelectionMode = QSelectionMode::Multiple;
  410. $objAssociatedArray = $this->objMenu->GetMenuItemArray();
  411. $objMenuItemArray = MenuItem::LoadAll();
  412. if ($objMenuItemArray) foreach ($objMenuItemArray as $objMenuItem) {
  413. $objListItem = new QListItem($objMenuItem->__toString(), $objMenuItem->Id);
  414. foreach ($objAssociatedArray as $objAssociated) {
  415. if ($objAssociated->Id == $objMenuItem->Id)
  416. $objListItem->Selected = true;
  417. }
  418. $this->lstMenuItems->AddItem($objListItem);
  419. }
  420. return $this->lstMenuItems;
  421. }
  422. /**
  423. * Create and setup QLabel lblMenuItems
  424. * @param string $strControlId optional ControlId to use
  425. * @param string $strGlue glue to display in between each associated object
  426. * @return QLabel
  427. */
  428. public function lblMenuItems_Create($strControlId = null, $strGlue = ', ') {
  429. $this->lblMenuItems = new QLabel($this->objParentObject, $strControlId);
  430. $this->lblMenuItems->Name = QApplication::Translate('Menu Items');
  431. $objAssociatedArray = $this->objMenu->GetMenuItemArray();
  432. $strItems = array();
  433. foreach ($objAssociatedArray as $objAssociated)
  434. $strItems[] = $objAssociated->__toString();
  435. $this->lblMenuItems->Text = implode($strGlue, $strItems);
  436. return $this->lblMenuItems;
  437. }
  438. /**
  439. * Refresh this MetaControl with Data from the local Menu object.
  440. * @param boolean $blnReload reload Menu from the database
  441. * @return void
  442. */
  443. public function Refresh($blnReload = false) {
  444. if ($blnReload)
  445. $this->objMenu->Reload();
  446. if ($this->lblId) if ($this->blnEditMode) $this->lblId->Text = $this->objMenu->Id;
  447. if ($this->txtName) $this->txtName->Text = $this->objMenu->Name;
  448. if ($this->lblName) $this->lblName->Text = $this->objMenu->Name;
  449. if ($this->txtTitle) $this->txtTitle->Text = $this->objMenu->Title;
  450. if ($this->lblTitle) $this->lblTitle->Text = $this->objMenu->Title;
  451. if ($this->txtCssClass) $this->txtCssClass->Text = $this->objMenu->CssClass;
  452. if ($this->lblCssClass) $this->lblCssClass->Text = $this->objMenu->CssClass;
  453. if ($this->txtSortOrder) $this->txtSortOrder->Text = $this->objMenu->SortOrder;
  454. if ($this->lblSortOrder) $this->lblSortOrder->Text = $this->objMenu->SortOrder;
  455. if ($this->chkShowTitle) $this->chkShowTitle->Checked = $this->objMenu->ShowTitle;
  456. if ($this->lblShowTitle) $this->lblShowTitle->Text = ($this->objMenu->ShowTitle) ? QApplication::Translate('Yes') : QApplication::Translate('No');
  457. if ($this->lstParentMenuItem) {
  458. $this->lstParentMenuItem->RemoveAllItems();
  459. $this->lstParentMenuItem->AddItem(QApplication::Translate('- Select One -'), null);
  460. $objParentMenuItemArray = MenuItem::LoadAll();
  461. if ($objParentMenuItemArray) foreach ($objParentMenuItemArray as $objParentMenuItem) {
  462. $objListItem = new QListItem($objParentMenuItem->__toString(), $objParentMenuItem->Id);
  463. if (($this->objMenu->ParentMenuItem) && ($this->objMenu->ParentMenuItem->Id == $objParentMenuItem->Id))
  464. $objListItem->Selected = true;
  465. $this->lstParentMenuItem->AddItem($objListItem);
  466. }
  467. }
  468. if ($this->lblParentMenuItemId) $this->lblParentMenuItemId->Text = ($this->objMenu->ParentMenuItem) ? $this->objMenu->ParentMenuItem->__toString() : null;
  469. if ($this->lstStatus) $this->lstStatus->SelectedValue = $this->objMenu->StatusId;
  470. if ($this->lblStatusId) $this->lblStatusId->Text = ($this->objMenu->StatusId) ? MenuStatusType::$NameArray[$this->objMenu->StatusId] : null;
  471. if ($this->lstType) $this->lstType->SelectedValue = $this->objMenu->TypeId;
  472. if ($this->lblTypeId) $this->lblTypeId->Text = ($this->objMenu->TypeId) ? MenuType::$NameArray[$this->objMenu->TypeId] : null;
  473. if ($this->lstContentBlocks) {
  474. $this->lstContentBlocks->RemoveAllItems();
  475. $objAssociatedArray = $this->objMenu->GetContentBlockArray();
  476. $objContentBlockArray = ContentBlock::LoadAll();
  477. if ($objContentBlockArray) foreach ($objContentBlockArray as $objContentBlock) {
  478. $objListItem = new QListItem($objContentBlock->__toString(), $objContentBlock->Id);
  479. foreach ($objAssociatedArray as $objAssociated) {
  480. if ($objAssociated->Id == $objContentBlock->Id)
  481. $objListItem->Selected = true;
  482. }
  483. $this->lstContentBlocks->AddItem($objListItem);
  484. }
  485. }
  486. if ($this->lblContentBlocks) {
  487. $objAssociatedArray = $this->objMenu->GetContentBlockArray();
  488. $strItems = array();
  489. foreach ($objAssociatedArray as $objAssociated)
  490. $strItems[] = $objAssociated->__toString();
  491. $this->lblContentBlocks->Text = implode($strGlue, $strItems);
  492. }
  493. if ($this->lstMenuItems) {
  494. $this->lstMenuItems->RemoveAllItems();
  495. $objAssociatedArray = $this->objMenu->GetMenuItemArray();
  496. $objMenuItemArray = MenuItem::LoadAll();
  497. if ($objMenuItemArray) foreach ($objMenuItemArray as $objMenuItem) {
  498. $objListItem = new QListItem($objMenuItem->__toString(), $objMenuItem->Id);
  499. foreach ($objAssociatedArray as $objAssociated) {
  500. if ($objAssociated->Id == $objMenuItem->Id)
  501. $objListItem->Selected = true;
  502. }
  503. $this->lstMenuItems->AddItem($objListItem);
  504. }
  505. }
  506. if ($this->lblMenuItems) {
  507. $objAssociatedArray = $this->objMenu->GetMenuItemArray();
  508. $strItems = array();
  509. foreach ($objAssociatedArray as $objAssociated)
  510. $strItems[] = $objAssociated->__toString();
  511. $this->lblMenuItems->Text = implode($strGlue, $strItems);
  512. }
  513. }
  514. ///////////////////////////////////////////////
  515. // PROTECTED UPDATE METHODS for ManyToManyReferences (if any)
  516. ///////////////////////////////////////////////
  517. protected function lstContentBlocks_Update() {
  518. if ($this->lstContentBlocks) {
  519. $this->objMenu->UnassociateAllContentBlocks();
  520. $objSelectedListItems = $this->lstContentBlocks->SelectedItems;
  521. if ($objSelectedListItems) foreach ($objSelectedListItems as $objListItem) {
  522. $this->objMenu->AssociateContentBlock(ContentBlock::Load($objListItem->Value));
  523. }
  524. }
  525. }
  526. protected function lstMenuItems_Update() {
  527. if ($this->lstMenuItems) {
  528. $this->objMenu->UnassociateAllMenuItems();
  529. $objSelectedListItems = $this->lstMenuItems->SelectedItems;
  530. if ($objSelectedListItems) foreach ($objSelectedListItems as $objListItem) {
  531. $this->objMenu->AssociateMenuItem(MenuItem::Load($objListItem->Value));
  532. }
  533. }
  534. }
  535. ///////////////////////////////////////////////
  536. // PUBLIC MENU OBJECT MANIPULATORS
  537. ///////////////////////////////////////////////
  538. /**
  539. * This will save this object's Menu instance,
  540. * updating only the fields which have had a control created for it.
  541. */
  542. public function SaveMenu() {
  543. try {
  544. // Update any fields for controls that have been created
  545. if ($this->txtName) $this->objMenu->Name = $this->txtName->Text;
  546. if ($this->txtTitle) $this->objMenu->Title = $this->txtTitle->Text;
  547. if ($this->txtCssClass) $this->objMenu->CssClass = $this->txtCssClass->Text;
  548. if ($this->txtSortOrder) $this->objMenu->SortOrder = $this->txtSortOrder->Text;
  549. if ($this->chkShowTitle) $this->objMenu->ShowTitle = $this->chkShowTitle->Checked;
  550. if ($this->lstParentMenuItem) $this->objMenu->ParentMenuItemId = $this->lstParentMenuItem->SelectedValue;
  551. if ($this->lstStatus) $this->objMenu->StatusId = $this->lstStatus->SelectedValue;
  552. if ($this->lstType) $this->objMenu->TypeId = $this->lstType->SelectedValue;
  553. // Update any UniqueReverseReferences (if any) for controls that have been created for it
  554. // Save the Menu object
  555. $this->objMenu->Save();
  556. // Finally, update any ManyToManyReferences (if any)
  557. $this->lstContentBlocks_Update();
  558. $this->lstMenuItems_Update();
  559. } catch (QCallerException $objExc) {
  560. $objExc->IncrementOffset();
  561. throw $objExc;
  562. }
  563. }
  564. /**
  565. * This will DELETE this object's Menu instance from the database.
  566. * It will also unassociate itself from any ManyToManyReferences.
  567. */
  568. public function DeleteMenu() {
  569. $this->objMenu->UnassociateAllContentBlocks();
  570. $this->objMenu->UnassociateAllMenuItems();
  571. $this->objMenu->Delete();
  572. }
  573. ///////////////////////////////////////////////
  574. // PUBLIC GETTERS and SETTERS
  575. ///////////////////////////////////////////////
  576. /**
  577. * Override method to perform a property "Get"
  578. * This will get the value of $strName
  579. *
  580. * @param string $strName Name of the property to get
  581. * @return mixed
  582. */
  583. public function __get($strName) {
  584. switch ($strName) {
  585. // General MetaControlVariables
  586. case 'Menu': return $this->objMenu;
  587. case 'TitleVerb': return $this->strTitleVerb;
  588. case 'EditMode': return $this->blnEditMode;
  589. // Controls that point to Menu fields -- will be created dynamically if not yet created
  590. case 'IdControl':
  591. if (!$this->lblId) return $this->lblId_Create();
  592. return $this->lblId;
  593. case 'IdLabel':
  594. if (!$this->lblId) return $this->lblId_Create();
  595. return $this->lblId;
  596. case 'NameControl':
  597. if (!$this->txtName) return $this->txtName_Create();
  598. return $this->txtName;
  599. case 'NameLabel':
  600. if (!$this->lblName) return $this->lblName_Create();
  601. return $this->lblName;
  602. case 'TitleControl':
  603. if (!$this->txtTitle) return $this->txtTitle_Create();
  604. return $this->txtTitle;
  605. case 'TitleLabel':
  606. if (!$this->lblTitle) return $this->lblTitle_Create();
  607. return $this->lblTitle;
  608. case 'CssClassControl':
  609. if (!$this->txtCssClass) return $this->txtCssClass_Create();
  610. return $this->txtCssClass;
  611. case 'CssClassLabel':
  612. if (!$this->lblCssClass) return $this->lblCssClass_Create();
  613. return $this->lblCssClass;
  614. case 'SortOrderControl':
  615. if (!$this->txtSortOrder) return $this->txtSortOrder_Create();
  616. return $this->txtSortOrder;
  617. case 'SortOrderLabel':
  618. if (!$this->lblSortOrder) return $this->lblSortOrder_Create();
  619. return $this->lblSortOrder;
  620. case 'ShowTitleControl':
  621. if (!$this->chkShowTitle) return $this->chkShowTitle_Create();
  622. return $this->chkShowTitle;
  623. case 'ShowTitleLabel':
  624. if (!$this->lblShowTitle) return $this->lblShowTitle_Create();
  625. return $this->lblShowTitle;
  626. case 'ParentMenuItemIdControl':
  627. if (!$this->lstParentMenuItem) return $this->lstParentMenuItem_Create();
  628. return $this->lstParentMenuItem;
  629. case 'ParentMenuItemIdLabel':
  630. if (!$this->lblParentMenuItemId) return $this->lblParentMenuItemId_Create();
  631. return $this->lblParentMenuItemId;
  632. case 'StatusIdControl':
  633. if (!$this->lstStatus) return $this->lstStatus_Create();
  634. return $this->lstStatus;
  635. case 'StatusIdLabel':
  636. if (!$this->lblStatusId) return $this->lblStatusId_Create();
  637. return $this->lblStatusId;
  638. case 'TypeIdControl':
  639. if (!$this->lstType) return $this->lstType_Create();
  640. return $this->lstType;
  641. case 'TypeIdLabel':
  642. if (!$this->lblTypeId) return $this->lblTypeId_Create();
  643. return $this->lblTypeId;
  644. case 'ContentBlockControl':
  645. if (!$this->lstContentBlocks) return $this->lstContentBlocks_Create();
  646. return $this->lstContentBlocks;
  647. case 'ContentBlockLabel':
  648. if (!$this->lblContentBlocks) return $this->lblContentBlocks_Create();
  649. return $this->lblContentBlocks;
  650. case 'MenuItemControl':
  651. if (!$this->lstMenuItems) return $this->lstMenuItems_Create();
  652. return $this->lstMenuItems;
  653. case 'MenuItemLabel':
  654. if (!$this->lblMenuItems) return $this->lblMenuItems_Create();
  655. return $this->lblMenuItems;
  656. default:
  657. try {
  658. return parent::__get($strName);
  659. } catch (QCallerException $objExc) {
  660. $objExc->IncrementOffset();
  661. throw $objExc;
  662. }
  663. }
  664. }
  665. /**
  666. * Override method to perform a property "Set"
  667. * This will set the property $strName to be $mixValue
  668. *
  669. * @param string $strName Name of the property to set
  670. * @param string $mixValue New value of the property
  671. * @return mixed
  672. */
  673. public function __set($strName, $mixValue) {
  674. try {
  675. switch ($strName) {
  676. // Controls that point to Menu fields
  677. case 'IdControl':
  678. return ($this->lblId = QType::Cast($mixValue, 'QControl'));
  679. case 'NameControl':
  680. return ($this->txtName = QType::Cast($mixValue, 'QControl'));
  681. case 'TitleControl':
  682. return ($this->txtTitle = QType::Cast($mixValue, 'QControl'));
  683. case 'CssClassControl':
  684. return ($this->txtCssClass = QType::Cast($mixValue, 'QControl'));
  685. case 'SortOrderControl':
  686. return ($this->txtSortOrder = QType::Cast($mixValue, 'QControl'));
  687. case 'ShowTitleControl':
  688. return ($this->chkShowTitle = QType::Cast($mixValue, 'QControl'));
  689. case 'ParentMenuItemIdControl':
  690. return ($this->lstParentMenuItem = QType::Cast($mixValue, 'QControl'));
  691. case 'StatusIdControl':
  692. return ($this->lstStatus = QType::Cast($mixValue, 'QControl'));
  693. case 'TypeIdControl':
  694. return ($this->lstType = QType::Cast($mixValue, 'QControl'));
  695. case 'ContentBlockControl':
  696. return ($this->lstContentBlocks = QType::Cast($mixValue, 'QControl'));
  697. case 'MenuItemControl':
  698. return ($this->lstMenuItems = QType::Cast($mixValue, 'QControl'));
  699. default:
  700. return parent::__set($strName, $mixValue);
  701. }
  702. } catch (QCallerException $objExc) {
  703. $objExc->IncrementOffset();
  704. throw $objExc;
  705. }
  706. }
  707. }
  708. ?>