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\Traits\ReportingFilterTrait; |
10
|
|
|
use Display; |
11
|
|
|
use Exception; |
12
|
|
|
use Symfony\Component\HttpFoundation\Response as HttpResponse; |
13
|
|
|
|
14
|
|
|
class ReportingController extends BaseController |
15
|
|
|
{ |
16
|
|
|
use ReportingFilterTrait; |
17
|
|
|
|
18
|
|
|
public function __invoke(): HttpResponse |
19
|
|
|
{ |
20
|
|
|
parent::__invoke(); |
21
|
|
|
|
22
|
|
|
$exercise = $this->em->find( |
23
|
|
|
CQuiz::class, |
24
|
|
|
$this->request->query->getInt('id') |
25
|
|
|
); |
26
|
|
|
|
27
|
|
|
if (!$exercise) { |
28
|
|
|
throw new Exception(); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
$courseCode = api_get_course_id(); |
32
|
|
|
$sessionId = api_get_session_id(); |
33
|
|
|
|
34
|
|
|
$tab1 = $this->generateTabSearch($exercise, $courseCode, $sessionId); |
35
|
|
|
|
36
|
|
|
$tab2 = $this->generateTabSampling($exercise); |
37
|
|
|
|
38
|
|
|
$content = Display::tabs( |
39
|
|
|
[ |
40
|
|
|
$this->plugin->get_lang('ReportByAttempts'), |
41
|
|
|
$this->plugin->get_lang('RandomSampling'), |
42
|
|
|
], |
43
|
|
|
[$tab1, $tab2], |
44
|
|
|
'exercise-focused-tabs', |
45
|
|
|
[], |
46
|
|
|
[], |
47
|
|
|
1 |
48
|
|
|
); |
49
|
|
|
|
50
|
|
|
$this->setBreadcrumb($exercise->getId()); |
51
|
|
|
|
52
|
|
|
return $this->renderView( |
53
|
|
|
get_lang('ReportByAttempts'), |
54
|
|
|
$content, |
55
|
|
|
$exercise->getTitle() |
56
|
|
|
); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @throws Exception |
61
|
|
|
*/ |
62
|
|
|
private function generateTabSearch(CQuiz $exercise, string $courseCode, int $sessionId): string |
63
|
|
|
{ |
64
|
|
|
$form = $this->createForm(); |
65
|
|
|
$form->updateAttributes(['action' => api_get_self().'?'.api_get_cidreq().'&id='.$exercise->getId()]); |
66
|
|
|
$form->addHidden('cidReq', $courseCode); |
67
|
|
|
$form->addHidden('id_session', $sessionId); |
68
|
|
|
$form->addHidden('gidReq', 0); |
69
|
|
|
$form->addHidden('gradebook', 0); |
70
|
|
|
$form->addHidden('origin', api_get_origin()); |
71
|
|
|
$form->addHidden('id', $exercise->getId()); |
72
|
|
|
|
73
|
|
|
$tableHtml = ''; |
74
|
|
|
|
75
|
|
|
if ($form->validate()) { |
76
|
|
|
$formValues = $form->exportValues(); |
77
|
|
|
|
78
|
|
|
$results = $this->findResults($formValues); |
79
|
|
|
|
80
|
|
|
$tableHtml = $this->createTable($results)->toHtml(); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
return $form->returnForm().$tableHtml; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
private function generateTabSampling(CQuiz $exercise): string |
87
|
|
|
{ |
88
|
|
|
$results = $this->findRandomResults($exercise->getId()); |
89
|
|
|
|
90
|
|
|
return $this->createTable($results)->toHtml(); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @return array<int, TrackEExercises> |
95
|
|
|
*/ |
96
|
|
|
private function setBreadcrumb($exerciseId): void |
97
|
|
|
{ |
98
|
|
|
$codePath = api_get_path('WEB_CODE_PATH'); |
99
|
|
|
$cidReq = api_get_cidreq(); |
100
|
|
|
|
101
|
|
|
$GLOBALS['interbreadcrumb'][] = [ |
102
|
|
|
'url' => $codePath."exercise/exercise.php?$cidReq", |
103
|
|
|
'name' => get_lang('Exercises'), |
104
|
|
|
]; |
105
|
|
|
$GLOBALS['interbreadcrumb'][] = [ |
106
|
|
|
'url' => $codePath."exercise/exercise_report.php?$cidReq&".http_build_query(['exerciseId' => $exerciseId]), |
107
|
|
|
'name' => get_lang('StudentScore'), |
108
|
|
|
]; |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|