protected function _getTracks($trackType, $pageRef, $trackTypeDescription)
 {
     switch ($trackType) {
         case 'tracks':
             $action = 'create';
             break;
         case 'respondents':
         case 'staff':
             $action = 'insert';
             break;
     }
     $orgId = intval($this->request->getParam(\MUtil_Model::REQUEST_ID2));
     $cacheId = strtr(__CLASS__ . '_' . $trackType . '_' . $orgId, '\\/', '__');
     $tracks = $this->cache->load($cacheId);
     if (!$tracks) {
         switch ($trackType) {
             case 'tracks':
                 $sql = "SELECT gtr_id_track, gtr_track_name\n                        FROM gems__tracks\n                        WHERE gtr_date_start < CURRENT_TIMESTAMP AND\n                            (gtr_date_until IS NULL OR gtr_date_until > CURRENT_TIMESTAMP) AND\n                            gtr_active = 1 AND\n                            gtr_organizations LIKE '%|{$orgId}|%'\n                         ORDER BY gtr_track_name";
                 break;
             case 'respondents':
                 $sql = "SELECT gsu_id_survey, gsu_survey_name\n                        FROM gems__surveys INNER JOIN gems__groups ON gsu_id_primary_group = ggp_id_group\n                        WHERE gsu_surveyor_active = 1 AND\n                            gsu_active = 1 AND\n                            ggp_group_active = 1 AND\n                            ggp_respondent_members = 1 AND\n                            gsu_insertable = 1 AND\n                            gsu_insert_organizations LIKE '%|{$orgId}|%'\n                        ORDER BY gsu_survey_name";
                 break;
             case 'staff':
                 $sql = "SELECT gsu_id_survey, gsu_survey_name\n                        FROM gems__surveys INNER JOIN gems__groups ON gsu_id_primary_group = ggp_id_group\n                        WHERE gsu_surveyor_active = 1 AND\n                            gsu_active = 1 AND\n                            ggp_group_active = 1 AND\n                            ggp_staff_members = 1 AND\n                            gsu_insertable = 1 AND\n                            gsu_insert_organizations LIKE '%|{$orgId}|%'\n                        ORDER BY gsu_survey_name";
                 break;
         }
         $tracks = $this->db->fetchPairs($sql);
         $this->cache->save($tracks, $cacheId, array('surveys', 'tracks'));
     }
     $div = \MUtil_Html::create()->div(array('class' => 'toolbox btn-group'));
     $menuIndex = $this->menu->findController('track', 'index');
     if ($tracks) {
         $menuCreate = $this->menu->findController('track', $action);
         if (!$menuCreate->isAllowed()) {
             return null;
         }
         if (\MUtil_Bootstrap::enabled()) {
             $div->button($trackTypeDescription, array('class' => 'toolanchor btn', 'data-toggle' => 'dropdown', 'type' => 'button'));
             $dropdownButton = $div->button(array('class' => 'btn dropdown-toggle', 'data-toggle' => 'dropdown', 'type' => 'button'));
             $dropdownButton->span(array('class' => 'caret', 'renderClosingTag' => true));
         } else {
             $div->a($menuIndex->toHRefAttribute($this->request), $trackTypeDescription, array('class' => 'toolanchor'));
         }
         $data = new \MUtil_Lazy_RepeatableByKeyValue($tracks);
         if ($trackType == 'tracks') {
             $menuView = $this->menu->findController('track', 'view');
             $params = array('gtr_id_track' => $data->key);
         } else {
             $menuView = $this->menu->findController('track', 'view-survey');
             $params = array('gsu_id_survey' => $data->key);
         }
         if (\MUtil_Bootstrap::enabled()) {
             if (count($tracks) > $this->scrollTreshold) {
                 // Add a header and scroll class so we keep rounded corners
                 $top = $div->ul(array('class' => 'dropdown-menu', 'role' => 'menu'));
                 $link = $top->li(array('class' => 'disabled'))->a('#');
                 $link->i(array('class' => 'fa fa-chevron-down fa-fw pull-left', 'renderClosingTag' => true));
                 $link->i(array('class' => 'fa fa-chevron-down fa-fw pull-right', 'renderClosingTag' => true));
                 // Add extra scroll-menu class
                 $li = $top->li()->ul(array('class' => 'dropdown-menu scroll-menu', 'role' => 'menu'), $data)->li();
             } else {
                 $li = $div->ul(array('class' => 'dropdown-menu', 'role' => 'menu'), $data)->li();
             }
             $link = $li->a($menuView->toHRefAttribute($this->request, $params), array('class' => 'rightFloat info'));
             $link->i(array('class' => 'fa fa-info-circle'))->raw('&nbsp;');
             if (count($tracks) > $this->scrollTreshold) {
                 // Add a footer so we keep rounded corners
                 $link = $top->li(array('class' => 'disabled'))->a('#');
                 $link->i(array('class' => 'fa fa-chevron-up fa-fw pull-left', 'renderClosingTag' => true));
                 $link->i(array('class' => 'fa fa-chevron-up fa-fw pull-right', 'renderClosingTag' => true));
             }
         } else {
             $li = $div->ul($data)->li();
             $li->a($menuView->toHRefAttribute($this->request, $params), array('class' => 'rightFloat'))->img(array('src' => 'info.png', 'width' => 12, 'height' => 12, 'alt' => $this->_('info')));
         }
         $toolboxRowAttributes = array('class' => 'add');
         $li->a($menuCreate->toHRefAttribute($this->request, $params), $data->value, $toolboxRowAttributes);
     } else {
         if (\MUtil_Bootstrap::enabled()) {
             $div->button($trackTypeDescription, array('class' => 'toolanchor btn disabled', 'data-toggle' => 'dropdown', 'type' => 'button'));
             $dropdownButton = $div->button(array('class' => 'disabled btn dropdown-toggle', 'data-toggle' => 'dropdown', 'type' => 'button'));
             $dropdownButton->span(array('class' => 'caret', 'renderClosingTag' => true));
             $options = array('class' => 'dropdown-menu disabled', 'role' => 'menu');
         } else {
             $div->a($menuIndex->toHRefAttribute($this->request), $trackTypeDescription, array('class' => 'toolanchor disabled'));
             $options = array('class' => 'disabled');
         }
         $div->ul($this->_('None available'), $options);
     }
     return $div;
 }
Exemplo n.º 2
0
 /**
  * Redirects the user to his/her start page.
  *
  * @param \Gems_Menu $menu
  * @param \Zend_Controller_Request_Abstract $request
  * @return \Gems_Menu_SubMenuItem
  */
 public function gotoStartPage(\Gems_Menu $menu, \Zend_Controller_Request_Abstract $request)
 {
     if ($this->isPasswordResetRequired()) {
         // Set menu OFF
         $menu->setVisible(false);
         $menuItem = $menu->findController('option', 'change-password');
         // This may not yet be true, but is needed for the redirect.
         $menuItem->set('allowed', true);
         $menuItem->set('visible', true);
     } else {
         $menuItem = $menu->findFirst(array('allowed' => true, 'visible' => true));
     }
     if ($menuItem) {
         // Prevent redirecting to the current page.
         if (!($menuItem->is('controller', $request->getControllerName()) && $menuItem->is('action', $request->getActionName()))) {
             if (!$menuItem->has('controller')) {
                 //This is a container, try to find first active child
                 $item = $menuItem;
                 foreach ($item->sortByOrder()->getChildren() as $menuItem) {
                     if ($menuItem->isAllowed() && $menuItem->has('controller')) {
                         break;
                     }
                     $menuItem = null;
                 }
             }
             if ($menuItem) {
                 $redirector = \Zend_Controller_Action_HelperBroker::getStaticHelper('redirector');
                 $redirector->gotoRoute($menuItem->toRouteUrl($request), null, true);
             }
         }
     }
     return $menuItem;
 }