Vous avez reçu un message "Your GitLab account has been locked ..." ? Pas d'inquiétude : lisez cet article https://docs.gricad-pages.univ-grenoble-alpes.fr/help/unlock/

helper.php 2.2 KB
Newer Older
1
2
3
4
5
6
7
8
9
<?php

/**
 * @copyright   2019 Université Grenoble Alpes
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */

namespace mod_labnbook\local;

10
11
use mod_labnbook\fetch;

12
13
14
15
16
/* @var $DB \moodle_database */

/**
 * Misc functions.
 */
17
18
19
20
21
22
23
24
25
class helper
{
    /**
     * Stop loading the current page if the current user has no LabnBook account.
     * Redirects on an account binding|creation if necessary.
     *
     * @global \Stdclass $COURSE
     * @throws \moodle_exception
     */
Francois Gannaz's avatar
Francois Gannaz committed
26
27
    public static function requireLabnbookAuthentication()
    {
28
29
30
31
        global $COURSE;
        if (fetch\user::isAuthenticated()) {
            return;
        }
Francois Gannaz's avatar
Francois Gannaz committed
32
        $institutionFetcher = new fetch\institution();
33
34
35
36
37
38
        switch ($institutionFetcher->loginUser()) {
            case fetch\institution::OK:
               return;
            case fetch\institution::ERROR_LOGIN_UNKNOWN:
                redirect(
                    "/mod/labnbook/user-binding.php?courseid={$COURSE->id}&return="
Francois Gannaz's avatar
Francois Gannaz committed
39
                    . \base64_encode($_SERVER['REQUEST_URI'])
40
41
42
43
44
45
46
47
                );
                break;
            case fetch\institution::ERROR_TOKEN_NOTVALID:
               throw new \moodle_exception("Internal error with LabNbook");
            default:
               throw new \moodle_exception("Unknown error with LabNbook");
        }
    }
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73

    /**
     * Grant teacher access to the LnB missions and classes linked to the course.
     *
     * @param int $courseId
     */
    public static function grantTeacherAccess($courseId)
    {
        global $DB, $SESSION;
        if (!empty($SESSION->labnbook->grantTeacherAccess[$courseId])) {
            return;
        }
        if (!fetch\user::isAuthenticated()) {
            return;
        }
        $ids = $DB->get_fieldset_select("labnbook", "labnbook_teamconfigid", "courseid = " . (int) $courseId);
        if ($ids) {
            $userFetcher = new fetch\user();
            $userFetcher->grantMissionsAccess($ids);
        }
        // use session to avoid repeating this query
        if (empty($SESSION->labnbook->grantTeacherAccess)) {
            $SESSION->labnbook->grantTeacherAccess = [];
        }
        $SESSION->labnbook->grantTeacherAccess[$courseId] = true;
    }
74
}