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

apsolu / enrol_select / 18468496422

13 Oct 2025 02:08PM UTC coverage: 13.833% (-0.05%) from 13.886%
18468496422

push

github

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

11 of 249 new or added lines in 4 files covered. (4.42%)

4 existing lines in 2 files now uncovered.

144 of 1041 relevant lines covered (13.83%)

0.55 hits per line

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

0.0
/classes/task/check_enrolment_payment.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 enrol_select\task;
18

19
use enrol_select_plugin;
20
use UniversiteRennes2\Apsolu\Payment;
21

22
/**
23
 * Classe représentant la tâche pour vérifier les paiements à l'inscription.
24
 *
25
 * @package    enrol_select
26
 * @copyright  2023 Université Rennes 2 <dsi-contact@univ-rennes2.fr>
27
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28
 */
29
class check_enrolment_payment extends \core\task\adhoc_task {
30
    /**
31
     * Retourne le nom de la tâche.
32
     *
33
     * @return string
34
     */
35
    public function get_name() {
36
        // Shown in admin screens.
37
        return get_string('check_enrolment_payment', 'enrol_select');
×
38
    }
39

40
    /**
41
     * Execute la tâche.
42
     *
43
     * @return void
44
     */
45
    public function execute() {
46
        global $CFG, $DB;
×
47

NEW
48
        require_once($CFG->dirroot . '/enrol/select/lib.php');
×
NEW
49
        require_once($CFG->dirroot . '/local/apsolu/classes/apsolu/payment.php');
×
50

51
        $customdata = $this->get_custom_data();
×
52
        $course = $DB->get_record('course', ['id' => $customdata->courseid]);
×
53

54
        if ($course === false) {
×
55
            // Le cours ne semble plus exister.
56
            return;
×
57
        }
58

59
        // Récupère les cartes dues pour le cours donné.
60
        $cards = [];
×
61
        foreach (Payment::get_user_cards_status_per_course($customdata->courseid, $this->get_userid()) as $card) {
×
62
            if ($card->status !== Payment::DUE) {
×
63
                continue;
×
64
            }
65

66
            $cards[] = $card->name;
×
67
        }
68

69
        if (isset($cards[0]) === false) {
×
70
            // Aucune carte due.
71
            return;
×
72
        }
73

74
        $enrolselectplugin = new enrol_select_plugin();
×
75

76
        // Détermine si l'utilisateur est toujours inscrit.
77
        $conditions = [
×
78
            'enrolid' => $customdata->enrolid,
×
79
            'userid' => $this->get_userid(),
×
80
            'status' => $enrolselectplugin::ACCEPTED,
×
81
        ];
×
82
        if ($DB->count_records('user_enrolments', $conditions) === 0) {
×
83
            // L'utilisateur n'est plus inscrit à ce cours.
84
            return;
×
85
        }
86

87
        // Désinscrit l'utilisateur du cours.
88
        $conditions = ['id' => $customdata->enrolid, 'enrol' => 'select', 'courseid' => $customdata->courseid];
×
89
        $instance = $DB->get_record('enrol', $conditions);
×
90

91
        $enrolselectplugin->unenrol_user($instance, $this->get_userid());
×
92

93
        // Notifie l'utilisateur.
94
        $cardlist = implode('</li><li>', $cards);
×
95
        $functionalcontact = get_config('local_apsolu', 'functional_contact');
×
96
        $params = ['coursename' => $course->fullname, 'cards' => $cardlist, 'contact' => $functionalcontact];
×
97
        $message = get_string('unenrolment_message', 'enrol_select', $params);
×
98

99
        $eventdata = new \core\message\message();
×
100
        $eventdata->name = 'select_notification';
×
101
        $eventdata->component = 'enrol_select';
×
102
        $eventdata->userfrom = get_admin();
×
103
        $eventdata->userto = $this->get_userid();
×
104
        $params = format_string($course->fullname, $striplinks = true, $course->id);
×
105
        $eventdata->subject = get_string('unenrolment_from', 'enrol_select', $course->fullname);
×
106
        $eventdata->fullmessage = $message;
×
107
        $eventdata->fullmessageformat = FORMAT_HTML;
×
108
        $eventdata->fullmessagehtml = $message;
×
109
        $eventdata->smallmessage = '';
×
110
        $eventdata->notification = 1;
×
111
        $eventdata->courseid = $course->id;
×
112

113
        message_send($eventdata);
×
114
    }
115
}
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