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-3561 Lesson source for Marks Transfer #66

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
74 changes: 74 additions & 0 deletions classes/assessment/lesson.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?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 lesson 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 lesson extends activity {

/**
* Get all participants.
*
* @return array
*/
public function get_all_participants(): array {
if ($this->sourceinstance->practice) {
watson8 marked this conversation as resolved.
Show resolved Hide resolved
// If this is a "Practice Lesson" it does not appear in gradebook.
return [];
}
$context = \context_module::instance($this->coursemodule->id);
return get_enrolled_users($context, 'mod/lesson:view');
}

/**
* Get the start date of this assessment.
*
* @return int|null
*/
public function get_start_date(): ?int {
return !$this->sourceinstance->practice && $this->sourceinstance->available > 0
? $this->sourceinstance->available : null;
}

/**
* Get the end date of this assessment.
*
* @return int|null
*/
public function get_end_date(): ?int {
return !$this->sourceinstance->practice && $this->sourceinstance->deadline > 0
? $this->sourceinstance->deadline : null;
}

/**
* Check assessment is valid for mapping.
*
* @return \stdClass
*/
public function check_assessment_validity(): \stdClass {
if ($this->sourceinstance->practice) {
return $this->set_validity_result(false, 'error:lesson_practice');
}
return parent::check_assessment_validity();
}
}
105 changes: 105 additions & 0 deletions classes/submission/lesson.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?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 lesson submission.
*
* @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 lesson extends submission {
/**
* Get hand in datetime.
*
* @return string
*/
public function get_handin_datetime(): string {
if ($this->submissiondata) {
return $this->get_iso8601_datetime($this->submissiondata->timesubmitted);
} 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('lesson', ['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;
if ($this->modinstance->practice) {
// If this is a "Practice Lesson" it does not appear in gradebook.
return;
}

// User may have multiple attempts if "Retakes allowed" is set to yes.
// In that case the grade may be the set to "Use maximum" or "Use mean".
// If it's "Use maximum" we return the details for the highest graded attempt here.
// If it's set to "Use mean", or retakes are set to not allowed, return the most recent attempt details held.

$params = ['lessonid' => $this->modinstance->id, 'userid' => $this->userid];

if ($this->modinstance->retake && $this->modinstance->usemaxgrade) {
$maxgrade = $DB->get_field_sql(
"SELECT MAX(grade) FROM {lesson_grades} WHERE lessonid = :lessonid AND userid = :userid",
$params
);
if ($maxgrade !== false) {
$params['maxgrade'] = $maxgrade;
$mostrecentmaxgradetime = $DB->get_field_sql(
"SELECT MAX(completed) FROM {lesson_grades}
WHERE lessonid = :lessonid AND userid = :userid AND grade = :maxgrade",
$params
);
$this->submissiondata = (object)['timesubmitted' => $mostrecentmaxgradetime];
}
} else {
// We want the mean grade, or retakes is set to not allowed, so just use most recent submit time.
$mostrecentgradetime = $DB->get_field_sql(
"SELECT MAX(completed) FROM {lesson_grades}
WHERE lessonid = :lessonid AND userid = :userid",
$params
);
$this->submissiondata = (object)['timesubmitted' => $mostrecentgradetime];
}
}
}
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:lesson_practice'] = 'Practice lessons have no grades';
$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