|
1
|
|
|
<?php |
|
2
|
|
|
/* For licensing terms, see /license.txt */ |
|
3
|
|
|
|
|
4
|
|
|
namespace Chamilo\CoreBundle\Controller\User; |
|
5
|
|
|
|
|
6
|
|
|
use Chamilo\CoreBundle\Entity\Course; |
|
7
|
|
|
use Chamilo\CoreBundle\Entity\CourseRelUser; |
|
8
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
|
9
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
10
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
11
|
|
|
use Chamilo\CoreBundle\Controller\BaseController; |
|
12
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
|
13
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; |
|
14
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Class UserController |
|
18
|
|
|
* @package Chamilo\CoreBundle\Controller |
|
19
|
|
|
* @author Julio Montoya <[email protected]> |
|
20
|
|
|
*/ |
|
21
|
|
|
class UserController extends BaseController |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* @Route("/me") |
|
25
|
|
|
* @Method({"GET"}) |
|
26
|
|
|
*/ |
|
27
|
|
|
public function indexAction(Request $request) |
|
28
|
|
|
{ |
|
29
|
|
|
$userInfo = api_get_user_info($this->getUser()->getUserId()); |
|
30
|
|
|
|
|
31
|
|
|
return $this->getTemplate()->render( |
|
32
|
|
|
$this->getTemplatePath().'me.tpl', |
|
33
|
|
|
array('user', $userInfo) |
|
34
|
|
|
); |
|
35
|
|
|
|
|
36
|
|
|
$response = $this->getTemplate()->renderTemplate( |
|
|
|
|
|
|
37
|
|
|
$this->getTemplatePath().'me.tpl' |
|
38
|
|
|
); |
|
39
|
|
|
|
|
40
|
|
|
return new Response($response, 200, array('user', $userInfo)); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @Route("/{username}") |
|
45
|
|
|
* @Method({"GET"}) |
|
46
|
|
|
* @Template("ChamiloCoreBundle:User:profile.html.twig") |
|
47
|
|
|
*/ |
|
48
|
|
|
public function profileAction($username) |
|
49
|
|
|
{ |
|
50
|
|
|
$userId = \UserManager::get_user_id_from_username($username); |
|
51
|
|
|
$userInfo = api_get_user_info($userId); |
|
52
|
|
|
|
|
53
|
|
|
return array( |
|
54
|
|
|
'user' => $userInfo, |
|
55
|
|
|
'form_send_message' => \MessageManager::generate_message_form( |
|
56
|
|
|
'send_message' |
|
57
|
|
|
), |
|
58
|
|
|
'form_send_invitation' => \MessageManager::generate_invitation_form( |
|
59
|
|
|
'send_invitation' |
|
60
|
|
|
), |
|
61
|
|
|
); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @Route("/me/my_courses", options={"expose"=true}) |
|
66
|
|
|
* @Method({"GET"}) |
|
67
|
|
|
*/ |
|
68
|
|
|
public function myCoursesAction() |
|
69
|
|
|
{ |
|
70
|
|
|
$user = $this->getUser(); |
|
71
|
|
|
$courses = $user->getCourses(); |
|
72
|
|
|
|
|
73
|
|
|
$output = array(); |
|
74
|
|
|
/** @var CourseRelUser $courseRelUser */ |
|
75
|
|
|
foreach ($courses as $courseRelUser) { |
|
76
|
|
|
$course = $courseRelUser->getCourse(); |
|
77
|
|
|
if ($course) { |
|
78
|
|
|
$output[] = array( |
|
79
|
|
|
'id' => $course->getId(), |
|
80
|
|
|
'title' => $course->getTitle(), |
|
81
|
|
|
); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
return $response = new JsonResponse(array('items' => $output)); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @Route("/online") |
|
90
|
|
|
* @Method({"GET"}) |
|
91
|
|
|
*/ |
|
92
|
|
|
public function onlineAction(Application $app) |
|
93
|
|
|
{ |
|
94
|
|
|
$response = $app['template']->renderLayout('layout_1_col.tpl'); |
|
95
|
|
|
|
|
96
|
|
|
return new Response($response, 200, array()); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* {@inheritdoc} |
|
101
|
|
|
*/ |
|
102
|
|
|
public function getTemplatePath() |
|
103
|
|
|
{ |
|
104
|
|
|
return 'user/'; |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.
Unreachable code is most often the result of
return,dieorexitstatements that have been added for debug purposes.In the above example, the last
return falsewill never be executed, because a return statement has already been met in every possible execution path.