ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjiLincClassroomGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
35 include_once "./classes/class.ilObjectGUI.php";
36 include_once "./Modules/ILinc/classes/class.ilObjiLincClassroom.php";
37 
39 {
40  private $form_gui = null;
41 
47  function ilObjiLincClassroomGUI($a_icla_id,$a_icrs_id,$a_call_by_reference = false,$a_prepare_output = false)
48  {
50 
51  $this->type = "icla";
52  $this->id = $a_icla_id;
53  $this->parent = $a_icrs_id;
54  $this->ilias =& $ilias;
55  $this->objDefinition =& $objDefinition;
56  $this->tpl =& $tpl;
57  $this->html = "";
58  $this->ctrl =& $ilCtrl;
59  $this->lng =& $lng;
60  $this->tree =& $tree;
61  $this->ilErr =& $ilErr;
62 
63  //$this->ctrl->saveParameter($this,'parent');
64  $this->lng->loadLanguageModule('ilinc');
65 
66  $this->formaction = array();
67  $this->return_location = array();
68  $this->target_frame = array();
69  //$this->tab_target_script = "adm_object.php";
70  $this->actions = "";
71  $this->sub_objects = "";
72 
73  //prepare output
74  if (false)
75  {
76  $this->prepareOutput();
77  }
78 
79  $this->assignObject();
80  }
81 
82  function assignObject()
83  {
84  $this->object = new ilObjiLincClassroom($this->id, $this->parent);
85  }
86 
87  public function create()
88  {
89  $this->prepareOutput();
90 
91  $this->initSettingsForm('create');
92  $this->getDefaultValues();
93  return $this->tpl->setVariable('ADM_CONTENT', $this->form_gui->getHtml());
94  }
95 
96  protected function getDefaultValues()
97  {
98  $data = array(
99  'title' => '',
100  'desc' => '',
101  'instructoruserid' => 0,
102  'alwaysopen' => 1
103  );
104 
105  $icrs_obj_id = ilObject::_lookupObjectId( $this->parent );
106  include_once 'Modules/ILinc/classes/class.ilObjiLincCourse.php';
107  $akclassvalues = ilObjiLincCourse::_getAKClassValues( $icrs_obj_id );
108  $data['akclassvalue1'] = $akclassvalues[0];
109  $data['akclassvalue2'] = $akclassvalues[1];
110 
111  $this->form_gui->setValuesByArray( $data );
112  }
113 
118  public function save()
119  {
120  $this->prepareOutput();
121 
122  $this->initSettingsForm('create');
123  if($this->form_gui->checkInput())
124  {
125  $_POST['Fobject']['title'] = $this->form_gui->getInput('title');
126  $_POST['Fobject']['desc'] = $this->form_gui->getInput('desc');
127  $_POST['Fobject']['instructoruserid'] = $this->form_gui->getInput('instructoruserid');
128  $_POST['Fobject']['alwaysopen'] = $this->form_gui->getInput('alwaysopen');
129 
130  // Akclassvalues
131  if($this->ilias->getSetting('ilinc_akclassvalues_active'))
132  {
133  $icrs_obj_id = ilObject::_lookupObjectId( $this->parent );
134  include_once 'Modules/ILinc/classes/class.ilObjiLincCourse.php';
135  $akclassvalues = ilObjiLincCourse::_getAKClassValues( $icrs_obj_id );
136 
137  $_POST['Fobject']['akclassvalue1'] = $akclassvalues[0];
138  $_POST['Fobject']['akclassvalue2'] = $akclassvalues[1];
139  }
140 
141  $ilinc_course_id = ilObjiLincClassroom::_lookupiCourseId( $this->parent );
142 
143  $this->object->ilincAPI->addClass($ilinc_course_id, $_POST['Fobject']);
144  $response = $this->object->ilincAPI->sendRequest('addClass');
145  if($response->isError())
146  {
147  $this->ilErr->raiseError($response->getErrorMsg(), $this->ilErr->MESSAGE);
148  }
149 
150  // Always send a message
151  ilUtil::sendInfo($response->getResultMsg(), true);
152 
153  $this->ctrl->redirectByClass('ilobjilinccoursegui');
154  }
155  else
156  {
157  if($this->ilias->getSetting('ilinc_akclassvalues_active'))
158  {
159  $icrs_obj_id = ilObject::_lookupObjectId( $this->parent );
160  include_once 'Modules/ILinc/classes/class.ilObjiLincCourse.php';
161  $akclassvalues = ilObjiLincCourse::_getAKClassValues( $icrs_obj_id );
162 
163  $_POST['akclassvalue1'] = $akclassvalues[0];
164  $_POST['akclassvalue2'] = $akclassvalues[1];
165  }
166 
167  $this->form_gui->setValuesByPost();
168  return $this->tpl->setVariable('ADM_CONTENT', $this->form_gui->getHtml());
169  }
170  }
171 
172  function joinClassroom()
173  {
174  // join class
175  $url = $this->object->joinClass($this->ilias->account,$_GET['class_id']);
176 
177  if (!$url)
178  {
179  $this->ilias->raiseError($this->object->getErrorMsg(),$this->ilias->error_obj->FATAL);
180  }
181 
182  ilUtil::redirect(trim($url));
183  }
184 
185  public function editClassroom()
186  {
187  $this->initSettingsForm('edit');
188  $this->getObjectValues();
189  return $this->tpl->setVariable('ADM_CONTENT', $this->form_gui->getHtml());
190  }
191 
192  protected function getObjectValues()
193  {
194  $data = array(
195  'title' => $this->object->getTitle(),
196  'desc' => $this->object->getDescription(),
197  'alwaysopen' => $this->object->getStatus(),
198  'instructoruserid' => $this->object->getDocentId()
199  );
200 
201  $icrs_obj_id = ilObject::_lookupObjectId( $this->parent );
202  include_once 'Modules/ILinc/classes/class.ilObjiLincCourse.php';
203  $akclassvalues = ilObjiLincCourse::_getAKClassValues( $icrs_obj_id );
204  $data['akclassvalue1'] = $akclassvalues[0];
205  $data['akclassvalue2'] = $akclassvalues[1];
206 
207  $this->form_gui->setValuesByArray( $data );
208  }
209 
210  protected function initSettingsForm($a_mode = 'create')
211  {
212  include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
213 
214  $this->form_gui = new ilPropertyFormGUI();
215  $this->form_gui->setTableWidth('600');
216  if($a_mode == 'create')
217  {
218  $this->form_gui->setTitle($this->lng->txt('icla_add'));
219  }
220  else
221  {
222  $this->form_gui->setTitle($this->lng->txt('icla_edit'));
223  }
224  $this->form_gui->setTitleIcon(ilUtil::getTypeIconPath('icla', 0));
225 
226  // Title
227  $text_input = new ilTextInputGUI($this->lng->txt('title'), 'title');
228  $text_input->setRequired(true);
229  $this->form_gui->addItem($text_input);
230 
231  // Description
232  $text_area = new ilTextAreaInputGUI($this->lng->txt('desc'), 'desc');
233  $this->form_gui->addItem($text_area);
234 
235  // Docentselection
236  $sel = new ilSelectInputGUI($this->lng->txt(ILINC_MEMBER_DOCENT), 'instructoruserid');
237  $docentlist = $this->object->getDocentList();
238  $docent_options = array();
239  $docent_options[0] = $this->lng->txt('please_choose');
240  foreach((array)$docentlist as $id => $data)
241  {
242  $docent_options[$id] = $data['fullname'];
243  }
244  $sel->setOptions($docent_options);
245  $this->form_gui->addItem($sel);
246 
247  // Open
248  $rg = new ilRadioGroupInputGUI($this->lng->txt('access'), 'alwaysopen');
249  $rg->setValue(0);
250  $ro = new ilRadioOption($this->lng->txt('ilinc_classroom_open'), 1);
251  $rg->addOption($ro);
252  $ro = new ilRadioOption($this->lng->txt('ilinc_classroom_closed'), 0);
253  $rg->addOption($ro);
254  $this->form_gui->addItem($rg);
255 
256  // Display akclassvalues
257  if($this->ilias->getSetting('ilinc_akclassvalues_active'))
258  {
259  $text_input = new ilTextInputGUI($this->lng->txt('akclassvalue1'), 'akclassvalue1');
260  $text_input->setDisabled(true);
261  $this->form_gui->addItem($text_input);
262 
263  $text_input = new ilTextInputGUI($this->lng->txt('akclassvalue2'), 'akclassvalue2');
264  $text_input->setDisabled(true);
265  $this->form_gui->addItem($text_input);
266  }
267 
268  // save and cancel commands
269  if($a_mode == 'create')
270  {
271  $this->ctrl->setParameter($this, 'mode', 'create');
272  $this->ctrl->setParameter($this, 'new_type', 'icla');
273 
274  $this->form_gui->addCommandButton('save', $this->lng->txt('icla_add'));
275  $this->form_gui->addCommandButton('cancel', $this->lng->txt('cancel'));
276  $this->form_gui->setFormAction($this->ctrl->getFormAction($this, 'save'));
277  }
278  else
279  {
280  $this->ctrl->setParameter($this, 'class_id', $this->object->id);
281 
282  $this->form_gui->addCommandButton('updateClassroom', $this->lng->txt('save'));
283  $this->form_gui->addCommandButton('cancel', $this->lng->txt('cancel'));
284  $this->form_gui->setFormAction($this->ctrl->getFormAction($this, 'updateClassroom'));
285  }
286  }
287 
293  function getTabs(&$tabs_gui)
294  {
295  // tabs are defined manually here. The autogeneration via objects.xml will be deprecated in future
296  // for usage examples see ilObjGroupGUI or ilObjSystemFolderGUI
297  }
298 
306  function removeClassroom($a_error = false)
307  {
308  unset($this->data);
309  $this->data["cols"] = array("type", "title", "last_change");
310 
311  $this->data["data"][$_GET['class_id']] = array(
312  "type" => $this->object->getType(),
313  "title" => $this->object->getTitle()."#separator#".$this->object->getDescription()." ", // workaround for empty desc
314  "last_update" => "n/a"
315  );
316 
317  $this->data["buttons"] = array( "confirmedDeleteClassroom" => $this->lng->txt("confirm"),
318  "cancelDeleteClassroom" => $this->lng->txt("cancel"));
319 
320  $this->getTemplateFile("confirm");
321 
322  if(!$a_error)
323  {
324  ilUtil::sendInfo($this->lng->txt("info_delete_sure"));
325  }
326 
327  $obj_str = "&class_id=".$this->object->id;
328  $this->tpl->setVariable("FORMACTION", $this->getFormAction("delete",$this->ctrl->getFormAction($this).$obj_str));
329 
330  // BEGIN TABLE HEADER
331  foreach ($this->data["cols"] as $key)
332  {
333  $this->tpl->setCurrentBlock("table_header");
334  $this->tpl->setVariable("TEXT",$this->lng->txt($key));
335  $this->tpl->parseCurrentBlock();
336  }
337  // END TABLE HEADER
338 
339  // BEGIN TABLE DATA
340  $counter = 0;
341 
342  foreach ($this->data["data"] as $key => $value)
343  {
344  // BEGIN TABLE CELL
345  foreach ($value as $key => $cell_data)
346  {
347  $this->tpl->setCurrentBlock("table_cell");
348 
349  // CREATE TEXT STRING
350  if ($key == "type")
351  {
352  $this->tpl->setVariable("TEXT_CONTENT",ilUtil::getImageTagByType($cell_data,$this->tpl->tplPath));
353  }
354  elseif ($key == "title")
355  {
356  $name_field = explode("#separator#",$cell_data);
357 
358  $this->tpl->setVariable("TEXT_CONTENT", "<b>".$name_field[0]."</b>");
359 
360  $this->tpl->setCurrentBlock("subtitle");
361  $this->tpl->setVariable("DESC", $name_field[1]);
362  $this->tpl->parseCurrentBlock();
363  $this->tpl->setCurrentBlock("table_cell");
364  }
365  else
366  {
367  $this->tpl->setVariable("TEXT_CONTENT",$cell_data);
368  }
369 
370  $this->tpl->parseCurrentBlock();
371  }
372 
373  $this->tpl->setCurrentBlock("table_row");
374  $this->tpl->setVariable("CSS_ROW",ilUtil::switchColor(++$counter,"tblrow1","tblrow2"));
375  $this->tpl->parseCurrentBlock();
376  // END TABLE CELL
377  }
378  // END TABLE DATA
379 
380  // BEGIN OPERATION_BTN
381  foreach ($this->data["buttons"] as $name => $value)
382  {
383  $this->tpl->setCurrentBlock("operation_btn");
384  $this->tpl->setVariable("IMG_ARROW",ilUtil::getImagePath("arrow_downright.gif"));
385  $this->tpl->setVariable("BTN_NAME",$name);
386  $this->tpl->setVariable("BTN_VALUE",$value);
387  $this->tpl->parseCurrentBlock();
388  }
389  }
390 
396  public function updateClassroom()
397  {
398  $this->initSettingsForm('edit');
399  if($this->form_gui->checkInput())
400  {
401  $this->object->setTitle( $this->form_gui->getInput('title' ));
402  $this->object->setDescription( $this->form_gui->getInput('desc') );
403  $this->object->setDocentId( $this->form_gui->getInput('instructoruserid') );
404  $this->object->setStatus( $this->form_gui->getInput('alwaysopen') );
405 
406  if(!$this->object->update())
407  {
408  $this->ilErr->raiseError($this->object->getErrorMsg(), $this->ilErr->MESSAGE);
409  }
410 
411  ilUtil::sendInfo($this->getResultMsg(), true);
412 
413  $this->ctrl->redirectByClass('ilobjilinccoursegui');
414  }
415  else
416  {
417  if($this->ilias->getSetting('ilinc_akclassvalues_active'))
418  {
419  $icrs_obj_id = ilObject::_lookupObjectId( $this->parent );
420  include_once 'Modules/ILinc/classes/class.ilObjiLincCourse.php';
421  $akclassvalues = ilObjiLincCourse::_getAKClassValues( $icrs_obj_id );
422 
423  $_POST['akclassvalue1'] = $akclassvalues[0];
424  $_POST['akclassvalue2'] = $akclassvalues[1];
425  }
426 
427  $this->form_gui->setValuesByPost();
428  return $this->tpl->setVariable('ADM_CONTENT', $this->form_gui->getHtml());
429  }
430  }
431 
432  function &executeCommand()
433  {
434  $next_class = $this->ctrl->getNextClass($this);
435  $cmd = $this->ctrl->getCmd();
436 
437  switch($next_class)
438  {
439  default:
440  $this->$cmd();
441  break;
442  }
443 
444  return true;
445  }
446 
453  {
454  session_unregister("saved_post");
455 
456  ilUtil::sendInfo($this->lng->txt("msg_cancel"),true);
457 
458  $this->ctrl->redirectByClass("ilobjilinccoursegui");
459  }
460 
465  {
466  if (!$this->object->delete())
467  {
468  $msg = $this->object->getErrorMsg();
469  }
470  else
471  {
472  $msg = $this->lng->txt('icla_deleted');
473  }
474 
475  // Feedback
476  ilUtil::sendInfo($msg,true);
477 
478  $this->ctrl->redirectByClass("ilobjilinccoursegui");
479  }
480 
481  function getResultMsg()
482  {
483  return $this->object->result_msg;
484  }
485 
490  function cancel()
491  {
492  ilUtil::sendInfo($this->lng->txt("msg_cancel"),true);
493 
494  $this->ctrl->redirectByClass("ilobjilinccoursegui");
495  }
496 } // END class.ilObjiLincClassroomGUI
497 ?>