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

apsolu / local_apsolu / 18495050592

14 Oct 2025 10:31AM UTC coverage: 9.435% (+0.2%) from 9.224%
18495050592

push

github

jboulen
fix(federation): améliore le champ numéro de section sur le formulaire d'exportation des licences

559 of 5925 relevant lines covered (9.43%)

0.12 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]);
8✔
50

51
        return true;
8✔
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(
67
        ?array $conditions = null,
68
        string $sort = '',
69
        string $fields = '*',
70
        int $limitfrom = 0,
71
        int $limitnum = 0
72
    ) {
73
        global $DB;
74

75
        $classname = get_called_class();
1✔
76

77
        $records = [];
1✔
78

79
        foreach ($DB->get_records($classname::TABLENAME, $conditions, $sort, $fields, $limitfrom, $limitnum) as $data) {
1✔
80
            $record = new $classname();
×
81
            $record->set_vars($data);
×
82
            $records[$record->id] = $record;
×
83
        }
84

85
        return $records;
1✔
86
    }
87

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

100
        $strictness = IGNORE_MISSING;
8✔
101
        if ($required) {
8✔
102
            $strictness = MUST_EXIST;
×
103
        }
104

105
        $record = $DB->get_record(get_called_class()::TABLENAME, ['id' => $recordid], $fields = '*', $strictness);
8✔
106

107
        if ($record === false) {
8✔
108
            return;
8✔
109
        }
110

111
        $this->set_vars($record);
8✔
112
    }
113

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

127
        if ($data !== null) {
6✔
128
            $this->set_vars($data);
6✔
129
        }
130

131
        if (empty($this->id) === true) {
6✔
132
            $this->id = $DB->insert_record(get_called_class()::TABLENAME, $this);
6✔
133
        } else {
134
            $DB->update_record(get_called_class()::TABLENAME, $this);
6✔
135
        }
136
    }
137

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

151
            $this->{$var} = $data->{$var};
×
152
            if (is_string($this->{$var}) === true) {
×
153
                $this->{$var} = trim($this->{$var});
×
154
            }
155
        }
156
    }
157
}
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