mirror of
https://github.com/moodle/moodle.git
synced 2025-08-06 17:36:38 +02:00
MDL-58768 mod_assign: Added userid param to calendar callbacks
The mod_assign_core_calendar_is_event_visible and mod_assign_core_calendar_provide_event_action functions now accept a new parameter ($userid) so they are not always dependet to the logged in user.
This commit is contained in:
parent
907b175c05
commit
fda4374a67
2 changed files with 218 additions and 10 deletions
|
@ -1826,20 +1826,25 @@ function assign_check_updates_since(cm_info $cm, $from, $filter = array()) {
|
|||
* the ASSIGN_EVENT_TYPE_GRADINGDUE event will not be shown to students on their calendar.
|
||||
*
|
||||
* @param calendar_event $event
|
||||
* @param int $userid User id to use for all capability checks, etc. Set to 0 for current user (default).
|
||||
* @return bool Returns true if the event is visible to the current user, false otherwise.
|
||||
*/
|
||||
function mod_assign_core_calendar_is_event_visible(calendar_event $event) {
|
||||
function mod_assign_core_calendar_is_event_visible(calendar_event $event, $userid = 0) {
|
||||
global $CFG, $USER;
|
||||
|
||||
require_once($CFG->dirroot . '/mod/assign/locallib.php');
|
||||
|
||||
$cm = get_fast_modinfo($event->courseid)->instances['assign'][$event->instance];
|
||||
if (empty($userid)) {
|
||||
$userid = $USER->id;
|
||||
}
|
||||
|
||||
$cm = get_fast_modinfo($event->courseid, $userid)->instances['assign'][$event->instance];
|
||||
$context = context_module::instance($cm->id);
|
||||
|
||||
$assign = new assign($context, $cm, null);
|
||||
|
||||
if ($event->eventtype == ASSIGN_EVENT_TYPE_GRADINGDUE) {
|
||||
return $assign->can_grade();
|
||||
return $assign->can_grade($userid);
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
|
@ -1853,22 +1858,28 @@ function mod_assign_core_calendar_is_event_visible(calendar_event $event) {
|
|||
*
|
||||
* @param calendar_event $event
|
||||
* @param \core_calendar\action_factory $factory
|
||||
* @param int $userid User id to use for all capability checks, etc. Set to 0 for current user (default).
|
||||
* @return \core_calendar\local\event\entities\action_interface|null
|
||||
*/
|
||||
function mod_assign_core_calendar_provide_event_action(calendar_event $event,
|
||||
\core_calendar\action_factory $factory) {
|
||||
\core_calendar\action_factory $factory,
|
||||
$userid = 0) {
|
||||
|
||||
global $CFG, $USER;
|
||||
|
||||
require_once($CFG->dirroot . '/mod/assign/locallib.php');
|
||||
|
||||
$cm = get_fast_modinfo($event->courseid)->instances['assign'][$event->instance];
|
||||
if (empty($userid)) {
|
||||
$userid = $USER->id;
|
||||
}
|
||||
|
||||
$cm = get_fast_modinfo($event->courseid, $userid)->instances['assign'][$event->instance];
|
||||
$context = context_module::instance($cm->id);
|
||||
|
||||
$assign = new assign($context, $cm, null);
|
||||
|
||||
// Apply overrides.
|
||||
$assign->update_effective_access($USER->id);
|
||||
$assign->update_effective_access($userid);
|
||||
|
||||
if ($event->eventtype == ASSIGN_EVENT_TYPE_GRADINGDUE) {
|
||||
$name = get_string('grade');
|
||||
|
@ -1877,16 +1888,16 @@ function mod_assign_core_calendar_provide_event_action(calendar_event $event,
|
|||
'action' => 'grader'
|
||||
]);
|
||||
$itemcount = $assign->count_submissions_need_grading();
|
||||
$actionable = $assign->can_grade() && (time() >= $assign->get_instance()->allowsubmissionsfromdate);
|
||||
$actionable = $assign->can_grade($userid) && (time() >= $assign->get_instance()->allowsubmissionsfromdate);
|
||||
} else {
|
||||
$usersubmission = $assign->get_user_submission($USER->id, false);
|
||||
$usersubmission = $assign->get_user_submission($userid, false);
|
||||
if ($usersubmission && $usersubmission->status === ASSIGN_SUBMISSION_STATUS_SUBMITTED) {
|
||||
// The user has already submitted.
|
||||
// We do not want to change the text to edit the submission, we want to remove the event from the Dashboard entirely.
|
||||
return null;
|
||||
}
|
||||
|
||||
$participant = $assign->get_participant($USER->id);
|
||||
$participant = $assign->get_participant($userid);
|
||||
|
||||
if (!$participant) {
|
||||
// If the user is not a participant in the assignment then they have
|
||||
|
@ -1901,7 +1912,7 @@ function mod_assign_core_calendar_provide_event_action(calendar_event $event,
|
|||
'action' => 'editsubmission'
|
||||
]);
|
||||
$itemcount = 1;
|
||||
$actionable = $assign->is_any_submission_plugin_enabled() && $assign->can_edit_submission($USER->id);
|
||||
$actionable = $assign->is_any_submission_plugin_enabled() && $assign->can_edit_submission($userid, $userid);
|
||||
}
|
||||
|
||||
return $factory->create_instance(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue