Skip to content
Extraits de code Groupes Projets
MenuAdmin.php 2,89 ko
Newer Older
  • Learn to ignore specific revisions
  • <?php
    /**
     * Piwik - Open source web analytics
    
    robocoder's avatar
    robocoder a validé
     * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
    
    mattab's avatar
    mattab a validé
    use Piwik\Piwik;
    
    class MenuAdmin extends MenuAbstract
    
        static private $instance = null;
    
    sgiehl's avatar
    sgiehl a validé
    
    
         * @return \Piwik\Menu\MenuAdmin
    
         */
        static public function getInstance()
        {
            if (self::$instance == null) {
                self::$instance = new self;
            }
            return self::$instance;
        }
    
         * 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.
    
        public function getMenu()
    
    
                /**
                 * 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');
    
            return parent::getMenu();
    
        /**
         * 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;
                    }