ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilPollAnswersRenderer.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use ILIAS\Refinery\Factory as Refinery;
22
24{
25 protected ilLanguage $lng;
26 protected Refinery $refinery;
27
28 public function __construct(
30 Refinery $refinery
31 ) {
32 $this->lng = $lng;
33 $this->refinery = $refinery;
34 }
35
36 public function render(
37 ilTemplate $tpl,
38 ilPollAnswersHandler $answers,
39 bool $disable_input
40 ): void {
41 $single_answer = ($answers->getAnswerLimit() === 1);
42
43 if (!is_null($last_vote = $answers->popLastVoteFromSession())) {
44 if (!$single_answer && empty($last_vote)) {
45 $error = $this->lng->txt("poll_vote_error_multi_no_answer");
46 } elseif (!$single_answer) {
47 $error = sprintf(
48 $this->lng->txt("poll_vote_error_multi"),
49 $answers->getAnswerLimit()
50 );
51 } else {
52 $error = $this->lng->txt("poll_vote_error_single");
53 }
54
55 $tpl->setCurrentBlock("error_bl");
56 $tpl->setVariable("FORM_ERROR", $error);
57 $tpl->parseCurrentBlock();
58 }
59
60 $tpl->setCurrentBlock('answer');
61 foreach ($answers->getAnswers() as $id => $answer) {
62 $this->renderAnswer(
63 $tpl,
64 $id,
65 $answer,
66 $last_vote,
67 $single_answer,
68 $disable_input
69 );
70 }
71
72 if (!$disable_input) {
73 $tpl->setVariable("URL_FORM", $answers->getVoteURL());
74 $tpl->setVariable("CMD_FORM", $answers->getVoteCommand());
75 $tpl->setVariable("TXT_SUBMIT", $this->lng->txt("poll_vote"));
76 }
77 }
78
79 protected function renderAnswer(
80 ilTemplate $tpl,
81 int $id,
82 string $answer,
83 ?array $last_vote,
84 bool $single_answer,
85 bool $disable_input
86 ): void {
87 if ($single_answer) {
88 $tpl->setVariable("ANSWER_INPUT", "radio");
89 $tpl->setVariable("ANSWER_NAME", "aw");
90 } else {
91 $tpl->setVariable("ANSWER_INPUT", "checkbox");
92 $tpl->setVariable("ANSWER_NAME", "aw[]");
93
94 $status = [];
95 if (!empty($last_vote) && is_array($last_vote) && in_array($id, $last_vote)) {
96 $status[] = 'checked="checked"';
97 }
98 if ($disable_input) {
99 $status[] = 'disabled';
100 }
101 if ($status) {
102 $tpl->setVariable("ANSWER_STATUS", implode(' ', $status));
103 }
104 }
105 $tpl->setVariable("VALUE_ANSWER", $id);
106 $tpl->setVariable(
107 "TXT_ANSWER_VOTE",
108 $this->refinery->encode()->htmlSpecialCharsAsEntities()->transform(nl2br($answer))
109 );
110 $tpl->parseCurrentBlock();
111 }
112}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:544
Builds data types.
Definition: Factory.php:36
language handling
popLastVoteFromSession()
TODO session handling should get its own class.
render(ilTemplate $tpl, ilPollAnswersHandler $answers, bool $disable_input)
__construct(ilLanguage $lng, Refinery $refinery)
renderAnswer(ilTemplate $tpl, int $id, string $answer, ?array $last_vote, bool $single_answer, bool $disable_input)
special template class to simplify handling of ITX/PEAR
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
if(!file_exists('../ilias.ini.php'))