1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
declare(strict_types=1);
|
|
|
18 |
|
|
|
19 |
namespace mod_subcourse\completion;
|
|
|
20 |
|
|
|
21 |
/**
|
|
|
22 |
* Custom completion rules for mod_subcourse
|
|
|
23 |
*
|
|
|
24 |
* @package mod_subcourse
|
|
|
25 |
* @copyright Catalyst IT
|
|
|
26 |
* @author Dan Marsden
|
|
|
27 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
28 |
*/
|
|
|
29 |
class custom_completion extends \core_completion\activity_custom_completion {
|
|
|
30 |
/**
|
|
|
31 |
* Returns completion state of the custom completion rules
|
|
|
32 |
*
|
|
|
33 |
* @param string $rule
|
|
|
34 |
* @return integer
|
|
|
35 |
*/
|
|
|
36 |
public function get_state(string $rule): int {
|
|
|
37 |
global $CFG, $DB;
|
|
|
38 |
require_once($CFG->dirroot.'/completion/completion_completion.php');
|
|
|
39 |
|
|
|
40 |
$this->validate_rule($rule);
|
|
|
41 |
|
|
|
42 |
$subcourse = $DB->get_record('subcourse', ['id' => $this->cm->instance], 'id,refcourse,completioncourse', MUST_EXIST);
|
|
|
43 |
|
|
|
44 |
if (empty($subcourse->completioncourse)) {
|
|
|
45 |
// The rule not enabled, return early.
|
|
|
46 |
return $type;
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
if (empty($subcourse->refcourse)) {
|
|
|
50 |
// Misconfigured subcourse instance, behave as if was not enabled.
|
|
|
51 |
return $type;
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
// Check if the referenced course is completed.
|
|
|
55 |
$coursecompletion = new \completion_completion(['userid' => $this->userid, 'course' => $subcourse->refcourse]);
|
|
|
56 |
|
|
|
57 |
return $coursecompletion->is_complete();
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
/**
|
|
|
61 |
* Fetch the list of custom completion rules that this module defines.
|
|
|
62 |
* @return array
|
|
|
63 |
*/
|
|
|
64 |
public static function get_defined_custom_rules(): array {
|
|
|
65 |
return ['completioncourse'];
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
/**
|
|
|
69 |
* Returns an associative array of the descriptions of custom completion rules.
|
|
|
70 |
* @return array
|
|
|
71 |
*/
|
|
|
72 |
public function get_custom_rule_descriptions(): array {
|
|
|
73 |
return ['completioncourse' => get_string('completioncourse', 'subcourse')];
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
/**
|
|
|
77 |
* Returns an array of all completion rules, in the order they should be displayed to users.
|
|
|
78 |
* @return array
|
|
|
79 |
*/
|
|
|
80 |
public function get_sort_order(): array {
|
|
|
81 |
return ['completioncourse'];
|
|
|
82 |
}
|
|
|
83 |
}
|