Source for file MenuTheme.abstract.php

Documentation is available at MenuTheme.abstract.php

  1. <?php
  2.  
  3. require_once(HARMONI."GUIManager/Theme.class.php");
  4.  
  5. /**
  6. * This MenuTheme abstract class implements solely the <code>addMenu</code> and <code>getMenu</code>
  7. * methods. If the user desires a proper complete implementation of the <code>MenuTheme</code>
  8. * interface, then there are two ways of doing that:<br /><br />
  9. * <ol>
  10. * <li> The user could overload setMenu so that as a new menu is added,
  11. * it is appropriately incorporated in a <code>Container</code> along with
  12. * the <code>Theme</code> component and all other previously added menus.
  13. * This is the recommended solution.
  14. * </li>
  15. * <li> The user could overload root Theme methods (at least <code>printPage()</code>) to
  16. * account for added menus. In other words, HTML generating methods will
  17. * dynamically generate menu-related output as they are called.
  18. * </li>
  19. * </ol>
  20. * <br />
  21. *
  22. * A <code>MenuTheme</code> is an extension of the generic <code>Theme</code> interface
  23. * that adds support for multi-level navigation menus. A <code>MenuTheme</code>,
  24. * like a normal </code>Theme</code> has a single <code>Component</code>; however,
  25. * it allows the user to surround that component with multi-level navigation menus.
  26. *
  27. * @package harmoni.gui
  28. *
  29. * @copyright Copyright &copy; 2005, Middlebury College
  30. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  31. *
  32. * @version $Id: MenuTheme.abstract.php,v 1.5 2007/09/04 20:25:21 adamfranco Exp $
  33. ***/
  34. class MenuThemeAbstract extends Theme /* implements MenuThemeInterface */ {
  35. /**
  36. * An array storing all menus of this theme. Each element is a <code>Menu</code>
  37. * object.
  38. * @attribute private array _menus
  39. */
  40. var $_menus;
  41. /**
  42. * Adds a new menu to this theme.
  43. * @access public
  44. * @param ref object menu A <code>Menu</code> object to be added to this theme.
  45. * @param integer level A positive integer specifying the <code>level</code> of the
  46. * menu that is being added. Only one menu can exist at any given level.
  47. * Levels cannot be skipped. Levels allow the user to create a hierarchy of menus.
  48. ***/
  49. function addMenu($menu, $level) {
  50. // ** parameter validation
  51. ArgumentValidator::validate($menu, ExtendsValidatorRule::getRule("Menu"), true);
  52. $greaterThanZero = $level > 0;
  53. ArgumentValidator::validate($greaterThanZero, TrueValidatorRule::getRule(), true);
  54. // ** end of parameter validation
  55. // two things need to be true in order for this menu to be added
  56. // 1) no levels before the given are empty
  57. // 2) no menu has been set for this level already
  58. if ($level > 1 && !isset($this->_menus[$level-1])) {
  59. $err = "Error when adding a menu to a theme: all prior menu levels must be non-empty.";
  60. throwError(new Error($err, "GUIManager", false));
  61. return;
  62. }
  63. if (isset($this->_menus[$level])) {
  64. $err = "A menu has already been set for the given level.";
  65. throwError(new Error($err, "GUIManager", false));
  66. return;
  67. }
  68. // now add the menu
  69. $this->_menus[$level] =$menu;
  70. }
  71. /**
  72. * Returns the menu (if exists) at the given level.
  73. * @access public
  74. * @param integer level An integer specifying the <code>level</code> of the
  75. * menu that is to be returned. Levels start at 1. Only one menu can exist at any given level.
  76. * Levels cannot be skipped. Levels allow the user to create a hierarchy of menus.
  77. * @return ref object The <code>Menu</code> object at the specified level, or <code>NULL</code>
  78. * if no menu was found.
  79. ***/
  80. function getMenu($level) {
  81. // ** parameter validation
  82. $greaterThanZero = $level > 0;
  83. ArgumentValidator::validate($greaterThanZero, TrueValidatorRule::getRule(), true);
  84. // ** end of parameter validation
  85. if (isset($this->_menus[$level]))
  86. return $this->_menus[$level];
  87. else
  88. return null;
  89. }
  90. /**
  91. * Returns the number of menus in this Theme.
  92. * @access public
  93. * @return integer The number of menus.
  94. ***/
  95. function getNumberOfMenus() {
  96. return count($this->_menus);
  97. }
  98. }
  99.  
  100. ?>

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