Newer
Older
mattpiwik
a validé
<?php
/**
* Piwik - Open source web analytics
mattpiwik
a validé
* @link http://piwik.org
mattpiwik
a validé
* @category Piwik
* @package Piwik_Menu
*/
namespace Piwik\Menu;
mattpiwik
a validé
/**
* @package Piwik_Menu
*/
class MenuAdmin extends MenuAbstract
mattpiwik
a validé
{
static private $instance = null;
* @return \Piwik\Menu\MenuAdmin
*/
static public function getInstance()
{
if (self::$instance == null) {
self::$instance = new self;
}
return self::$instance;
}
mattpiwik
a validé
* Adds a new AdminMenu entry.
*
* @param string $adminMenuName
* @param string $url
* @param boolean $displayedForCurrentUser
* @param int $order
* @api
*/
public static function addEntry($adminMenuName, $url, $displayedForCurrentUser = true, $order = 20)
{
self::getInstance()->add('General_Settings', 'General_Settings', $adminMenuName, $url, $displayedForCurrentUser, $order);
}
/**
* Triggers the Menu.MenuAdmin.addItems hook and returns the admin menu.
*
* @return Array
*/
{
if (!$this->menu) {
/**
* This event is triggered to collect all available admin menu items. Subscribe to this event if you want
* to add one or more items to the Piwik admin menu. Just define the name of your menu item as well as a
* controller and an action that should be executed once a user selects your menu item. It is also possible
* to display the item only for users having a specific role.
*
* Example:
* ```
* public function addMenuItems()
* {
* \Piwik\Menu\MenuAdmin::getInstance()->add(
* 'MenuName',
* 'SubmenuName',
* array('module' => 'MyPlugin', 'action' => 'index'),
* Piwik::isUserIsSuperUser(),
* $order = 6
* );
* }
* ```
*/
Piwik::postEvent('Menu.MenuAdmin.addItems');
mattpiwik
a validé
/**
* Returns the current AdminMenu name
*
* @return boolean
*/
function getCurrentAdminMenuName()
{
$menu = \Piwik\Menu\MenuAdmin::getInstance();
$currentModule = Piwik::getModule();
$currentAction = Piwik::getAction();
foreach ($menu as $submenu) {
foreach ($submenu as $subMenuName => $parameters) {
if (strpos($subMenuName, '_') !== 0 &&
$parameters['_url']['module'] == $currentModule
&& $parameters['_url']['action'] == $currentAction
) {
return $subMenuName;
}
}
}
return false;