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.

154 lines
4.2 KiB

  1. <?php
  2. if(!defined('QUINTACMS') ) die("No quinta.");
  3. /**
  4. * This is the Controller class for display functionality of the Menu class.
  5. * It provides a div based area for content with hierarchy, css id and class
  6. * and a relationship to the basic areas managed by ContentBlockController. It is to a
  7. * Menu that a MenuItem is assigned. This class will render any child Menus
  8. * and all associated Items.
  9. * These associations may configured via the QuintaCMS Dashboard interface and
  10. * will then automatically be reflected in the associated ContentBlockController display.
  11. *
  12. *@author Erik Winn <sidewalksoftware@gmail.com>
  13. *
  14. *@version 0.3
  15. *
  16. * @package Quinta
  17. * @subpackage Controllers
  18. *
  19. */
  20. class MenuController extends QPanel{
  21. // Local instances of the Parent object, Menu and MenuItems
  22. protected $objParentObject;
  23. protected $objMenu;
  24. public $aryMenuItemControllers;
  25. protected $strTitle;
  26. protected $intLevel = 0;
  27. // This Menu block's CSS id
  28. protected $strCssId;
  29. protected $strCssclass;
  30. public function __construct($objParentObject, Menu $objMenu/*, $strCssId*/){
  31. //Parent must always be a ContentBlock or a MenuController
  32. $this->objParentObject = $objParentObject;
  33. $this->strCssId = preg_replace('/\s/', '',$objMenu->Name);
  34. // $this->strCssId = $strCssId;
  35. try {
  36. parent::__construct($this->objParentObject, $this->strCssId);
  37. } catch (QCallerException $objExc) {
  38. $objExc->IncrementOffset();
  39. throw $objExc;
  40. }
  41. if( !$objMenu )
  42. throw new QCallerException(sprintf("Menu %s created without a MenuItem!", $strCssId) );
  43. else
  44. $this->objMenu = $objMenu;
  45. $this->strTitle = $this->objMenu->Title;
  46. if($objMenu->CssClass)
  47. $this->AddCssClass($objMenu->CssClass);
  48. $this->AddCssClass($objMenu->Type);
  49. $this->Template = __QUINTA_CORE_VIEWS__ . '/MenuView.tpl.php';
  50. $aryMenuItems = $this->objMenu->GetMenuItemArray( QQ::Clause(
  51. QQ::OrderBy(QQN::MenuItem()->SortOrder)
  52. ));
  53. foreach($aryMenuItems as $objMenuItem ){
  54. $objMenuItemController = new MenuItemController( $this, $objMenuItem );
  55. //Note: this will increment
  56. $objMenuItemController->Level = $this->Level + 1;
  57. $this->aryMenuItemControllers[] = $objMenuItemController;
  58. }
  59. /* if(!$this->mctMenu || !$this->objMenu )
  60. $this->Template = 'BasicMenu.tpl.php';
  61. else
  62. switch( $this->objMenu->Type )
  63. {
  64. case 'Menu':
  65. $this->Template = 'MenuMenu.tpl.php';
  66. break;
  67. case 'MenuItem':
  68. $this->Template = 'MenuItemMenu.tpl.php';
  69. break;
  70. case 'Header':
  71. $this->Template = 'HeaderMenu.tpl.php';
  72. break;
  73. case 'RightPanel':
  74. $this->Template = 'RightPanelMenu.tpl.php';
  75. break;
  76. case 'LeftPanel':
  77. $this->Template = 'LeftPanelMenu.tpl.php';
  78. break;
  79. case 'CenterPanel':
  80. $this->Template = 'CenterPanelMenu.tpl.php';
  81. break;
  82. case 'Footer':
  83. $this->Template = 'FooterMenu.tpl.php';
  84. break;
  85. case 'BlockHeader':
  86. $this->Template = 'BlockHeaderMenu.tpl.php';
  87. break;
  88. case 'BlockFooter':
  89. $this->Template = 'BlockFooterMenu.tpl.php';
  90. break;
  91. default:
  92. $this->Template = 'BasicMenu.tpl.php';
  93. }*/
  94. }
  95. public function __get($strName){
  96. switch ($strName){
  97. case 'Level':
  98. return $this->intLevel ;
  99. case 'CssId':
  100. return $this->strCssId ;
  101. case 'Title':
  102. return $this->strTitle ;
  103. case 'ShowTitle':
  104. return $this->objMenu->ShowTitle ;
  105. case 'Name':
  106. return $this->objMenu->Name ;
  107. case 'MenuItemControllers':
  108. return $this->aryMenuItemControllers ;
  109. default:
  110. try {
  111. return parent::__get($strName);
  112. } catch (QCallerException $objExc) {
  113. $objExc->IncrementOffset();
  114. throw $objExc;
  115. }
  116. }
  117. }
  118. public function __set($strName, $mixValue){
  119. switch ($strName){
  120. case 'Level':
  121. try {
  122. return ($this->intLevel = QType::Cast($mixValue, QType::Integer));
  123. } catch (QInvalidCastException $objExc) {
  124. $objExc->IncrementOffset();
  125. throw $objExc;
  126. }
  127. default:
  128. try {
  129. return (parent::__set($strName, $mixValue));
  130. } catch (QCallerException $objExc) {
  131. $objExc->IncrementOffset();
  132. throw $objExc;
  133. }
  134. }
  135. }
  136. }
  137. ?>