ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjPollGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 require_once "./Services/Object/classes/class.ilObject2GUI.php";
6 
19 {
20  function __construct($a_id = 0, $a_id_type = self::REPOSITORY_NODE_ID, $a_parent_node_id = 0)
21  {
22  global $lng;
23 
24  parent::__construct($a_id, $a_id_type, $a_parent_node_id);
25 
26  $lng->loadLanguageModule("poll");
27  }
28 
29  function getType()
30  {
31  return "poll";
32  }
33 
34  protected function afterSave(ilObject $a_new_object)
35  {
36  global $ilCtrl;
37 
38  ilUtil::sendSuccess($this->lng->txt("object_added"), true);
39  $ilCtrl->redirect($this, "render");
40  }
41 
42  protected function initEditCustomForm(ilPropertyFormGUI $a_form)
43  {
44  global $lng;
45 
46  // activation
47 
48  include_once "Services/Object/classes/class.ilObjectActivation.php";
49  $this->lng->loadLanguageModule('rep');
50 
52  $section->setTitle($this->lng->txt('rep_activation_availability'));
53  $a_form->addItem($section);
54 
55  // additional info only with multiple references
56  $act_obj_info = $act_ref_info = "";
57  if(sizeof(ilObject::_getAllReferences($this->object->getId())) > 1)
58  {
59  $act_obj_info = ' '.$this->lng->txt('rep_activation_online_object_info');
60  $act_ref_info = $this->lng->txt('rep_activation_access_ref_info');
61  }
62 
63  $online = new ilCheckboxInputGUI($this->lng->txt('rep_activation_online'),'online');
64  $online->setInfo($this->lng->txt('poll_activation_online_info').$act_obj_info);
65  $a_form->addItem($online);
66 
67  $act_type = new ilRadioGroupInputGUI($this->lng->txt('rep_activation_access'),'access_type');
68  $act_type->setInfo($act_ref_info);
69 
70  $opt = new ilRadioOption($this->lng->txt('rep_visibility_limitless'), ilObjectActivation::TIMINGS_DEACTIVATED);
71  $opt->setInfo($this->lng->txt('poll_availability_limitless_info'));
72  $act_type->addOption($opt);
73 
74  $opt = new ilRadioOption($this->lng->txt('rep_visibility_until'), ilObjectActivation::TIMINGS_ACTIVATION);
75  $opt->setInfo($this->lng->txt('poll_availability_until_info'));
76 
77  $date = $this->object->getAccessBegin();
78 
79  $start = new ilDateTimeInputGUI($this->lng->txt('rep_activation_limited_start'),'access_begin');
80  $start->setShowTime(true);
81  $start->setDate(new ilDateTime($date ? $date : time(), IL_CAL_UNIX));
82  $opt->addSubItem($start);
83 
84  $date = $this->object->getAccessEnd();
85 
86  $end = new ilDateTimeInputGUI($this->lng->txt('rep_activation_limited_end'),'access_end');
87  $end->setShowTime(true);
88  $end->setDate(new ilDateTime($date ? $date : time(), IL_CAL_UNIX));
89  $opt->addSubItem($end);
90 
91  /*
92  $visible = new ilCheckboxInputGUI($this->lng->txt('rep_activation_limited_visibility'), 'access_visiblity');
93  $visible->setInfo($this->lng->txt('poll_activation_limited_visibility_info'));
94  $opt->addSubItem($visible);
95  */
96 
97  $act_type->addOption($opt);
98 
99  $a_form->addItem($act_type);
100 
101 
102  // period/results
103 
105  $section->setTitle($this->lng->txt('poll_voting_period_and_results'));
106  $a_form->addItem($section);
107 
108  $prd = new ilRadioGroupInputGUI($this->lng->txt('poll_voting_period'),'period');
109 
110  $opt = new ilRadioOption($this->lng->txt('poll_voting_period_unlimited'), 0);
111  $prd->addOption($opt);
112 
113  $opt = new ilRadioOption($this->lng->txt('poll_voting_period_limited'), 1);
114  $prd->addOption($opt);
115 
116  $date = $this->object->getVotingPeriodBegin();
117 
118  $start = new ilDateTimeInputGUI($this->lng->txt('poll_voting_period_start'),'period_begin');
119  $start->setShowTime(true);
120  $start->setDate(new ilDateTime($date ? $date : time(), IL_CAL_UNIX));
121  $opt->addSubItem($start);
122 
123  $date = $this->object->getVotingPeriodEnd();
124 
125  $end = new ilDateTimeInputGUI($this->lng->txt('poll_voting_period_end'),'period_end');
126  $end->setShowTime(true);
127  $end->setDate(new ilDateTime($date ? $date : time(), IL_CAL_UNIX));
128  $opt->addSubItem($end);
129 
130  $a_form->addItem($prd);
131 
132  $results = new ilRadioGroupInputGUI($lng->txt("poll_view_results"), "results");
133  $results->setRequired(true);
134  $results->addOption(new ilRadioOption($lng->txt("poll_view_results_always"),
136  $results->addOption(new ilRadioOption($lng->txt("poll_view_results_never"),
138  $results->addOption(new ilRadioOption($lng->txt("poll_view_results_after_vote"),
140  $results->addOption(new ilRadioOption($lng->txt("poll_view_results_after_period"),
142  $a_form->addItem($results);
143  }
144 
145  protected function getEditFormCustomValues(array &$a_values)
146  {
147  $a_values["online"] = $this->object->IsOnline();
148  // $a_values["question"] = $this->object->getQuestion();
149  // $a_values["image"] = $this->object->getImage();
150  $a_values["results"] = $this->object->getViewResults();
151  $a_values["access_type"] = $this->object->getAccessType();
152  // $a_values["access_begin"] = $this->object->getAccessBegin();
153  // $a_values["access_end"] = $this->object->getAccessEnd();
154  // $a_values["access_visiblity"] = $this->object->getAccessVisibility();
155  $a_values["period"] = $this->object->getVotingPeriod();
156  $a_values["period_begin"] = $this->object->getVotingPeriodBegin();
157  $a_values["period_end"] = $this->object->getVotingPeriodEnd();
158  }
159 
160  protected function updateCustom(ilPropertyFormGUI $a_form)
161  {
162  $this->object->setViewResults($a_form->getInput("results"));
163  $this->object->setOnline($a_form->getInput("online"));
164 
165  include_once "Services/Object/classes/class.ilObjectActivation.php";
166  $this->object->setAccessType($a_form->getInput("access_type"));
167  if($this->object->getAccessType() == ilObjectActivation::TIMINGS_ACTIVATION)
168  {
169  $date = new ilDateTime($_POST['access_begin']['date'] . ' ' . $_POST['access_begin']['time'], IL_CAL_DATETIME);
170  $this->object->setAccessBegin($date->get(IL_CAL_UNIX));
171  $date = new ilDateTime($_POST['access_end']['date'] . ' ' . $_POST['access_end']['time'], IL_CAL_DATETIME);
172  $this->object->setAccessEnd($date->get(IL_CAL_UNIX));
173  // $this->object->setAccessVisibility($a_form->getInput("access_visiblity"));
174  }
175  $this->object->setVotingPeriod($a_form->getInput("period"));
176  if($this->object->getVotingPeriod())
177  {
178  $date = new ilDateTime($_POST['period_begin']['date'] . ' ' . $_POST['period_begin']['time'], IL_CAL_DATETIME);
179  $this->object->setVotingPeriodBegin($date->get(IL_CAL_UNIX));
180  $date = new ilDateTime($_POST['period_end']['date'] . ' ' . $_POST['period_end']['time'], IL_CAL_DATETIME);
181  $this->object->setVotingPeriodEnd($date->get(IL_CAL_UNIX));
182  }
183  }
184 
185  function setTabs()
186  {
187  global $lng, $ilHelp;
188 
189  $ilHelp->setScreenIdComponent("poll");
190 
191  if ($this->checkPermissionBool("write"))
192  {
193  $this->tabs_gui->addTab("content",
194  $lng->txt("content"),
195  $this->ctrl->getLinkTarget($this, ""));
196  }
197 
198  if ($this->checkPermissionBool("write"))
199  {
200  $this->tabs_gui->addTab("settings",
201  $lng->txt("settings"),
202  $this->ctrl->getLinkTarget($this, "edit"));
203 
204  $this->tabs_gui->addTab("participants",
205  $lng->txt("poll_result"),
206  $this->ctrl->getLinkTarget($this, "showParticipants"));
207 
208  $this->tabs_gui->addTab("export",
209  $lng->txt("export"),
210  $this->ctrl->getLinkTargetByClass("ilexportgui", ""));
211  }
212 
213  // will add permissions if needed
214  parent::setTabs();
215  }
216 
217  function executeCommand()
218  {
219  global $ilCtrl, $tpl, $ilTabs, $ilNavigationHistory;
220 
221  $next_class = $ilCtrl->getNextClass($this);
222  $cmd = $ilCtrl->getCmd();
223 
224  $tpl->getStandardTemplate();
225 
226  // add entry to navigation history
227  if(!$this->getCreationMode() &&
228  $this->getAccessHandler()->checkAccess("read", "", $this->node_id))
229  {
230  $link = $ilCtrl->getLinkTargetByClass("ilrepositorygui", "frameset");
231  $ilNavigationHistory->addItem($this->node_id, $link, "poll");
232  }
233 
234  switch($next_class)
235  {
236  case "ilinfoscreengui":
237  $this->prepareOutput();
238  $this->infoScreenForward();
239  break;
240 
241  case "ilcommonactiondispatchergui":
242  include_once("Services/Object/classes/class.ilCommonActionDispatcherGUI.php");
244  $this->ctrl->forwardCommand($gui);
245  break;
246 
247  case "ilpermissiongui":
248  $this->prepareOutput();
249  $ilTabs->activateTab("id_permissions");
250  include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
251  $perm_gui = new ilPermissionGUI($this);
252  $this->ctrl->forwardCommand($perm_gui);
253  break;
254 
255  case "ilobjectcopygui":
256  include_once "./Services/Object/classes/class.ilObjectCopyGUI.php";
257  $cp = new ilObjectCopyGUI($this);
258  $cp->setType("poll");
259  $this->ctrl->forwardCommand($cp);
260  break;
261 
262  case 'ilexportgui':
263  $this->prepareOutput();
264  $ilTabs->activateTab("export");
265  include_once("./Services/Export/classes/class.ilExportGUI.php");
266  $exp_gui = new ilExportGUI($this);
267  $exp_gui->addFormat("xml");
268  $ilCtrl->forwardCommand($exp_gui);
269  break;
270 
271  default:
272  return parent::executeCommand();
273  }
274 
275  return true;
276  }
277 
278 
279  // --- ObjectGUI End
280 
281 
285  function render($a_form = null)
286  {
287  global $tpl, $ilTabs, $ilCtrl, $lng, $ilToolbar, $ilUser;
288 
289  if(!$this->checkPermissionBool("write"))
290  {
291  ilUtil::sendInfo($lng->txt("no_permission"));
292  return;
293  }
294 
295  $ilTabs->activateTab("content");
296 
297  if(!$a_form)
298  {
299  if($this->object->countVotes())
300  {
301  $url = $ilCtrl->getLinkTarget($this, "showParticipants");
302  ilUtil::sendInfo($lng->txt("poll_votes_no_edit").
303  " <a href=\"".$url."\">&raquo;".$lng->txt("poll_result")."</a>");
304  }
305 
306  $a_form = $this->initQuestionForm($this->object->countVotes());
307  }
308 
309  include_once('Services/PermanentLink/classes/class.ilPermanentLinkGUI.php');
310  $plink = new ilPermanentLinkGUI('poll', $this->node_id);
311 
312  $tpl->setContent($a_form->getHTML().$plink->getHTML());
313  }
314 
315  protected function initQuestionForm($a_read_only = false)
316  {
317  global $lng, $ilCtrl;
318 
319  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
320  $form = new ilPropertyFormGUI();
321  $form->setFormAction($ilCtrl->getFormAction($this, "saveQuestion"));
322  $form->setTitle($lng->txt("obj_poll"));
323 
324  $question = new ilTextAreaInputGUI($lng->txt("poll_question"), "question");
325  $question->setRequired(true);
326  $question->setCols(40);
327  $question->setRows(2);
328  $question->setValue($this->object->getQuestion());
329  $question->setDisabled($a_read_only);
330  $form->addItem($question);
331 
332  $dimensions = " (".ilObjPoll::getImageSize()."px)";
333  $img = new ilImageFileInputGUI($lng->txt("poll_image").$dimensions, "image");
334  $img->setDisabled($a_read_only);
335  $form->addItem($img);
336 
337  // show existing file
338  $file = $this->object->getImageFullPath(true);
339  if($file)
340  {
341  $img->setImage($file);
342  }
343 
344  $answers = new ilTextInputGUI($lng->txt("poll_answers"), "answers");
345  $answers->setRequired(true);
346  $answers->setMulti(true, true);
347  $answers->setDisabled($a_read_only);
348  $form->addItem($answers);
349 
350  $multi_answers = array();
351  foreach($this->object->getAnswers() as $idx => $item)
352  {
353  if(!$idx)
354  {
355  $answers->setValue($item["answer"]);
356  }
357  $multi_answers[] = $item["answer"];
358  }
359  $answers->setMultiValues($multi_answers);
360 
361  if(!$a_read_only)
362  {
363  $form->addCommandButton("saveQuestion", $lng->txt("save"));
364  }
365 
366  return $form;
367  }
368 
369  function saveQuestion()
370  {
371  $form = $this->initQuestionForm();
372  if($form->checkInput())
373  {
374  $this->object->setQuestion($form->getInput("question"));
375 
376  $image = $form->getItemByPostVar("image");
377  if($_FILES["image"]["tmp_name"])
378  {
379  $this->object->uploadImage($_FILES["image"]);
380  }
381  else if($image->getDeletionFlag())
382  {
383  $this->object->deleteImage();
384  }
385 
386  $this->object->saveAnswers($form->getInput("answers"));
387 
388  if($this->object->update())
389  {
390  ilUtil::sendSuccess($this->lng->txt("settings_saved"), true);
391  $this->ctrl->redirect($this, "render");
392  }
393  }
394 
395  $form->setValuesByPost();
396  $this->render($form);
397  }
398 
399  function showParticipants()
400  {
401  global $lng, $ilTabs, $tpl;
402 
403  if(!$this->checkPermissionBool("write"))
404  {
405  ilUtil::sendInfo($lng->txt("no_permission"));
406  return;
407  }
408 
409  $ilTabs->activateTab("participants");
410 
411  include_once "Modules/Poll/classes/class.ilPollAnswerTableGUI.php";
412  $tbl = new ilPollAnswerTableGUI($this, "showParticipants");
413  $tpl->setContent($tbl->getHTML());
414  }
415 
417  {
418  global $lng, $tpl, $ilTabs;
419 
420  if(!$this->checkPermissionBool("write"))
421  {
422  ilUtil::sendInfo($lng->txt("no_permission"));
423  return;
424  }
425 
426  $ilTabs->activateTab("participants");
427 
428  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
429  $cgui = new ilConfirmationGUI();
430  $cgui->setHeaderText($lng->txt("poll_delete_votes_sure"));
431 
432  $cgui->setFormAction($this->ctrl->getFormAction($this));
433  $cgui->setCancel($lng->txt("cancel"), "showParticipants");
434  $cgui->setConfirm($lng->txt("confirm"), "deleteAllVotes");
435 
436  $tpl->setContent($cgui->getHTML());
437  }
438 
439  function deleteAllVotes()
440  {
441  global $ilCtrl, $lng;
442 
443  if(!$this->checkPermissionBool("write"))
444  {
445  ilUtil::sendInfo($lng->txt("no_permission"));
446  return;
447  }
448 
449  $this->object->deleteAllVotes();
450 
451  $ilCtrl->redirect($this, "showParticipants");
452  }
453 
454  function vote()
455  {
456  global $tree, $ilUser;
457 
458  if($_POST["aw"])
459  {
460  $this->object->saveVote($ilUser->getId(), $_POST["aw"]);
461  }
462 
463  include_once "Services/Link/classes/class.ilLink.php";
464  ilUtil::redirect(ilLink:: _getLink($tree->getParentId($this->ref_id)));
465  }
466 
472  function getHTML()
473  {
474 
475  }
476 
477  function addLocatorItems()
478  {
479  global $ilLocator;
480 
481  if (is_object($this->object))
482  {
483  $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, ""), "", $this->node_id);
484  }
485  }
486 
492  function _goto($a_target)
493  {
494  global $tree;
495 
496  $id = explode("_", $a_target);
497 
498  // is sideblock: so show parent instead
499  $container_id = $tree->getParentId($id[0]);
500 
501  // #11810
502  include_once "Services/Link/classes/class.ilLink.php";
503  ilUtil::redirect(ilLink::_getLink($container_id).
504  "#poll".ilObject::_lookupObjId($id[0]));
505 
506  /*
507  $_GET["baseClass"] = "ilRepositoryGUI";
508  $_GET["ref_id"] = $container_id;
509  $_GET["cmd"] = "render";
510 
511  include("ilias.php");
512  exit;
513  */
514  }
515 }
516 
517 ?>