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

Add new mods support #71

Merged
merged 12 commits into from
Oct 28, 2024
3 changes: 3 additions & 0 deletions classes/assessment/activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ public function get_user_grade(int $userid, ?int $partid = null): ?array {
* @return array
*/
public function get_grade_items(): array {
global $CFG;
require_once("$CFG->libdir/gradelib.php");

$gradeitems = grade_item::fetch_all([
'itemtype' => $this->get_type(),
'itemmodule' => $this->get_module_name(),
Expand Down
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;
}
}
61 changes: 61 additions & 0 deletions classes/assessment/hvp.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 hvp (mod_hvp plugin, not core H5P) assessment.
* Note that the default for "Grade > Maximum grade" when HVP is added to a course is 10.
* If it is to be a candidate for marks transfer, this needs to be set to 100 by the teacher.
* Otherwise it will not be shown as a source for marks transfer.
*
* @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 hvp extends activity {

/**
* Get all participants.
*
* @return array
*/
public function get_all_participants(): array {
$context = \context_module::instance($this->coursemodule->id);
return get_enrolled_users($context, 'mod/hvp:view');
}

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

/**
* Get the end date of the assessment.
*
* @return int|null
*/
public function get_end_date(): ?int {
// Activity does not have an end date.
return null;
}
}
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) {
// 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();
}
}
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');
watson8 marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* 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 an end 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');
}
}
8 changes: 1 addition & 7 deletions classes/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -1216,15 +1216,9 @@ public function validate_component_grade(int $componentgradeid, string $sourcety
public function get_all_course_activities(int $courseid): array {
$activities = [];
foreach (self::allowed_activities() as $modname) {
// Skip if the activity is not installed.
if (!array_key_exists($modname, core_component::get_plugin_list('mod'))) {
continue;
}
watson8 marked this conversation as resolved.
Show resolved Hide resolved

if (!empty($results = get_coursemodules_in_course($modname, $courseid))) {
foreach ($results as $result) {
$assessemnt = assessmentfactory::get_assessment(assessmentfactory::SOURCETYPE_MOD, $result->id);
$activities[] = $assessemnt;
$activities[] = assessmentfactory::get_assessment(assessmentfactory::SOURCETYPE_MOD, $result->id);
}
}
}
Expand Down
Loading
Loading