Source for file MenuItemLink.class.php

Documentation is available at MenuItemLink.class.php

  1. <?php
  2.  
  3. /**
  4. * The <code>MenuItemLink</code> class is an extension of the <code>MenuItem</code>
  5. * interface adding support for attaching extra data like URL, target window, an
  6. * access key (shortcut), a toolTip, etc.
  7. * <br /><br />
  8. * <code>MenuItem</code> is an extension of <code>Component</code>; <code>MenuItems</code>
  9. * have display names and the ability to be added to <code>Menu</code> objects.
  10. *
  11. * @package harmoni.gui.components
  12. *
  13. * @copyright Copyright &copy; 2005, Middlebury College
  14. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  15. *
  16. * @version $Id: MenuItemLink.class.php,v 1.10 2007/09/04 20:25:22 adamfranco Exp $
  17. */
  18. class MenuItemLink extends Component /* implements MenuItemInterface */ {
  19.  
  20. /**
  21. * The url of this menu item.
  22. * @var string _url
  23. * @access private
  24. */
  25. var $_url;
  26. /**
  27. * The display name of this menu item.
  28. * @var string _displayName
  29. * @access private
  30. */
  31. var $_displayName;
  32. /**
  33. * The selected state of this menu item.
  34. * @var boolean _selected
  35. * @access private
  36. */
  37. var $_selected;
  38. /**
  39. * The target window of this menu item.
  40. * @var string _target
  41. * @access private
  42. */
  43. var $_target;
  44. /**
  45. * The access key (shortcut) for this menut item.
  46. * @var string _accessKey
  47. * @access private
  48. */
  49. var $_accessKey;
  50. /**
  51. * The toolTip for this menu item.
  52. * @var string _toolTip
  53. * @access private
  54. */
  55. var $_toolTip;
  56. /**
  57. * An associative array of additional HTML attributes to be included with
  58. * the <code>a href</code> tag. The key is the attribute, and the element
  59. * is the value.
  60. * @var array _attributes
  61. * @access private
  62. */
  63. var $_attributes;
  64. /**
  65. * The constructor.
  66. * @param string displayName The display name of this menu item.
  67. * @param string url The url of this menu item.
  68. * @param boolean selected The selected state of this menu item.
  69. * @param integer index The index of this component. The index has no semantic meaning:
  70. * you can think of the index as 'level' of the component. Alternatively,
  71. * the index could serve as means of distinguishing between components with
  72. * the same type. Most often one would use the index in conjunction with
  73. * the <code>getStylesForComponentType()</code> and
  74. * <code>addStyleForComponentType()</code> methods.
  75. * @param string target The target window of this menu item.
  76. * @param string accessKey The access key (shortcut) of this menu item.
  77. * @param string toolTip The toolTip of this menu item.
  78. * @access public
  79. ***/
  80. function MenuItemLink($displayName, $url, $selected, $index, $target = null, $accessKey = null, $toolTip = null) {
  81. // ** parameter validation
  82. $rule = StringValidatorRule::getRule();
  83. $optionalRule = OptionalRule::getRule($rule);
  84. ArgumentValidator::validate($displayName, $rule, true);
  85. ArgumentValidator::validate($url, $rule, true);
  86. ArgumentValidator::validate($selected, BooleanValidatorRule::getRule(), true);
  87. ArgumentValidator::validate($target, $optionalRule, true);
  88. ArgumentValidator::validate($accessKey, $optionalRule, true);
  89. ArgumentValidator::validate($toolTip, $optionalRule, true);
  90. // ** end of parameter validation
  91. $this->_displayName = $displayName;
  92. $this->_url = $url;
  93. $this->_selected = $selected;
  94. $this->_target = $target;
  95. $this->_accessKey = $accessKey;
  96. $this->_toolTip = $toolTip;
  97. $this->_attributes = array();
  98. $type = ($selected) ? MENU_ITEM_LINK_SELECTED : MENU_ITEM_LINK_UNSELECTED;
  99.  
  100. $this->Component(null, $type, $index);
  101. }
  102.  
  103. /**
  104. * Renders the component on the screen.
  105. * @param ref object theme The Theme object to use in producing the result
  106. * of this method.
  107. * @param string tabs This is a string (normally a bunch of tabs) that will be
  108. * prepended to each text line. This argument is optional but its usage is highly
  109. * recommended in order to produce a nicely formatted HTML output.
  110. * @access public
  111. ***/
  112. function render($theme, $tabs = "") {
  113. // pre-html
  114. echo $this->getPreHTML($theme, $tabs);
  115. // the url
  116. echo $tabs."<a href=\"$this->_url\"";
  117. // the target window
  118. if (isset($this->_target))
  119. echo " target=\"$this->_target\"";
  120. // the access key (shortcut)
  121. if (isset($this->_accessKey))
  122. echo " accesskey=\"$this->_accessKey\"";
  123. // the tooltip
  124. if (isset($this->_toolTip))
  125. echo " title=\"$this->_toolTip\"";
  126. // any additional attributes
  127. foreach ($this->_attributes as $attribute => $value)
  128. echo " $attribute=\"$value\"";
  129. echo ">";
  130. // the display name
  131. echo $this->_displayName;
  132. echo "</a>\n";
  133. // psot-html
  134. echo $this->getPostHTML($theme, $tabs);
  135. }
  136.  
  137. /**
  138. * Returns the URL of this menu item.
  139. * @access public
  140. * @return string url The URL of this menu item.
  141. ***/
  142. function getURL() {
  143. return $this->_url;
  144. }
  145. /**
  146. * Sets the URL of this menu item.
  147. * @access public
  148. * @param string The URL to set.
  149. ***/
  150. function setURL($url) {
  151. // ** parameter validation
  152. ArgumentValidator::validate($url, StringValidatorRule::getRule(), true);
  153. // ** end of parameter validation
  154.  
  155. $this->_url = $url;
  156. }
  157. /**
  158. * Returns the display name of this menu item.
  159. * @access public
  160. * @return string The display name of this menu item.
  161. ***/
  162. function getDisplayName() {
  163. return $this->_displayName;
  164. }
  165. /**
  166. * Sets the display name of this menu item.
  167. * @access public
  168. * @param string displayName The new display name.
  169. ***/
  170. function setDisplayName($displayName) {
  171. // ** parameter validation
  172. ArgumentValidator::validate($displayName, StringValidatorRule::getRule(), true);
  173. // ** end of parameter validation
  174.  
  175. $this->_displayName = $displayName;
  176. }
  177. /**
  178. * Returns whether the menu item is currently selected.
  179. * @access public
  180. * @return boolean <code>TRUE</code> if the menu item is selected; <code>FALSE</code>
  181. * otherwise.
  182. ***/
  183. function isSelected() {
  184. return $this->_selected;
  185. }
  186. /**
  187. * Sets the selected state of this menu item.
  188. * @access public
  189. * @param boolean selected <code>TRUE</code> means selected; <code>FALSE</code>
  190. * is unselected.
  191. ***/
  192. function setSelected($selected) {
  193. // ** parameter validation
  194. ArgumentValidator::validate($selected, BooleanValidatorRule::getRule(), true);
  195. // ** end of parameter validation
  196.  
  197. $this->_selected = $selected;
  198.  
  199. $type = ($selected) ? MENU_ITEM_LINK_SELECTED : MENU_ITEM_LINK_UNSELECTED;
  200. $this->_type = $type;
  201. }
  202. /**
  203. * Returns the target window for this menu item.
  204. * @access public
  205. * @return string The target window.
  206. ***/
  207. function getTarget() {
  208. return $this->_target;
  209. }
  210. /**
  211. * Sets the target window for this menu item.
  212. * @access public
  213. * @param string target The target window.
  214. ***/
  215. function setTarget($target) {
  216. // ** parameter validation
  217. ArgumentValidator::validate($target, StringValidatorRule::getRule(), true);
  218. // ** end of parameter validation
  219.  
  220. $this->_target = $target;
  221. }
  222.  
  223. /**
  224. * Returns the access key character (shortcut) for this menu item.
  225. * @access public
  226. * @return string The access key character (shortcut) for this menu item.
  227. ***/
  228. function getAccessKey() {
  229. return $this->_accessKey;
  230. }
  231. /**
  232. * Sets the access key character (shortcut) for this menu item.
  233. * @access public
  234. * @param string accessKey The new access key character (shortcut) for this menu item.
  235. ***/
  236. function setAccessKey($accessKey) {
  237. // ** parameter validation
  238. ArgumentValidator::validate($accessKey, StringValidatorRule::getRule(), true);
  239. // ** end of parameter validation
  240.  
  241. $this->_accessKey = $accessKey;
  242. }
  243. /**
  244. * Returns the toolTip text for this menu item.
  245. * @access public
  246. * @return string The toolTip.
  247. ***/
  248. function getToolTip() {
  249. return $this->_toolTip;
  250. }
  251. /**
  252. * Sets the toolTip text for this menu item.
  253. * @access public
  254. * @param string tooltip The new toolTip.
  255. ***/
  256. function setToolTip($toolTip) {
  257. // ** parameter validation
  258. ArgumentValidator::validate($toolTip, StringValidatorRule::getRule(), true);
  259. // ** end of parameter validation
  260.  
  261. $this->_toolTip = $toolTip;
  262. }
  263. /**
  264. * Add an additional attribute to the <code>a href</code> HTML tag. For example,
  265. * this could be a javascript event or simply any additional functionality
  266. * not available through the standard get/set methods. Repeated attributes are
  267. * not permitted.
  268. * @access public
  269. * @param string attribute The name of the attribute, for example: "tabindex".
  270. * @param string value The value of the attribute, for example: "3".
  271. ***/
  272. function addAttribute($attribute, $value) {
  273. // ** parameter validation
  274. $rule = StringValidatorRule::getRule();
  275. ArgumentValidator::validate($attribute, $rule, true);
  276. ArgumentValidator::validate($value, $rule, true);
  277. // ** end of parameter validation
  278. if (!isset($this->_attributes[$attribute]))
  279. $this->_attributes[$attribute] = $value;
  280. }
  281.  
  282. }
  283.  
  284. ?>

Documentation generated on Wed, 19 Sep 2007 10:25:02 -0400 by phpDocumentor 1.3.0RC3