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
declare(strict_types=1);
17
 
18
namespace mod_questionnaire\completion;
19
 
20
defined('MOODLE_INTERNAL') || die();
21
 
22
require_once($CFG->dirroot . '/mod/questionnaire/lib.php');
23
 
24
use coding_exception;
25
use core_completion\activity_custom_completion;
26
use moodle_exception;
27
 
28
/**
29
 * Activity custom completion subclass for the data activity.
30
 *
31
 * Class for defining mod_oucontent's custom completion rules and fetching the completion statuses
32
 * of the custom completion rules for a given data instance and a user.
33
 *
34
 * @package mod_questionnaire
35
 * @copyright 2022 The Open University
36
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37
 */
38
class custom_completion extends activity_custom_completion {
39
    /**
40
     * Fetches the completion state for a given completion rule.
41
     *
42
     * @param string $rule
43
     * @return int
44
     */
45
    public function get_state(string $rule): int {
46
        $this->validate_rule($rule);
47
        $userid = $this->userid;
48
        $cm = $this->cm;
49
        $status = questionnaire_get_completion_state($cm, $userid, $rule);
50
        return $status ? COMPLETION_COMPLETE : COMPLETION_INCOMPLETE;
51
    }
52
 
53
    /**
54
     * Fetch the list of custom completion rules that this module defines.
55
     *
56
     * @return array
57
     */
58
    public static function get_defined_custom_rules(): array {
59
        return [
60
            'completionsubmit'
61
        ];
62
    }
63
 
64
    /**
65
     * Returns an associative array of the descriptions of custom completion rules.
66
     *
67
     * @return array
68
     */
69
    public function get_custom_rule_descriptions(): array {
70
        return [
71
            'completionsubmit' => get_string('completionsubmit', 'questionnaire')
72
        ];
73
    }
74
 
75
    /**
76
     * Returns an array of all completion rules, in the order they should be displayed to users.
77
     *
78
     * @return array
79
     */
80
    public function get_sort_order(): array {
81
        return [
82
            'completionsubmit',
83
        ];
84
    }
85
}