A Qcodo based CMS/ecommerce framework
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.

240 lines
8.7 KiB

12 years ago
  1. <?php
  2. /**
  3. * This is the MenuItemView 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 MenuView -
  16. * for MenuView 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 PageView
  23. * without a total reload of the page. Ie. pass a callback that can hide/show
  24. * areas.
  25. *
  26. *@author Erik Winn <erikwinnmail@yahoo.com>
  27. *
  28. *
  29. * $Id: MenuItemView.class.php 426 2008-12-14 04:18:10Z erikwinn $
  30. *@version 0.1
  31. *
  32. *@copyright (C) 2008 by Erik Winn
  33. *@license GPL v.2
  34. This program is free software; you can redistribute it and/or modify
  35. it under the terms of the GNU General Public License as published by
  36. the Free Software Foundation; either version 2 of the License, or
  37. (at your option) any later version.
  38. This program is distributed in the hope that it will be useful,
  39. but WITHOUT ANY WARRANTY; without even the implied warranty of
  40. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  41. GNU General Public License for more details.
  42. You should have received a copy of the GNU General Public License
  43. along with this program; if not, write to the Free Software
  44. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
  45. *
  46. * @package Quasi
  47. * @subpackage Views
  48. *
  49. */
  50. class MenuItemView extends QControl
  51. {
  52. /**
  53. * Local reference to the Parent object: MenuItem or a Menu normally
  54. * @var QPanel objParentObject
  55. */
  56. protected $objControlBlock;
  57. protected $mixMenuItem;
  58. private $_objMenuItem = null;
  59. private $_objMenu = null;
  60. // The presented item - may contain text or an image
  61. protected $strLabel = '';
  62. protected $strHref = '';
  63. protected $strImgSrc = null;
  64. // This MenuItem's CSS
  65. protected $strCssId = '';
  66. protected $strCssclass = '';
  67. // State flags
  68. protected $intLevel = 1;
  69. protected $blnEnabled = true;
  70. protected $blnUseDivs = false;
  71. protected $blnUseSpans = false;
  72. protected $blnUseImgSrc = false;
  73. protected $isLocal = true;
  74. public function ParsePostData() {}
  75. public function Validate() {return true;}
  76. /**
  77. * MenuItemView constructor
  78. * This constructor will accept any QPanel as the control block, this is normally a MenuView.
  79. * The second parameter may be either a Menu or a MenuItem.
  80. *
  81. *@param QPanel objControlBlock - the DOM parent, should be a ContentBlockView or a MenuView
  82. *@param QPanel mixMenuItem - the item to display, a Menu or a MenuItem
  83. */
  84. public function __construct($objControlBlock, $mixMenuItem)
  85. {
  86. //Parent should always be a ContentBlockView or a MenuView
  87. $this->objControlBlock = $objControlBlock;
  88. $this->strCssId = preg_replace('/\s/', '',$mixMenuItem->Name);
  89. try {
  90. parent::__construct($this->objControlBlock, $this->strCssId);
  91. } catch (QCallerException $objExc) {
  92. $objExc->IncrementOffset();
  93. throw $objExc;
  94. }
  95. if( $mixMenuItem instanceof MenuItem )
  96. {
  97. $this->_objMenuItem = $mixMenuItem;
  98. if('/'. $this->MenuItem->Uri == Quasi::$PathInfo)
  99. $this->AddCssClass("currentlink");
  100. }
  101. elseif ( $mixMenuItem instanceof Menu )
  102. {
  103. $this->AddCssClass("Menu");
  104. $this->_objMenu = $mixMenuItem;
  105. }
  106. if($mixMenuItem->CssClass)
  107. $this->AddCssClass($mixMenuItem->CssClass);
  108. $this->AddCssClass($mixMenuItem->Type);
  109. $this->strHref = $this->CreateHref();
  110. }
  111. /**
  112. * Creates the HTML for this MenuItem - returns address to be wrapped
  113. * @todo
  114. * - be more intelligent here, perhaps support odd number ports, possibly
  115. * omit http* and servername for local items.
  116. * - There is also an odd behaviour in QCodo - it gets confused when switching
  117. * between ssl and plain connections .. fixme.
  118. * - Possibly allow for document.location if js is available
  119. *
  120. * @return string
  121. */
  122. public function CreateHref()
  123. {
  124. //we are a menu .. return.
  125. if($this->Menu )
  126. return '';
  127. if($this->MenuItem->IsSsl)
  128. $strReturn = 'https://';
  129. else
  130. $strReturn = 'http://';
  131. if($this->MenuItem->IsLocal)
  132. $strReturn .= Quasi::$ServerName . __QUASI_SUBDIRECTORY__ . '/index.php/';
  133. $strReturn .= $this->MenuItem->Uri;
  134. return $strReturn;
  135. }
  136. /**
  137. * Get the HTML for this MenuItem - returns the anchor wrapped in li or div
  138. * @return string
  139. */
  140. public function GetControlHtml()
  141. {
  142. if($this->Menu)
  143. $object = $this->Menu;
  144. else
  145. $object = $this->MenuItem;
  146. $strAttributes = $this->GetAttributes();
  147. $strStyle = $this->GetStyleAttributes();
  148. if ( '' != $strStyle)
  149. $strStyle = 'style="' . $strStyle . '"';
  150. if($object instanceof Menu)
  151. return sprintf(' %s', 'Submenus TBD-FIXME' );
  152. /* if($this->blnUseDivs)
  153. return sprintf('<div id="%s" %s%s><a href="%s"> %s</a></div>',
  154. $this->strCssId, $strAttributes, $strStyle, $this->Href, $object->Label);
  155. /* return sprintf('<li id="%s" %s%s><a href="%s"> %s</a></li>',
  156. $this->strCssId, $strAttributes, $strStyle, $this->Href, $object->Label);*/
  157. return sprintf('<a %s %s href="%s"> %s</a>',
  158. $strAttributes, $strStyle, $this->Href, $object->Label);
  159. }
  160. public function __get($strName)
  161. {
  162. switch ($strName)
  163. {
  164. case 'UseDivs':
  165. return $this->blnUseDivs ;
  166. case 'CssId':
  167. return $this->strCssId ;
  168. case 'Cssclass':
  169. return $this->strCssclass ;
  170. case 'Href':
  171. return $this->strHref ;
  172. case 'Level':
  173. return $this->intLevel ;
  174. case 'Menu':
  175. return $this->_objMenu;
  176. case 'MenuItem':
  177. return $this->_objMenuItem;
  178. case 'Label':
  179. case 'Title':
  180. if($this->mixMenuItem instanceof Menu )
  181. return $this->_objMenu->Title ;
  182. else
  183. return $this->_objMenuItem->Label ;
  184. default:
  185. try {
  186. return parent::__get($strName);
  187. } catch (QCallerException $objExc) {
  188. $objExc->IncrementOffset();
  189. throw $objExc;
  190. }
  191. }
  192. }
  193. public function __set($strName, $mixValue)
  194. {
  195. switch ($strName)
  196. {
  197. case 'Level':
  198. try {
  199. return ($this->intLevel = QType::Cast($mixValue, QType::Integer));
  200. } catch (QInvalidCastException $objExc) {
  201. $objExc->IncrementOffset();
  202. throw $objExc;
  203. }
  204. default:
  205. try {
  206. return (parent::__set($strName, $mixValue));
  207. } catch (QCallerException $objExc) {
  208. $objExc->IncrementOffset();
  209. throw $objExc;
  210. }
  211. }
  212. }
  213. }
  214. ?>