You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

NavigationManager.php 2.5KB

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