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 - https://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 <https://www.gnu.org/licenses/>.
16
 
17
/**
18
 * Activity custom completion subclass for the stickynotes activity.
19
 *
20
 * @package     mod_stickynotes
21
 * @category    string
22
 * @copyright   2021 Olivier VALENTIN
23
 * @license     https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24
 */
25
 
26
declare(strict_types=1);
27
 
28
namespace mod_stickynotes\completion;
29
 
30
use core_completion\activity_custom_completion;
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
        $userid = $this->userid;
46
        $stickyid = $this->cm->instance;
47
 
48
        if (!$stickynotes = $DB->get_record('stickynotes', ['id' => $stickyid])) {
49
            throw new \moodle_exception('Unable to find stickynotes activity with id ' . $stickyid);
50
        }
51
 
52
        $params = ['userid' => $userid, 'stickyid' => $stickyid];
53
        $sql = "SELECT COUNT(*)
54
                           FROM {stickynotes_note} sn
55
                           JOIN {stickynotes_column} sc ON sn.stickycolid = sc.id
56
                          WHERE sn.userid = :userid
57
                            AND sc.stickyid = :stickyid";
58
 
59
        if ($rule == 'completionstickynotes') {
60
            $machin = $DB->count_records_sql($sql, $params);
61
            $status = $stickynotes->completionstickynotes <= $DB->count_records_sql($sql, $params);
62
        }
63
// print_object("nombre de notes ".$machin);
64
// echo "<br/>";
65
// print_object("statut ".$status);
66
// exit();
67
        return $status ? COMPLETION_COMPLETE : COMPLETION_INCOMPLETE;
68
    }
69
 
70
    /**
71
     * Fetch the list of custom completion rules that this module defines.
72
     *
73
     * @return array
74
     */
75
    public static function get_defined_custom_rules(): array {
76
        return [
77
            'completionstickynotes',
78
        ];
79
    }
80
 
81
    /**
82
     * Returns an associative array of the descriptions of custom completion rules.
83
     *
84
     * @return array
85
     */
86
    public function get_custom_rule_descriptions(): array {
87
        $completionstickynotes = $this->cm->customdata['customcompletionrules']['completionstickynotes'] ?? 0;
88
 
89
        return [
90
            'completionstickynotes' => get_string('completionstickynotesdetail:notes', 'mod_stickynotes', $completionstickynotes)
91
        ];
92
    }
93
 
94
    /**
95
     * Returns an array of all completion rules, in the order they should be displayed to users.
96
     *
97
     * @return array
98
     */
99
    public function get_sort_order(): array {
100
        return [
101
            'completionview',
102
            'completionstickynotes'
103
        ];
104
    }
105
}
106