3 declare(strict_types=1);
40 public function __construct(
int $a_id = 0,
int $a_id_type = self::REPOSITORY_NODE_ID,
int $a_parent_node_id = 0)
44 $this->
lng = $DIC->language();
45 $this->
ctrl = $DIC->ctrl();
46 $this->
help = $DIC[
"ilHelp"];
47 $this->tpl = $DIC[
"tpl"];
48 $this->
tabs = $DIC->tabs();
49 $this->nav_history = $DIC[
"ilNavigationHistory"];
50 $this->
toolbar = $DIC->toolbar();
51 $this->
user = $DIC->user();
52 $this->tree = $DIC->repositoryTree();
53 $this->
locator = $DIC[
"ilLocator"];
54 $this->ui_factory = $DIC->ui()->factory();
55 $this->ui_renderer = $DIC->ui()->renderer();
59 $this->
lng->loadLanguageModule(
"poll");
69 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
"object_added"),
true);
70 $this->
ctrl->redirect($this,
"render");
76 $this->
lng->loadLanguageModule(
'rep');
79 $section->setTitle($this->
lng->txt(
'rep_activation_availability'));
83 $act_obj_info = $act_ref_info =
"";
85 $act_obj_info =
' ' . $this->
lng->txt(
'rep_activation_online_object_info');
86 $act_ref_info = $this->
lng->txt(
'rep_activation_access_ref_info');
90 $online->setInfo($this->
lng->txt(
'poll_activation_online_info') . $act_obj_info);
94 $dur->setShowTime(
true);
101 $section->setTitle($this->
lng->txt(
'poll_voting_period_and_results'));
105 $vdur->setShowTime(
true);
110 $this->
lng->txt(
"poll_view_results_always"),
114 $this->
lng->txt(
"poll_view_results_never"),
118 $this->
lng->txt(
"poll_view_results_after_vote"),
122 $this->
lng->txt(
"poll_view_results_after_period"),
129 $this->
lng->txt(
"poll_barchart"),
132 $show_result_as->addOption($result_bar);
134 $this->
lng->txt(
"poll_piechart"),
137 $a_form->
addItem($show_result_as);
141 $sort->addOption(
new ilRadioOption($this->
lng->txt(
"poll_result_sorting_votes"),
"1"));
145 $section->setTitle($this->
lng->txt(
'poll_comments'));
155 $a_values[
"online"] = !$this->
object->getOfflineStatus();
156 $a_values[
"results"] = $this->
object->getViewResults();
157 $a_values[
"access_period"][
"start"] = $this->
object->getAccessBegin()
160 $a_values[
"access_period"][
"end"] = $this->
object->getAccessEnd()
163 $a_values[
"voting_period"][
"start"] = $this->
object->getVotingPeriodBegin()
166 $a_values[
"voting_period"][
"end"] = $this->
object->getVotingPeriodEnd()
169 $a_values[
"sort"] = (string) (
int) $this->
object->getSortResultByVotes();
170 $a_values[
"comment"] = $this->
object->getShowComments();
171 $a_values[
"show_results_as"] = $this->
object->getShowResultsAs();
177 if ($form->
getInput(
"online") && !$this->
object->getAnswers()) {
178 $form->
getItemByPostVar(
"online")->setAlert($this->
lng->txt(
"poll_cannot_set_online_no_answers"));
182 if (!array_filter($form->
getInput(
"voting_period")) &&
184 $form->
getItemByPostVar(
"results")->setAlert($this->
lng->txt(
"poll_view_results_after_period_impossible"));
188 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
"form_input_not_valid"));
191 return parent::validateCustom($form);
196 $this->
object->setViewResults((
int) $form->
getInput(
"results"));
197 $this->
object->setOfflineStatus(!((
string) $form->
getInput(
"online") ===
"1"));
198 $this->
object->setSortResultByVotes((
bool) $form->
getInput(
"sort"));
199 $this->
object->setShowComments((
bool) $form->
getInput(
"comment"));
200 $this->
object->setShowResultsAs((
int) $form->
getInput(
"show_results_as"));
203 if ($period->getStart() && $period->getEnd()) {
205 $this->
object->setAccessBegin($period->getStart()->get(
IL_CAL_UNIX));
206 $this->
object->setAccessEnd($period->getEnd()->get(
IL_CAL_UNIX));
212 if ($period->getStart() && $period->getEnd()) {
213 $this->
object->setVotingPeriod(
true);
214 $this->
object->setVotingPeriodBegin($period->getStart()->get(
IL_CAL_UNIX));
215 $this->
object->setVotingPeriodEnd($period->getEnd()->get(
IL_CAL_UNIX));
217 $this->
object->setVotingPeriodBegin(0);
218 $this->
object->setVotingPeriodEnd(0);
219 $this->
object->setVotingPeriod(
false);
225 $this->
help->setScreenIdComponent(
"poll");
228 $this->tabs_gui->addTab(
230 $this->
lng->txt(
"question"),
231 $this->
ctrl->getLinkTarget($this,
"")
236 $this->tabs_gui->addTab(
238 $this->
lng->txt(
"settings"),
239 $this->
ctrl->getLinkTarget($this,
"edit")
242 $this->tabs_gui->addTab(
244 $this->
lng->txt(
"poll_result"),
245 $this->
ctrl->getLinkTarget($this,
"showParticipants")
248 $this->tabs_gui->addTab(
250 $this->
lng->txt(
"export"),
251 $this->
ctrl->getLinkTargetByClass(
"ilexportgui",
"")
261 $next_class = $this->
ctrl->getNextClass($this);
262 $cmd = $this->
ctrl->getCmd();
264 $this->tpl->loadStandardTemplate();
269 $link = $this->
ctrl->getLinkTargetByClass(
"ilrepositorygui",
"frameset");
270 $this->nav_history->addItem($this->node_id, $link,
"poll");
273 switch ($next_class) {
274 case "ilcommonactiondispatchergui":
276 $this->
ctrl->forwardCommand($gui);
279 case "ilpermissiongui":
281 $this->
tabs->activateTab(
"id_permissions");
283 $this->
ctrl->forwardCommand($perm_gui);
286 case "ilobjectcopygui":
288 $cp->setType(
"poll");
289 $this->
ctrl->forwardCommand($cp);
294 $this->
tabs->activateTab(
"export");
296 $exp_gui->addFormat(
"xml");
297 $this->
ctrl->forwardCommand($exp_gui);
301 parent::executeCommand();
308 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
"no_permission"));
312 $this->
tabs->activateTab(
"question");
316 if ($this->
object->countVotes()) {
317 $url = $this->
ctrl->getLinkTarget($this,
"showParticipants");
319 $mbox = $this->ui_factory->messageBox()->info($this->
lng->txt(
"poll_votes_no_edit"))
320 ->withLinks([$this->ui_factory->link()->standard(
321 $this->
lng->txt(
"poll_result"),
325 $message = $this->ui_renderer->render($mbox);
331 $this->tpl->setPermanentLink(
'poll', $this->node_id);
333 $this->tpl->setContent(
$message . $a_form->getHTML());
339 $form->setFormAction($this->
ctrl->getFormAction($this,
"saveQuestion"));
340 $form->setTitle($this->
lng->txt(
"obj_poll"));
344 $question->setCols(40);
345 $question->setRows(2);
346 $question->setValue($this->
object->getQuestion());
347 $question->setDisabled($a_read_only);
348 $form->addItem($question);
353 $form->addItem($img);
356 $file = $this->
object->getImageFullPath(
true);
363 $option->
setInfo($this->
lng->txt(
"poll_mode_anonymous_info"));
364 $anonymous->addOption($option);
366 $option->
setInfo($this->
lng->txt(
"poll_mode_personal_info"));
367 $anonymous->addOption($option);
368 $anonymous->setValue($this->
object->getNonAnonymous() ?
"1" :
"0");
369 $anonymous->setDisabled($a_read_only);
370 $form->addItem($anonymous);
373 $answers->setRequired(
true);
374 $answers->setMulti(
true,
true);
375 $answers->setDisabled($a_read_only);
376 $form->addItem($answers);
378 $multi_answers = array();
379 foreach ($this->
object->getAnswers() as $idx => $item) {
380 $answer = (string) ($item[
'answer'] ??
'');
382 $answers->setValue($answer);
384 $multi_answers[] = $answer;
386 $answers->setMultiValues($multi_answers);
388 $answer_count = count($this->
object->getAnswers());
390 $limit->setChecked($this->
object->getMaxNumberOfAnswers() !== $answer_count);
391 $limit->setDisabled($a_read_only);
392 $nanswers =
new ilNumberInputGUI($this->
lng->txt(
"poll_max_number_of_answers"),
"nanswers");
393 $nanswers->setRequired(
true);
394 $nanswers->setMinValue(1);
395 $nanswers->setSize(3);
397 if ($this->
object->getMaxNumberOfAnswers() < $answer_count) {
398 $max_answers = $this->
object->getMaxNumberOfAnswers();
400 $nanswers->setValue((
string) $max_answers);
401 $nanswers->setDisabled($a_read_only);
402 $limit->addSubItem($nanswers);
403 $form->addItem($limit);
406 $form->addCommandButton(
"saveQuestion", $this->
lng->txt(
"save"));
416 if ($form->checkInput()) {
417 $prelim_nr_of_answers = count((array) $form->getInput(
"answers"));
420 $form->getInput(
"limit") &&
421 (
int) $form->getInput(
"nanswers") >= $prelim_nr_of_answers
423 $form->getItemByPostVar(
'nanswers')->setAlert(
424 $this->
lng->txt(
'poll_limit_not_below_answer_count')
426 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'form_input_not_valid'));
427 $form->setValuesByPost();
432 $nr_of_anwers = $this->
object->saveAnswers((array) $form->getInput(
"answers"));
434 if ($form->getInput(
"limit")) {
436 $this->
object->setMaxNumberOfAnswers(min((
int) $form->getInput(
"nanswers"), $nr_of_anwers));
438 $this->
object->setMaxNumberOfAnswers($nr_of_anwers);
441 $this->
object->setQuestion((
string) $form->getInput(
"question"));
442 $this->
object->setNonAnonymous((
bool) $form->getInput(
"mode"));
444 $image = $form->getItemByPostVar(
"image");
445 $res = $form->getFileUpload(
"image");
447 $this->
object->uploadImage(
$res);
448 } elseif ($image->getDeletionFlag()) {
449 $this->
object->deleteImage();
452 if ($this->
object->update()) {
453 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
"settings_saved"),
true);
454 $this->
ctrl->redirect($this,
"render");
458 $form->setValuesByPost();
464 if (!$this->
object->getNonAnonymous()) {
468 $this->
tabs->addSubTab(
470 $this->
lng->txt(
"poll_result_answers"),
471 $this->
ctrl->getLinkTarget($this,
"showParticipants")
473 $this->
tabs->addSubTab(
475 $this->
lng->txt(
"poll_result_users"),
476 $this->
ctrl->getLinkTarget($this,
"showParticipantVotes")
479 $this->
tabs->activateSubTab($a_active);
485 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
"no_permission"));
489 $this->
tabs->activateTab(
"participants");
494 if ($tbl->getItems()) {
496 $this->ui_factory->button()->standard(
497 $this->
lng->txt(
"poll_delete_votes"),
498 $this->
ctrl->getLinkTarget($this,
'confirmDeleteAllVotes')
503 $this->tpl->setContent($tbl->getHTML());
509 !$this->
object->getNonAnonymous()) {
510 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
"no_permission"));
514 $this->
tabs->activateTab(
"participants");
518 $this->tpl->setContent($tbl->getHTML());
524 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
"no_permission"));
528 $this->
tabs->activateTab(
"participants");
531 $cgui->setHeaderText($this->
lng->txt(
"poll_delete_votes_sure"));
533 $cgui->setFormAction($this->
ctrl->getFormAction($this));
534 $cgui->setCancel($this->
lng->txt(
"cancel"),
"showParticipants");
535 $cgui->setConfirm($this->
lng->txt(
"confirm"),
"deleteAllVotes");
537 $this->tpl->setContent($cgui->getHTML());
543 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
"no_permission"));
547 $this->
object->deleteAllVotes();
549 $this->
ctrl->redirect($this,
"showParticipants");
555 $aw = (array) ($DIC->http()->request()->getParsedBody()[
'aw'] ?? array());
558 if ($this->
object->getMaxNumberOfAnswers() > 1) {
559 if (count($aw) > $this->
object->getMaxNumberOfAnswers()) {
565 } elseif ((
int) !$aw) {
571 unset($session_last_poll_vote[$this->
object->getId()]);
573 $this->
object->saveVote($this->
user->getId(), $aw);
577 $session_last_poll_vote[$this->
object->getId()] = $aw;
581 ilUtil::redirect(ilLink::_getLink($this->tree->getParentId($this->ref_id)));
588 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
"poll_notification_activated"),
true);
589 ilUtil::redirect(ilLink::_getLink($this->tree->getParentId($this->ref_id)));
596 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
"poll_notification_deactivated"),
true);
597 ilUtil::redirect(ilLink::_getLink($this->tree->getParentId($this->ref_id)));
609 if (!count($users)) {
614 $ntf->setLangModules(array(
"poll"));
615 $ntf->setRefId($this->ref_id);
617 $ntf->setSubjectLangId(
'poll_vote_notification_subject');
618 $ntf->setIntroductionLangId(
'poll_vote_notification_body');
619 $ntf->setGotoLangId(
'poll_vote_notification_link');
620 $ntf->setReasonLangId(
'poll_vote_notification_reason');
622 $notified = $ntf->sendMailAndReturnRecipients($users, null,
"read");
629 if (is_object($this->
object)) {
634 public static function _goto(
string $a_target): void
638 $tree = $DIC->repositoryTree();
639 $ilAccess = $DIC->access();
640 $ilCtrl = $DIC->ctrl();
642 $id = explode(
"_", $a_target);
646 if ($ilAccess->checkAccess(
"write",
"",
$ref_id)) {
647 $ilCtrl->setParameterByClass(self::class,
"ref_id",
$ref_id);
648 $ilCtrl->redirectByClass([ilRepositoryGUI::class, self::class,],
"showParticipants");
static get(string $a_var)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
An entity that renders components to a string output.
const VIEW_RESULTS_AFTER_PERIOD
setParticipantsSubTabs(string $a_active)
const VIEW_RESULTS_AFTER_VOTE
updateCustom(ilPropertyFormGUI $form)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
New implementation of ilObjectGUI.
GUI class for the workflow of copying objects.
const VIEW_RESULTS_ALWAYS
static _getAllReferences(int $id)
get all reference ids for object ID
const SHOW_RESULTS_AS_PIECHART
const TIMINGS_DEACTIVATED
ilNavigationHistory $nav_history
prepareOutput(bool $show_sub_objects=true)
static getNotificationsForObject(int $type, int $id, ?int $page_id=null, bool $ignore_threshold=false)
Get all users/recipients for given object.
initEditCustomForm(ilPropertyFormGUI $a_form)
const SHOW_RESULTS_AS_BARCHART
validateCustom(ilPropertyFormGUI $form)
static _lookupObjId(int $ref_id)
Export User Interface Class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
initQuestionForm(bool $a_read_only=false)
checkPermissionBool(string $perm, string $cmd="", string $type="", ?int $node_id=null)
static setNotification(int $type, int $user_id, int $id, bool $status=true)
Set notification status for object and user.
__construct(int $a_id=0, int $a_id_type=self::REPOSITORY_NODE_ID, int $a_parent_node_id=0)
static _goto(string $a_target)
getParentId(int $a_node_id)
get parent id of given node
Last visited history for repository items.
static updateNotificationTime(int $type, int $id, array $user_ids, ?int $page_id=null, bool $activate_new_entries=true)
Update the last mail timestamp for given object and users.
static redirect(string $a_script)
afterSave(ilObject $new_object)
This class represents a text area property in a property form.
static signFile(string $path_to_file)
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
render(?ilPropertyFormGUI $a_form=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static set(string $a_var, $a_val)
Set a value.
static getInstanceFromAjaxCall()
(Re-)Build instance from ajax call
TableGUI class for poll users.
getEditFormCustomValues(array &$a_values)