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.

212 lines
6.3 KiB

  1. <?php
  2. /**
  3. * This is the MenuItemController class for the display functionality
  4. * of the MenuItem class. It determines the type of menu to create
  5. * based on flags in MenuItem, creating local soft hrefs (href#target)
  6. * or external links. The rendering is based on <li> for CSS styling
  7. * when there are lists or optionally a simple div with an anchor. The label
  8. * may be text or an img src (CSS images are prefered). A div may be
  9. * used for stand alone links that are not part of a menu
  10. *
  11. * The CSS Id is the Name column in the menu_item table, class may
  12. * be set in the administration as well - each class will be added, a default
  13. * class of Menu or MenuItem will be applied in any case.
  14. *
  15. * The constructor may be passed either a MenuItem or a MenuController -
  16. * for MenuController GetControlHtml will make a li or a div in which to create
  17. * the children of the menu (NOTE: this is unimplemented ..)
  18. *
  19. *@todo
  20. * - implement Menu child items
  21. * - check permissions for the item ..
  22. * - (maybe) add js actions to simply change the CenterPanel of a PageController
  23. * without a total reload of the page. Ie. pass a callback that can hide/show
  24. * areas.
  25. *
  26. *@author Erik Winn <sidewalksoftware@gmail.com>
  27. *
  28. *@version 0.3
  29. *
  30. * @package Quinta
  31. * @subpackage Controllers
  32. *
  33. */
  34. class MenuItemController extends QControl{
  35. /**
  36. * Local reference to the Parent object: MenuItem or a Menu normally
  37. * @var QPanel objParentObject
  38. */
  39. protected $objControlBlock;
  40. protected $mixMenuItem;
  41. private $_objMenuItem = null;
  42. private $_objMenu = null;
  43. // The presented item - may contain text or an image
  44. protected $strLabel = '';
  45. protected $strHref = '';
  46. protected $strImgSrc = null;
  47. // This MenuItem's CSS
  48. protected $strCssId = '';
  49. protected $strCssclass = '';
  50. // State flags
  51. protected $intLevel = 1;
  52. protected $blnEnabled = true;
  53. protected $blnUseDivs = false;
  54. protected $blnUseSpans = false;
  55. protected $blnUseImgSrc = false;
  56. protected $isLocal = true;
  57. public function ParsePostData() {}
  58. public function Validate() {return true;}
  59. /**
  60. * MenuItemController constructor
  61. * This constructor will accept any QPanel as the control block, this is normally a MenuController.
  62. * The second parameter may be either a Menu or a MenuItem.
  63. *
  64. *@param QPanel objControlBlock - the DOM parent, should be a ContentBlockController or a MenuController
  65. *@param QPanel mixMenuItem - the item to display, a Menu or a MenuItem
  66. */
  67. public function __construct($objControlBlock, $mixMenuItem){
  68. //Parent should always be a ContentBlockController or a MenuController
  69. $this->objControlBlock = $objControlBlock;
  70. $this->strCssId = preg_replace('/\s/', '',$mixMenuItem->Name);
  71. try {
  72. parent::__construct($this->objControlBlock, $this->strCssId);
  73. } catch (QCallerException $objExc) {
  74. $objExc->IncrementOffset();
  75. throw $objExc;
  76. }
  77. if( $mixMenuItem instanceof MenuItem )
  78. {
  79. $this->_objMenuItem = $mixMenuItem;
  80. if('/'. $this->MenuItem->Uri == Quinta::$PathInfo)
  81. $this->AddCssClass("currentlink");
  82. }
  83. elseif ( $mixMenuItem instanceof Menu )
  84. {
  85. $this->AddCssClass("Menu");
  86. $this->_objMenu = $mixMenuItem;
  87. }
  88. if($mixMenuItem->CssClass)
  89. $this->AddCssClass($mixMenuItem->CssClass);
  90. $this->AddCssClass($mixMenuItem->Type);
  91. $this->strHref = $this->CreateHref();
  92. }
  93. /**
  94. * Creates the HTML for this MenuItem - returns address to be wrapped
  95. * @todo
  96. * - be more intelligent here, perhaps support odd number ports, possibly
  97. * omit http* and servername for local items.
  98. * - There is also an odd behaviour in QCodo - it gets confused when switching
  99. * between ssl and plain connections .. fixme.
  100. * - Possibly allow for document.location if js is available
  101. *
  102. * @return string
  103. */
  104. public function CreateHref(){
  105. //we are a menu .. return.
  106. if($this->Menu )
  107. return '';
  108. if($this->MenuItem->IsSsl)
  109. $strReturn = 'https://';
  110. else
  111. $strReturn = 'http://';
  112. if($this->MenuItem->IsLocal)
  113. $strReturn .= Quinta::$ServerName . __QUINTA_SUBDIRECTORY__ . '/index.php/';
  114. $strReturn .= $this->MenuItem->Uri;
  115. return $strReturn;
  116. }
  117. /**
  118. * Get the HTML for this MenuItem - returns the anchor wrapped in li or div
  119. * @return string
  120. */
  121. public function GetControlHtml(){
  122. if($this->Menu)
  123. $object = $this->Menu;
  124. else
  125. $object = $this->MenuItem;
  126. $strAttributes = $this->GetAttributes();
  127. $strStyle = $this->GetStyleAttributes();
  128. if ( '' != $strStyle)
  129. $strStyle = 'style="' . $strStyle . '"';
  130. if($object instanceof Menu)
  131. return sprintf(' %s', 'Submenus TBD-FIXME' );
  132. /* if($this->blnUseDivs)
  133. return sprintf('<div id="%s" %s%s><a href="%s"> %s</a></div>',
  134. $this->strCssId, $strAttributes, $strStyle, $this->Href, $object->Label);
  135. /* return sprintf('<li id="%s" %s%s><a href="%s"> %s</a></li>',
  136. $this->strCssId, $strAttributes, $strStyle, $this->Href, $object->Label);*/
  137. return sprintf('<a %s %s href="%s"> %s</a>',
  138. $strAttributes, $strStyle, $this->Href, $object->Label);
  139. }
  140. public function __get($strName){
  141. switch ($strName){
  142. case 'UseDivs':
  143. return $this->blnUseDivs ;
  144. case 'CssId':
  145. return $this->strCssId ;
  146. case 'Cssclass':
  147. return $this->strCssclass ;
  148. case 'Href':
  149. return $this->strHref ;
  150. case 'Level':
  151. return $this->intLevel ;
  152. case 'Menu':
  153. return $this->_objMenu;
  154. case 'MenuItem':
  155. return $this->_objMenuItem;
  156. case 'Label':
  157. case 'Title':
  158. if($this->mixMenuItem instanceof Menu )
  159. return $this->_objMenu->Title ;
  160. else
  161. return $this->_objMenuItem->Label ;
  162. default:
  163. try {
  164. return parent::__get($strName);
  165. } catch (QCallerException $objExc) {
  166. $objExc->IncrementOffset();
  167. throw $objExc;
  168. }
  169. }
  170. }
  171. public function __set($strName, $mixValue){
  172. switch ($strName){
  173. case 'Level':
  174. try {
  175. return ($this->intLevel = QType::Cast($mixValue, QType::Integer));
  176. } catch (QInvalidCastException $objExc) {
  177. $objExc->IncrementOffset();
  178. throw $objExc;
  179. }
  180. default:
  181. try {
  182. return (parent::__set($strName, $mixValue));
  183. } catch (QCallerException $objExc) {
  184. $objExc->IncrementOffset();
  185. throw $objExc;
  186. }
  187. }
  188. }
  189. }
  190. ?>