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);
101 $section->setTitle($this->
lng->txt(
'poll_voting_period_and_results'));
111 $this->
lng->txt(
"poll_view_results_always"),
115 $this->
lng->txt(
"poll_view_results_never"),
119 $this->
lng->txt(
"poll_view_results_after_vote"),
123 $this->
lng->txt(
"poll_view_results_after_period"),
131 $this->
lng->txt(
"poll_barchart"),
134 $show_result_as->addOption($result_bar);
136 $this->
lng->txt(
"poll_piechart"),
139 $a_form->
addItem($show_result_as);
143 $sort->addOption(
new ilRadioOption($this->
lng->txt(
"poll_result_sorting_answers"),
"0"));
144 $sort->addOption(
new ilRadioOption($this->
lng->txt(
"poll_result_sorting_votes"),
"1"));
148 $section->setTitle($this->
lng->txt(
'poll_comments'));
158 $a_values[
"online"] = !$this->
object->getOfflineStatus();
159 $a_values[
"results"] = $this->
object->getViewResults();
160 $a_values[
"access_period"][
"start"] = $this->
object->getAccessBegin()
163 $a_values[
"access_period"][
"end"] = $this->
object->getAccessEnd()
166 $a_values[
"voting_period"][
"start"] = $this->
object->getVotingPeriodBegin()
169 $a_values[
"voting_period"][
"end"] = $this->
object->getVotingPeriodEnd()
172 $a_values[
"sort"] = (string) (
int) $this->
object->getSortResultByVotes();
173 $a_values[
"comment"] = $this->
object->getShowComments();
174 $a_values[
"show_results_as"] = $this->
object->getShowResultsAs();
180 if (!$form->
getInput(
"voting_period") &&
182 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
"form_input_not_valid"));
183 $form->
getItemByPostVar(
"results")->setAlert($this->
lng->txt(
"poll_view_results_after_period_impossible"));
186 return parent::validateCustom($form);
191 $this->
object->setViewResults((
int) $form->
getInput(
"results"));
192 $this->
object->setOfflineStatus(!((
string) $form->
getInput(
"online") ===
"1"));
193 $this->
object->setSortResultByVotes((
bool) $form->
getInput(
"sort"));
194 $this->
object->setShowComments((
bool) $form->
getInput(
"comment"));
195 $this->
object->setShowResultsAs((
int) $form->
getInput(
"show_results_as"));
198 if ($period->getStart() && $period->getEnd()) {
200 $this->
object->setAccessBegin($period->getStart()->get(
IL_CAL_UNIX));
201 $this->
object->setAccessEnd($period->getEnd()->get(
IL_CAL_UNIX));
207 if ($period->getStart() && $period->getEnd()) {
208 $this->
object->setVotingPeriod(
true);
209 $this->
object->setVotingPeriodBegin($period->getStart()->get(
IL_CAL_UNIX));
210 $this->
object->setVotingPeriodEnd($period->getEnd()->get(
IL_CAL_UNIX));
212 $this->
object->setVotingPeriodBegin(0);
213 $this->
object->setVotingPeriodEnd(0);
214 $this->
object->setVotingPeriod(
false);
220 $this->
help->setScreenIdComponent(
"poll");
223 $this->tabs_gui->addTab(
225 $this->
lng->txt(
"content"),
226 $this->
ctrl->getLinkTarget($this,
"")
231 $this->tabs_gui->addTab(
233 $this->
lng->txt(
"settings"),
234 $this->
ctrl->getLinkTarget($this,
"edit")
237 $this->tabs_gui->addTab(
239 $this->
lng->txt(
"poll_result"),
240 $this->
ctrl->getLinkTarget($this,
"showParticipants")
243 $this->tabs_gui->addTab(
245 $this->
lng->txt(
"export"),
246 $this->
ctrl->getLinkTargetByClass(
"ilexportgui",
"")
256 $next_class = $this->
ctrl->getNextClass($this);
257 $cmd = $this->
ctrl->getCmd();
259 $this->tpl->loadStandardTemplate();
264 $link = $this->
ctrl->getLinkTargetByClass(
"ilrepositorygui",
"frameset");
265 $this->nav_history->addItem($this->node_id, $link,
"poll");
268 switch ($next_class) {
269 case "ilcommonactiondispatchergui":
271 $this->
ctrl->forwardCommand($gui);
274 case "ilpermissiongui":
276 $this->
tabs->activateTab(
"id_permissions");
278 $this->
ctrl->forwardCommand($perm_gui);
281 case "ilobjectcopygui":
283 $cp->setType(
"poll");
284 $this->
ctrl->forwardCommand($cp);
289 $this->
tabs->activateTab(
"export");
291 $exp_gui->addFormat(
"xml");
292 $this->
ctrl->forwardCommand($exp_gui);
296 parent::executeCommand();
303 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
"no_permission"));
307 $this->
tabs->activateTab(
"content");
311 if ($this->
object->countVotes()) {
312 $url = $this->
ctrl->getLinkTarget($this,
"showParticipants");
314 $mbox = $this->ui_factory->messageBox()->info($this->
lng->txt(
"poll_votes_no_edit"))
315 ->withLinks([$this->ui_factory->link()->standard(
316 $this->
lng->txt(
"poll_result"),
320 $message = $this->ui_renderer->render($mbox);
326 $this->tpl->setPermanentLink(
'poll', $this->node_id);
328 $this->tpl->setContent(
$message . $a_form->getHTML());
334 $form->setFormAction($this->
ctrl->getFormAction($this,
"saveQuestion"));
335 $form->setTitle($this->
lng->txt(
"obj_poll"));
339 $question->setCols(40);
340 $question->setRows(2);
341 $question->setValue($this->
object->getQuestion());
342 $question->setDisabled($a_read_only);
343 $form->addItem($question);
347 $img->setDisabled($a_read_only);
348 $form->addItem(
$img);
351 $file = $this->
object->getImageFullPath(
true);
359 $option->
setInfo($this->
lng->txt(
"poll_mode_anonymous_info"));
360 $anonymous->addOption($option);
362 $option->
setInfo($this->
lng->txt(
"poll_mode_personal_info"));
363 $anonymous->addOption($option);
364 $anonymous->setValue($this->
object->getNonAnonymous() ?
"1" :
"0");
365 $anonymous->setDisabled($a_read_only);
366 $form->addItem($anonymous);
368 $nanswers =
new ilNumberInputGUI($this->
lng->txt(
"poll_max_number_of_answers"),
"nanswers");
370 $nanswers->setMinValue(1);
371 $nanswers->setSize(3);
372 $nanswers->setValue((
string) $this->
object->getMaxNumberOfAnswers());
373 $nanswers->setDisabled($a_read_only);
374 $form->addItem($nanswers);
377 $answers->setRequired(
true);
378 $answers->setMulti(
true,
true);
379 $answers->setDisabled($a_read_only);
380 $form->addItem($answers);
382 $multi_answers = array();
383 foreach ($this->
object->getAnswers() as $idx => $item) {
384 $answer = (string) ($item[
'answer'] ??
'');
386 $answers->setValue($answer);
388 $multi_answers[] = $answer;
390 $answers->setMultiValues($multi_answers);
393 $form->addCommandButton(
"saveQuestion", $this->
lng->txt(
"save"));
402 if ($form->checkInput()) {
403 $this->
object->setQuestion((
string) $form->getInput(
"question"));
404 $this->
object->setNonAnonymous((
bool) $form->getInput(
"mode"));
406 $image = $form->getItemByPostVar(
"image");
407 $res = $form->getFileUpload(
"image");
409 $this->
object->uploadImage(
$res);
410 } elseif ($image->getDeletionFlag()) {
411 $this->
object->deleteImage();
414 $nr_of_anwers = $this->
object->saveAnswers((array) $form->getInput(
"answers"));
417 $this->
object->setMaxNumberOfAnswers(min((
int) $form->getInput(
"nanswers"), $nr_of_anwers));
419 if ($this->
object->update()) {
420 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
"settings_saved"),
true);
421 $this->
ctrl->redirect($this,
"render");
425 $form->setValuesByPost();
431 if (!$this->
object->getNonAnonymous()) {
435 $this->
tabs->addSubTab(
437 $this->
lng->txt(
"poll_result_answers"),
438 $this->
ctrl->getLinkTarget($this,
"showParticipants")
440 $this->
tabs->addSubTab(
442 $this->
lng->txt(
"poll_result_users"),
443 $this->
ctrl->getLinkTarget($this,
"showParticipantVotes")
446 $this->
tabs->activateSubTab($a_active);
452 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
"no_permission"));
456 $this->
tabs->activateTab(
"participants");
460 $this->tpl->setContent($tbl->getHTML());
466 !$this->
object->getNonAnonymous()) {
467 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
"no_permission"));
471 $this->
tabs->activateTab(
"participants");
475 $this->tpl->setContent($tbl->getHTML());
481 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
"no_permission"));
485 $this->
tabs->activateTab(
"participants");
488 $cgui->setHeaderText($this->
lng->txt(
"poll_delete_votes_sure"));
490 $cgui->setFormAction($this->
ctrl->getFormAction($this));
491 $cgui->setCancel($this->
lng->txt(
"cancel"),
"showParticipants");
492 $cgui->setConfirm($this->
lng->txt(
"confirm"),
"deleteAllVotes");
494 $this->tpl->setContent($cgui->getHTML());
500 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
"no_permission"));
504 $this->
object->deleteAllVotes();
506 $this->
ctrl->redirect($this,
"showParticipants");
512 $aw = (array) ($DIC->http()->request()->getParsedBody()[
'aw'] ?? array());
515 if ($this->
object->getMaxNumberOfAnswers() > 1) {
516 if (count($aw) > $this->
object->getMaxNumberOfAnswers()) {
522 } elseif ((
int) !$aw) {
528 unset($session_last_poll_vote[$this->
object->getId()]);
530 $this->
object->saveVote($this->
user->getId(), $aw);
534 $session_last_poll_vote[$this->
object->getId()] = $aw;
545 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
"settings_saved"),
true);
553 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
"settings_saved"),
true);
566 if (!count($users)) {
571 $ntf->setLangModules(array(
"poll"));
572 $ntf->setRefId($this->ref_id);
574 $ntf->setSubjectLangId(
'poll_vote_notification_subject');
575 $ntf->setIntroductionLangId(
'poll_vote_notification_body');
576 $ntf->setGotoLangId(
'poll_vote_notification_link');
577 $ntf->setReasonLangId(
'poll_vote_notification_reason');
579 $notified = $ntf->sendMailAndReturnRecipients($users, null,
"read");
586 if (is_object($this->
object)) {
591 public static function _goto(
string $a_target): void
595 $tree = $DIC->repositoryTree();
596 $ilAccess = $DIC->access();
597 $ilCtrl = $DIC->ctrl();
599 $id = explode(
"_", $a_target);
603 if ($ilAccess->checkAccess(
"write",
"",
$ref_id)) {
604 $ilCtrl->setParameterByClass(self::class,
"ref_id",
$ref_id);
605 $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)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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
static _getLink(?int $a_ref_id, string $a_type='', array $a_params=array(), string $append="")
Navigation History of 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)
__construct(Container $dic, ilPlugin $plugin)
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.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getEditFormCustomValues(array &$a_values)