Passed
Pull Request — 1.11.x (#4900)
by Angel Fernando Quiroz
08:52
created

DetailController::getTable()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 24
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 24
rs 9.8333
cc 2
nc 2
nop 1
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\CQuiz;
9
use Chamilo\PluginBundle\ExerciseFocused\Entity\Log;
10
use Display;
11
use Doctrine\ORM\OptimisticLockException;
12
use Doctrine\ORM\ORMException;
13
use Doctrine\ORM\TransactionRequiredException;
14
use Exception;
15
use HTML_Table;
16
use Symfony\Component\HttpFoundation\Response as HttpResponse;
17
18
class DetailController extends BaseController
19
{
20
    /**
21
     * @throws OptimisticLockException
22
     * @throws TransactionRequiredException
23
     * @throws ORMException
24
     * @throws Exception
25
     */
26
    public function __invoke(): HttpResponse
27
    {
28
        parent::__invoke();
29
30
        $exeId = $this->request->query->getInt('id');
31
        $exe = $this->em->find(TrackEExercises::class, $exeId);
32
33
        if (!$exe) {
34
            throw new Exception();
35
        }
36
37
        $session = api_get_session_entity($exe->getSessionId());
38
        $user = api_get_user_entity($exe->getExeUserId());
39
40
        $subHeader = Display::page_subheader($user->getCompleteNameWithUsername());
41
        $subHeader2 = $session ? Display::page_subheader2($session->getName()) : '';
0 ignored issues
show
introduced by
$session is of type Chamilo\CoreBundle\Entity\Session, thus it always evaluated to true.
Loading history...
42
43
        $logs = $this->logRepository->findBy(['exe' => $exe], ['updatedAt' => 'ASC']);
44
        $table = $this->getTable($logs);
45
46
        return HttpResponse::create(
47
            $subHeader.$subHeader2.$table->toHtml()
48
        );
49
    }
50
51
    /**
52
     * @param array<int, Log> $logs
53
     *
54
     * @return void
55
     */
56
    private function getTable(array $logs): HTML_Table
57
    {
58
        $table = new HTML_Table(['class' => 'table table-hover table-striped data_table']);
59
        $table->setHeaderContents(0, 0, get_lang('Action'));
60
        $table->setHeaderContents(0, 1, get_lang('DateTime'));
61
62
        $row = 1;
63
64
        foreach ($logs as $log) {
65
            $table->setCellContents(
66
                $row,
67
                0,
68
                $this->plugin->getActionTitle($log->getAction())
69
            );
70
            $table->setCellContents(
71
                $row,
72
                1,
73
                api_get_local_time($log->getCreatedAt(), null, null, true, true, true)
74
            );
75
76
            $row++;
77
        }
78
79
        return $table;
80
    }
81
}
82