ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ILIAS\Test\Results\Presentation\AttemptResultsTable Class Reference
+ Collaboration diagram for ILIAS\Test\Results\Presentation\AttemptResultsTable:

Public Member Functions

 __construct (UIFactory $ui_factory, private UIRenderer $ui_renderer, private Refinery $refinery, private HTTPService $http, DataFactory $data_factory, Language $lng, private AttemptSolutions $test_results, Settings $settings, string $title, bool $for_print)
 
 render ()
 
 getTableComponent ()
 

Protected Attributes

PresentationTable $table
 

Private Member Functions

 applyControls (string $mode, string $sortation, array $question_results)
 
 getViewControlNamespace ()
 
 getViewControlsParameter ()
 
 getViewControls (UIFactory $ui_factory, Language $lng, URLBuilder $target, string $mode, string $sortation)
 return array<\ILIAS\UI\ViewControl\ViewControl> More...
 
 getMapping ()
 

Private Attributes

const ENV = 'e'
 
const LNG = 'l'
 
const URL_NAMESPACE = ['taresult', 'vc']
 
const PARAM_MODE = 'm'
 
const MODE_OPT_ALL = "all"
 
const MODE_OPT_CORRECT = "ok"
 
const MODE_OPT_INCORRECT = "fail"
 
const PARAM_SORT = 's'
 
const SORT_OPT_ORDEROFAPPEARANCE = 'ooa'
 
const SORT_OPT_POSSIBLESCORE = 'ms'
 

Detailed Description

Definition at line 35 of file AttemptResultsTable.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Test\Results\Presentation\AttemptResultsTable::__construct ( UIFactory  $ui_factory,
private UIRenderer  $ui_renderer,
private Refinery  $refinery,
private HTTPService  $http,
DataFactory  $data_factory,
Language  $lng,
private AttemptSolutions  $test_results,
Settings  $settings,
string  $title,
bool  $for_print 
)

Definition at line 50 of file AttemptResultsTable.php.

61 {
62 list($mode, $sortation) = $this->getViewControlsParameter();
63 $results = $this->applyControls($mode, $sortation, $test_results->getQuestionResults());
64 $target = new URLBuilder($data_factory->uri($http->request()->getUri()->__toString()));
65
66 $this->table = $ui_factory->table()->presentation(
67 $title,
68 $for_print ? [] : $this->getViewControls($ui_factory, $lng, $target, $mode, $sortation),
69 $this->getMapping()
70 )
71 ->withEnvironment([
72 self::ENV => $settings,
73 self::LNG => $lng
74 ])
75 ->withData($results);
76 }
applyControls(string $mode, string $sortation, array $question_results)
getViewControls(UIFactory $ui_factory, Language $lng, URLBuilder $target, string $mode, string $sortation)
return array<\ILIAS\UI\ViewControl\ViewControl>
$http
Definition: deliver.php:30
global $lng
Definition: privfeed.php:31
$results

References $http, $lng, $results, ILIAS\Test\Results\Presentation\AttemptResultsTable\applyControls(), ILIAS\Test\Results\Presentation\AttemptResultsTable\getMapping(), ILIAS\Test\Results\Data\AttemptSolutions\getQuestionResults(), ILIAS\Test\Results\Presentation\AttemptResultsTable\getViewControls(), and ILIAS\Test\Results\Presentation\AttemptResultsTable\getViewControlsParameter().

+ Here is the call graph for this function:

Member Function Documentation

◆ applyControls()

ILIAS\Test\Results\Presentation\AttemptResultsTable::applyControls ( string  $mode,
string  $sortation,
array  $question_results 
)
private
Parameters
array<QuestionResult>$question_results

Definition at line 91 of file AttemptResultsTable.php.

95 {
96 switch ($mode) {
98 $filter = static fn($qr) => $qr->getCorrect() === QuestionResult::CORRECT_FULL;
99 break;
101 $filter = static fn($qr) => $qr->getCorrect() !== QuestionResult::CORRECT_FULL;
102 break;
104 default:
105 $filter = static fn($qr) => true;
106 }
107 $question_results = array_filter($question_results, $filter);
108
109 if ($sortation === self::SORT_OPT_POSSIBLESCORE) {
110 usort(
111 $question_results,
112 static fn(QuestionResult $a, QuestionResult $b) => $a->getQuestionScore() <=> $b->getQuestionScore()
113 );
114 $question_results = array_reverse($question_results);
115 }
116 return $question_results;
117 }
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples

References Vendor\Package\$a, Vendor\Package\$b, ILIAS\Test\Results\Data\QuestionResult\CORRECT_FULL, ILIAS\Test\Results\Presentation\AttemptResultsTable\MODE_OPT_ALL, ILIAS\Test\Results\Presentation\AttemptResultsTable\MODE_OPT_CORRECT, and ILIAS\Test\Results\Presentation\AttemptResultsTable\MODE_OPT_INCORRECT.

Referenced by ILIAS\Test\Results\Presentation\AttemptResultsTable\__construct().

+ Here is the caller graph for this function:

◆ getMapping()

ILIAS\Test\Results\Presentation\AttemptResultsTable::getMapping ( )
private

Definition at line 182 of file AttemptResultsTable.php.

182 : \Closure
183 {
184 return function (PresentationRow $row, QuestionResult $question, UIFactory $ui_factory, array $environment) {
185 $env = $environment[self::ENV];
186 $lng = $environment[self::LNG];
187
188 $title = $this->refinery->encode()->htmlSpecialCharsAsEntities()->transform(
189 $question->getTitle()
190 );
191
192 $important_fields = [
193 $lng->txt('position') => (string) ($question->getPosition() + 1),
194 $lng->txt('question_id') => (string) $question->getId(),
195 $lng->txt('question_type') => $lng->txt($question->getType()),
196 $lng->txt('points') => sprintf(
197 '%s/%s (%s%%)',
198 (string) $question->getUserScore(),
199 (string) $question->getQuestionScore(),
200 (string) $question->getUserScorePercent()
201 )
202 ];
203
204 $stats_fields = $important_fields;
205 $stats = $ui_factory->listing()->characteristicValue()->text($stats_fields);
206
207 $contents = [
208 $stats
209 ];
210
211 if ($recap = $question->getContentForRecapitulation()) {
212 $contents[] = $ui_factory->listing()->descriptive([
213 $lng->txt('suggested_solution') => $recap
214 ]);
215 }
216
217 $user_answer = $question->getUserAnswer();
218 $answer_contents = [
219 $ui_factory->listing()->descriptive([$lng->txt('tst_header_participant') => $user_answer])
220 ];
221 if ($env->getShowBestSolution()) {
222 $answer_contents[] = $ui_factory->listing()->descriptive([
223 $lng->txt('tst_header_solution') => $question->getBestSolution()
224 ]);
225 }
226
227 $answers = $ui_factory->layout()->alignment()->horizontal()->evenlyDistributed(...$answer_contents);
228 $contents[] = $answers;
229
230 $content = $ui_factory->layout()->alignment()->vertical(...$contents);
231
232 switch ($question->getCorrect()) {
234 $icon_name = 'icon_ok.svg';
235 $label = $lng->txt("answer_is_right");
236 break;
238 $icon_name = 'icon_mostly_ok.svg';
239 $label = $lng->txt("answer_is_not_correct_but_positive");
240 break;
242 $icon_name = 'icon_not_ok.svg';
243 $label = $lng->txt("answer_is_wrong");
244 break;
245 }
246 $path = \ilUtil::getImagePath('standard/' . $icon_name);
247 $correct_icon = $ui_factory->symbol()->icon()->custom(
248 $path,
249 $label
250 );
251
252 return $row
253 ->withHeadline($title)
254 ->withLeadingSymbol($correct_icon)
255 ->withImportantFields($important_fields)
256 ->withContent($content);
257 };
258 }
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
$path
Definition: ltiservices.php:30

References $lng, $path, ILIAS\Test\Results\Data\QuestionResult\CORRECT_FULL, ILIAS\Test\Results\Data\QuestionResult\CORRECT_NONE, ILIAS\Test\Results\Data\QuestionResult\CORRECT_PARTIAL, ilUtil\getImagePath(), ILIAS\Repository\refinery(), and ILIAS\UI\Component\Table\PresentationRow\withHeadline().

Referenced by ILIAS\Test\Results\Presentation\AttemptResultsTable\__construct().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getTableComponent()

ILIAS\Test\Results\Presentation\AttemptResultsTable::getTableComponent ( )

Definition at line 83 of file AttemptResultsTable.php.

83 : PresentationTable
84 {
85 return $this->table;
86 }

References ILIAS\Test\Results\Presentation\AttemptResultsTable\$table.

◆ getViewControlNamespace()

ILIAS\Test\Results\Presentation\AttemptResultsTable::getViewControlNamespace ( )
private

Definition at line 119 of file AttemptResultsTable.php.

119 : array
120 {
122 $namespace[] = (string) $this->test_results->getActiveId();
123 $namespace[] = (string) $this->test_results->getAttempt();
124 return $namespace;
125 }
if($err=$client->getError()) $namespace

References $namespace, and ILIAS\Test\Results\Presentation\AttemptResultsTable\URL_NAMESPACE.

Referenced by ILIAS\Test\Results\Presentation\AttemptResultsTable\getViewControlsParameter().

+ Here is the caller graph for this function:

◆ getViewControls()

ILIAS\Test\Results\Presentation\AttemptResultsTable::getViewControls ( UIFactory  $ui_factory,
Language  $lng,
URLBuilder  $target,
string  $mode,
string  $sortation 
)
private

return array<\ILIAS\UI\ViewControl\ViewControl>

Definition at line 144 of file AttemptResultsTable.php.

150 : array {
151 $builder = $target->acquireParameter($this->getViewControlNamespace(), self::PARAM_MODE);
152 [$target, $token] = $builder;
153
154 $modes = [
155 $lng->txt('resulttable_all') => $target->withParameter($token, self::MODE_OPT_ALL)->buildURI()->__toString(),
156 $lng->txt('resulttable_correct') => $target->withParameter($token, self::MODE_OPT_CORRECT)->buildURI()->__toString(),
157 $lng->txt('resulttable_incorrect') => $target->withParameter($token, self::MODE_OPT_INCORRECT)->buildURI()->__toString(),
158 ];
160 $active = array_search($mode, $check);
161
162 $vc_mode = $ui_factory->viewControl()->mode($modes, $lng->txt('ta_resulttable_vc_mode_aria'))
163 ->withActive(array_keys($modes)[$active]);
164
165 $options = [
166 self::SORT_OPT_ORDEROFAPPEARANCE => $lng->txt('resulttable_vc_sort_iooa'),
167 self::SORT_OPT_POSSIBLESCORE => $lng->txt('resulttable_vc_sort_posscore')
168 ];
169
171 $vc_sort = $ui_factory->viewControl()->sortation($options, $sortation)->withTargetURL(
172 $target->buildURI()->__toString(),
173 $pre . self::PARAM_SORT
174 );
175
176 return [
177 $vc_mode,
178 $vc_sort
179 ];
180 }
$check
Definition: buildRTE.php:81
const SEPARATOR
Separator for parts of a parameter's namespace.
Definition: URLBuilder.php:50
$token
Definition: xapitoken.php:70

Referenced by ILIAS\Test\Results\Presentation\AttemptResultsTable\__construct().

+ Here is the caller graph for this function:

◆ getViewControlsParameter()

ILIAS\Test\Results\Presentation\AttemptResultsTable::getViewControlsParameter ( )
private

Definition at line 127 of file AttemptResultsTable.php.

127 : array
128 {
129 $request = $this->http->wrapper()->query();
131
132 $mode = $request->has($pre . self::PARAM_MODE) ?
133 $request->retrieve($pre . self::PARAM_MODE, $this->refinery->kindlyTo()->string()) : self::MODE_OPT_ALL;
134
135 $sortation = $request->has($pre . self::PARAM_SORT) ?
136 $request->retrieve($pre . self::PARAM_SORT, $this->refinery->kindlyTo()->string()) : self::SORT_OPT_ORDEROFAPPEARANCE;
137
138 return [$mode, $sortation];
139 }
static http()
Fetches the global http state from ILIAS.

References ILIAS\Test\Results\Presentation\AttemptResultsTable\getViewControlNamespace(), ILIAS\FileDelivery\http(), ILIAS\Test\Results\Presentation\AttemptResultsTable\MODE_OPT_ALL, ILIAS\Repository\refinery(), ILIAS\UI\URLBuilder\SEPARATOR, and ILIAS\Test\Results\Presentation\AttemptResultsTable\SORT_OPT_ORDEROFAPPEARANCE.

Referenced by ILIAS\Test\Results\Presentation\AttemptResultsTable\__construct().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ render()

ILIAS\Test\Results\Presentation\AttemptResultsTable::render ( )

Definition at line 78 of file AttemptResultsTable.php.

78 : string
79 {
80 return $this->ui_renderer->render($this->table);
81 }

Field Documentation

◆ $table

PresentationTable ILIAS\Test\Results\Presentation\AttemptResultsTable::$table
protected

◆ ENV

const ILIAS\Test\Results\Presentation\AttemptResultsTable::ENV = 'e'
private

Definition at line 37 of file AttemptResultsTable.php.

◆ LNG

const ILIAS\Test\Results\Presentation\AttemptResultsTable::LNG = 'l'
private

Definition at line 38 of file AttemptResultsTable.php.

◆ MODE_OPT_ALL

const ILIAS\Test\Results\Presentation\AttemptResultsTable::MODE_OPT_ALL = "all"
private

◆ MODE_OPT_CORRECT

const ILIAS\Test\Results\Presentation\AttemptResultsTable::MODE_OPT_CORRECT = "ok"
private

◆ MODE_OPT_INCORRECT

const ILIAS\Test\Results\Presentation\AttemptResultsTable::MODE_OPT_INCORRECT = "fail"
private

◆ PARAM_MODE

const ILIAS\Test\Results\Presentation\AttemptResultsTable::PARAM_MODE = 'm'
private

Definition at line 40 of file AttemptResultsTable.php.

◆ PARAM_SORT

const ILIAS\Test\Results\Presentation\AttemptResultsTable::PARAM_SORT = 's'
private

Definition at line 44 of file AttemptResultsTable.php.

◆ SORT_OPT_ORDEROFAPPEARANCE

const ILIAS\Test\Results\Presentation\AttemptResultsTable::SORT_OPT_ORDEROFAPPEARANCE = 'ooa'
private

◆ SORT_OPT_POSSIBLESCORE

const ILIAS\Test\Results\Presentation\AttemptResultsTable::SORT_OPT_POSSIBLESCORE = 'ms'
private

Definition at line 46 of file AttemptResultsTable.php.

◆ URL_NAMESPACE

const ILIAS\Test\Results\Presentation\AttemptResultsTable::URL_NAMESPACE = ['taresult', 'vc']
private

The documentation for this class was generated from the following file: