/** * Generates a list of JSON items. * * @return void */ public function display($tpl = null) { $user = JFactory::getUser(); $access = JRequest::getUInt('filter_access'); // No access if not logged in if ($user->id == 0) { JError::raiseError(403, JText::_('JERROR_ALERTNOAUTHOR')); return false; } // Check Access for non-admins if (!$user->authorise('core.admin')) { $allowed = PFAccessHelper::getGroupsByAccessLevel($access, true); $groups = $user->getAuthorisedGroups(); $can_access = false; foreach ($groups as $group) { if (in_array($group, $allowed)) { $can_access = true; break; } } if (!$can_access) { JError::raiseError(403, JText::_('JERROR_ALERTNOAUTHOR')); return false; } } $this->items = $this->get('Items'); // Check for errors. if (count($errors = $this->get('Errors'))) { JError::raiseWarning(500, implode("\n", $errors)); return false; } parent::display($tpl); }
/** * Build an SQL query to load the list data. * * @return jdatabasequery */ protected function getListQuery() { $query = $this->_db->getQuery(true); // Get possible filters $filter_search = $this->getState('filter.search'); $filter_access = (int) $this->getState('filter.access'); $filter_groups = PFAccessHelper::getGroupsByAccessLevel($filter_access, true); if (!count($filter_groups)) { return $query; } // Select the required fields from the table. $query->select($this->getState('list.select', 'a.id, a.username, a.name')); $query->from('#__users AS a'); // Join on user groups $query->join('INNER', '#__user_usergroup_map AS m ON m.user_id = a.id'); $query->where('m.group_id IN(' . implode(',', $filter_groups) . ')'); // Filter by search if (!empty($filter_search)) { if (stripos($filter_search, 'id:') === 0) { $query->where('a.id = ' . (int) substr($filter_search, 3)); } else { $search = $this->_db->quote('%' . $this->_db->escape($filter_search, true) . '%'); $query->where('(a.name LIKE ' . $search . ' OR a.username LIKE ' . $search . ')'); } } $order_col = $this->state->get('list.ordering', 'a.username'); $order_dir = $this->state->get('list.direction', 'asc'); $query->group('a.id'); $query->order($this->_db->escape($order_col . ' ' . $order_dir)); return $query; }
/** * Method to get a list of user id's which are observing the item * * @param string $context The item context * @param object $table Instance of the item table * @param boolean $is_new True if the item is new * * @return array */ public static function getObservers($context, $table, $is_new = false) { $plugin = JPluginHelper::getPlugin('content', 'pfnotifications'); $params = new JRegistry($plugin->params); $opt_out = (int) $params->get('sub_method', 0); $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('a.user_id')->from('#__pf_ref_observer AS a')->where('a.item_type = ' . $db->quote('com_pfprojects.project'))->where('a.item_id = ' . $db->quote((int) $table->id)); $db->setQuery($query); $users = (array) $db->loadColumn(); if ($opt_out) { $blacklist = $users; $users = array(); $groups = PFAccessHelper::getGroupsByAccessLevel($table->access); if (!count($groups)) { return array(); } $query->clear()->select('a.user_id')->from('#__user_usergroup_map AS a')->innerJoin('#__users AS u ON u.id = a.user_id'); if (count($blacklist)) { $query->where('a.user_id NOT IN(' . implode(', ', $blacklist) . ')'); } $query->where('a.group_id IN(' . implode(', ', $groups) . ')')->group('a.user_id')->order('a.user_id ASC'); $db->setQuery($query); $users = (array) $db->loadColumn(); } return $users; }
/** * Method to get the filtering groups (null means no filtering) * * @return mixed $groups Array of filtering groups */ protected function getGroups() { static $groups = ''; if ($groups !== '') { return $groups; } $access = (int) $this->form->getValue('access'); if (!$access) { return ''; } $groups = array(); $group_list = (array) PFAccessHelper::getGroupsByAccessLevel($access); foreach ($group_list as $group) { $groups[] = (int) $group; } if (!count($groups)) { $groups = ''; } return $groups; }
/** * Method to get a list of user id's which are observing the item * * @param string $context The item context * @param object $table Instance of the item table * @param boolean $is_new True if the item is new * * @return array */ public static function getObservers($context, $table, $is_new = false) { if (!$is_new) { return array(); } $plugin = JPluginHelper::getPlugin('content', 'pfnotifications'); $params = new JRegistry($plugin->params); $opt_out = (int) $params->get('sub_method', 0); $db = JFactory::getDbo(); $query = $db->getQuery(true); $task_ms = 0; if ($table->context == 'com_pftasks.task') { $query->select('milestone_id')->from('#__pf_tasks')->where('id = ' . (int) $table->item_id); $db->setQuery($query); $task_ms = (int) $db->loadResult(); } $query->clear(); $query->select('a.user_id')->from('#__pf_ref_observer AS a'); if ($table->context != 'com_pfprojects.form' && $table->context != 'com_pfprojects.project' && isset($table->project_id)) { if ($task_ms) { $query->where('(a.item_type = ' . $db->quote($db->escape($table->context)) . ' AND a.item_id = ' . $db->quote((int) $table->item_id) . ')' . ' OR (a.item_type = ' . $db->quote('com_pfmilestones.milestone') . ' AND a.item_id = ' . $task_ms . ')' . ' OR (a.item_type = ' . $db->quote('com_pfprojects.project') . ' AND a.item_id = ' . $table->project_id . ')'); } else { $query->where('(a.item_type = ' . $db->quote($db->escape($table->context)) . ' AND a.item_id = ' . $db->quote((int) $table->item_id) . ')' . ' OR (a.item_type = ' . $db->quote('com_pfprojects.project') . ' AND a.item_id = ' . $table->project_id . ')'); } } else { $query->where('a.item_type = ' . $db->quote($db->escape($table->context)))->where('a.item_id = ' . $db->quote((int) $table->item_id)); } $db->setQuery($query); $users = (array) $db->loadColumn(); if ($opt_out) { $blacklist = $users; $users = array(); $tables = array('com_pfprojects.project' => '#__pf_projects', 'com_pfmilestones.milestone' => '#__pf_milestones', 'com_pftasks.task' => '#__pf_tasks', 'com_pfdesigns.design' => '#__pf_designs', 'com_pfdesigns.revision' => '#__pf_designs', 'com_pfrepo.file' => '#__pf_repo_files', 'com_pfrepo.note' => '#__pf_repo_notes'); if (!isset($tables[$table->context])) { return array(); } $q_table = $tables[$table->context]; $q_id = (int) $table->item_id; if ($table->context == 'com_pfdesigns.revision') { $query->clear()->select('parent_id')->from('#__pf_design_revisions')->where('id = ' . $q_id); $db->setQuery($query); $q_id = (int) $db->loadResult(); } if (!$q_id) { return array(); } $query->clear()->select('access')->from($q_table)->where('id = ' . $q_id); $db->setQuery($query); $item_access = (int) $db->loadResult(); $item_groups = PFAccessHelper::getGroupsByAccessLevel($item_access); $query->clear()->select('access')->from('#__pf_projects')->where('id = ' . (int) $table->project_id); $db->setQuery($query); $project_access = $db->loadResult(); $p_groups = PFAccessHelper::getGroupsByAccessLevel($project_access); $groups = array_unique(array_merge($p_groups, $item_groups)); if (!count($groups)) { return array(); } $query->clear()->select('a.user_id')->from('#__user_usergroup_map AS a')->innerJoin('#__users AS u ON u.id = a.user_id'); if (count($blacklist)) { $query->where('a.user_id NOT IN(' . implode(', ', $blacklist) . ')'); } $query->where('a.group_id IN(' . implode(', ', $groups) . ')')->group('a.user_id')->order('a.user_id ASC'); $db->setQuery($query); $users = (array) $db->loadColumn(); } return $users; }
/** * Method to get the user groups assigned to a project * * @param integer The project id * * @return array The user groups **/ public function getUserGroups($pk = NULL) { $pk = !empty($pk) ? $pk : (int) $this->getState($this->getName() . '.id'); $table = $this->getTable(); if ($pk > 0) { // Attempt to load the row. $return = $table->load($pk); // Check for a table object error. if ($return === false && $table->getError()) { $this->setError($table->getError()); return false; } return PFAccessHelper::getGroupsByAccessLevel($table->access); } return false; }
/** * Method to get a list of user id's which are observing the item * * @param string $context The item context * @param object $table Instance of the item table * @param boolean $is_new True if the item is new * * @return array */ public static function getObservers($context, $table, $is_new = false) { $plugin = JPluginHelper::getPlugin('content', 'pfnotifications'); $params = new JRegistry($plugin->params); $opt_out = (int) $params->get('sub_method', 0); $db = JFactory::getDbo(); $query = $db->getQuery(true); // Get observers $query->select('a.user_id')->from('#__pf_ref_observer AS a')->where('(' . 'a.item_type = ' . $db->quote('com_pftasks.task') . ' AND a.item_id = ' . (int) $table->id . ')' . ($table->milestone_id > 0 ? ' OR (' . 'a.item_type = ' . $db->quote('com_pfmilestones.milestone') . ' AND a.item_id = ' . (int) $table->milestone_id . ')' : '') . ' OR (' . 'a.item_type = ' . $db->quote('com_pfprojects.project') . ' AND a.item_id = ' . (int) $table->project_id . ')'); $db->setQuery($query); $users = (array) $db->loadColumn(); // Get assigned users $query->clear()->select('user_id')->from('#__pf_ref_users')->where('item_type = ' . $db->quote('com_pftasks.task'))->where('item_id = ' . (int) $table->id); $db->setQuery($query); $assigned = (array) $db->loadColumn(); $return = array_merge($users, $assigned); if ($opt_out) { $blacklist = $users; $t_groups = PFAccessHelper::getGroupsByAccessLevel($table->access); if ($table->milestone_id > 0) { $query->clear()->select('access')->from('#__pf_milestones')->where('id = ' . (int) $table->milestone_id); $db->setQuery($query); $ms_access = $db->loadResult(); $ms_groups = PFAccessHelper::getGroupsByAccessLevel($ms_access); } else { $ms_groups = array(); } $query->clear()->select('access')->from('#__pf_projects')->where('id = ' . (int) $table->project_id); $db->setQuery($query); $project_access = $db->loadResult(); $p_groups = PFAccessHelper::getGroupsByAccessLevel($project_access); $groups = array_unique(array_merge($t_groups, $p_groups, $ms_groups)); if (!count($groups)) { return array(); } $query->clear()->select('a.user_id')->from('#__user_usergroup_map AS a')->innerJoin('#__users AS u ON u.id = a.user_id'); if (count($blacklist)) { $query->where('a.user_id NOT IN(' . implode(', ', $blacklist) . ')'); } $query->where('a.group_id IN(' . implode(', ', $groups) . ')')->group('a.user_id')->order('a.user_id ASC'); $db->setQuery($query); $return = (array) $db->loadColumn(); } return $return; }
/** * Method to get a list of user id's which are observing the item * * @param string $context The item context * @param object $table Instance of the item table * @param boolean $is_new True if the item is new * * @return array */ public static function getObservers($context, $table, $is_new = false) { $plugin = JPluginHelper::getPlugin('content', 'pfnotifications'); $params = new JRegistry($plugin->params); $opt_out = (int) $params->get('sub_method', 0); $db = JFactory::getDbo(); $query = $db->getQuery(true); if (in_array($context, array('com_pfrepo.file', 'com_pfrepo.fileform', 'com_pfrepo.note', 'com_pfrepo.noteform'))) { $parents = self::getParentDirectories($table->dir_id); $query = $db->getQuery(true); $query->select('a.user_id')->from('#__pf_ref_observer AS a'); $query->where('(' . 'a.item_type = ' . $db->quote('com_pfrepo.directory') . ' AND a.item_id IN(' . implode(', ', $parents) . ') ' . ')' . ' OR (' . 'a.item_type = ' . $db->quote('com_pfprojects.project') . ' AND a.item_id = ' . (int) $table->project_id . ')'); } else { if (isset($table->item_type) && isset($table->item_id) && !$is_new) { $query = $db->getQuery(true); $query->select('a.user_id')->from('#__pf_ref_observer AS a'); $query->where('a.item_type = ' . $db->quote($db->escape($table->item_type)))->where('a.item_id = ' . $db->quote((int) $table->item_id)); } else { return array(); } } $db->setQuery($query); $users = (array) $db->loadColumn(); if ($opt_out) { $blacklist = $users; $users = array(); $repo_groups = array(); if (isset($table->access)) { $repo_groups = PFAccessHelper::getGroupsByAccessLevel($table->access); } $query->clear()->select('access')->from('#__pf_projects')->where('id = ' . (int) $table->project_id); $db->setQuery($query); $project_access = $db->loadResult(); $p_groups = PFAccessHelper::getGroupsByAccessLevel($project_access); $groups = array_unique(array_merge($p_groups, $repo_groups)); if (!count($groups)) { return array(); } $query->clear()->select('a.user_id')->from('#__user_usergroup_map AS a')->innerJoin('#__users AS u ON u.id = a.user_id'); if (count($blacklist)) { $query->where('a.user_id NOT IN(' . implode(', ', $blacklist) . ')'); } $query->where('a.group_id IN(' . implode(', ', $groups) . ')')->group('a.user_id')->order('a.user_id ASC'); $db->setQuery($query); $users = (array) $db->loadColumn(); } return $users; }