Skip to content

Commit

Permalink
CTP-3660 check LTI grade eligibility
Browse files Browse the repository at this point in the history
  • Loading branch information
watson8 committed Oct 8, 2024
1 parent 4f2966c commit 206853c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 28 deletions.
67 changes: 39 additions & 28 deletions classes/assessment/lti.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,35 +32,11 @@ class lti extends activity {
* @return array
*/
public function get_all_participants(): array {
global $DB, $CFG;
// For LTI_SETTING_ constants.
require_once("$CFG->dirroot/mod/lti/locallib.php");

$context = \context_module::instance($this->coursemodule->id);
$capability = 'mod/lti:view';

// Which type of LTI tool is this?
$typeid = $this->sourceinstance->typeid;
if (!$typeid) {
$tool = lti_get_tool_by_url_match($this->sourceinstance->toolurl, $this->sourceinstance->course);
if ($tool) {
$typeid = $tool->id;
}
if (!self::check_assessment_validity()->valid) {
return [];
}

// Has this tool been configured to accept grades globally or not?
$acceptgradestool = $DB->get_field(
'lti_types_config', 'value', ['typeid' => $typeid, 'name' => 'acceptgrades']
);
if ($acceptgradestool == LTI_SETTING_ALWAYS) {
return get_enrolled_users($context, $capability);
} else if ($acceptgradestool == LTI_SETTING_DELEGATE) {
// Whether or not grades are accepted is determined at course level.
return $this->sourceinstance->instructorchoiceacceptgrades == LTI_SETTING_ALWAYS
? get_enrolled_users($context, $capability)
: [];
}
return [];
$context = \context_module::instance($this->coursemodule->id);
return get_enrolled_users($context, 'mod/lti:view');
}

/**
Expand All @@ -82,4 +58,39 @@ public function get_end_date(): ?int {
// This activity does not have a start date.
return null;
}

/**
* Check assessment is valid for mapping.
*
* @return \stdClass
*/
public function check_assessment_validity(): \stdClass {
global $CFG, $DB;

// For LTI_SETTING_ constants.
require_once("$CFG->dirroot/mod/lti/locallib.php");

// Which type of LTI tool is this?
$typeid = $this->sourceinstance->typeid;
if (!$typeid) {
$tool = lti_get_tool_by_url_match($this->sourceinstance->toolurl, $this->sourceinstance->course);
if ($tool) {
$typeid = $tool->id;
}
}

// Has this tool been configured to accept grades globally or not?
$acceptgradestool = $DB->get_field(
'lti_types_config', 'value', ['typeid' => $typeid, 'name' => 'acceptgrades']
);
if ($acceptgradestool == LTI_SETTING_ALWAYS) {
// At system level, LTI grades are set to be sent to gradebook.
return parent::check_assessment_validity();
} else if ($acceptgradestool == LTI_SETTING_DELEGATE &&
$this->sourceinstance->instructorchoiceacceptgrades == LTI_SETTING_ALWAYS) {
// Whether or not grades are accepted is delegated to course level, which is set to yes.
return parent::check_assessment_validity();
}
return $this->set_validity_result(false, 'error:lti_no_grades');
}
}
1 change: 1 addition & 0 deletions lang/en/local_sitsgradepush.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
$string['error:inserttask'] = 'Failed to insert task.';
$string['error:invalid_source_type'] = 'Invalid source type. {$a}';
$string['error:lesson_practice'] = 'Practice lessons have no grades';
$string['error:lti_no_grades'] = 'LTI activity is set to not send grades to gradebook';
$string['error:mab_has_push_records'] = 'Assessment component mapping cannot be updated as marks have been transfered for {$a}';
$string['error:mab_invalid_for_mapping'] = 'This assessment component is not valid for mapping due to the following reasons: {$a}.';
$string['error:mab_not_found'] = 'Assessment component not found. ID: {$a}';
Expand Down

0 comments on commit 206853c

Please sign in to comment.