mirror of
https://github.com/moodle/moodle.git
synced 2025-04-07 09:23:31 +02:00
MDL-60063 feedback: show feedback events on calendar for teacher
This commit is contained in:
parent
21bb56fd96
commit
f2c3818b39
mod/feedback
@ -3440,22 +3440,6 @@ function feedback_check_updates_since(cm_info $cm, $from, $filter = array()) {
|
||||
return $updates;
|
||||
}
|
||||
|
||||
/**
|
||||
* The event is only visible anywhere if the user can submit feedback.
|
||||
*
|
||||
* @param calendar_event $event
|
||||
* @return bool Returns true if the event is visible to the current user, false otherwise.
|
||||
*/
|
||||
function mod_feedback_core_calendar_is_event_visible(calendar_event $event) {
|
||||
global $DB;
|
||||
|
||||
$cm = get_fast_modinfo($event->courseid)->instances['feedback'][$event->instance];
|
||||
$feedbackcompletion = new mod_feedback_completion(null, $cm, 0);
|
||||
|
||||
// The event is only visible if the user can submit it.
|
||||
return $feedbackcompletion->can_complete();
|
||||
}
|
||||
|
||||
/**
|
||||
* This function receives a calendar event and returns the action associated with it, or null if there is none.
|
||||
*
|
||||
@ -3477,6 +3461,11 @@ function mod_feedback_core_calendar_provide_event_action(calendar_event $event,
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!$feedbackcompletion->can_complete()) {
|
||||
// The user can't complete the feedback so there is no action for them.
|
||||
return null;
|
||||
}
|
||||
|
||||
// The feedback is actionable if it does not have timeopen or timeopen is in the past.
|
||||
$actionable = $feedbackcompletion->is_open();
|
||||
|
||||
|
@ -260,9 +260,9 @@ class mod_feedback_lib_testcase extends advanced_testcase {
|
||||
}
|
||||
|
||||
/**
|
||||
* A user that cannot submit the feedback should not see the event.
|
||||
* A user that can not submit feedback should not have an action.
|
||||
*/
|
||||
public function test_feedback_core_calendar_is_event_visible_can_not_submit() {
|
||||
public function test_feedback_core_calendar_provide_event_action_can_not_submit() {
|
||||
global $DB;
|
||||
|
||||
$this->resetAfterTest();
|
||||
@ -278,41 +278,13 @@ class mod_feedback_lib_testcase extends advanced_testcase {
|
||||
$this->getDataGenerator()->enrol_user($user->id, $course->id, $studentrole->id, 'manual');
|
||||
|
||||
$this->setUser($user);
|
||||
|
||||
assign_capability('mod/feedback:complete', CAP_PROHIBIT, $studentrole->id, $context);
|
||||
$context->mark_dirty();
|
||||
|
||||
$visible = mod_feedback_core_calendar_is_event_visible($event);
|
||||
$factory = new \core_calendar\action_factory();
|
||||
$action = mod_feedback_core_calendar_provide_event_action($event, $factory);
|
||||
|
||||
$this->assertFalse($visible);
|
||||
}
|
||||
|
||||
/**
|
||||
* A user that can submit the feedback should see the event.
|
||||
*/
|
||||
public function test_feedback_core_calendar_is_event_visible_can_submit() {
|
||||
global $DB;
|
||||
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
$studentrole = $DB->get_record('role', array('shortname' => 'student'));
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$feedback = $this->getDataGenerator()->create_module('feedback', ['course' => $course->id]);
|
||||
$event = $this->create_action_event($course->id, $feedback->id, FEEDBACK_EVENT_TYPE_OPEN);
|
||||
$cm = get_coursemodule_from_instance('feedback', $feedback->id);
|
||||
$context = context_module::instance($cm->id);
|
||||
$this->getDataGenerator()->enrol_user($user->id, $course->id, $studentrole->id, 'manual');
|
||||
|
||||
$this->setUser($user);
|
||||
|
||||
assign_capability('mod/feedback:complete', CAP_ALLOW, $studentrole->id, $context->id);
|
||||
$context->mark_dirty();
|
||||
|
||||
$visible = mod_feedback_core_calendar_is_event_visible($event);
|
||||
|
||||
$this->assertTrue($visible);
|
||||
$this->assertNull($action);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user