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

apsolu / local_apsolu / 14643316622

24 Apr 2025 01:49PM UTC coverage: 10.48% (-2.7%) from 13.18%
14643316622

push

github

jboulen
fix(behat): supprime le positionnement de la variable debug à la valeur DEBUG_DEVELOPER

520 of 4962 relevant lines covered (10.48%)

0.24 hits per line

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

60.71
/classes/core/record.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
/**
20
 * Classe faisant le lien entre les classes PHP apsolu et la base de données Moodle.
21
 *
22
 * Elle regroupe les méthodes de base communes à tous les objets apsolu.
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
abstract class record {
29
    /**
30
     * Affiche une représentation textuelle de l'objet.
31
     *
32
     * @return string
33
     */
34
    public function __toString() {
35
        return $this->name;
×
36
    }
37

38
    /**
39
     * Supprime un objet en base de données.
40
     *
41
     * @throws dml_exception A DML specific exception is thrown for any errors.
42
     *
43
     * @return bool true.
44
     */
45
    public function delete() {
46
        global $DB;
47

48
        // Supprime l'objet en base de données.
49
        $DB->delete_records(get_called_class()::TABLENAME, ['id' => $this->id]);
16✔
50

51
        return true;
16✔
52
    }
53

54
    /**
55
     * Recherche et instancie des objets depuis la base de données.
56
     *
57
     * @see Se référer à la documentation de la méthode get_records() de la variable globale $DB.
58
     * @param array|null $conditions Critères de sélection des objets.
59
     * @param string     $sort       Champs par lesquels s'effectue le tri.
60
     * @param string     $fields     Liste des champs retournés.
61
     * @param int        $limitfrom  Retourne les enregistrements à partir de n+$limitfrom.
62
     * @param int        $limitnum   Nombre total d'enregistrements retournés.
63
     *
64
     * @return array Un tableau d'objets instanciés.
65
     */
66
    public static function get_records(?array $conditions = null, string $sort = '', string $fields = '*',
67
                                       int $limitfrom = 0, int $limitnum = 0) {
68
        global $DB;
69

70
        $classname = get_called_class();
2✔
71

72
        $records = [];
2✔
73

74
        foreach ($DB->get_records($classname::TABLENAME, $conditions, $sort, $fields, $limitfrom, $limitnum) as $data) {
2✔
75
            $record = new $classname();
×
76
            $record->set_vars($data);
×
77
            $records[$record->id] = $record;
×
78
        }
79

80
        return $records;
2✔
81
    }
82

83
    /**
84
     * Charge un objet à partir de son identifiant.
85
     *
86
     * @param int|string $recordid Identifiant de l'objet à charger.
87
     * @param bool       $required Si true, lève une exception lorsque l'objet n'existe pas.
88
     *                             Valeur par défaut: false (pas d'exception levée).
89
     *
90
     * @return void
91
     */
92
    public function load($recordid, bool $required = false) {
93
        global $DB;
94

95
        $strictness = IGNORE_MISSING;
16✔
96
        if ($required) {
16✔
97
            $strictness = MUST_EXIST;
×
98
        }
99

100
        $record = $DB->get_record(get_called_class()::TABLENAME, ['id' => $recordid], $fields = '*', $strictness);
16✔
101

102
        if ($record === false) {
16✔
103
            return;
16✔
104
        }
105

106
        $this->set_vars($record);
16✔
107
    }
108

109
    /**
110
     * Enregistre un objet en base de données.
111
     *
112
     * @throws dml_exception A DML specific exception is thrown for any errors.
113
     *
114
     * @param object|null $data  StdClass représentant l'objet à enregistrer.
115
     * @param object|null $mform Mform représentant un formulaire Moodle nécessaire à la gestion d'un champ de type editor.
116
     *
117
     * @return void
118
     */
119
    public function save(?object $data = null, ?object $mform = null) {
120
        global $DB;
121

122
        if ($data !== null) {
12✔
123
            $this->set_vars($data);
12✔
124
        }
125

126
        if (empty($this->id) === true) {
12✔
127
            $this->id = $DB->insert_record(get_called_class()::TABLENAME, $this);
12✔
128
        } else {
129
            $DB->update_record(get_called_class()::TABLENAME, $this);
12✔
130
        }
131
    }
132

133
    /**
134
     * Définis les propriétés de la classe à partir d'un objet.
135
     *
136
     * @param object $data stdClass représentant l'objet.
137
     *
138
     * @return void
139
     */
140
    protected function set_vars(object $data) {
141
        foreach (get_class_vars(get_called_class()) as $var => $value) {
×
142
            if (isset($data->{$var}) === false) {
×
143
                continue;
×
144
            }
145

146
            $this->{$var} = $data->{$var};
×
147
            if (is_string($this->{$var}) === true) {
×
148
                $this->{$var} = trim($this->{$var});
×
149
            }
150
        }
151
    }
152
}
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