Lithron.LCssDropDownMenu
[ class tree: Lithron.LCssDropDownMenu ] [ index: Lithron.LCssDropDownMenu ] [ all elements ]

Source for file LCssDropDownMenuNode.php

Documentation is available at LCssDropDownMenuNode.php

  1. <?php
  2.  
  3.  
  4. /**
  5. * TCssDropDownMenuNode class file
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the BSD License.
  9. *
  10. * Copyright(c) 2004 by Scott Fuelberth.
  11. *
  12. * To contact the author write to {@link mailto:skot@bastardcat.org Scott Fuelberth}
  13. * The latest version of PRADO can be obtained from:
  14. * {@link http://prado.sourceforge.net/}
  15. *
  16. * =================================================
  17. * NOTICE: This is an pre-alpha version for PRADO v3
  18. * author: Tobias Munk <webmaster@lithron.de>
  19. * =================================================
  20. *
  21. * @author Scott Fuelberth <skot@bastardcat.org>
  22. * @version $Revision: 188 $ $Date: 2006-05-11 10:50:16 +0200 (Do, 11 Mai 2006) $
  23. * @package Lithron.LCssDropDownMenu
  24. * @subpackage WebControls
  25. */
  26.  
  27. /**
  28. * TCssDropDownMenuNode class
  29. *
  30. * TCssDropDownMenuNode displays a css driven menu item. You can set the link through the
  31. * through the <b>LinkUrl</b> property. You can set the Text displayed for the item through the <b>Text</b> property.
  32. * You can set the roles that are allowed to access the item through the <b>Roles</b> property.
  33. *
  34. * Example: <code><com:TCssDropDownMenuNode ID="ViewUsers" LinkUrl="?page=ViewUsersPage"
  35. * Text="View Users" Roles="root,admin" BorderColor="green" BorderStyle="solid" BorderWidth="1" BackColor="white"/></code>
  36. *
  37. * Namespace: Lithron.Web.UI.WebControls
  38. *
  39. * Properties
  40. * - <b>LinkUrl</b>, string, kept in viewstate
  41. * <br/>Set the link for the item.
  42. * - <b>Text</b>, string, kept in viewstate
  43. * <br/>Set the text for the item.
  44. * - <b>Roles</b>, string, kept in viewstate
  45. * <br/>The user roles allowed to view the item.
  46. *
  47. * @package System.Web.UI.WebControls
  48. */
  49. class LCssDropDownMenuNode extends TWebControl
  50. {
  51.  
  52. /**
  53. * top parent flag
  54. * @var boolean
  55. */
  56. private $isTopParent= false;
  57.  
  58. /**
  59. * top parent css class name
  60. * @var string
  61. */
  62. private $topParentNodeCssClass= '';
  63.  
  64. /**
  65. * parent node css class name
  66. * @var string
  67. */
  68. private $parentNodeCssClass= '';
  69.  
  70. /**
  71. * node css class name
  72. * @var string
  73. */
  74. private $nodeCssClass= '';
  75.  
  76. /**
  77. * disabled node css class name
  78. * @var string
  79. */
  80. private $disabledNodeCssClass= '';
  81.  
  82. private $_tagName;
  83.  
  84. protected function getTagName()
  85. {
  86. return $this->_tagName;
  87. }
  88.  
  89. function setTagName($value)
  90. {
  91. $this->_tagName= $value;
  92. }
  93.  
  94. /**
  95. * Constructor.
  96. * Sets TagName property to 'li'
  97. */
  98. function __construct()
  99. {
  100. parent :: __construct();
  101. $this->setTagName('li');
  102. }
  103.  
  104. /**
  105. * @return string the Roles allowd to view this element
  106. */
  107. public function getRoles()
  108. {
  109. return $this->getViewState('Roles', '');
  110. }
  111.  
  112. /**
  113. * @param string the Roles allowed to view this element
  114. */
  115. public function setRoles($value)
  116. {
  117. $this->setViewState('Roles', $value, '');
  118. }
  119.  
  120. /**
  121. * @return string the LinkUrl of the node
  122. */
  123. public function getLinkUrl()
  124. {
  125. return $this->getViewState('LinkUrl', '');
  126. }
  127.  
  128. /**
  129. * @param string the LinkUrl of the node
  130. */
  131. public function setLinkUrl($value)
  132. {
  133. $this->setViewState('LinkUrl', $value, '');
  134. }
  135. /**
  136. * @return string the LinkId of the node (service)
  137. */
  138. public function getLinkId()
  139. {
  140. return $this->getViewState('LinkId', '');
  141. }
  142.  
  143. /**
  144. * @param string the LinkId of the node (service)
  145. */
  146. public function setLinkId($value)
  147. {
  148. $this->setViewState('LinkId', $value, '');
  149. }
  150.  
  151. /**
  152. * @return string the Text of the node
  153. */
  154. public function getText()
  155. {
  156. return $this->getViewState('Text', '');
  157. }
  158.  
  159. /**
  160. * @param string the Text of the node
  161. */
  162. public function setText($value)
  163. {
  164. $this->setViewState('Text', $value, '');
  165. }
  166.  
  167. /**
  168. * @return string the link Target
  169. */
  170. public function getTarget()
  171. {
  172. return $this->getViewState('Target', '');
  173. }
  174.  
  175. /**
  176. * @param string the link target
  177. */
  178. public function setTarget($value)
  179. {
  180. $this->setViewState('Target', $value, '');
  181. }
  182.  
  183. /**
  184. * @return bool top parent flag
  185. */
  186. public function isTopParent()
  187. {
  188. return $this->isTopParent;
  189. }
  190.  
  191. /**
  192. * @param bool the top parent flag
  193. */
  194. public function setTopParent($value)
  195. {
  196. $this->isTopParent= $value;
  197. }
  198.  
  199. /**
  200. * @return string the top parent css class
  201. */
  202. public function getTopParentNodeCssClass()
  203. {
  204. return $this->topParentNodeCssClass;
  205. }
  206.  
  207. /**
  208. * #param string the top parent css class
  209. */
  210. public function setTopParentNodeCssClass($value)
  211. {
  212. $this->topParentNodeCssClass= $value;
  213. }
  214.  
  215. /**
  216. * @return string the parent css class
  217. */
  218. public function getParentNodeCssClass()
  219. {
  220. return $this->parentNodeCssClass;
  221. }
  222.  
  223. /**
  224. * @param string the parent css class
  225. */
  226. public function setParentNodeCssClass($value)
  227. {
  228. $this->parentNodeCssClass= $value;
  229. }
  230.  
  231. /**
  232. * @param string the node css class
  233. */
  234. public function setNodeCssClass($value)
  235. {
  236. $this->nodeCssClass= $value;
  237. }
  238.  
  239. /**
  240. * @return string the node css class
  241. */
  242. public function getNodeCssClass()
  243. {
  244. return $this->nodeCssClass;
  245. }
  246.  
  247. /**
  248. * @param string the node css class
  249. */
  250. public function setDisabledNodeCssClass($value)
  251. {
  252. $this->disabledNodeCssClass= $value;
  253. }
  254.  
  255. /**
  256. * @return string the node css class
  257. */
  258. public function getDisabledNodeCssClass()
  259. {
  260. return $this->disabledNodeCssClass;
  261. }
  262.  
  263. /**
  264. * @param sets selected status
  265. */
  266. public function setSelectedPath($value)
  267. {
  268. $this->setViewState("SelectedPath", $value);
  269. if ($this->Parent instanceof LCssDropDownMenuNode)
  270. {
  271. #echo "parent";
  272. $this->Parent->setSelectedPath($value);
  273. }
  274. }
  275.  
  276. /**
  277. * @return gets selected status
  278. */
  279. public function getSelectedPath()
  280. {
  281. return $this->getViewState("SelectedPath");
  282. }
  283.  
  284. /**
  285. * Renders the menu.
  286. * Will go through all TCssDropDownMenuNode children and render them
  287. * at the correct place.
  288. * @return void
  289. */
  290. public function renderContents($writer)
  291. {
  292.  
  293. $user= $this->getPage()->getUser();
  294. if (!is_null($user))
  295. {
  296. if (!$user->isInRole($this->getRoles()))
  297. {
  298. #return null; TEMP HACK - TODO
  299. //return $content;
  300. }
  301. }
  302.  
  303. if ($this->getEnabled())
  304. {
  305. if ($this->isTopParent())
  306. {
  307. $cssClass= $this->getTopParentNodeCssClass();
  308. }
  309. elseif ($this->getControls()->getCount())
  310. {
  311. $cssClass= $this->getParentNodeCssClass();
  312. $cssClass .= $this->getNodeCssClass() . "parent"; // TODO
  313. }
  314. else
  315. {
  316. $cssClass= $this->getNodeCssClass();
  317. }
  318. }
  319. else
  320. {
  321. $this->setLinkUrl(false);
  322. $cssClass= $this->getDisabledNodeCssClass();
  323. }
  324.  
  325. $style= $this->getStyle();
  326. if (($width= $this->getWidth()) > 0)
  327. $style['width']= $width . 'px';
  328. if (($height= $this->getHeight()) > 0)
  329. $style['height']= $height . 'px';
  330. $foreColor= $this->getForeColor();
  331. if (strlen($foreColor))
  332. $style['color']= $foreColor;
  333. $s= '';
  334. if (count($style) > 0)
  335. {
  336. foreach ($style as $k => $v)
  337. $s .= "$k:$v;";
  338. }
  339.  
  340. if ($s == null || $s == "")
  341. {
  342. $styleString= "";
  343. }
  344. else
  345. {
  346. $styleString= 'style="' . $s . '"';
  347. }
  348.  
  349. #TODO -------------------------------------
  350. $_id= $this->getLinkId();
  351. #$_id = 22;
  352. if (empty ($_id))
  353. {
  354. $_p= $_url= $this->getLinkUrl();
  355. preg_match("/=(.*)&?/", $_url, $match);
  356. if (isset ($match[0]))
  357. {
  358. $_p= str_replace("=", "", $match[0]);
  359. $_p= str_replace(strstr($_p, "&"), "", $_p);
  360. }
  361. $link= $this->Service->constructUrl($_p);
  362. }
  363. else
  364. $link= $this->Service->constructUrl($_id);
  365.  
  366. $page= $this->Service->constructUrl($this->Service->getServicePage());
  367. #echo $link . "<hr>" . $page;
  368. if ($link == $page)
  369. {
  370. $cssClass= $cssClass . " selected";
  371. $this->setSelectedPath(true);
  372. }
  373. if ($this->getSelectedPath() === true)
  374. {
  375. $cssClass= $cssClass . " selectedPath"; # TODO does not work, we are already in render :( FIXME
  376. }
  377.  
  378. if ($cssClass == null || $cssClass == "")
  379. {
  380. $cssString= '';
  381. }
  382. else
  383. {
  384. $cssString= 'class="' . $cssClass . '"';
  385. }
  386.  
  387. if (strlen($this->getLinkUrl()))
  388. {
  389. if (strlen($this->getTarget()))
  390. {
  391.  
  392. $link= '<a href="' . $this->getLinkUrl() . '" ' . $styleString . ' ' . $cssString . ' target="' . $this->getTarget() . '" >' . $this->getText() . '</a>';
  393. }
  394. else
  395. {
  396. $link= '<a href="' . $this->getLinkUrl() . '" ' . $styleString . ' ' . $cssString . ' >' . $this->getText() . '</a>';
  397. }
  398. }
  399. else
  400. {
  401. $link= '<span ' . $styleString . ' ' . $cssString . ' >' . $this->getText() . '</span>';
  402. }
  403. $writer->write($link);
  404.  
  405. $body= $this->getControls()->getCount();
  406. if ($body)
  407. {
  408. $writer->renderBeginTag('ul');
  409. foreach ($this->getControls() as $item)
  410. {
  411. if ($item instanceof LCssDropDownMenuNode)
  412. {
  413.  
  414. $item->setTopParent(false);
  415. $item->setTopParentNodeCssClass($this->getTopParentNodeCssClass());
  416. $item->setParentNodeCssClass($this->getParentNodeCssClass());
  417. $item->setNodeCssClass($this->getNodeCssClass());
  418. $item->setDisabledNodeCssClass($this->getDisabledNodeCssClass());
  419. if ($item->getVisible())
  420. {
  421. $item->render($writer);
  422. }
  423. }
  424. }
  425. $writer->renderEndTag('ul');
  426. }
  427. #Prado :: trace("Returning node children content", 'Lithron.LCssDrownDownMenu');
  428. }
  429. }
  430. ?>

Documentation generated on Tue, 20 Jun 2006 05:15:07 +0200 by phpDocumentor 1.3.0RC4