Phundament-Components
[ class tree: Phundament-Components ] [ index: Phundament-Components ] [ all elements ]

Source for file LCssDropDownMenuNode.php

Documentation is available at LCssDropDownMenuNode.php

  1. <?php
  2.  
  3.  
  4. /**
  5.  * LCssDropDownMenuNode 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.  * Copyright(c) 2006 by Tobias Munk.
  12.  *
  13.  * The latest version of PRADO can be obtained from:
  14.  * {@link http://prado.sourceforge.net/}
  15.  *
  16.  *
  17.  * @author Scott Fuelberth <skot@bastardcat.org>, Tobias Munk <webmaster@lithron.de>
  18.  * @version $Revision: 634 $  $Date: 2007-02-25 02:10:40 +0100 (Sun, 25 Feb 2007) $
  19.  * @package Phundament.Components
  20.  * @subpackage WebControls
  21.  */
  22.  
  23. /**
  24.  * LCssDropDownMenuNode class
  25.  *
  26.  * LCssDropDownMenuNode displays a css driven menu item. You can set the link through the
  27.  * through the <b>LinkUrl</b> property. You can set the Text displayed for the item through the <b>Text</b> property.
  28.  * You can set the roles that are allowed to access the item through the <b>Roles</b> property.
  29.  *
  30.  * Example: <code><com:TCssDropDownMenuNode ID="ViewUsers" LinkUrl="?page=ViewUsersPage"
  31.  * Text="View Users" Roles="root,admin" BorderColor="green" BorderStyle="solid" BorderWidth="1" BackColor="white"/></code>
  32.  *
  33.  * Namespace: Lithron.Web.UI.WebControls
  34.  *
  35.  * Properties
  36.  * - <b>LinkUrl</b>, string, kept in viewstate
  37.  *   <br/>Set the link for the item.
  38.  * - <b>Text</b>, string, kept in viewstate
  39.  *   <br/>Set the text for the item.
  40.  * - <b>Roles</b>, string, kept in viewstate
  41.  *   <br/>The user roles allowed to view the item.
  42.  *
  43.  * @package System.Web.UI.WebControls
  44.  * @subpackage Navigation
  45.  */
  46. class LCssDropDownMenuNode extends TWebControl
  47. {
  48.  
  49.     /**
  50.      * top parent flag
  51.      * @var boolean 
  52.      */
  53.     private $isTopParentfalse;
  54.  
  55.     /**
  56.      * top parent css class name
  57.      * @var string 
  58.      */
  59.     private $topParentNodeCssClass'';
  60.  
  61.     /**
  62.      * parent node css class name
  63.      * @var string 
  64.      */
  65.     private $parentNodeCssClass'';
  66.  
  67.     /**
  68.      * node css class name
  69.      * @var string 
  70.      */
  71.     private $nodeCssClass'';
  72.  
  73.     /**
  74.      * disabled node css class name
  75.      * @var string 
  76.      */
  77.     private $disabledNodeCssClass'';
  78.  
  79.     private $_tagName;
  80.     private $_hasChilds;
  81.  
  82.     private $_IsSelected;
  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 
  265.      */
  266.     public function setIsSelected($value)
  267.     {
  268.         $this->_IsSelected $value;
  269.     }
  270.  
  271.     /**
  272.      * @return 
  273.      */
  274.     public function getIsSelected()
  275.     {
  276.         return $this->_IsSelected;
  277.     }
  278.  
  279.  
  280.  
  281.     /**
  282.      * @param sets selected status
  283.      */
  284.     public function setSelectedPath($value)
  285.     {
  286.         $this->setViewState("SelectedPath"$value);
  287.         #echo get_class($this->Parent);
  288.         if ($this->Parent instanceof LCssDropDownMenuNode)
  289.         {
  290.             #echo "parent";
  291.             $this->Parent->setSelectedPath($value);
  292.         }
  293.     }
  294.  
  295.     /**
  296.      * @return gets selected status
  297.      */
  298.     public function getSelectedPath()
  299.     {
  300.         return $this->getViewState("SelectedPath");
  301.     }
  302.  
  303.     function onPreRender($param)
  304.     {
  305.         parent::onPreRender($param);
  306.         if (count($this->Controls)) $this->_hasChilds true// TODO
  307.  
  308.  
  309.         if ($this->Service instanceof LPageService)
  310.             $page$this->Service->constructUrl($this->Service->getServicePage(true));
  311.         else
  312.             $pagenull;
  313.  
  314.         if (substr($this->LinkUrl(strlen($page)*-1)) == $page// HOTFIX - TODO
  315.         {
  316.             $this->setIsSelected(true);
  317.             $this->setSelectedPath(true);
  318.         }
  319.     }
  320.  
  321.     /**
  322.      * Renders the menu.
  323.      * Will go through all TCssDropDownMenuNode children and render them
  324.      * at the correct place.
  325.      * @return void 
  326.      */
  327.     public function renderContents($writer)
  328.     {
  329.         #echo $this->Text.$this->SelectedPath."<br>";
  330.  
  331.         $roles$this->getRoles();
  332.         if ($roles)
  333.         {
  334.             $user$this->User;
  335.             if (!is_null($user))
  336.             {
  337.                 foreach (explode(","$rolesAS $role)
  338.                 {
  339.                     $killtrue;
  340.                     if ($user->isInRole($role$this->getRoles()))
  341.                     {
  342.                         $killfalse;
  343.                         break;
  344.                     }
  345.                 }
  346.             }
  347.             else
  348.             {
  349.                 $killfalse;
  350.             }
  351.             if ($killreturn;
  352.         }
  353.  
  354.         if ($this->getEnabled())
  355.         {
  356.  
  357.             if (false && $this->isTopParent())
  358.             {
  359.                 $cssClass$this->getTopParentNodeCssClass();
  360.             }
  361.             elseif count($this->getControls()) )
  362.             {
  363.                 $cssClass$this->getParentNodeCssClass();
  364.                 $cssClass .= $this->getNodeCssClass(" parent"// TODO
  365.             }
  366.             else
  367.             {
  368.                 $cssClass$this->getNodeCssClass();
  369.             }
  370.         }
  371.         else
  372.         {
  373.             $this->setLinkUrl(false);
  374.             $cssClass$this->getDisabledNodeCssClass();
  375.         }
  376.  
  377.         $style$this->getStyle();
  378.         if (($width$this->getWidth()) 0)
  379.             $style['width']$width 'px';
  380.         if (($height$this->getHeight()) 0)
  381.             $style['height']$height 'px';
  382.         $foreColor$this->getForeColor();
  383.         if (strlen($foreColor))
  384.             $style['color']$foreColor;
  385.         $s'';
  386.         if (count($style0)
  387.         {
  388.             foreach ($style as $k => $v)
  389.                 $s .= "$k:$v;";
  390.         }
  391.  
  392.         if ($s == null || $s == "")
  393.         {
  394.             $styleString"";
  395.         }
  396.         else
  397.         {
  398.             $styleString'style="' $s '"';
  399.         }
  400.  
  401.         #TODO -------------------------------------
  402.         $_id$this->getLinkId();
  403.         #$_id = 22;
  404.         if (empty ($_id))
  405.         {
  406.             $_p$_url$this->getLinkUrl();
  407.  
  408.             if (substr($_p,0,1== "/"$_p substr($_p1)// HACK - TODO
  409.  
  410.             preg_match("/=(.*)&?/"$_url$match);
  411.             if (isset ($match[0]))
  412.             {
  413.                 $_pstr_replace("="""$match[0]);
  414.                 $_pstr_replace(strstr($_p"&")""$_p);
  415.             }
  416.             $link$this->Service->constructUrl($_p);
  417.         }
  418.         else
  419.             $link$this->Service->constructUrl($_id);
  420.  
  421.  
  422.         #$link . "------" . $page."<hr>";
  423.         if ($this->getIsSelected(=== true)
  424.         {
  425.             $cssClass$cssClass " selected";
  426.         }
  427.         if ($this->getSelectedPath(=== true)
  428.         {
  429.             $cssClass$cssClass " selectedPath"# TODO does not work, we are already in render :( FIXME
  430.         }
  431.  
  432.         if ($cssClass == null || $cssClass == "")
  433.         {
  434.             $cssString'';
  435.         }
  436.         else
  437.         {
  438.             $cssString'class="' $cssClass '"';
  439.         }
  440.  
  441.         if (strlen($this->getLinkUrl()))
  442.         {
  443.             if (strlen($this->getTarget()))
  444.             {
  445.  
  446.                 $link'<a href="' $this->getLinkUrl('" ' $styleString ' ' $cssString ' target="' $this->getTarget('" >' $this->getText('</a>';
  447.             }
  448.             else
  449.             {
  450.                 $link'<a href="' $this->getLinkUrl('" ' $styleString ' ' $cssString ' >' $this->getText('</a>';
  451.             }
  452.         }
  453.         else
  454.         {
  455.             $link'<span ' $styleString ' ' $cssString ' >' $this->getText('</span>';
  456.         }
  457.         $writer->write($link);
  458.  
  459.         $body$this->getControls()->getCount();
  460.         if ($body)
  461.         {
  462.             $writer->renderBeginTag('ul');
  463.             foreach ($this->getControls(as $item)
  464.             {
  465.                 if ($item instanceof LCssDropDownMenuNode)
  466.                 {
  467.  
  468.                     $item->setTopParent(false);
  469.                     $item->setTopParentNodeCssClass($this->getTopParentNodeCssClass());
  470.                     $item->setParentNodeCssClass($this->getParentNodeCssClass());
  471.                     $item->setNodeCssClass($this->getNodeCssClass());
  472.                     $item->setDisabledNodeCssClass($this->getDisabledNodeCssClass());
  473.                     if ($item->getVisible())
  474.                     {
  475.                         $item->render($writer);
  476.                     }
  477.                 }
  478.             }
  479.             $writer->renderEndTag('ul');
  480.         }
  481.         #Prado :: trace("Returning node children content", 'Lithron.LCssDrownDownMenu');
  482.     }
  483. }
  484. ?>

Documentation generated on Sun, 25 Feb 2007 16:10:14 +0100 by phpDocumentor 1.3.1