How to add user tab with Active Resources

From aMember Pro Documentation
Revision as of 05:47, 6 August 2013 by Caesar (talk | contribs) (Created page with "Add this code to site.php file: <source> Am_Di::getInstance()->hook->add('userMenu', 'siteUserMenu'); function siteUserMenu(Am_Event $event) { $user = $event->getUse...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Add this code to site.php file:


Am_Di::getInstance()->hook->add('userMenu', 'siteUserMenu');
function siteUserMenu(Am_Event $event)
{
      $user = $event->getUser(); // if required
      $menu = $event->getMenu();

      $items = array();
      foreach(Am_Di::getInstance()->resourceAccessTable->getAllowedResources($user,
            ResourceAccess::USER_VISIBLE_TYPES) as $r) {

          $url = $r->getUrl();
          $title = $r->getLinkTitle();
          if (!$url || !$title || $r->hide) continue;
          $items[] = array(
              'id' => 'resource-' . $r->pk(),
              'uri' => $url,
              'label' => $title
          );
      }

      if ($items) { //if we have at least one available resource
          $menu->addPage(array(
                  'id' => 'site-resources',
                  'label' => ___('Active Resources'),
                  'uri' => '#',
                  'order' => 300,
                  'pages' => $items
          ));
      }
}
//remove default Active Resources block
Am_Di::getInstance()->blocks->remove('member-main-resources');