2023-05-17 21:19:14 +02:00
|
|
|
<?php
|
2023-08-24 23:02:41 +02:00
|
|
|
// This file is part of the Studyplan plugin for Moodle
|
|
|
|
//
|
|
|
|
// 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 <https://www.gnu.org/licenses/>.
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @package local_treestudyplan
|
|
|
|
* @copyright 2023 P.M. Kuipers
|
|
|
|
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
*/
|
|
|
|
|
2023-05-17 21:19:14 +02:00
|
|
|
namespace local_treestudyplan;
|
|
|
|
require_once($CFG->libdir.'/externallib.php');
|
|
|
|
|
|
|
|
abstract class aggregator {
|
|
|
|
private const FALLBACK = "bistate";
|
2023-08-25 09:33:42 +02:00
|
|
|
private static $modsupported = [];
|
2023-05-17 21:19:14 +02:00
|
|
|
|
2023-08-24 23:02:41 +02:00
|
|
|
public static function supported($mod) {
|
2023-08-25 09:33:42 +02:00
|
|
|
if (!array_key_exists($mod, self::$modsupported)) {
|
|
|
|
self::$modsupported[$mod] = class_exists(self::aggregator_name($mod));
|
2023-05-17 21:19:14 +02:00
|
|
|
}
|
2023-08-25 09:33:42 +02:00
|
|
|
return self::$modsupported[$mod];
|
2023-05-17 21:19:14 +02:00
|
|
|
}
|
|
|
|
|
2023-08-24 23:02:41 +02:00
|
|
|
private static function aggregator_name($mod) {
|
2023-05-17 21:19:14 +02:00
|
|
|
return "\local_treestudyplan\\local\\aggregators\\{$mod}_aggregator";
|
|
|
|
}
|
|
|
|
|
2023-08-24 23:02:41 +02:00
|
|
|
public static function list() {
|
2023-08-25 09:44:34 +02:00
|
|
|
// Static list, since we'd need to implement a lot of static data for new aggregation methods anyway.
|
|
|
|
// And this is faster than any dynamic method.
|
2023-05-17 21:19:14 +02:00
|
|
|
return [
|
2023-08-25 10:41:56 +02:00
|
|
|
"core", // Use moodle core completion.
|
2023-08-24 23:02:41 +02:00
|
|
|
"bistate",
|
2023-08-25 10:41:56 +02:00
|
|
|
"tristate", // Deprecated.
|
2023-05-17 21:19:14 +02:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2023-08-24 23:02:41 +02:00
|
|
|
public static function create($mod, $configstr) {
|
|
|
|
if (self::supported($mod)) {
|
2023-08-25 09:33:42 +02:00
|
|
|
$agclass = self::aggregator_name($mod);
|
|
|
|
return new $agclass($configstr);
|
2023-05-17 21:19:14 +02:00
|
|
|
} else {
|
|
|
|
throw new \InvalidArgumentException("Cannot find aggregator '{$mod}'");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-24 23:02:41 +02:00
|
|
|
public static function createOrDefault($mod, $configstr) {
|
2023-05-17 21:19:14 +02:00
|
|
|
try {
|
2023-08-24 23:02:41 +02:00
|
|
|
return self::create($mod, $configstr);
|
2023-08-25 10:41:56 +02:00
|
|
|
} catch (\ValueError $x) {
|
2023-08-24 23:02:41 +02:00
|
|
|
return self::create(self::FALLBACK, "");
|
2023-05-17 21:19:14 +02:00
|
|
|
}
|
|
|
|
}
|
2023-08-24 23:02:41 +02:00
|
|
|
|
2023-05-17 21:19:14 +02:00
|
|
|
private function __construct($configstr) {
|
|
|
|
$this->initialize($configstr);
|
|
|
|
}
|
|
|
|
|
2023-08-25 10:41:56 +02:00
|
|
|
protected function initialize($configstr) {
|
|
|
|
}
|
2023-05-17 21:19:14 +02:00
|
|
|
|
|
|
|
public abstract function needSelectGradables();
|
|
|
|
public abstract function isDeprecated();
|
|
|
|
public abstract function aggregate_course(courseinfo $courseinfo, studyitem $studyitem, $userid);
|
|
|
|
public abstract function aggregate_junction(array $completion, studyitem $studyitem, $userid);
|
|
|
|
|
|
|
|
public abstract function grade_completion(gradeinfo $gradeinfo, $userid);
|
|
|
|
|
2023-08-24 23:02:41 +02:00
|
|
|
// Aggregation method makes use of "required grades" in a course/module.
|
2023-05-17 21:19:14 +02:00
|
|
|
public abstract function useRequiredGrades();
|
2023-08-24 23:02:41 +02:00
|
|
|
// Aggregation method makes use of .
|
2023-05-17 21:19:14 +02:00
|
|
|
public abstract function useItemConditions();
|
|
|
|
|
2023-08-24 23:02:41 +02:00
|
|
|
// Whether the aggregation method uses core_completion, or treestudyplan custom completion.
|
|
|
|
public function usecorecompletioninfo() {
|
2023-05-17 21:19:14 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-08-24 23:02:41 +02:00
|
|
|
// Parameter editing functions - override in child class to implement parameter config for aggregation.
|
2023-05-17 21:19:14 +02:00
|
|
|
|
2023-08-24 23:02:41 +02:00
|
|
|
// Return the current configuration string.
|
2023-05-17 21:19:14 +02:00
|
|
|
public function config_string() {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2023-08-24 23:02:41 +02:00
|
|
|
public static function basic_structure($value=VALUE_REQUIRED) {
|
2023-05-17 21:19:14 +02:00
|
|
|
return new \external_single_structure([
|
|
|
|
"useRequiredGrades" => new \external_value(PARAM_BOOL, 'id of studyplan'),
|
|
|
|
"useItemConditions" => new \external_value(PARAM_BOOL, 'name of studyplan'),
|
2023-08-24 23:02:41 +02:00
|
|
|
], "Aggregator requirements", $value);
|
2023-05-17 21:19:14 +02:00
|
|
|
}
|
|
|
|
|
2023-08-24 23:02:41 +02:00
|
|
|
public function basic_model() {
|
|
|
|
return [
|
2023-05-17 21:19:14 +02:00
|
|
|
"useRequiredGrades" => $this->useRequiredGrades(),
|
|
|
|
"useItemConditions" => $this->useItemConditions(),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2023-08-24 23:02:41 +02:00
|
|
|
public static function list_structure($value=VALUE_REQUIRED) {
|
2023-05-17 21:19:14 +02:00
|
|
|
return new \external_multiple_structure(new \external_single_structure([
|
|
|
|
"id" => new \external_value(PARAM_TEXT, 'id of aggregator'),
|
|
|
|
"name" => new \external_value(PARAM_TEXT, 'name of agregator'),
|
|
|
|
"deprecated" => new \external_value(PARAM_BOOL, 'if method is deprecated'),
|
|
|
|
"defaultconfig" => new \external_value(PARAM_TEXT, 'default config of agregator'),
|
|
|
|
|
2023-08-24 23:02:41 +02:00
|
|
|
], "Available aggregators", $value));
|
2023-05-17 21:19:14 +02:00
|
|
|
}
|
|
|
|
|
2023-08-24 23:02:41 +02:00
|
|
|
public static function list_model() {
|
|
|
|
|
2023-05-17 21:19:14 +02:00
|
|
|
$list = [];
|
2023-08-24 23:02:41 +02:00
|
|
|
foreach (self::list() as $agid) {
|
2023-08-25 10:41:56 +02:00
|
|
|
$a = self::create($agid, ""); // Create new one with empty config string.
|
2023-05-17 21:19:14 +02:00
|
|
|
$list[] = [
|
|
|
|
'id' => $agid,
|
2023-08-24 23:02:41 +02:00
|
|
|
'name' => get_string("{$agid}_aggregator_title", "local_treestudyplan"),
|
2023-05-17 21:19:14 +02:00
|
|
|
'deprecated' => $a->isDeprecated(),
|
|
|
|
'defaultconfig' => $a->config_string(),
|
|
|
|
];
|
|
|
|
}
|
2023-08-24 23:02:41 +02:00
|
|
|
|
2023-05-17 21:19:14 +02:00
|
|
|
return $list;
|
|
|
|
}
|
2023-08-25 10:41:56 +02:00
|
|
|
}
|