Files
grzanieplus.pl/plugins/stNavigationPlugin/lib/stNavigationMenu.class.php
2025-03-12 17:06:23 +01:00

86 lines
1.7 KiB
PHP

<?php
class stNavigationMenu implements \Iterator, \Countable
{
/**
* Elementy menu
*
* @var stNavigationMenuItem[]
*/
private $items = array();
/**
* Dodaje elementu menu
*
* @param string $id Unikalne id elementu
* @param string $title Tytuł elementu
* @param string $url Url elementu
* @param array $options Dodatkowe opcje elementu (icon, i18n, children)
* @return stNavigationMenuItem
*/
public function addItem($id, $title, $url = null, array $options = array())
{
$item = new stNavigationMenuItem($title, $url, $options);
$this->items[$id] = $item;
return $item;
}
/**
* Zwraca elementu menu o podanym id
*
* @param string $id Id elementu menu
* @return stNavigationMenuItem
*/
public function getItem($id)
{
if (!isset($this->items[$id]))
{
throw new Exception(sprintf('Item "%s" does not exist', $id));
}
return $this->items[$id];
}
/**
* Zwraca tablicę elementów menu
*
* @return stNavigationMenuItem[]
*/
public function getItems()
{
return $this->items;
}
public function current()
{
return current($this->items);
}
public function next()
{
return next($this->items);
}
public function key()
{
return key($this->items);
}
public function valid()
{
return null !== $this->key();
}
public function rewind()
{
return reset($this->items);
}
public function count()
{
return count($this->items);
}
}