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
|
|
|
$actions = ''; |
75
|
|
|
|
76
|
|
|
if ($form->validate()) { |
77
|
|
|
$formValues = $form->exportValues(); |
78
|
|
|
|
79
|
|
|
$action = Display::url( |
80
|
|
|
Display::return_icon('export_excel.png', get_lang('ExportExcel'), [], ICON_SIZE_MEDIUM), |
81
|
|
|
api_get_path(WEB_PLUGIN_PATH).'exercisefocused/pages/export.php?'.http_build_query($formValues) |
82
|
|
|
); |
83
|
|
|
|
84
|
|
|
$actions = Display::toolbarAction( |
85
|
|
|
'em-actions', |
86
|
|
|
[$action] |
87
|
|
|
); |
88
|
|
|
|
89
|
|
|
$results = $this->findResults($formValues); |
90
|
|
|
|
91
|
|
|
$tableHtml = $this->createTable($results)->toHtml(); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
return $form->returnForm().$actions.$tableHtml; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
private function generateTabSampling(CQuiz $exercise): string |
98
|
|
|
{ |
99
|
|
|
$results = $this->findRandomResults($exercise->getId()); |
100
|
|
|
|
101
|
|
|
return $this->createTable($results)->toHtml(); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @return array<int, TrackEExercises> |
106
|
|
|
*/ |
107
|
|
|
private function setBreadcrumb($exerciseId): void |
108
|
|
|
{ |
109
|
|
|
$codePath = api_get_path('WEB_CODE_PATH'); |
110
|
|
|
$cidReq = api_get_cidreq(); |
111
|
|
|
|
112
|
|
|
$GLOBALS['interbreadcrumb'][] = [ |
113
|
|
|
'url' => $codePath."exercise/exercise.php?$cidReq", |
114
|
|
|
'name' => get_lang('Exercises'), |
115
|
|
|
]; |
116
|
|
|
$GLOBALS['interbreadcrumb'][] = [ |
117
|
|
|
'url' => $codePath."exercise/exercise_report.php?$cidReq&".http_build_query(['exerciseId' => $exerciseId]), |
118
|
|
|
'name' => get_lang('StudentScore'), |
119
|
|
|
]; |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|