5 include_once(
"./Services/Block/classes/class.ilBlockGUI.php");
6 include_once(
"./Modules/Poll/classes/class.ilObjPoll.php");
32 $this->lng = $DIC->language();
33 $this->ctrl = $DIC->ctrl();
34 $this->
user = $DIC->user();
35 $this->access = $DIC->access();
36 $lng = $DIC->language();
40 $lng->loadLanguageModule(
"poll");
49 return self::$block_type;
67 return "ilobjpollgui";
84 $this->poll_block = $a_block;
94 $next_class = $ilCtrl->getNextClass();
95 $cmd = $ilCtrl->getCmd(
"getHTML");
97 switch ($next_class) {
113 $mess = $this->poll_block->getMessage(
$ilUser->getId());
115 $this->tpl->setVariable(
"TXT_QUESTION", $mess);
124 if ($this->poll_block->maySeeQuestion(
$ilUser->getId())) {
125 $this->tpl->setCurrentBlock(
"mode_info_bl");
126 if ($this->poll_block->getPoll()->getNonAnonymous()) {
127 $mode_info =
$lng->txt(
"poll_non_anonymous_warning");
129 $mode_info =
$lng->txt(
"poll_anonymous_warning");
131 $this->tpl->setVariable(
"MODE_INFO", $mode_info);
132 $this->tpl->parseCurrentBlock();
134 $is_multi_answer = ($this->poll_block->getPoll()->getMaxNumberOfAnswers() > 1);
136 if (isset(
$_SESSION[
"last_poll_vote"][$this->poll_block->getPoll()->getId()])) {
137 $last_vote =
$_SESSION[
"last_poll_vote"][$this->poll_block->getPoll()->getId()];
138 unset(
$_SESSION[
"last_poll_vote"][$this->poll_block->getPoll()->getId()]);
140 if ($is_multi_answer) {
142 $lng->txt(
"poll_vote_error_multi"),
143 $this->poll_block->getPoll()->getMaxNumberOfAnswers()
146 $error =
$lng->txt(
"poll_vote_error_single");
149 $this->tpl->setCurrentBlock(
"error_bl");
150 $this->tpl->setVariable(
"FORM_ERROR", $error);
151 $this->tpl->parseCurrentBlock();
154 $this->tpl->setCurrentBlock(
"answer");
155 foreach ($a_poll->getAnswers() as $item) {
157 if (!$is_multi_answer) {
158 $this->tpl->setVariable(
"ANSWER_INPUT",
"radio");
159 $this->tpl->setVariable(
"ANSWER_NAME",
"aw");
161 $this->tpl->setVariable(
"ANSWER_INPUT",
"checkbox");
162 $this->tpl->setVariable(
"ANSWER_NAME",
"aw[]");
164 if (is_array($last_vote) && in_array($item[
"id"], $last_vote)) {
165 $status[] =
'checked="checked"';
169 if (!$this->poll_block->mayVote(
$ilUser->getId())) {
170 $status[] =
'disabled';
173 if (!empty($status)) {
174 $this->tpl->setVariable(
"ANSWER_STATUS", implode(
' ', $status));
177 $this->tpl->setVariable(
"VALUE_ANSWER", $item[
"id"]);
178 $this->tpl->setVariable(
"TXT_ANSWER_VOTE", nl2br($item[
"answer"]));
179 $this->tpl->parseCurrentBlock();
182 if ($this->poll_block->mayVote(
$ilUser->getId())) {
183 $ilCtrl->setParameterByClass(
188 $url = $ilCtrl->getLinkTargetByClass(
194 $url .=
"#poll" . $a_poll->getID();
196 $this->tpl->setVariable(
"URL_FORM",
$url);
197 $this->tpl->setVariable(
"CMD_FORM",
"vote");
198 $this->tpl->setVariable(
"TXT_SUBMIT",
$lng->txt(
"poll_vote"));
201 if ($this->poll_block->getPoll()->getVotingPeriod()) {
202 $this->tpl->setVariable(
203 "TXT_VOTING_END_PERIOD",
205 $lng->txt(
"poll_voting_period_info"),
214 if ($this->poll_block->maySeeResults(
$ilUser->getId())) {
215 if (!$this->poll_block->mayNotResultsYet(
$ilUser->getId())) {
217 foreach ($a_poll->getAnswers() as $item) {
218 $answers[$item[
"id"]] = $item[
"answer"];
221 $perc = $this->poll_block->getPoll()->getVotePercentages();
223 $perc = $perc[
"perc"];
225 $this->tpl->setVariable(
"TOTAL_ANSWERS", sprintf(
$lng->txt(
"poll_population"),
$total));
229 if ($this->poll_block->getPoll()->getSortResultByVotes()) {
232 foreach (array_keys($answers) as $answer_id) {
233 if (!in_array($answer_id, $order)) {
234 $order[] = $answer_id;
238 $order = array_keys($answers);
243 include_once(
"./Services/Chart/classes/class.ilChart.php");
246 $chart->setSize(
"100%", 200);
247 $chart->setAutoResize(
true);
249 $chart_data = $chart->getDataInstance();
251 foreach ($order as $answer_id) {
252 $chart_data->addPoint(
253 round($perc[$answer_id][
"perc"]),
254 nl2br($answers[$answer_id])
261 $chart->addData($chart_data);
263 $pie_legend_id =
"poll_legend_" . $this->
getRefId();
265 $legend->setContainer($pie_legend_id);
266 $chart->setLegend($legend);
268 $this->tpl->setVariable(
"PIE_LEGEND_ID", $pie_legend_id);
269 $this->tpl->setVariable(
"PIE_CHART", $chart->getHTML());
272 include_once
"Services/UIComponent/ProgressBar/classes/class.ilProgressBar.php";
274 $this->tpl->setCurrentBlock(
"answer_result");
275 foreach ($order as $answer_id) {
277 $pbar->setCurrent(round($perc[$answer_id][
"perc"]));
278 $this->tpl->setVariable(
"PERC_ANSWER_RESULT", $pbar->render());
279 $this->tpl->setVariable(
"TXT_ANSWER_RESULT", nl2br($answers[$answer_id]));
280 $this->tpl->parseCurrentBlock();
287 $end = $this->poll_block->getPoll()->getVotingPeriodEnd();
293 if ($this->poll_block->getPoll()->hasUserVoted(
$ilUser->getId())) {
294 $info .=
$lng->txt(
"poll_block_message_already_voted") .
" ";
297 $this->tpl->setVariable(
"TOTAL_ANSWERS", $info .
298 sprintf(
$lng->txt(
"poll_block_results_available_on"), $end));
300 } elseif ($this->poll_block->getPoll()->hasUserVoted(
$ilUser->getId())) {
301 $this->tpl->setVariable(
"TOTAL_ANSWERS",
$lng->txt(
"poll_block_message_already_voted"));
305 if (!$this->poll_block->maySeeQuestion(
$ilUser->getId()) && !$this->poll_block->getPoll()->hasUserVoted(
$ilUser->getId())) {
306 if ($this->poll_block->getPoll()->getVotingPeriod()) {
307 $this->tpl->setVariable(
310 $lng->txt(
"poll_voting_period_full_info"),
317 $this->tpl->setVariable(
"TXT_QUESTION", nl2br(trim($a_poll->getQuestion())));
319 $img = $a_poll->getImageFullPath();
321 require_once(
'./Services/WebAccessChecker/classes/class.ilWACSignedPath.php');
327 $this->tpl->setVariable(
"ANCHOR_ID", $a_poll->getID());
330 $desc = trim($a_poll->getDescription());
332 $this->tpl->setVariable(
"TXT_DESC", nl2br($desc));
337 $this->tpl->setCurrentBlock(
"anon_warning");
338 $this->tpl->setVariable(
"ANON_WARNING", $this->lng->txt(
'no_access_item_public'));
339 $this->tpl->parseCurrentBlock();
343 if ($this->poll_block->showComments()) {
344 $this->tpl->setCurrentBlock(
"comment_link");
345 $this->tpl->setVariable(
"LANG_COMMENTS",
$lng->txt(
'poll_comments'));
346 $this->tpl->setVariable(
"COMMENT_JSCALL", $this->
commentJSCall());
347 $this->tpl->setVariable(
"COMMENTS_COUNT_ID", $this->
getRefId());
351 if ($comments_count > 0) {
352 $this->tpl->setVariable(
"COMMENTS_COUNT",
"(" . $comments_count .
")");
355 if (!self::$js_init) {
356 $redraw_url = $ilCtrl->getLinkTarget(
358 "getNumberOfCommentsForRedraw",
363 $this->tpl->setVariable(
"COMMENTS_REDRAW_URL", $redraw_url);
365 $tpl->addJavaScript(
"Modules/Poll/js/ilPoll.js");
366 self::$js_init =
true;
381 $this->poll_block->setRefId($this->
getRefId());
382 $this->may_write = $ilAccess->checkAccess(
"write",
"", $this->
getRefId());
383 $this->has_content = $this->poll_block->hasAnyContent(
$ilUser->getId(), $this->
getRefId());
385 #22078 and 22079 it always contains something. 391 $poll_obj = $this->poll_block->getPoll();
392 $this->
setTitle($poll_obj->getTitle());
393 $this->
setData(array($poll_obj));
395 $ilCtrl->setParameterByClass(
401 if (!$this->poll_block->getMessage(
$ilUser->getId())) {
403 include_once
"./Services/Notification/classes/class.ilNotification.php";
406 $ilCtrl->getLinkTargetByClass(
410 $lng->txt(
"poll_notification_unsubscribe")
414 $ilCtrl->getLinkTargetByClass(
418 $lng->txt(
"poll_notification_subscribe")
423 if ($this->may_write) {
426 $ilCtrl->getLinkTargetByClass(
430 $lng->txt(
"edit_content")
433 $ilCtrl->getLinkTargetByClass(
437 $lng->txt(
"settings")
443 return parent::getHTML();
453 include_once(
"./Services/Notes/classes/class.ilNoteGUI.php");
454 include_once(
"./Services/Object/classes/class.ilCommonActionDispatcherGUI.php");
468 $jsCall =
$comment->getListCommentsJSCall($ajaxHash,
"ilPoll.redrawComments(" .
$refId .
");");
481 echo
"(" . $number .
")";
497 include_once(
"./Services/Notes/classes/class.ilNote.php");
502 if (count($number) == 0) {
536 return $this->tpl->get();
static sortArray( $array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
executeCommand()
execute command
static hasNotification($type, $user_id, $id)
Check notification status for object and user.
fillDataSection()
Fill data section.
getRowTemplateDir()
Get Row Template Directory.
commentJSCall()
Builds JavaScript Call to open CommentLayer via html link.
setDataSection($a_content)
Call this from overwritten fillDataSection(), if standard row based data is not used.
getNumberOfComments($ref_id)
Get comment count.
const SHOW_RESULTS_AS_PIECHART
getRepositoryObjectGUIName()
Get repository object GUI name.
static _lookupObjectId($a_ref_id)
static setUseRelativeDates($a_status)
set use relative dates
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date public.
static useRelativeDates()
check if relative dates are used
getHTML()
Get block HTML code.
static getInstance()
Factory.
setTitle($a_title)
Set Title.
static _countNotesAndComments( $a_rep_obj_id, $a_sub_obj_id=null, $a_obj_type="", $a_news_id=0)
Get all notes related to a specific object.
setBlockId($a_block_id=0)
Set Block Id.
setData($a_data)
Set Data.
static signFile($path_to_file)
static buildAjaxHash( $a_node_type, $a_node_id, $a_obj_type, $a_obj_id, $a_sub_type=null, $a_sub_id=null, $a_news_id=0)
Build ajax hash.
getRefId()
Get Ref Id (only used if isRepositoryObject() is true).
BlockGUI class for polls.
__construct(Container $dic, ilPlugin $plugin)
getRowTemplateName()
Get Row Template Name.
getNumberOfCommentsForRedraw()
Returns comment count for JS Redraw.
This class represents a block method of a block.
addBlockCommand(string $a_href, string $a_text, string $a_onclick="")
Add Block Command.
__construct()
Constructor.
setRowTemplate($a_rowtemplatename, $a_rowtemplatedir="")
Set Row Template Name.
static getScreenMode()
Get Screen Mode for current command.
static getInstanceByType($a_type, $a_id)
Get type instance.
setBlock($a_block)
Do most of the initialisation.