Example #1
0
 /**
  * @return array
  * array(
  *     'shop' => 'shop my nav html...',
  *     'helpdesk' => 'helpdesk my nav html...',
  *     ...
  * )
  */
 public function myNav($ul_class = true)
 {
     $domain = wa()->getRouting()->getDomain(null, true);
     $domain_config_path = wa()->getConfig()->getConfigPath('domains/' . $domain . '.php', true, 'site');
     if (file_exists($domain_config_path)) {
         $domain_config = (include $domain_config_path);
     } else {
         $domain_config = array();
     }
     $routes = wa()->getRouting()->getRoutes();
     $apps = wa()->getApps();
     $result = array();
     foreach ($routes as $r) {
         if (isset($r['app']) && !empty($apps[$r['app']]['my_account'])) {
             $result[$r['app']] = $r;
         }
     }
     if (isset($domain_config['personal'])) {
         $tmp = array();
         foreach ($domain_config['personal'] as $app_id => $enabled) {
             if (!isset($result[$app_id])) {
                 continue;
             }
             if ($enabled) {
                 $tmp[$app_id] = $result[$app_id];
             } else {
                 unset($result[$app_id]);
             }
         }
         foreach ($result as $app_id => $r) {
             $tmp[$app_id] = $r;
         }
         $result = array_reverse($tmp, true);
     }
     $old_app = wa()->getApp();
     $my_nav_selected = $this->view->getVars('my_nav_selected');
     $old_params = waRequest::param();
     $i = 0;
     foreach ($result as $app_id => $r) {
         unset($r['url']);
         unset($r['app']);
         if ($i || $old_app != $app_id) {
             waSystem::getInstance($app_id, null, true);
             waRequest::setParam($r);
         }
         $class_name = $app_id . 'MyNavAction';
         if (class_exists($class_name)) {
             /**
              * @var waViewAction $action
              */
             try {
                 $action = new $class_name();
                 wa()->getView()->assign('my_nav_selected', $app_id == $old_app ? $my_nav_selected : '');
                 $result[$app_id] = $action->display();
             } catch (Exception $e) {
                 unset($result[$app_id]);
             }
         } else {
             unset($result[$app_id]);
         }
         $i++;
     }
     if (isset($app_id) && $old_app != $app_id) {
         waRequest::setParam($old_params);
         wa()->setActive($old_app);
     }
     $result = array_reverse($result, true);
     if ($ul_class) {
         $html = '<ul' . (is_string($ul_class) ? ' class="' . $ul_class . '"' : '') . '>';
         foreach ($result as $app_result) {
             $html .= $app_result;
         }
         $html .= '</ul>';
         return $html;
     } else {
         return $result;
     }
 }