|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* @author Xavier Chopin <[email protected]> |
|
5
|
|
|
* |
|
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
7
|
|
|
* file that was distributed with this source code. |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace App\Controller; |
|
11
|
|
|
|
|
12
|
|
|
use App\Model\User; |
|
13
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
14
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
|
15
|
|
|
|
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @Route("/tools") |
|
19
|
|
|
*/ |
|
20
|
|
|
class AdminController extends AbstractController implements AdminAuthenticatedController |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* GET : Renders a form page to find a student |
|
24
|
|
|
* POST : Returns JSON data for a name given |
|
25
|
|
|
* |
|
26
|
|
|
* @Route("/find-student", name="find-student") |
|
27
|
|
|
* @param Request $request |
|
28
|
|
|
* @return \Symfony\Component\HttpFoundation\JsonResponse | \Symfony\Component\HttpFoundation\Response |
|
29
|
|
|
*/ |
|
30
|
|
|
public function findStudent(Request $request) |
|
31
|
|
|
{ |
|
32
|
|
|
if ($request->isMethod('POST')) { |
|
33
|
|
|
$keyword = $request->get('name'); |
|
34
|
|
|
$filter = '(&(businesscategory=E*)(displayname=*' . $keyword . '*))'; |
|
35
|
|
|
$students = $this->ldap($filter, ['displayname', 'uid']); |
|
36
|
|
|
$res = []; |
|
37
|
|
|
|
|
38
|
|
|
foreach($students as $student) { |
|
39
|
|
|
if ($student['uid'][0] != null) |
|
40
|
|
|
$res += [ $student['uid'][0] => $student['displayname'][0] ]; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
return $this->json($res); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
return $this->render('Admin/find-student.twig'); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
|
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Renders the profile of a student with several data from OpenLRW API. |
|
53
|
|
|
* |
|
54
|
|
|
* @Route("/student-profile/{id}", name="student-profile") |
|
55
|
|
|
* @param Request $request |
|
56
|
|
|
* @param $id |
|
57
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
|
58
|
|
|
*/ |
|
59
|
|
|
public function studentProfile(Request $request, $id = '') |
|
|
|
|
|
|
60
|
|
|
{ |
|
61
|
|
|
$classes = []; |
|
62
|
|
|
$moodleId = User::moodleId($id); |
|
63
|
|
|
|
|
64
|
|
|
if ($moodleId === null) { |
|
65
|
|
|
$this->addFlash('error', "Student `$id` does not exist"); |
|
66
|
|
|
return $this->redirectToRoute('home'); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
$enrollments = $this->http->get('users/' . User::moodleId($id) . '/enrollments', [ |
|
70
|
|
|
'headers' => ['Authorization' => 'Bearer ' . $this->createJWT()->token] |
|
71
|
|
|
]); |
|
72
|
|
|
|
|
73
|
|
|
foreach (json_decode($enrollments->getBody()->getContents()) as $enrollment) { |
|
74
|
|
|
if ($enrollment->class->title != null) |
|
75
|
|
|
array_push($classes, $enrollment->class); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
return $this->render('admin/user.twig',[ |
|
79
|
|
|
'classes' => $classes, |
|
80
|
|
|
'student_name' => $this->ldapFirst("uid=$id")['displayname'][0] |
|
81
|
|
|
]); |
|
82
|
|
|
|
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.