mirror of
https://github.com/moodle/moodle.git
synced 2025-01-29 19:50:14 +01:00
MDL-63147 mod_resource: Accept userid in resource event_action
This commit is contained in:
parent
44890bd738
commit
3ff8068fc5
@ -559,12 +559,19 @@ function resource_check_updates_since(cm_info $cm, $from, $filter = array()) {
|
||||
* @return \core_calendar\local\event\entities\action_interface|null
|
||||
*/
|
||||
function mod_resource_core_calendar_provide_event_action(calendar_event $event,
|
||||
\core_calendar\action_factory $factory) {
|
||||
$cm = get_fast_modinfo($event->courseid)->instances['resource'][$event->instance];
|
||||
\core_calendar\action_factory $factory, $userid = 0) {
|
||||
|
||||
global $USER;
|
||||
|
||||
if (empty($userid)) {
|
||||
$userid = $USER->id;
|
||||
}
|
||||
|
||||
$cm = get_fast_modinfo($event->courseid, $userid)->instances['resource'][$event->instance];
|
||||
|
||||
$completion = new \completion_info($cm->get_course());
|
||||
|
||||
$completiondata = $completion->get_data($cm, false);
|
||||
$completiondata = $completion->get_data($cm, false, $userid);
|
||||
|
||||
if ($completiondata->completionstate != COMPLETION_INCOMPLETE) {
|
||||
return null;
|
||||
|
@ -212,6 +212,55 @@ class mod_resource_lib_testcase extends advanced_testcase {
|
||||
$this->assertNull($actionevent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test mod_resource_core_calendar_provide_event_action with user override
|
||||
*/
|
||||
public function test_resource_core_calendar_provide_event_action_user_override() {
|
||||
global $CFG, $USER;
|
||||
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
$CFG->enablecompletion = 1;
|
||||
|
||||
// Create the activity.
|
||||
$course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1));
|
||||
$resource = $this->getDataGenerator()->create_module('resource', array('course' => $course->id),
|
||||
array('completion' => 2, 'completionview' => 1, 'completionexpected' => time() + DAYSECS));
|
||||
|
||||
// Get some additional data.
|
||||
$cm = get_coursemodule_from_instance('resource', $resource->id);
|
||||
|
||||
// Create a calendar event.
|
||||
$event = $this->create_action_event($course->id, $resource->id,
|
||||
\core_completion\api::COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED);
|
||||
|
||||
// Mark the activity as completed.
|
||||
$completion = new completion_info($course);
|
||||
$completion->set_module_viewed($cm);
|
||||
|
||||
// Create an action factory.
|
||||
$factory = new \core_calendar\action_factory();
|
||||
|
||||
// Decorate action event.
|
||||
$actionevent = mod_resource_core_calendar_provide_event_action($event, $factory, $USER->id);
|
||||
|
||||
// Decorate action with a userid override.
|
||||
$actionevent2 = mod_resource_core_calendar_provide_event_action($event, $factory, $user->id);
|
||||
|
||||
// Ensure result was null because it has been marked as completed for the associated user.
|
||||
// Logic was brought across from the "_already_completed" function.
|
||||
$this->assertNull($actionevent);
|
||||
|
||||
// Confirm the event was decorated.
|
||||
$this->assertNotNull($actionevent2);
|
||||
$this->assertInstanceOf('\core_calendar\local\event\value_objects\action', $actionevent2);
|
||||
$this->assertEquals(get_string('view'), $actionevent2->get_name());
|
||||
$this->assertInstanceOf('moodle_url', $actionevent2->get_url());
|
||||
$this->assertEquals(1, $actionevent2->get_item_count());
|
||||
$this->assertTrue($actionevent2->is_actionable());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an action event.
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user