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-3563 add mod_coursework support #64

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
61 changes: 61 additions & 0 deletions classes/assessment/coursework.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?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 coursework plugin (mod_coursework) 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 coursework extends activity {

/**
* Get all participants.
* @see \mod_coursework\models\coursework::get_students() which we don't use as it returns objects.
* @return \stdClass[]
*/
public function get_all_participants(): array {
$context = \context_module::instance($this->coursemodule->id);
$modinfo = get_fast_modinfo($this->get_course_id());
$cm = $modinfo->get_cm($this->coursemodule->id);
$info = new \core_availability\info_module($cm);

$users = get_enrolled_users($context, 'mod/coursework:submit');
return $info->filter_user_list($users);
}

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

/**
* Get the end date of this assessment.
*
* @return int|null
*/
public function get_end_date(): ?int {
return $this->sourceinstance->deadline > 0 ? $this->sourceinstance->deadline : null;
}
}
88 changes: 88 additions & 0 deletions classes/submission/coursework.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?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.
*
* @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 coursework 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('coursework', ['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;

// We don't expect there will be more than one submission per user, but check that here and throw exception if so.
// We use authorid to identify the user being graded, since userid may be the user who submitted on their behalf.
$submissions = $DB->get_records_sql(
"SELECT id, userid as submittedby, authorid as userid, timecreated, timemodified, finalised,
manualsrscode, createdby, lastupdatedby, allocatableid, allocatableuser, allocatablegroup,
allocatabletype, firstpublished, lastpublished, timesubmitted
FROM {coursework_submissions}
WHERE courseworkid = :courseworkid AND authorid = :gradeduserid",
['courseworkid' => $this->modinstance->id, 'gradeduserid' => $this->userid],
0, 2
);
$countrecords = count($submissions);
if ($countrecords > 1) {
throw new \coding_exception("Unexpected multiple attempts or grades found for user " . $this->userid);
} else if ($countrecords == 1) {
$this->submissiondata = reset($submissions);
}
}
}
Loading