-
Notifications
You must be signed in to change notification settings - Fork 1
/
helpers.php
34 lines (30 loc) · 862 Bytes
/
helpers.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
function view(...$names) {
include('view/header.php');
foreach ($names as $name)
if (substr($name, 0, 1) == '<')
echo $name;
else
include("view/{$name}.php");
include('view/footer.php');
}
function helper_get_moodle_user($user) {
$user = (array) $user;
if (!$user['active']) return false;
$moodle = new App\Moodle($user['token']);
if (!$moodle->checkToken()) {
$moodle->login($user['login'], $user['password']);
if ($moodle->checkToken()) {
$user['token'] = $moodle->token();
App\User::token($user['id'], $user['token']);
} else {
$user['active'] = false;
App\User::active($user['id'], false);
return false;
}
}
return [
'user' => $user,
'moodle' => $moodle,
];
}