Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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
 /**
18
  * New base class for defining reengagement custom completion requirements.
19
  * @package    mod_reengagement
20
  * @copyright  2021 Catalyst IT
21
  * @author     Sumaiya Javed <sumaiya.javed@catalyst.net.nz>
22
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
  */
24
 
25
namespace mod_reengagement\completion;
26
 
27
use core_completion\activity_custom_completion;
28
 
29
/**
30
 * Custom_completion class.
31
 */
32
class custom_completion extends activity_custom_completion {
33
 
34
    /**
35
     * Fetches the completion state for a given completion rule.
36
     *
37
     * @param string $rule The completion rule.
38
     * @return int The completion state.
39
     */
40
    public function get_state(string $rule): int {
41
        global $DB;
42
 
43
        $this->validate_rule($rule);
44
 
45
        // Survey only supports duration as a custom rule.
46
        $status = $DB->record_exists('course_modules_completion', ['coursemoduleid' => $this->cm->id, 'userid' => $this->userid]);
47
        return $status ? COMPLETION_COMPLETE : COMPLETION_INCOMPLETE;
48
    }
49
 
50
    /**
51
     * Fetch the list of custom completion rules that this module defines.
52
     *
53
     * @return array
54
     */
55
    public static function get_defined_custom_rules(): array {
56
        return ['duration'];
57
    }
58
 
59
    /**
60
     * Returns an associative array of the descriptions of custom completion rules.
61
     *
62
     * @return array
63
     */
64
    public function get_custom_rule_descriptions(): array {
65
        return [
66
            'duration' => get_string('duration', 'reengagement')
67
        ];
68
    }
69
 
70
    /**
71
     * Returns an array of all completion rules, in the order they should be displayed to users.
72
     *
73
     * @return array
74
     */
75
    public function get_sort_order(): array {
76
        return [
77
            'duration',
78
        ];
79
    }
80
}