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

apsolu / local_apsolu / 14666526810

25 Apr 2025 01:04PM UTC coverage: 10.429% (-2.8%) from 13.18%
14666526810

push

github

jboulen
test(github): supprime temporairement l'exécution des tests Behat sur Moodle 5.x et supérieur

518 of 4967 relevant lines covered (10.43%)

0.49 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) {
4✔
58
            $transaction = $DB->start_delegated_transaction();
4✔
59
        }
60

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

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

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

72
        return true;
4✔
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(?array $conditions = null, string $sort = '', string $fields = '*',
88
                                       int $limitfrom = 0, int $limitnum = 0) {
89
        global $DB;
90

91
        if ($conditions !== null) {
×
92
            throw new coding_exception('You cannot define your own value for $conditions argument.');
×
93
        }
94

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

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

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

107
        $records = [];
×
108

109
        $sql = "SELECT cc.id, cc.name, cc.parent, acg.url
×
110
                  FROM {course_categories} cc
111
                  JOIN {apsolu_courses_groupings} acg ON acg.id = cc.id";
×
112
        if ($sort !== '') {
×
113
            $sql .= " ORDER BY ".$sort;
×
114
        }
115

116
        foreach ($DB->get_records_sql($sql) as $data) {
×
117
            $record = new grouping();
×
118
            $record->set_vars($data);
×
119
            $records[$record->id] = $record;
×
120
        }
121

122
        return $records;
×
123
    }
124

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

137
        $strictness = IGNORE_MISSING;
4✔
138
        if ($required) {
4✔
139
            $strictness = MUST_EXIST;
×
140
        }
141

142
        $sql = "SELECT cc.id, cc.name, cc.parent, acg.url".
4✔
143
            " FROM {course_categories} cc".
4✔
144
            " JOIN {apsolu_courses_groupings} acg ON acg.id = cc.id".
4✔
145
            " WHERE acg.id = :recordid";
4✔
146
        $record = $DB->get_record_sql($sql, ['recordid' => $recordid], $strictness);
4✔
147

148
        if ($record === false) {
4✔
149
            return;
4✔
150
        }
151

152
        $this->set_vars($record);
4✔
153
    }
154

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

168
        if ($data !== null) {
4✔
169
            $this->set_vars($data);
4✔
170
        }
171

172
        // Démarre une transaction, si ce n'est pas déjà fait.
173
        if ($DB->is_transaction_started() === false) {
4✔
174
            $transaction = $DB->start_delegated_transaction();
4✔
175
        }
176

177
        if (empty($this->id) === true) {
4✔
178
            $this->parent = 0;
4✔
179
            $coursecat = core_course_category::create($this);
4✔
180

181
            $this->id = $coursecat->id;
4✔
182

183
            // Note: insert_record() exige l'absence d'un id.
184
            $sql = "INSERT INTO {apsolu_courses_groupings} (id, url) VALUES(:id, :url)";
4✔
185
            $DB->execute($sql, ['id' => $this->id, 'url' => $this->url]);
4✔
186
        } else {
187
            $DB->update_record(self::TABLENAME, $this);
4✔
188

189
            $category = $DB->get_record('course_categories', ['id' => $this->id]);
4✔
190
            if ($category !== false) {
4✔
191
                $category->name = $this->name;
4✔
192
                $category->parent = 0;
4✔
193
                $DB->update_record('course_categories', $category);
4✔
194
            }
195
        }
196

197
        // Trie la catégorie parent.
198
        $category = core_course_category::get((int) $this->parent);
4✔
199
        if ($category->can_resort_subcategories()) {
4✔
200
            \core_course\management\helper::action_category_resort_subcategories($category, $sort = 'name');
×
201
        }
202

203
        // Valide la transaction en cours.
204
        if (isset($transaction) === true) {
4✔
205
            $transaction->allow_commit();
4✔
206
        }
207
    }
208
}
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