navigationmanager.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /**
  3. * @author Bart Visscher <bartv@thisnet.nl>
  4. * @author Joas Schilling <nickvergessen@owncloud.com>
  5. * @author Morris Jobke <hey@morrisjobke.de>
  6. * @author Robin McCorkell <rmccorkell@karoshi.org.uk>
  7. * @author Thomas Müller <thomas.mueller@tmit.eu>
  8. *
  9. * @copyright Copyright (c) 2015, ownCloud, Inc.
  10. * @license AGPL-3.0
  11. *
  12. * This code is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License, version 3,
  14. * as published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License, version 3,
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>
  23. *
  24. */
  25. namespace OC;
  26. /**
  27. * Manages the ownCloud navigation
  28. */
  29. class NavigationManager implements \OCP\INavigationManager {
  30. protected $entries = array();
  31. protected $closureEntries = array();
  32. protected $activeEntry;
  33. /**
  34. * Creates a new navigation entry
  35. *
  36. * @param array|\Closure $entry Array containing: id, name, order, icon and href key
  37. * The use of a closure is preferred, because it will avoid
  38. * loading the routing of your app, unless required.
  39. * @return void
  40. */
  41. public function add($entry) {
  42. if ($entry instanceof \Closure) {
  43. $this->closureEntries[] = $entry;
  44. return;
  45. }
  46. $entry['active'] = false;
  47. if(!isset($entry['icon'])) {
  48. $entry['icon'] = '';
  49. }
  50. $this->entries[] = $entry;
  51. }
  52. /**
  53. * returns all the added Menu entries
  54. * @return array an array of the added entries
  55. */
  56. public function getAll() {
  57. foreach ($this->closureEntries as $c) {
  58. $this->add($c());
  59. }
  60. $this->closureEntries = array();
  61. return $this->entries;
  62. }
  63. /**
  64. * removes all the entries
  65. */
  66. public function clear() {
  67. $this->entries = array();
  68. $this->closureEntries = array();
  69. }
  70. /**
  71. * Sets the current navigation entry of the currently running app
  72. * @param string $id of the app entry to activate (from added $entry)
  73. */
  74. public function setActiveEntry($id) {
  75. $this->activeEntry = $id;
  76. }
  77. /**
  78. * gets the active Menu entry
  79. * @return string id or empty string
  80. *
  81. * This function returns the id of the active navigation entry (set by
  82. * setActiveEntry
  83. */
  84. public function getActiveEntry() {
  85. return $this->activeEntry;
  86. }
  87. }