1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* For licensing terms, see /license.txt */ |
4
|
|
|
|
5
|
|
|
namespace Chamilo\PluginBundle\ExerciseFocused\Controller; |
6
|
|
|
|
7
|
|
|
use Chamilo\CoreBundle\Entity\TrackEExercises; |
8
|
|
|
use Chamilo\CourseBundle\Entity\CQuizQuestion; |
9
|
|
|
use Chamilo\PluginBundle\ExerciseFocused\Entity\Log; |
10
|
|
|
use Chamilo\PluginBundle\ExerciseFocused\Traits\DetailControllerTrait; |
11
|
|
|
use Doctrine\ORM\OptimisticLockException; |
12
|
|
|
use Doctrine\ORM\ORMException; |
13
|
|
|
use Doctrine\ORM\TransactionRequiredException; |
14
|
|
|
use Exception; |
15
|
|
|
use Exercise; |
16
|
|
|
use HTML_Table; |
17
|
|
|
use Symfony\Component\HttpFoundation\Response as HttpResponse; |
18
|
|
|
|
19
|
|
|
class DetailController extends BaseController |
20
|
|
|
{ |
21
|
|
|
use DetailControllerTrait; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @throws OptimisticLockException |
25
|
|
|
* @throws TransactionRequiredException |
26
|
|
|
* @throws ORMException |
27
|
|
|
* @throws Exception |
28
|
|
|
*/ |
29
|
|
|
public function __invoke(): HttpResponse |
30
|
|
|
{ |
31
|
|
|
parent::__invoke(); |
32
|
|
|
|
33
|
|
|
$exeId = $this->request->query->getInt('id'); |
34
|
|
|
$exe = $this->em->find(TrackEExercises::class, $exeId); |
35
|
|
|
|
36
|
|
|
if (!$exe) { |
37
|
|
|
throw new Exception(); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
$user = api_get_user_entity($exe->getExeUserId()); |
41
|
|
|
|
42
|
|
|
$objExercise = new Exercise(); |
43
|
|
|
$objExercise->read($exe->getExeExoId()); |
44
|
|
|
|
45
|
|
|
$logs = $this->logRepository->findBy(['exe' => $exe], ['updatedAt' => 'ASC']); |
46
|
|
|
$table = $this->getTable($objExercise, $logs); |
47
|
|
|
|
48
|
|
|
$content = $this->generateHeader($objExercise, $user, $exe) |
49
|
|
|
.'<hr>' |
50
|
|
|
.$table->toHtml(); |
51
|
|
|
|
52
|
|
|
return HttpResponse::create($content); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param array<int, Log> $logs |
57
|
|
|
* |
58
|
|
|
* @return void |
59
|
|
|
*/ |
60
|
|
|
private function getTable(Exercise $objExercise, array $logs): HTML_Table |
61
|
|
|
{ |
62
|
|
|
$table = new HTML_Table(['class' => 'table table-hover table-striped data_table']); |
63
|
|
|
$table->setHeaderContents(0, 0, get_lang('Action')); |
64
|
|
|
$table->setHeaderContents(0, 1, get_lang('DateTime')); |
65
|
|
|
$table->setHeaderContents(0, 2, $this->plugin->get_lang('LevelReached')); |
66
|
|
|
|
67
|
|
|
$row = 1; |
68
|
|
|
|
69
|
|
|
foreach ($logs as $log) { |
70
|
|
|
$strLevel = ''; |
71
|
|
|
|
72
|
|
|
if (ONE_PER_PAGE == $objExercise->selectType()) { |
73
|
|
|
try { |
74
|
|
|
$question = $this->em->find(CQuizQuestion::class, $log->getLevel()); |
75
|
|
|
|
76
|
|
|
$strLevel = $question->getQuestion(); |
77
|
|
|
} catch (Exception $exception) { |
|
|
|
|
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
$table->setCellContents( |
82
|
|
|
$row, |
83
|
|
|
0, |
84
|
|
|
$this->plugin->getActionTitle($log->getAction()) |
85
|
|
|
); |
86
|
|
|
$table->setCellContents( |
87
|
|
|
$row, |
88
|
|
|
1, |
89
|
|
|
api_get_local_time($log->getCreatedAt(), null, null, true, true, true) |
90
|
|
|
); |
91
|
|
|
$table->setCellContents($row, 2, $strLevel); |
92
|
|
|
|
93
|
|
|
$row++; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
return $table; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|