示例#1
0
 protected function get_available_records($filter)
 {
     if (has_capability('block/curr_admin:cluster:role_assign_cluster_users', $this->get_context(), NULL, false)) {
         global $CURMAN, $CFG;
         $context = $this->get_context();
         $roleid = required_param('role', PARAM_INT);
         $pagenum = optional_param('page', 0, PARAM_INT);
         $perpage = 30;
         $sort = optional_param('sort', 'name', PARAM_ACTION);
         $order = optional_param('dir', 'ASC', PARAM_ACTION);
         if ($order != 'DESC') {
             $order = 'ASC';
         }
         static $sortfields = array('name' => array('lastname', 'firstname'), 'idnumber' => 'idnumber');
         if (!array_key_exists($sort, $sortfields)) {
             $sort = key($sortfields);
         }
         if (is_array($sortfields[$sort])) {
             $sortclause = implode(', ', array_map(create_function('$x', "return \"\$x {$order}\";"), $sortfields[$sort]));
         } else {
             $sortclause = "{$sortfields[$sort]} {$order}";
         }
         $where = "idnumber NOT IN (SELECT mu.idnumber\n                                         FROM {$CURMAN->db->prefix_table('user')} mu\n                                    LEFT JOIN {$CURMAN->db->prefix_table('role_assignments')} ra\n                                              ON ra.userid = mu.id\n                                        WHERE ra.contextid = {$context->id}\n                                          AND ra.roleid = {$roleid}\n                                          AND mu.mnethostid = {$CFG->mnet_localhost_id})\n                            AND id IN (SELECT userid\n                                         FROM {$CURMAN->db->prefix_table('crlm_usercluster')} uc\n                                        WHERE uc.clusterid = {$context->instanceid})";
         $extrasql = $filter->get_sql_filter();
         if ($extrasql) {
             $where .= " AND {$extrasql}";
         }
         $count = $CURMAN->db->count_records_select('crlm_user usr', $where);
         $users = $CURMAN->db->get_records_select('crlm_user usr', $where, $sortclause, '*', $pagenum * $perpage, $perpage);
         return array($users, $count);
     } else {
         return parent::get_available_records($filter);
     }
 }
示例#2
0
 protected function get_available_records($filter)
 {
     if (has_capability('local/elisprogram:userset_role_assign_userset_users', $this->get_context(), NULL, false)) {
         global $CFG, $DB;
         $context = $this->get_context();
         $roleid = required_param('role', PARAM_INT);
         $pagenum = optional_param('page', 0, PARAM_INT);
         $perpage = 30;
         $sort = optional_param('sort', 'name', PARAM_ACTION);
         $order = optional_param('dir', 'ASC', PARAM_ACTION);
         if ($order != 'DESC') {
             $order = 'ASC';
         }
         static $sortfields = array('name' => array('lastname', 'firstname'), 'idnumber' => 'idnumber');
         if (!array_key_exists($sort, $sortfields)) {
             $sort = key($sortfields);
         }
         if (is_array($sortfields[$sort])) {
             $sortclause = implode(', ', array_map(create_function('$x', "return \"\$x {$order}\";"), $sortfields[$sort]));
         } else {
             $sortclause = "{$sortfields[$sort]} {$order}";
         }
         $where = "NOT EXISTS (SELECT 'x'\n                                  FROM {" . usermoodle::TABLE . "} um\n                                  JOIN {user} mu\n                                    ON um.muserid = mu.id\n                                  JOIN {role_assignments} ra\n                                    ON mu.id = ra.userid\n                                  WHERE ra.contextid = :contextid\n                                    AND ra.roleid = :roleid\n                                    AND mu.mnethostid = :mnethostid\n                                    AND {" . user::TABLE . "}.id = um.cuserid)\n                      AND EXISTS (SELECT 'x'\n                                  FROM {" . usermoodle::TABLE . "} um\n                                  JOIN {" . clusterassignment::TABLE . "} ca\n                                    ON um.cuserid = ca.userid\n                                  WHERE {" . user::TABLE . "}.id = um.cuserid\n                                    AND ca.clusterid = :clusterid)";
         $params = array('contextid' => $context->id, 'roleid' => $roleid, 'mnethostid' => $CFG->mnet_localhost_id, 'clusterid' => $context->instanceid);
         list($extrasql, $extraparams) = $filter->get_sql_filter();
         if ($extrasql) {
             $where .= " AND {$extrasql}";
             $params = array_merge($params, $extraparams);
         }
         $count = $DB->count_records_select(user::TABLE, $where, $params);
         $users = $DB->get_recordset_select(user::TABLE, $where, $params, $sortclause, '*', $pagenum * $perpage, $perpage);
         return array($users, $count);
     } else {
         return parent::get_available_records($filter);
     }
 }