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->generateTabResume($exercise); |
35
|
|
|
|
36
|
|
|
$tab2 = $this->generateTabSearch($exercise, $courseCode, $sessionId); |
37
|
|
|
|
38
|
|
|
$tab3 = $this->generateTabSampling($exercise); |
39
|
|
|
|
40
|
|
|
$content = Display::tabs( |
41
|
|
|
[ |
42
|
|
|
$this->plugin->get_lang('ReportByAttempts'), |
43
|
|
|
get_lang('Search'), |
44
|
|
|
$this->plugin->get_lang('RandomSampling'), |
45
|
|
|
], |
46
|
|
|
[$tab1, $tab2, $tab3], |
47
|
|
|
'exercise-focused-tabs', |
48
|
|
|
[], |
49
|
|
|
[], |
50
|
|
|
isset($_GET['submit']) ? 2 : 1 |
51
|
|
|
); |
52
|
|
|
|
53
|
|
|
$this->setBreadcrumb($exercise->getId()); |
54
|
|
|
|
55
|
|
|
return $this->renderView( |
56
|
|
|
$this->plugin->get_lang('ReportByAttempts'), |
57
|
|
|
$content, |
58
|
|
|
$exercise->getTitle() |
59
|
|
|
); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
private function generateTabResume(CQuiz $exercise): string |
63
|
|
|
{ |
64
|
|
|
$results = $this->findResultsInCourse($exercise->getId()); |
65
|
|
|
|
66
|
|
|
return $this->createTable($results)->toHtml(); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @throws Exception |
71
|
|
|
*/ |
72
|
|
|
private function generateTabSearch(CQuiz $exercise, string $courseCode, int $sessionId): string |
73
|
|
|
{ |
74
|
|
|
$form = $this->createForm(); |
75
|
|
|
$form->updateAttributes(['action' => api_get_self().'?'.api_get_cidreq().'&id='.$exercise->getId()]); |
76
|
|
|
$form->addHidden('cidReq', $courseCode); |
77
|
|
|
$form->addHidden('id_session', $sessionId); |
78
|
|
|
$form->addHidden('gidReq', 0); |
79
|
|
|
$form->addHidden('gradebook', 0); |
80
|
|
|
$form->addHidden('origin', api_get_origin()); |
81
|
|
|
$form->addHidden('id', $exercise->getId()); |
82
|
|
|
|
83
|
|
|
$tableHtml = ''; |
84
|
|
|
$actions = ''; |
85
|
|
|
|
86
|
|
|
if ($form->validate()) { |
87
|
|
|
$formValues = $form->exportValues(); |
88
|
|
|
|
89
|
|
|
$actionLeft = Display::url( |
90
|
|
|
Display::return_icon('export_excel.png', get_lang('ExportExcel'), [], ICON_SIZE_MEDIUM), |
91
|
|
|
api_get_path(WEB_PLUGIN_PATH).'exercisefocused/pages/export.php?'.http_build_query($formValues) |
92
|
|
|
); |
93
|
|
|
$actionRight = Display::toolbarButton( |
94
|
|
|
get_lang('Clean'), |
95
|
|
|
api_get_path(WEB_PLUGIN_PATH) |
96
|
|
|
.'exercisefocused/pages/reporting.php?' |
97
|
|
|
.api_get_cidreq().'&'.http_build_query(['id' => $exercise->getId(), 'submit' => '']), |
98
|
|
|
'search' |
99
|
|
|
); |
100
|
|
|
|
101
|
|
|
$actions = Display::toolbarAction( |
102
|
|
|
'em-actions', |
103
|
|
|
[$actionLeft, $actionRight] |
104
|
|
|
); |
105
|
|
|
|
106
|
|
|
$results = $this->findResults($formValues); |
107
|
|
|
|
108
|
|
|
$tableHtml = $this->createTable($results)->toHtml(); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
return $form->returnForm().$actions.$tableHtml; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
private function generateTabSampling(CQuiz $exercise): string |
115
|
|
|
{ |
116
|
|
|
$results = $this->findRandomResults($exercise->getId()); |
117
|
|
|
|
118
|
|
|
return $this->createTable($results)->toHtml(); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @return array<int, TrackEExercises> |
123
|
|
|
*/ |
124
|
|
|
private function setBreadcrumb($exerciseId): void |
125
|
|
|
{ |
126
|
|
|
$codePath = api_get_path('WEB_CODE_PATH'); |
127
|
|
|
$cidReq = api_get_cidreq(); |
128
|
|
|
|
129
|
|
|
$GLOBALS['interbreadcrumb'][] = [ |
130
|
|
|
'url' => $codePath."exercise/exercise.php?$cidReq", |
131
|
|
|
'name' => get_lang('Exercises'), |
132
|
|
|
]; |
133
|
|
|
$GLOBALS['interbreadcrumb'][] = [ |
134
|
|
|
'url' => $codePath."exercise/exercise_report.php?$cidReq&".http_build_query(['exerciseId' => $exerciseId]), |
135
|
|
|
'name' => get_lang('StudentScore'), |
136
|
|
|
]; |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
|