Commit 006fac90 authored by Damyon Wiese's avatar Damyon Wiese
Browse files

Merge branch 'MDL-49498-master' of git://github.com/jleyva/moodle

Conflicts:
	lib/db/services.php
	version.php
parents 6661d5de 7a334a9b
......@@ -503,6 +503,15 @@ $functions = array(
'capabilities' => '',
),
'core_user_view_user_list' => array(
'classname' => 'core_user_external',
'methodname' => 'view_user_list',
'classpath' => 'user/externallib.php',
'description' => 'Simulates the web-interface view of user/index.php (triggering events).',
'type' => 'write',
'capabilities' => 'moodle/course:viewparticipants',
),
// === enrol related functions ===
'core_enrol_get_enrolled_users_with_capability' => array(
......@@ -1075,6 +1084,7 @@ $services = array(
'core_completion_get_activities_completion_status',
'core_notes_get_course_notes',
'core_completion_get_course_completion_status',
'core_user_view_user_list',
),
'enabled' => 0,
'restrictedusers' => 0,
......
......@@ -1243,6 +1243,81 @@ class core_user_external extends external_api {
);
}
/**
* Returns description of method parameters
*
* @return external_function_parameters
* @since Moodle 2.9
*/
public static function view_user_list_parameters() {
return new external_function_parameters(
array(
'courseid' => new external_value(PARAM_INT, 'id of the course, 0 for site')
)
);
}
/**
* 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;
}
/**
* Returns description of method result value
*
* @return external_description
* @since Moodle 2.9
*/
public static function view_user_list_returns() {
return new external_single_structure(
array(
'status' => new external_value(PARAM_BOOL, 'status: true if success'),
'warnings' => new external_warnings()
)
);
}
}
/**
......
......@@ -23,6 +23,7 @@
*/
require_once('../config.php');
require_once($CFG->dirroot.'/user/lib.php');
require_once($CFG->libdir.'/tablelib.php');
require_once($CFG->libdir.'/filelib.php');
......@@ -105,16 +106,8 @@ if (empty($rolenames) && !$isfrontpage) {
}
}
$event = \core\event\user_list_viewed::create(array(
'objectid' => $course->id,
'courseid' => $course->id,
'context' => $context,
'other' => array(
'courseshortname' => $course->shortname,
'coursefullname' => $course->fullname
)
));
$event->trigger();
// Trigger events.
user_list_view($course, $context);
$bulkoperations = has_capability('moodle/course:bulkmessaging', $context);
......
......@@ -1002,3 +1002,24 @@ function user_remove_user_device($uuid, $appid = "") {
return true;
}
/**
* Trigger user_list_viewed event.
*
* @param stdClass $course course object
* @param stdClass $context course context object
* @since Moodle 2.9
*/
function user_list_view($course, $context) {
$event = \core\event\user_list_viewed::create(array(
'objectid' => $course->id,
'courseid' => $course->id,
'context' => $context,
'other' => array(
'courseshortname' => $course->shortname,
'coursefullname' => $course->fullname
)
));
$event->trigger();
}
......@@ -347,4 +347,34 @@ class core_userliblib_testcase extends advanced_testcase {
$this->assertEquals(1, $DB->count_records('user_password_history', array('userid' => $user1->id)));
$this->assertEquals(0, $DB->count_records('user_password_history', array('userid' => $user2->id)));
}
/**
* 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']);
}
}
......@@ -29,7 +29,7 @@
defined('MOODLE_INTERNAL') || die();
$version = 2015040600.00; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2015040600.01; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment