ILIAS  Release_4_4_x_branch Revision 61816
 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 ilCheckboxInputGUI($this->lng->txt('rep_visibility_until'),'access_type');
68  // $act_type->setInfo($this->lng->txt('poll_availability_until_info'));
69 
70  $this->tpl->addJavaScript('./Services/Form/js/date_duration.js');
71  include_once "Services/Form/classes/class.ilDateDurationInputGUI.php";
72  $dur = new ilDateDurationInputGUI($this->lng->txt('rep_time_period'), "access_period");
73  $dur->setShowTime(true);
74  $date = $this->object->getAccessBegin();
75  $dur->setStart(new ilDateTime($date ? $date : time(), IL_CAL_UNIX));
76  $dur->setStartText($this->lng->txt('rep_activation_limited_start'));
77  $date = $this->object->getAccessEnd();
78  $dur->setEnd(new ilDateTime($date ? $date : time(), IL_CAL_UNIX));
79  $dur->setEndText($this->lng->txt('rep_activation_limited_end'));
80  $act_type->addSubItem($dur);
81 
82  $a_form->addItem($act_type);
83 
84 
85  // period/results
86 
88  $section->setTitle($this->lng->txt('poll_voting_period_and_results'));
89  $a_form->addItem($section);
90 
91  $prd = new ilCheckboxInputGUI($this->lng->txt('poll_voting_period_limited'),'period');
92 
93  $vdur = new ilDateDurationInputGUI($this->lng->txt('rep_time_period'), "voting_period");
94  $vdur->setShowTime(true);
95  $date = $this->object->getVotingPeriodBegin();
96  $vdur->setStart(new ilDateTime($date ? $date : time(), IL_CAL_UNIX));
97  $vdur->setStartText($this->lng->txt('poll_voting_period_start'));
98  $date = $this->object->getVotingPeriodEnd();
99  $vdur->setEnd(new ilDateTime($date ? $date : time(), IL_CAL_UNIX));
100  $vdur->setEndText($this->lng->txt('poll_voting_period_end'));
101  $prd->addSubItem($vdur);
102 
103  $a_form->addItem($prd);
104 
105  $results = new ilRadioGroupInputGUI($lng->txt("poll_view_results"), "results");
106  $results->setRequired(true);
107  $results->addOption(new ilRadioOption($lng->txt("poll_view_results_always"),
109  $results->addOption(new ilRadioOption($lng->txt("poll_view_results_never"),
111  $results->addOption(new ilRadioOption($lng->txt("poll_view_results_after_vote"),
113  $results->addOption(new ilRadioOption($lng->txt("poll_view_results_after_period"),
115  $a_form->addItem($results);
116  }
117 
118  protected function getEditFormCustomValues(array &$a_values)
119  {
120  include_once "Services/Object/classes/class.ilObjectActivation.php";
121 
122  $a_values["online"] = $this->object->IsOnline();
123  $a_values["results"] = $this->object->getViewResults();
124  $a_values["access_type"] = ($this->object->getAccessType() == ilObjectActivation::TIMINGS_ACTIVATION);
125  $a_values["period"] = $this->object->getVotingPeriod();
126  }
127 
128  protected function updateCustom(ilPropertyFormGUI $a_form)
129  {
130  $this->object->setViewResults($a_form->getInput("results"));
131  $this->object->setOnline($a_form->getInput("online"));
132 
133  include_once "Services/Object/classes/class.ilObjectActivation.php";
134  if($a_form->getInput("access_type"))
135  {
136  $this->object->setAccessType(ilObjectActivation::TIMINGS_ACTIVATION);
137 
138  $period = $a_form->getItemByPostVar("access_period");
139  $this->object->setAccessBegin($period->getStart()->get(IL_CAL_UNIX));
140  $this->object->setAccessEnd($period->getEnd()->get(IL_CAL_UNIX));
141  }
142  else
143  {
144  $this->object->setAccessType(ilObjectActivation::TIMINGS_DEACTIVATED);
145  }
146 
147  if($a_form->getInput("period"))
148  {
149  $this->object->setVotingPeriod(1);
150 
151  $period = $a_form->getItemByPostVar("voting_period");
152  $this->object->setVotingPeriodBegin($period->getStart()->get(IL_CAL_UNIX));
153  $this->object->setVotingPeriodEnd($period->getEnd()->get(IL_CAL_UNIX));
154  }
155  else
156  {
157  $this->object->setVotingPeriod(0);
158  }
159  }
160 
161  function setTabs()
162  {
163  global $lng, $ilHelp;
164 
165  $ilHelp->setScreenIdComponent("poll");
166 
167  if ($this->checkPermissionBool("write"))
168  {
169  $this->tabs_gui->addTab("content",
170  $lng->txt("content"),
171  $this->ctrl->getLinkTarget($this, ""));
172  }
173 
174  if ($this->checkPermissionBool("write"))
175  {
176  $this->tabs_gui->addTab("settings",
177  $lng->txt("settings"),
178  $this->ctrl->getLinkTarget($this, "edit"));
179 
180  $this->tabs_gui->addTab("participants",
181  $lng->txt("poll_result"),
182  $this->ctrl->getLinkTarget($this, "showParticipants"));
183 
184  $this->tabs_gui->addTab("export",
185  $lng->txt("export"),
186  $this->ctrl->getLinkTargetByClass("ilexportgui", ""));
187  }
188 
189  // will add permissions if needed
190  parent::setTabs();
191  }
192 
193  function executeCommand()
194  {
195  global $ilCtrl, $tpl, $ilTabs, $ilNavigationHistory;
196 
197  $next_class = $ilCtrl->getNextClass($this);
198  $cmd = $ilCtrl->getCmd();
199 
200  $tpl->getStandardTemplate();
201 
202  // add entry to navigation history
203  if(!$this->getCreationMode() &&
204  $this->getAccessHandler()->checkAccess("read", "", $this->node_id))
205  {
206  $link = $ilCtrl->getLinkTargetByClass("ilrepositorygui", "frameset");
207  $ilNavigationHistory->addItem($this->node_id, $link, "poll");
208  }
209 
210  switch($next_class)
211  {
212  case "ilinfoscreengui":
213  $this->prepareOutput();
214  $this->infoScreenForward();
215  break;
216 
217  case "ilcommonactiondispatchergui":
218  include_once("Services/Object/classes/class.ilCommonActionDispatcherGUI.php");
220  $this->ctrl->forwardCommand($gui);
221  break;
222 
223  case "ilpermissiongui":
224  $this->prepareOutput();
225  $ilTabs->activateTab("id_permissions");
226  include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
227  $perm_gui = new ilPermissionGUI($this);
228  $this->ctrl->forwardCommand($perm_gui);
229  break;
230 
231  case "ilobjectcopygui":
232  include_once "./Services/Object/classes/class.ilObjectCopyGUI.php";
233  $cp = new ilObjectCopyGUI($this);
234  $cp->setType("poll");
235  $this->ctrl->forwardCommand($cp);
236  break;
237 
238  case 'ilexportgui':
239  $this->prepareOutput();
240  $ilTabs->activateTab("export");
241  include_once("./Services/Export/classes/class.ilExportGUI.php");
242  $exp_gui = new ilExportGUI($this);
243  $exp_gui->addFormat("xml");
244  $ilCtrl->forwardCommand($exp_gui);
245  break;
246 
247  default:
248  return parent::executeCommand();
249  }
250 
251  return true;
252  }
253 
254 
255  // --- ObjectGUI End
256 
257 
261  function render($a_form = null)
262  {
263  global $tpl, $ilTabs, $ilCtrl, $lng, $ilToolbar, $ilUser;
264 
265  if(!$this->checkPermissionBool("write"))
266  {
267  ilUtil::sendInfo($lng->txt("no_permission"));
268  return;
269  }
270 
271  $ilTabs->activateTab("content");
272 
273  if(!$a_form)
274  {
275  if($this->object->countVotes())
276  {
277  $url = $ilCtrl->getLinkTarget($this, "showParticipants");
278  ilUtil::sendInfo($lng->txt("poll_votes_no_edit").
279  " <a href=\"".$url."\">&raquo;".$lng->txt("poll_result")."</a>");
280  }
281 
282  $a_form = $this->initQuestionForm($this->object->countVotes());
283  }
284 
285  include_once('Services/PermanentLink/classes/class.ilPermanentLinkGUI.php');
286  $plink = new ilPermanentLinkGUI('poll', $this->node_id);
287 
288  $tpl->setContent($a_form->getHTML().$plink->getHTML());
289  }
290 
291  protected function initQuestionForm($a_read_only = false)
292  {
293  global $lng, $ilCtrl;
294 
295  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
296  $form = new ilPropertyFormGUI();
297  $form->setFormAction($ilCtrl->getFormAction($this, "saveQuestion"));
298  $form->setTitle($lng->txt("obj_poll"));
299 
300  $question = new ilTextAreaInputGUI($lng->txt("poll_question"), "question");
301  $question->setRequired(true);
302  $question->setCols(40);
303  $question->setRows(2);
304  $question->setValue($this->object->getQuestion());
305  $question->setDisabled($a_read_only);
306  $form->addItem($question);
307 
308  $dimensions = " (".ilObjPoll::getImageSize()."px)";
309  $img = new ilImageFileInputGUI($lng->txt("poll_image").$dimensions, "image");
310  $img->setDisabled($a_read_only);
311  $form->addItem($img);
312 
313  // show existing file
314  $file = $this->object->getImageFullPath(true);
315  if($file)
316  {
317  $img->setImage($file);
318  }
319 
320  $answers = new ilTextInputGUI($lng->txt("poll_answers"), "answers");
321  $answers->setRequired(true);
322  $answers->setMulti(true, true);
323  $answers->setDisabled($a_read_only);
324  $form->addItem($answers);
325 
326  $multi_answers = array();
327  foreach($this->object->getAnswers() as $idx => $item)
328  {
329  if(!$idx)
330  {
331  $answers->setValue($item["answer"]);
332  }
333  $multi_answers[] = $item["answer"];
334  }
335  $answers->setMultiValues($multi_answers);
336 
337  if(!$a_read_only)
338  {
339  $form->addCommandButton("saveQuestion", $lng->txt("save"));
340  }
341 
342  return $form;
343  }
344 
345  function saveQuestion()
346  {
347  $form = $this->initQuestionForm();
348  if($form->checkInput())
349  {
350  $this->object->setQuestion($form->getInput("question"));
351 
352  $image = $form->getItemByPostVar("image");
353  if($_FILES["image"]["tmp_name"])
354  {
355  $this->object->uploadImage($_FILES["image"]);
356  }
357  else if($image->getDeletionFlag())
358  {
359  $this->object->deleteImage();
360  }
361 
362  $this->object->saveAnswers($form->getInput("answers"));
363 
364  if($this->object->update())
365  {
366  ilUtil::sendSuccess($this->lng->txt("settings_saved"), true);
367  $this->ctrl->redirect($this, "render");
368  }
369  }
370 
371  $form->setValuesByPost();
372  $this->render($form);
373  }
374 
375  function showParticipants()
376  {
377  global $lng, $ilTabs, $tpl;
378 
379  if(!$this->checkPermissionBool("write"))
380  {
381  ilUtil::sendInfo($lng->txt("no_permission"));
382  return;
383  }
384 
385  $ilTabs->activateTab("participants");
386 
387  include_once "Modules/Poll/classes/class.ilPollAnswerTableGUI.php";
388  $tbl = new ilPollAnswerTableGUI($this, "showParticipants");
389  $tpl->setContent($tbl->getHTML());
390  }
391 
393  {
394  global $lng, $tpl, $ilTabs;
395 
396  if(!$this->checkPermissionBool("write"))
397  {
398  ilUtil::sendInfo($lng->txt("no_permission"));
399  return;
400  }
401 
402  $ilTabs->activateTab("participants");
403 
404  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
405  $cgui = new ilConfirmationGUI();
406  $cgui->setHeaderText($lng->txt("poll_delete_votes_sure"));
407 
408  $cgui->setFormAction($this->ctrl->getFormAction($this));
409  $cgui->setCancel($lng->txt("cancel"), "showParticipants");
410  $cgui->setConfirm($lng->txt("confirm"), "deleteAllVotes");
411 
412  $tpl->setContent($cgui->getHTML());
413  }
414 
415  function deleteAllVotes()
416  {
417  global $ilCtrl, $lng;
418 
419  if(!$this->checkPermissionBool("write"))
420  {
421  ilUtil::sendInfo($lng->txt("no_permission"));
422  return;
423  }
424 
425  $this->object->deleteAllVotes();
426 
427  $ilCtrl->redirect($this, "showParticipants");
428  }
429 
430  function vote()
431  {
432  global $tree, $ilUser;
433 
434  if($_POST["aw"])
435  {
436  $this->object->saveVote($ilUser->getId(), $_POST["aw"]);
437  }
438 
439  include_once "Services/Link/classes/class.ilLink.php";
440  ilUtil::redirect(ilLink:: _getLink($tree->getParentId($this->ref_id)));
441  }
442 
448  function getHTML()
449  {
450 
451  }
452 
453  function addLocatorItems()
454  {
455  global $ilLocator;
456 
457  if (is_object($this->object))
458  {
459  $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, ""), "", $this->node_id);
460  }
461  }
462 
468  function _goto($a_target)
469  {
470  global $tree;
471 
472  $id = explode("_", $a_target);
473 
474  // is sideblock: so show parent instead
475  $container_id = $tree->getParentId($id[0]);
476 
477  // #11810
478  include_once "Services/Link/classes/class.ilLink.php";
479  ilUtil::redirect(ilLink::_getLink($container_id).
480  "#poll".ilObject::_lookupObjId($id[0]));
481 
482  /*
483  $_GET["baseClass"] = "ilRepositoryGUI";
484  $_GET["ref_id"] = $container_id;
485  $_GET["cmd"] = "render";
486 
487  include("ilias.php");
488  exit;
489  */
490  }
491 }
492 
493 ?>