Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CTP-3660 LTI source for Marks Transfer #65

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 96 additions & 0 deletions classes/assessment/lti.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

namespace local_sitsgradepush\assessment;

/**
* Class for LTI assessment.
*
* @package local_sitsgradepush
* @copyright 2024 onwards University College London {@link https://www.ucl.ac.uk/}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @author David Watson <[email protected]>
*/
class lti extends activity {

/**
* Get all participants.
*
* @return array
*/
public function get_all_participants(): array {
if (!self::check_assessment_validity()->valid) {
return [];
}
$context = \context_module::instance($this->coursemodule->id);
return get_enrolled_users($context, 'mod/lti:view');
}

/**
* Get the start date of this assessment.
*
* @return int|null
*/
public function get_start_date(): ?int {
// This activity does not have a start date.
return null;
}

/**
* Get the end date of this assessment.
*
* @return int|null
*/
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');
}
}
80 changes: 80 additions & 0 deletions classes/submission/lti.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

namespace local_sitsgradepush\submission;

/**
* Class for coursework plugin (mod_coursework) submission.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Class for LTI?

*
* @package local_sitsgradepush
* @copyright 2024 onwards University College London {@link https://www.ucl.ac.uk/}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @author David Watson <[email protected]>
*/
class lti extends submission {
/**
* Get hand in datetime.
*
* @return string
*/
public function get_handin_datetime(): string {
if ($this->submissiondata->datesubmitted ?? null) {
return $this->get_iso8601_datetime($this->submissiondata->datesubmitted);
} else {
return "";
}
}

/**
* Set the module instance.
*
* @return void
* @throws \dml_exception
* @throws \moodle_exception
*/
protected function set_module_instance() {
global $DB;
if (!$instance = $DB->get_record('lti', ['id' => $this->coursemodule->instance])) {
throw new \moodle_exception(
'error:coursemodulenotfound', 'local_sitsgradepush', '', null,
"Instance ID: " . $this->coursemodule->instance
);
}

$this->modinstance = $instance;
}

/**
* Set submission.
*
* @return void
* @throws \dml_exception
* @throws \moodle_exception
*/
protected function set_submission_data(): void {
global $DB;

// User may have multiple attempts.
// In that case we return the most recent attempt details.
$params = ['ltiid' => $this->modinstance->id, 'userid' => $this->userid];
$attempts = $DB->get_records(
'lti_submission', $params, 'datesubmitted DESC', '*', 0, 1
);
if (!empty($attempts)) {
$this->submissiondata = reset($attempts);
}
}
}
1 change: 1 addition & 0 deletions lang/en/local_sitsgradepush.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
$string['error:gradetype_not_supported'] = 'The grade type of this assessment is not supported for marks transfer.';
$string['error:inserttask'] = 'Failed to insert task.';
$string['error:invalid_source_type'] = 'Invalid source type. {$a}';
$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
Loading