• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

apsolu / local_apsolu / 18468445848

13 Oct 2025 02:06PM UTC coverage: 9.418% (+0.2%) from 9.224%
18468445848

push

github

jboulen
refactor(core): applique des corrections pour le nouveau coding style de Moodle

69 of 875 new or added lines in 51 files covered. (7.89%)

47 existing lines in 11 files now uncovered.

557 of 5914 relevant lines covered (9.42%)

0.12 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

63.79
/classes/core/grouping.php
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
namespace local_apsolu\core;
18

19
use core_course_category;
20

21
/**
22
 * Classe gérant les groupements d'activités sportives (sous-catégories de cours Moodle).
23
 *
24
 * @package    local_apsolu
25
 * @copyright  2020 Université Rennes 2 <dsi-contact@univ-rennes2.fr>
26
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27
 */
28
class grouping extends record {
29
    /**
30
     * Nom de la table de référence en base de données.
31
     */
32
    const TABLENAME = 'apsolu_courses_groupings';
33

34
    /** @var int|string Identifiant numérique du groupement d'activités sportives. */
35
    public $id = 0;
36

37
    /** @var string $name Nom du groupement d'activités sportives. */
38
    public $name = '';
39

40
    /** @var int $parent Entier représentant l'identifiant du groupement d'activité. */
41
    public $parent = '';
42

43
    /** @var string $url Page web décrivant le groupement d'activités sportives. */
44
    public $url = '';
45

46
    /**
47
     * Supprime un objet en base de données.
48
     *
49
     * @throws dml_exception A DML specific exception is thrown for any errors.
50
     *
51
     * @return bool true.
52
     */
53
    public function delete() {
54
        global $DB;
55

56
        // Démarre une transaction, si ce n'est pas déjà fait.
57
        if ($DB->is_transaction_started() === false) {
1✔
58
            $transaction = $DB->start_delegated_transaction();
1✔
59
        }
60

61
        // Supprime l'objet en base de données.
62
        $DB->delete_records(self::TABLENAME, ['id' => $this->id]);
1✔
63

64
        $coursecat = core_course_category::get($this->id, MUST_EXIST, true);
1✔
65
        $coursecat->delete_full();
1✔
66

67
        // Valide la transaction en cours.
68
        if (isset($transaction) === true) {
1✔
69
            $transaction->allow_commit();
×
70
        }
71

72
        return true;
1✔
73
    }
74

75
    /**
76
     * Recherche et instancie des objets depuis la base de données.
77
     *
78
     * @see Se référer à la documentation de la méthode get_records() de la variable globale $DB.
79
     * @param array|null $conditions Critères de sélection des objets.
80
     * @param string     $sort       Champs par lesquels s'effectue le tri.
81
     * @param string     $fields     Liste des champs retournés.
82
     * @param int        $limitfrom  Retourne les enregistrements à partir de n+$limitfrom.
83
     * @param int        $limitnum   Nombre total d'enregistrements retournés.
84
     *
85
     * @return array Un tableau d'objets instanciés.
86
     */
87
    public static function get_records(
88
        ?array $conditions = null,
89
        string $sort = '',
90
        string $fields = '*',
91
        int $limitfrom = 0,
92
        int $limitnum = 0
93
    ) {
94
        global $DB;
95

96
        if ($conditions !== null) {
×
97
            throw new coding_exception('You cannot define your own value for $conditions argument.');
×
98
        }
99

100
        if ($fields !== '*') {
×
101
            throw new coding_exception('You cannot define your own value for $fields argument.');
×
102
        }
103

104
        if ($limitfrom !== 0) {
×
105
            throw new coding_exception('You cannot define your own value for $limitfrom argument.');
×
106
        }
107

108
        if ($limitnum !== 0) {
×
109
            throw new coding_exception('You cannot define your own value for $limitnum argument.');
×
110
        }
111

112
        $records = [];
×
113

114
        $sql = "SELECT cc.id, cc.name, cc.parent, acg.url
×
115
                  FROM {course_categories} cc
116
                  JOIN {apsolu_courses_groupings} acg ON acg.id = cc.id";
×
117
        if ($sort !== '') {
×
NEW
118
            $sql .= " ORDER BY " . $sort;
×
119
        }
120

121
        foreach ($DB->get_records_sql($sql) as $data) {
×
122
            $record = new grouping();
×
123
            $record->set_vars($data);
×
124
            $records[$record->id] = $record;
×
125
        }
126

127
        return $records;
×
128
    }
129

130
    /**
131
     * Charge un objet à partir de son identifiant.
132
     *
133
     * @param int|string $recordid Identifiant de l'objet à charger.
134
     * @param bool       $required Si true, lève une exception lorsque l'objet n'existe pas.
135
     *                             Valeur par défaut: false (pas d'exception levée).
136
     *
137
     * @return void
138
     */
139
    public function load($recordid, bool $required = false) {
140
        global $DB;
141

142
        $strictness = IGNORE_MISSING;
1✔
143
        if ($required) {
1✔
144
            $strictness = MUST_EXIST;
×
145
        }
146

147
        $sql = "SELECT cc.id, cc.name, cc.parent, acg.url" .
1✔
148
            " FROM {course_categories} cc" .
1✔
149
            " JOIN {apsolu_courses_groupings} acg ON acg.id = cc.id" .
1✔
150
            " WHERE acg.id = :recordid";
1✔
151
        $record = $DB->get_record_sql($sql, ['recordid' => $recordid], $strictness);
1✔
152

153
        if ($record === false) {
1✔
154
            return;
1✔
155
        }
156

157
        $this->set_vars($record);
1✔
158
    }
159

160
    /**
161
     * Enregistre un objet en base de données.
162
     *
163
     * @throws dml_exception A DML specific exception is thrown for any errors.
164
     *
165
     * @param object|null $data  StdClass représentant l'objet à enregistrer.
166
     * @param object|null $mform Mform représentant un formulaire Moodle nécessaire à la gestion d'un champ de type editor.
167
     *
168
     * @return void
169
     */
170
    public function save(?object $data = null, ?object $mform = null) {
171
        global $DB;
172

173
        if ($data !== null) {
1✔
174
            $this->set_vars($data);
1✔
175
        }
176

177
        // Démarre une transaction, si ce n'est pas déjà fait.
178
        if ($DB->is_transaction_started() === false) {
1✔
179
            $transaction = $DB->start_delegated_transaction();
1✔
180
        }
181

182
        if (empty($this->id) === true) {
1✔
183
            $this->parent = 0;
1✔
184
            $coursecat = core_course_category::create($this);
1✔
185

186
            $this->id = $coursecat->id;
1✔
187

188
            // Note: insert_record() exige l'absence d'un id.
189
            $sql = "INSERT INTO {apsolu_courses_groupings} (id, url) VALUES(:id, :url)";
1✔
190
            $DB->execute($sql, ['id' => $this->id, 'url' => $this->url]);
1✔
191
        } else {
192
            $DB->update_record(self::TABLENAME, $this);
1✔
193

194
            $category = $DB->get_record('course_categories', ['id' => $this->id]);
1✔
195
            if ($category !== false) {
1✔
196
                $category->name = $this->name;
1✔
197
                $category->parent = 0;
1✔
198
                $DB->update_record('course_categories', $category);
1✔
199
            }
200
        }
201

202
        // Trie la catégorie parent.
203
        $category = core_course_category::get((int) $this->parent);
1✔
204
        if ($category->can_resort_subcategories()) {
1✔
205
            \core_course\management\helper::action_category_resort_subcategories($category, $sort = 'name');
×
206
        }
207

208
        // Valide la transaction en cours.
209
        if (isset($transaction) === true) {
1✔
210
            $transaction->allow_commit();
1✔
211
        }
212
    }
213
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc