Ejemplo n.º 1
0
 function get_records($filter)
 {
     global $USER;
     $sort = optional_param('sort', 'name', PARAM_ALPHA);
     $dir = optional_param('dir', 'ASC', PARAM_ALPHA);
     $pagenum = optional_param('page', 0, PARAM_INT);
     $perpage = optional_param('perpage', 30, PARAM_INT);
     if ($sort == 'name') {
         $sort = 'lastname';
     }
     $extrasql = $filter->get_sql_filter();
     //filter based on cluster role assignments
     $context_set = pm_context_set::for_user_with_capability('cluster', 'local/elisprogram:user_edit', $USER->id);
     // Get list of users
     $items = usermanagement_get_users_recordset($sort, $dir, $perpage * $pagenum, $perpage, $extrasql, $context_set);
     $numitems = usermanagement_count_users($extrasql, $context_set);
     return array($items, $numitems);
 }
Ejemplo n.º 2
0
 /**
  * Test the basic functionality of the methods for fetching users as a
  * recordset when applying userset permissions and an appropriate SQL filter
  */
 public function test_usermanagementgetsusersrecordsetrespectsfilters()
 {
     global $USER, $DB;
     require_once elispm::lib('data/clusterassignment.class.php');
     require_once elispm::lib('data/user.class.php');
     require_once elispm::lib('lib.php');
     // Make sure we don't hit corner-cases with permissions.
     set_config('siteguest', '');
     set_config('siteadmins', '');
     // Prevent accesslib caching.
     accesslib_clear_all_caches(true);
     // Data setup.
     $this->load_csv_data();
     $this->set_up_users();
     // Assign a second user to the user set.
     $secondclusteruser = new user(array('idnumber' => 'secondclusteruser', 'username' => 'secondclusteruser', 'firstname' => 'Secondcluster', 'lastname' => 'User', 'email' => '*****@*****.**', 'country' => 'CA'));
     $secondclusteruser->save();
     $clusterassignment = new clusterassignment(array('clusterid' => 1, 'userid' => $secondclusteruser->id));
     $clusterassignment->save();
     // The context set our user set administrator has access to.
     $contextset = pm_context_set::for_user_with_capability('cluster', 'local/elisprogram:user_edit', $USER->id);
     // Add a filter to filter down to only our first test user.
     $extrasql = array('username = :testusername', array('testusername' => 'clusteruser'));
     // Validate record.
     $users = usermanagement_get_users_recordset('name', 'ASC', 0, 0, $extrasql, $contextset);
     $this->assertTrue($users->valid());
     $user = $users->current();
     $this->assertEquals('clusteruser', $user->idnumber);
     $this->assertNull($users->next());
 }
 /**
  * Specifies available report filters
  * (empty by default but can be implemented by child class)
  *
  * @param   boolean  $init_data  If true, signal the report to load the
  *                               actual content of the filter objects
  *
  * @return  array                The list of available filters
  */
 function get_filters($init_data = true)
 {
     global $CFG, $CURMAN, $SESSION;
     $filters = array();
     $users = array();
     if ($init_data) {
         $contexts = get_contexts_by_capability_for_user('user', $this->access_capability, $this->userid);
         $user_objects = usermanagement_get_users_recordset('name', 'ASC', 0, 0, '', $contexts);
         // If in interactive mode, user should have access to at least their own info
         if ($this->execution_mode == php_report::EXECUTION_MODE_INTERACTIVE) {
             $cm_user_id = cm_get_crlmuserid($this->userid);
             $user_object = new user($cm_user_id);
             $users[$user_object->id] = fullname($user_object) . ' (' . $user_object->idnumber . ')';
         }
         if (!empty($user_objects)) {
             // Create a list of users this user has permissions to view
             while ($user_object = rs_fetch_next_record($user_objects)) {
                 $users[$user_object->id] = $user_object->name . ' (' . $user_object->idnumber . ')';
             }
         }
     }
     $filters[] = new generalized_filter_entry('userid', 'crlmuser', 'id', get_string('filter_user', $this->lang_file), false, 'simpleselect', array('choices' => $users, 'numeric' => true, 'noany' => true, 'help' => array('individual_course_progress_user_help', get_string('displayname', 'rlreport_individual_course_progress'), 'block_php_report')));
     // Needs to pull from saved prefs
     $user_preferences = php_report_filtering_get_user_preferences('php_report_' . $this->get_report_shortname());
     $report_index = 'php_report_' . $this->get_report_shortname() . '/field' . $this->id;
     if (!isset($user_preferences[$report_index]) || ($default_fieldid_list = @unserialize(base64_decode($user_preferences[$report_index]))) === false) {
         $default_fieldid_list = array();
     }
     $field_list = array('fieldids' => $default_fieldid_list);
     // Add block id to field list array
     $field_list['block_instance'] = $this->id;
     $field_list['reportname'] = $this->get_report_shortname();
     // Need help text
     $field_list['help'] = array('individual_course_progress_field_help', get_string('displayname', 'rlreport_individual_course_progress'), 'block_php_report');
     $this->multiselect_filter = new generalized_filter_entry('field' . $this->id, 'field' . $this->id, 'id', get_string('selectcustomfields', $this->lang_file), false, 'custom_field_multiselect_values', $field_list);
     $filters[] = $this->multiselect_filter;
     return $filters;
 }
 /**
  * Specifies available report filters
  * (empty by default but can be implemented by child class)
  *
  * @param   boolean  $init_data  If true, signal the report to load the
  *                               actual content of the filter objects
  *
  * @return  array                The list of available filters
  */
 function get_filters($init_data = true)
 {
     $filters = array();
     $users = array();
     if ($init_data) {
         $contexts = get_contexts_by_capability_for_user('user', $this->access_capability, $this->userid);
         $user_objects = usermanagement_get_users_recordset('name', 'ASC', 0, 0, '', $contexts);
         // If in interactive mode, user should have access to at least their own info
         if ($this->execution_mode == php_report::EXECUTION_MODE_INTERACTIVE) {
             $cm_user_id = cm_get_crlmuserid($this->userid);
             $user_object = new user($cm_user_id);
             $users[$user_object->id] = fullname($user_object) . ' (' . $user_object->idnumber . ')';
         }
         if (!empty($user_objects)) {
             // Create a list of users this user has permissions to view
             while ($user_object = rs_fetch_next_record($user_objects)) {
                 $users[$user_object->id] = $user_object->name . ' (' . $user_object->idnumber . ')';
             }
         }
     }
     $filters[] = new generalized_filter_entry('userid', 'usr', 'id', get_string('filter_user', $this->lang_file), false, 'simpleselect', array('choices' => $users, 'numeric' => true, 'noany' => true, 'help' => array('individual_user_report_help', get_string('displayname', 'rlreport_individual_user'), 'block_php_report')));
     return $filters;
 }