5 include_once(
"./Services/Block/classes/class.ilBlockGUI.php");
6 include_once(
"./Modules/Poll/classes/class.ilObjPoll.php");
32 parent::__construct();
34 $lng->loadLanguageModule(
"poll");
45 return self::$block_type;
65 return "ilobjpollgui";
82 $this->poll_block = $a_block;
92 $next_class = $ilCtrl->getNextClass();
93 $cmd = $ilCtrl->getCmd(
"getHTML");
109 $mess = $this->poll_block->getMessage($ilUser->getId());
112 $this->tpl->setVariable(
"TXT_QUESTION", $mess);
122 if($this->poll_block->mayVote($ilUser->getId()))
124 $this->tpl->setCurrentBlock(
"mode_info_bl");
125 if($this->poll_block->getPoll()->getNonAnonymous())
127 $mode_info = $lng->txt(
"poll_non_anonymous_warning");
131 $mode_info = $lng->txt(
"poll_anonymous_warning");
133 $this->tpl->setVariable(
"MODE_INFO", $mode_info);
134 $this->tpl->parseCurrentBlock();
136 $is_multi_answer = ($this->poll_block->getPoll()->getMaxNumberOfAnswers() > 1);
138 if(isset(
$_SESSION[
"last_poll_vote"][$this->poll_block->getPoll()->getId()]))
140 $last_vote =
$_SESSION[
"last_poll_vote"][$this->poll_block->getPoll()->getId()];
141 unset(
$_SESSION[
"last_poll_vote"][$this->poll_block->getPoll()->getId()]);
145 $error = sprintf($lng->txt(
"poll_vote_error_multi"),
146 $this->poll_block->getPoll()->getMaxNumberOfAnswers());
150 $error = $lng->txt(
"poll_vote_error_single");
153 $this->tpl->setCurrentBlock(
"error_bl");
154 $this->tpl->setVariable(
"FORM_ERROR",
$error);
155 $this->tpl->parseCurrentBlock();
158 $this->tpl->setCurrentBlock(
"answer");
159 foreach($a_poll->getAnswers() as $item)
161 if(!$is_multi_answer)
163 $this->tpl->setVariable(
"ANSWER_INPUT",
"radio");
164 $this->tpl->setVariable(
"ANSWER_NAME",
"aw");
168 $this->tpl->setVariable(
"ANSWER_INPUT",
"checkbox");
169 $this->tpl->setVariable(
"ANSWER_NAME",
"aw[]");
171 if(is_array($last_vote) && in_array($item[
"id"], $last_vote))
173 $this->tpl->setVariable(
"ANSWER_STATUS",
'checked="checked"');
176 $this->tpl->setVariable(
"VALUE_ANSWER", $item[
"id"]);
177 $this->tpl->setVariable(
"TXT_ANSWER_VOTE", nl2br($item[
"answer"]));
178 $this->tpl->parseCurrentBlock();
187 $url .=
"#poll".$a_poll->getID();
189 $this->tpl->setVariable(
"URL_FORM",
$url);
190 $this->tpl->setVariable(
"CMD_FORM",
"vote");
191 $this->tpl->setVariable(
"TXT_SUBMIT", $lng->txt(
"poll_vote"));
193 if($this->poll_block->getPoll()->getVotingPeriod())
195 $this->tpl->setVariable(
"TXT_VOTING_PERIOD",
196 sprintf($lng->txt(
"poll_voting_period_info"),
203 if ($this->poll_block->maySeeResults($ilUser->getId()))
205 if (!$this->poll_block->mayNotResultsYet($ilUser->getId()))
208 foreach ($a_poll->getAnswers() as $item)
210 $answers[$item[
"id"]] = $item[
"answer"];
213 $perc = $this->poll_block->getPoll()->getVotePercentages();
215 $perc = $perc[
"perc"];
217 $this->tpl->setVariable(
"TOTAL_ANSWERS", sprintf($lng->txt(
"poll_population"),
$total));
222 if ($this->poll_block->getPoll()->getSortResultByVotes())
226 foreach (array_keys($answers) as $answer_id)
228 if (!in_array($answer_id, $order))
230 $order[] = $answer_id;
236 $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)
253 $chart_data->addPoint(
254 round($perc[$answer_id][
"perc"]),
255 nl2br($answers[$answer_id])
262 $chart->addData($chart_data);
264 $pie_legend_id =
"poll_legend_".$this->getRefId();
266 $legend->setContainer($pie_legend_id);
269 $this->tpl->setVariable(
"PIE_LEGEND_ID", $pie_legend_id);
270 $this->tpl->setVariable(
"PIE_CHART",
$chart->getHTML());
275 include_once
"Services/UIComponent/ProgressBar/classes/class.ilProgressBar.php";
277 $this->tpl->setCurrentBlock(
"answer_result");
278 foreach ($order as $answer_id)
281 $pbar->setCurrent(round($perc[$answer_id][
"perc"]));
282 $this->tpl->setVariable(
"PERC_ANSWER_RESULT", $pbar->render());
283 $this->tpl->setVariable(
"TXT_ANSWER_RESULT", nl2br($answers[$answer_id]));
284 $this->tpl->parseCurrentBlock();
293 $end = $this->poll_block->getPoll()->getVotingPeriodEnd();
299 if($this->poll_block->getPoll()->hasUserVoted($ilUser->getId()))
301 $info .= $lng->txt(
"poll_block_message_already_voted").
" ";
304 $this->tpl->setVariable(
"TOTAL_ANSWERS",
$info.
305 sprintf($lng->txt(
"poll_block_results_available_on"), $end));
308 else if($this->poll_block->getPoll()->hasUserVoted($ilUser->getId()))
310 $this->tpl->setVariable(
"TOTAL_ANSWERS", $lng->txt(
"poll_block_message_already_voted"));
315 $this->tpl->setVariable(
"ANCHOR_ID", $a_poll->getID());
316 $this->tpl->setVariable(
"TXT_QUESTION", nl2br(trim($a_poll->getQuestion())));
318 $desc = trim($a_poll->getDescription());
321 $this->tpl->setVariable(
"TXT_DESC", nl2br($desc));
324 $img = $a_poll->getImageFullPath();
327 require_once(
'./Services/WebAccessChecker/classes/class.ilWACSignedPath.php');
331 if ($this->poll_block->showComments()) {
332 $this->tpl->setCurrentBlock(
"comment_link");
333 $this->tpl->setVariable(
"LANG_COMMENTS", $lng->txt(
'poll_comments'));
334 $this->tpl->setVariable(
"COMMENT_JSCALL", $this->
commentJSCall());
335 $this->tpl->setVariable(
"COMMENTS_COUNT_ID", $this->
getRefId());
339 if($comments_count > 0)
341 $this->tpl->setVariable(
"COMMENTS_COUNT",
"(".$comments_count.
")");
346 $redraw_url = $ilCtrl->getLinkTarget($this,
"getNumberOfCommentsForRedraw",
348 $this->tpl->setVariable(
"COMMENTS_REDRAW_URL", $redraw_url);
350 $tpl->addJavaScript(
"Modules/Poll/js/ilPoll.js");
351 self::$js_init =
true;
364 $this->poll_block->setRefId($this->
getRefId());
365 $this->may_write = $ilAccess->checkAccess(
"write",
"", $this->
getRefId());
366 $this->has_content = $this->poll_block->hasAnyContent($ilUser->getId(), $this->
getRefId());
368 if(!$this->may_write && !$this->has_content)
373 $poll_obj = $this->poll_block->getPoll();
374 $this->
setTitle($poll_obj->getTitle());
380 if(!$this->poll_block->getMessage($ilUser->getId()))
383 include_once
"./Services/Notification/classes/class.ilNotification.php";
389 $lng->txt(
"poll_notification_unsubscribe"));
396 $lng->txt(
"poll_notification_subscribe"));
400 if ($this->may_write)
406 $lng->txt(
"edit_content"));
410 $lng->txt(
"settings"));
430 return parent::getHTML();
440 include_once(
"./Services/Notes/classes/class.ilNoteGUI.php");
441 include_once(
"./Services/Object/classes/class.ilCommonActionDispatcherGUI.php");
451 $jsCall =
$comment->getListCommentsJSCall($ajaxHash,
"ilPoll.redrawComments(".$refId.
");");
465 echo "(".$number.
")";
483 include_once(
"./Services/Notes/classes/class.ilNote.php");
488 if(count($number) == 0)
executeCommand()
execute command
static hasNotification($type, $user_id, $id)
Check notification status for object and user.
commentJSCall()
Builds JavaScript Call to open CommentLayer via html link.
static _countNotesAndComments($a_rep_obj_id, $a_sub_obj_id=null)
Get all notes related to a specific object.
getNumberOfComments($ref_id)
Get comment count.
const SHOW_RESULTS_AS_PIECHART
getRepositoryObjectGUIName()
Get repository object GUI name.
static _lookupObjectId($a_ref_id)
addBlockCommand($a_href, $a_text, $a_target="", $a_img="", $a_right_aligned=false, $a_checked=false, $a_html="")
Add Block Command.
static setUseRelativeDates($a_status)
set use relative dates
static sortArray($array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
static useRelativeDates()
check if relative dates are used
getHTML()
Get block HTML code.
static getBlockType()
Get block type.
static getInstance()
Factory.
setTitle($a_title)
Set Title.
static buildAjaxHash($a_node_type, $a_node_id, $a_obj_type, $a_obj_id, $a_sub_type=null, $a_sub_id=null)
Build ajax hash.
setBlockId($a_block_id=0)
Set Block Id.
setData($a_data)
Set Data.
static formatDate(ilDateTime $date)
Format a date public.
static signFile($path_to_file)
Create styles array
The data for the language used.
static isRepositoryObject()
Is block of repository object?
getRefId()
Get Ref Id (only used if isRepositoryObject() is true).
BlockGUI class for polls.
getNumberOfCommentsForRedraw()
Returns comment count for JS Redraw.
This class represents a block method of a block.
__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.