Esempio n. 1
0
 /**
  * Test user_list_view function
  */
 public function test_user_list_view()
 {
     $this->resetAfterTest();
     // Course without sections.
     $course = $this->getDataGenerator()->create_course();
     $context = context_course::instance($course->id);
     $this->setAdminUser();
     // Redirect events to the sink, so we can recover them later.
     $sink = $this->redirectEvents();
     user_list_view($course, $context);
     $events = $sink->get_events();
     $this->assertCount(1, $events);
     $event = reset($events);
     // Check the event details are correct.
     $this->assertInstanceOf('\\core\\event\\user_list_viewed', $event);
     $this->assertEquals($context, $event->get_context());
     $this->assertEquals($course->shortname, $event->other['courseshortname']);
     $this->assertEquals($course->fullname, $event->other['coursefullname']);
 }
Esempio n. 2
0
}
// Make sure other roles may not be selected by any means.
if (empty($rolenames[$roleid])) {
    print_error('noparticipants');
}
// No roles to display yet?
// frontpage course is an exception, on the front page course we should display all users.
if (empty($rolenames) && !$isfrontpage) {
    if (has_capability('moodle/role:assign', $context)) {
        redirect($CFG->wwwroot . '/' . $CFG->admin . '/roles/assign.php?contextid=' . $context->id);
    } else {
        print_error('noparticipants');
    }
}
// Trigger events.
user_list_view($course, $context);
$bulkoperations = has_capability('moodle/course:bulkmessaging', $context);
$countries = get_string_manager()->get_list_of_countries();
$strnever = get_string('never');
$datestring = new stdClass();
$datestring->year = get_string('year');
$datestring->years = get_string('years');
$datestring->day = get_string('day');
$datestring->days = get_string('days');
$datestring->hour = get_string('hour');
$datestring->hours = get_string('hours');
$datestring->min = get_string('min');
$datestring->mins = get_string('mins');
$datestring->sec = get_string('sec');
$datestring->secs = get_string('secs');
if ($mode !== null) {
Esempio n. 3
0
 /**
  * Simulate the /user/index.php web interface page triggering events
  *
  * @param int $courseid id of course
  * @return array of warnings and status result
  * @since Moodle 2.9
  * @throws moodle_exception
  */
 public static function view_user_list($courseid)
 {
     global $CFG;
     require_once $CFG->dirroot . "/user/lib.php";
     $params = self::validate_parameters(self::view_user_list_parameters(), array('courseid' => $courseid));
     $warnings = array();
     if (empty($params['courseid'])) {
         $params['courseid'] = SITEID;
     }
     $course = get_course($params['courseid']);
     if ($course->id == SITEID) {
         $context = context_system::instance();
     } else {
         $context = context_course::instance($course->id);
     }
     self::validate_context($context);
     if ($course->id == SITEID) {
         require_capability('moodle/site:viewparticipants', $context);
     } else {
         require_capability('moodle/course:viewparticipants', $context);
     }
     user_list_view($course, $context);
     $result = array();
     $result['status'] = true;
     $result['warnings'] = $warnings;
     return $result;
 }