Exemple #1
0
 /**
  * Method to get the options to populate list
  *
  * @return  array  The field option objects.
  *
  * @since   3.2
  */
 protected function getOptions()
 {
     // Hash for caching
     $hash = md5($this->element);
     if (!isset(static::$options[$hash])) {
         static::$options[$hash] = parent::getOptions();
         $options = array();
         $db = JFactory::getDbo();
         $user = JFactory::getUser();
         $query = $db->getQuery(true)->select('a.id AS value')->select('a.title AS text')->select('COUNT(DISTINCT b.id) AS level')->from('#__categories as a')->where('a.extension = "' . $this->extension . '"')->join('LEFT', '#__categories AS b ON a.lft > b.lft AND a.rgt < b.rgt')->group('a.id, a.title, a.lft, a.rgt')->order('a.lft ASC');
         $isRoot = $user->authorise('core.admin');
         if (!$isRoot) {
             require_once JPATH_COMPONENT_ADMINISTRATOR . '/helpers/imc.php';
             $allowed_catids = ImcHelper::getCategoriesByUserGroups();
             $allowed_catids = implode(',', $allowed_catids);
             if (!empty($allowed_catids)) {
                 $query->where('a.id IN (' . $allowed_catids . ')');
             }
         }
         $db->setQuery($query);
         if ($options = $db->loadObjectList()) {
             foreach ($options as &$option) {
                 $option->text = str_repeat('- ', $option->level) . $option->text;
             }
             static::$options[$hash] = array_merge(static::$options[$hash], $options);
         }
     }
     return static::$options[$hash];
 }
Exemple #2
0
 /**
  * Build an SQL query to load the list data.
  *
  * @return	JDatabaseQuery
  * @since	1.6
  */
 protected function getListQuery()
 {
     $user = JFactory::getUser();
     // Create a new query object.
     $db = $this->getDbo();
     $query = $db->getQuery(true);
     // Select the required fields from the table.
     $query->select($this->getState('list.select', 'DISTINCT a.*'));
     $query->from('`#__imc_issues` AS a');
     // Join over the users for the checked out user
     $query->select("uc.name AS editor");
     $query->join("LEFT", "#__users AS uc ON uc.id=a.checked_out");
     // Join over the category 'catid'
     $query->select('catid.title AS catid_title');
     $query->join('LEFT', '#__categories AS catid ON catid.id = a.catid');
     // Join over the user field 'created_by'
     $query->select('created_by.name AS created_by');
     $query->join('LEFT', '#__users AS created_by ON created_by.id = a.created_by');
     // Join over the asset groups.
     $query->select('ag.title AS access_level')->join('LEFT', '#__viewlevels AS ag ON ag.id = a.access');
     // Join over the imc steps.
     $query->select('st.title AS stepid_title, st.stepcolor AS stepid_color')->join('LEFT', '#__imc_steps AS st ON st.id = a.stepid');
     // Filter by published state
     $published = $this->getState('filter.state');
     if (is_numeric($published)) {
         $query->where('a.state = ' . (int) $published);
     } else {
         if ($published === '') {
             $query->where('(a.state IN (0, 1))');
         }
     }
     // Filter by search in title
     $search = $this->getState('filter.search');
     if (!empty($search)) {
         if (stripos($search, 'id:') === 0) {
             $query->where('a.id = ' . (int) substr($search, 3));
         } else {
             $search = $db->Quote('%' . $db->escape($search, true) . '%');
             $query->where('( a.title LIKE ' . $search . '  OR  a.address LIKE ' . $search . ' )');
         }
     }
     // Filter by access level.
     if ($access = $this->getState('filter.access')) {
         $query->where('a.access = ' . (int) $access);
     }
     // Implement View Level Access
     if (!$user->authorise('core.admin')) {
         $groups = implode(',', $user->getAuthorisedViewLevels());
         $query->where('a.access IN (' . $groups . ')');
     }
     //Filtering stepid
     if ($stepid = $this->getState('filter.stepid')) {
         $query->where('a.stepid = ' . (int) $stepid);
     }
     //Filtering catid
     $filter_catid = $this->state->get("filter.catid");
     if ($filter_catid) {
         $query->where("a.catid = '" . $db->escape($filter_catid) . "'");
     }
     //Filtering by category usergroups except if access imc.showall.issues = true
     $canDo = ImcHelper::getActions();
     $canShowAllIssues = $canDo->get('imc.showall.issues');
     if (!$canShowAllIssues) {
         require_once JPATH_COMPONENT . '/helpers/imc.php';
         $allowed_catids = ImcHelper::getCategoriesByUserGroups();
         $allowed_catids = implode(',', $allowed_catids);
         if (!empty($allowed_catids)) {
             $query->where('a.catid IN (' . $allowed_catids . ')');
         } else {
             //show nothing
             $query->where('a.catid = -1');
         }
     }
     //Filtering by subgroup
     $filter_subgroup = $this->state->get("filter.subgroup");
     if ($filter_subgroup) {
         $query->where("a.subgroup = '" . $db->escape($filter_subgroup) . "'");
     }
     // Add the list ordering clause.
     $orderCol = $this->state->get('list.ordering');
     $orderDirn = $this->state->get('list.direction');
     if ($orderCol == 'access_level') {
         $orderCol = 'ag.title';
     }
     if ($orderCol && $orderDirn) {
         $query->order($db->escape($orderCol . ' ' . $orderDirn));
     }
     return $query;
 }