ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilPollAnswersRenderer Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Collaboration diagram for ilPollAnswersRenderer:

Public Member Functions

 __construct (ilLanguage $lng)
 
 render (ilTemplate $tpl, ilPollAnswersHandler $answers, bool $disable_input)
 

Protected Member Functions

 renderAnswer (ilTemplate $tpl, int $id, string $answer, ?array $last_vote, bool $single_answer, bool $disable_input)
 
 specialCharsAsEntities (string $string)
 

Protected Attributes

ilLanguage $lng
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning

Definition at line 22 of file class.ilPollAnswersRenderer.php.

Constructor & Destructor Documentation

◆ __construct()

ilPollAnswersRenderer::__construct ( ilLanguage  $lng)

Definition at line 26 of file class.ilPollAnswersRenderer.php.

References $lng, and ILIAS\Repository\lng().

+ Here is the call graph for this function:

Member Function Documentation

◆ render()

ilPollAnswersRenderer::render ( ilTemplate  $tpl,
ilPollAnswersHandler  $answers,
bool  $disable_input 
)

Definition at line 31 of file class.ilPollAnswersRenderer.php.

References $id, ilPollAnswersHandler\getAnswerLimit(), ilPollAnswersHandler\getAnswers(), ilPollAnswersHandler\getVoteCommand(), ilPollAnswersHandler\getVoteURL(), ILIAS\Repository\lng(), ilTemplate\parseCurrentBlock(), ilPollAnswersHandler\popLastVoteFromSession(), renderAnswer(), ilTemplate\setCurrentBlock(), and HTML_Template_IT\setVariable().

35  : void {
36  $single_answer = ($answers->getAnswerLimit() === 1);
37 
38  if (!is_null($last_vote = $answers->popLastVoteFromSession())) {
39  if (!$single_answer && empty($last_vote)) {
40  $error = $this->lng->txt("poll_vote_error_multi_no_answer");
41  } elseif (!$single_answer) {
42  $error = sprintf(
43  $this->lng->txt("poll_vote_error_multi"),
44  $answers->getAnswerLimit()
45  );
46  } else {
47  $error = $this->lng->txt("poll_vote_error_single");
48  }
49 
50  $tpl->setCurrentBlock("error_bl");
51  $tpl->setVariable("FORM_ERROR", $error);
52  $tpl->parseCurrentBlock();
53  }
54 
55  $tpl->setCurrentBlock('answer');
56  foreach ($answers->getAnswers() as $id => $answer) {
57  $this->renderAnswer(
58  $tpl,
59  $id,
60  $answer,
61  $last_vote,
62  $single_answer,
63  $disable_input
64  );
65  }
66 
67  if (!$disable_input) {
68  $tpl->setVariable("URL_FORM", $answers->getVoteURL());
69  $tpl->setVariable("CMD_FORM", $answers->getVoteCommand());
70  $tpl->setVariable("TXT_SUBMIT", $this->lng->txt("poll_vote"));
71  }
72  }
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
renderAnswer(ilTemplate $tpl, int $id, string $answer, ?array $last_vote, bool $single_answer, bool $disable_input)
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:546
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
popLastVoteFromSession()
TODO session handling should get its own class.
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
+ Here is the call graph for this function:

◆ renderAnswer()

ilPollAnswersRenderer::renderAnswer ( ilTemplate  $tpl,
int  $id,
string  $answer,
?array  $last_vote,
bool  $single_answer,
bool  $disable_input 
)
protected

Definition at line 74 of file class.ilPollAnswersRenderer.php.

References ilTemplate\parseCurrentBlock(), HTML_Template_IT\setVariable(), and specialCharsAsEntities().

Referenced by render().

81  : void {
82  if ($single_answer) {
83  $tpl->setVariable("ANSWER_INPUT", "radio");
84  $tpl->setVariable("ANSWER_NAME", "aw");
85  } else {
86  $tpl->setVariable("ANSWER_INPUT", "checkbox");
87  $tpl->setVariable("ANSWER_NAME", "aw[]");
88 
89  $status = [];
90  if (!empty($last_vote) && is_array($last_vote) && in_array($id, $last_vote)) {
91  $status[] = 'checked="checked"';
92  }
93  if ($disable_input) {
94  $status[] = 'disabled';
95  }
96  if ($status) {
97  $tpl->setVariable("ANSWER_STATUS", implode(' ', $status));
98  }
99  }
100  $tpl->setVariable("VALUE_ANSWER", $id);
101  $tpl->setVariable(
102  "TXT_ANSWER_VOTE",
103  $this->specialCharsAsEntities(nl2br($answer))
104  );
105  $tpl->parseCurrentBlock();
106  }
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:546
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ specialCharsAsEntities()

ilPollAnswersRenderer::specialCharsAsEntities ( string  $string)
protected

Definition at line 108 of file class.ilPollAnswersRenderer.php.

Referenced by renderAnswer().

108  : string
109  {
110  // Should be replaced by a proper refinery transformation once https://github.com/ILIAS-eLearning/ILIAS/pull/6314 is merged
111  return htmlspecialchars(
112  $string,
113  ENT_QUOTES | ENT_SUBSTITUTE,
114  'utf-8'
115  );
116  }
+ Here is the caller graph for this function:

Field Documentation

◆ $lng

ilLanguage ilPollAnswersRenderer::$lng
protected

Definition at line 24 of file class.ilPollAnswersRenderer.php.

Referenced by __construct().


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