ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilConditionHandlerInterface.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 
24 
37 {
38  var $ctrl = null;
39 
40  var $lng;
41  var $tpl;
42  var $tree;
43 
44  var $ch_obj;
51 
53 
54  function ilConditionHandlerInterface(&$gui_obj,$a_ref_id = null)
55  {
56  global $lng,$tpl,$tree,$ilCtrl;
57 
58  include_once "./classes/class.ilConditionHandler.php";
59 
60  $this->ch_obj =& new ilConditionHandler();
61 
62  $this->ctrl =& $ilCtrl;
63  $this->gui_obj =& $gui_obj;
64  $this->lng =& $lng;
65  $this->tpl =& $tpl;
66  $this->tree =& $tree;
67 
68  if($a_ref_id)
69  {
70  $this->target_obj =& ilObjectFactory::getInstanceByRefId($a_ref_id);
71  }
72  else
73  {
74  $this->target_obj =& $this->gui_obj->object;
75  }
76 
77  // this only works for ilObject derived objects (other objects
78  // should call set() methods manually
79  if (is_object($this->target_obj))
80  {
81  $this->setTargetId($this->target_obj->getId());
82  $this->setTargetRefId($this->target_obj->getRefId());
83  $this->setTargetType($this->target_obj->getType());
84  $this->setTargetTitle($this->target_obj->getTitle());
85  }
86 
87  }
88 
89  function setBackButtons($a_btn_arr)
90  {
91  $_SESSION['precon_btn'] = $a_btn_arr;
92  }
93  function getBackButtons()
94  {
95  return $_SESSION['precon_btn'] ? $_SESSION['precon_btn'] : array();
96  }
97 
98  function &executeCommand()
99  {
100  $next_class = $this->ctrl->getNextClass($this);
101  $cmd = $this->ctrl->getCmd();
102 
103  switch ($next_class)
104  {
105  default:
106  if (empty($cmd))
107  {
108  $cmd = "view";
109  }
110  $this->$cmd();
111  break;
112  }
113  }
114 
115  function setAutomaticValidation($a_status)
116  {
117  $this->automatic_validation = $a_status;
118  }
120  {
122  }
123 
124 
128  function setTargetId($a_target_id)
129  {
130  $this->target_id = $a_target_id;
131  }
132 
136  function getTargetId()
137  {
138  return $this->target_id;
139  }
140 
144  function setTargetRefId($a_target_ref_id)
145  {
146  $this->target_ref_id = $a_target_ref_id;
147  }
148 
152  function getTargetRefId()
153  {
154  return $this->target_ref_id;
155  }
156 
160  function setTargetType($a_target_type)
161  {
162  $this->target_type = $a_target_type;
163  }
164 
168  function getTargetType()
169  {
170  return $this->target_type;
171  }
172 
176  function setTargetTitle($a_target_title)
177  {
178  $this->target_title = $a_target_title;
179  }
180 
184  function getTargetTitle()
185  {
186  return $this->target_title;
187  }
188 
189  function chi_init(&$chi_target_obj,$a_ref_id = null)
190  {
191  echo 'deprecated';
192 
193  include_once "./classes/class.ilConditionHandler.php";
194 
195  $this->ch_obj =& new ilConditionHandler();
196 
197  if($a_ref_id)
198  {
199  $this->target_obj =& ilObjectFactory::getInstanceByRefId($a_ref_id);
200  }
201  else
202  {
203  $this->target_obj =& $this->object;
204  }
205 
206  return true;
207  }
208 
209 
210  function listConditions()
211  {
212  global $ilObjDataCache;
213 
214  $this->lng->loadLanguageModule('crs');
215 
216  $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.condition_handler_edit.html');
217  $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
218  $this->tpl->setVariable("COLL_TITLE_IMG",ilUtil::getImagePath('icon_'.$this->getTargetType().'.gif'));
219  $this->tpl->setVariable("COLL_TITLE_IMG_ALT",$this->lng->txt('obj_'.$this->getTargetType()));
220  $this->tpl->setVariable("TABLE_TITLE",$this->getTargetTitle().' ('.$this->lng->txt('preconditions').')');
221 
222  // Table header
223  $this->tpl->setVariable("HEAD_TITLE",$this->lng->txt('title'));
224  $this->tpl->setVariable("HEAD_CONDITION",$this->lng->txt('condition'));
225 
226  // Table footer
227  $this->tpl->setVariable("BTN_DELETE",$this->lng->txt('delete'));
228  $this->tpl->setVariable("BTN_ADD",$this->lng->txt('add_condition'));
229  $this->tpl->setVariable("DOWNRIGHT",ilUtil::getImagePath('arrow_downright.gif'));
230 
231 
232  if(!count($conditions = ilConditionHandler::_getConditionsOfTarget($this->getTargetRefId(),$this->getTargetId(), $this->getTargetType())))
233  {
234  $this->tpl->setVariable("EMPTY_TXT",$this->lng->txt('no_conditions_found'));
235  return true;
236  }
237 
238  $counter = 0;
239  foreach($conditions as $condition)
240  {
241  $this->tpl->setCurrentBlock("table_content");
242 
243  $this->tpl->setVariable('TRIGGER_SRC',ilUtil::getImagePath('icon_'.$condition['trigger_type'].'_s.gif'));
244  $this->tpl->setVariable('TRIGGER_ALT',$this->lng->txt('obj_'.$condition['trigger_type']));
245  $this->tpl->setVariable("ROWCOL", ilUtil::switchColor($counter++,"tblrow1","tblrow2"));
246  $this->tpl->setVariable("CHECKBOX",ilUtil::formCheckbox(0,"conditions[]",$condition['id']));
247  $this->tpl->setVariable("TITLE",$ilObjDataCache->lookupTitle($condition['trigger_obj_id']));
248  if(strlen($desc = $ilObjDataCache->lookupDescription($condition['trigger_obj_id'])))
249  {
250  $this->tpl->setVariable("DESCRIPTION",$desc);
251  }
252  $this->tpl->setVariable("OBJ_CONDITION",$this->lng->txt('condition_'.$condition['operator']));
253 
254  // Edit link
255  $this->tpl->setVariable("EDIT",$this->lng->txt('edit'));
256 
257  $this->ctrl->setParameter($this,'condition_id',$condition['id']);
258  $this->tpl->setVariable("EDIT_LINK",$this->ctrl->getLinkTarget($this,'edit'));
259  $this->ctrl->clearParameters($this);
260  $this->tpl->parseCurrentBlock();
261  }
262  return true;
263  }
264 
265  function edit()
266  {
267  global $ilObjDataCache;
268 
269  if(!$_GET['condition_id'])
270  {
271  ilUtil::sendInfo("Missing id: condition_id");
272  $this->listConditions();
273  return false;
274  }
275  $condition = ilConditionHandler::_getCondition((int) $_GET['condition_id']);
276 
277  $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.condition_handler_edit_condition.html');
278  $this->ctrl->setParameter($this,'condition_id',(int) $_GET['condition_id']);
279 
280  $this->initFormCondition($condition['trigger_ref_id'],(int) $_GET['condition_id'],'edit');
281  $this->tpl->setVariable('CONDITION_TABLE',$this->form->getHTML());
282  }
283 
284  function updateCondition()
285  {
286  global $ilObjDataCache;
287 
288  if(!$_GET['condition_id'])
289  {
290  ilUtil::sendInfo("Missing id: condition_id");
291  $this->listConditions();
292  return false;
293  }
294 
295  // Update condition
296  include_once 'classes/class.ilConditionHandler.php';
297  $condition_handler = new ilConditionHandler();
298 
299  $condition = ilConditionHandler::_getCondition((int) $_GET['condition_id']);
300  $condition_handler->setOperator($_POST['operator']);
301  $condition_handler->setTargetRefId($this->getTargetRefId());
302  $condition_handler->setValue('');
303  switch($this->getTargetType())
304  {
305  case 'st':
306  $condition_handler->setReferenceHandlingType($_POST['ref_handling']);
307  break;
308 
309  default:
310  $condition_handler->setReferenceHandlingType(ilConditionHandler::UNIQUE_CONDITIONS);
311  break;
312  }
313  $condition_handler->updateCondition($condition['id']);
314 
315  // Update relevant sco's
316  if($condition['trigger_type'] == 'sahs')
317  {
318  include_once 'Services/Tracking/classes/class.ilLPCollections.php';
319  $lp_collection = new ilLPCollections($condition['trigger_obj_id']);
320  $lp_collection->deleteAll();
321 
322  $items = is_array($_POST['item_ids']) ? $_POST['item_ids'] : array();
323  foreach($items as $item_id)
324  {
325  $lp_collection->add($item_id);
326  }
327  }
328 
329  ilUtil::sendInfo($this->lng->txt('settings_saved'));
330  $this->listConditions();
331  }
332 
333 
334  function delete()
335  {
336  if(!count($_POST['conditions']))
337  {
338  ilUtil::sendInfo('no_condition_selected');
339  $this->listConditions();
340  return true;
341  }
342 
343  foreach($_POST['conditions'] as $condition_id)
344  {
345  $this->ch_obj->deleteCondition($condition_id);
346  }
347  ilUtil::sendInfo($this->lng->txt('condition_deleted'));
348  $this->listConditions();
349 
350  return true;
351  }
352 
353  function selector()
354  {
355  include_once ("classes/class.ilConditionSelector.php");
356 
357  $this->tpl->addBlockFile('ADM_CONTENT', "adm_content", "tpl.condition_selector.html");
358 
359  ilUtil::sendInfo($this->lng->txt("condition_select_object"));
360 
361  $exp = new ilConditionSelector($this->ctrl->getLinkTarget($this,'copySelector'));
362  $exp->setExpand($_GET["condition_selector_expand"] ? $_GET["condition_selector_expand"] : $this->tree->readRootId());
363  $exp->setExpandTarget($this->ctrl->getLinkTarget($this,'selector'));
364  $exp->setTargetGet("ref_id");
365  $exp->setRefId($this->getTargetRefId());
366 
367  $exp->addFilter('crs');
368  $exp->addFilter('tst');
369  $exp->addFilter('sahs');
370  $exp->addFilter('svy');
371 
372  $exp->setSelectableTypes($this->ch_obj->getTriggerTypes());
373  $exp->setControlClass($this);
374  // build html-output
375  $exp->setOutput(0);
376 
377  $this->tpl->setCurrentBlock("adm_content");
378  $this->tpl->setVariable("EXPLORER",$exp->getOutput());
379  $this->tpl->parseCurrentBlock();
380  }
381 
382  function add()
383  {
384  global $ilObjDataCache;
385 
386  if(!$_GET['source_id'])
387  {
388  ilUtil::sendInfo("Missing id: condition_id");
389  $this->selector();
390  return false;
391  }
392 
393  $this->initFormCondition((int) $_GET['source_id'],0,'add');
394  $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.condition_handler_add.html');
395  $this->tpl->setVariable('CONDITION_TABLE',$this->form->getHTML());
396  }
397 
398 
402  function assign()
403  {
404  if(!isset($_GET['source_id']))
405  {
406  echo "class.ilConditionHandlerInterface: no source_id given";
407 
408  return false;
409  }
410  if(!strlen($_POST['operator']))
411  {
412  ilUtil::sendInfo($this->lng->txt('no_operator_selected'));
413  $this->add();
414 
415  return false;
416  }
417 
418 
419  $this->ch_obj->setTargetRefId($this->getTargetRefId());
420  $this->ch_obj->setTargetObjId($this->getTargetId());
421  $this->ch_obj->setTargetType($this->getTargetType());
422 
423  switch($this->getTargetType())
424  {
425  case 'st':
426  $this->ch_obj->setReferenceHandlingType($_POST['ref_handling']);
427  break;
428 
429  default:
430  $this->ch_obj->setReferenceHandlingType(ilConditionHandler::UNIQUE_CONDITIONS);
431  break;
432  }
433  // this has to be changed, if non referenced trigger are implemted
434  if(!$trigger_obj =& ilObjectFactory::getInstanceByRefId((int) $_GET['source_id'],false))
435  {
436  echo 'ilConditionHandler: Trigger object does not exist';
437  }
438  $this->ch_obj->setTriggerRefId($trigger_obj->getRefId());
439  $this->ch_obj->setTriggerObjId($trigger_obj->getId());
440  $this->ch_obj->setTriggerType($trigger_obj->getType());
441  $this->ch_obj->setOperator($_POST['operator']);
442  $this->ch_obj->setValue('');
443 
444  // Save assigned sco's
445  if($this->ch_obj->getTriggerType() == 'sahs')
446  {
447  include_once 'Services/Tracking/classes/class.ilLPCollections.php';
448  $lp_collection = new ilLPCollections($this->ch_obj->getTriggerObjId());
449  $lp_collection->deleteAll();
450 
451  $items = is_array($_POST['item_ids']) ? $_POST['item_ids'] : array();
452  foreach($items as $item_id)
453  {
454  $lp_collection->add($item_id);
455  }
456  }
457 
458  $this->ch_obj->enableAutomaticValidation($this->getAutomaticValidation());
459  if(!$this->ch_obj->storeCondition())
460  {
461  ilUtil::sendInfo($this->ch_obj->getErrorMessage());
462  }
463  else
464  {
465  ilUtil::sendInfo($this->lng->txt('added_new_condition'));
466  }
467 
468  $this->listConditions();
469 
470  return true;
471  }
472 
473  function chi_update()
474  {
475  #if(in_array('',$_POST['operator']))
476  #{
477  # ilUtil::sendInfo($this->lng->txt('select_one_operator'));
478 
479  # return false;
480  #}
481  foreach($this->__getConditionsOfTarget() as $condition)
482  {
483  $this->ch_obj->setOperator($_POST['operator'][$condition["id"]]);
484  $this->ch_obj->setValue($_POST['value'][$condition["id"]]);
485  $this->ch_obj->updateCondition($condition['id']);
486 
487  }
488  ilUtil::sendInfo($this->lng->txt('conditions_updated'));
489 
490  $this->ctrl->returnToParent($this);
491 
492  return true;
493  }
495  {
496  include_once './classes/class.ilConditionHandler.php';
497 
498  foreach(ilConditionHandler::_getConditionsOfTarget($this->getTargetRefId(),$this->getTargetId(), $this->getTargetType()) as $condition)
499  {
500  if($condition['operator'] == 'not_member')
501  {
502  continue;
503  }
504  else
505  {
506  $cond[] = $condition;
507  }
508  }
509  return $cond ? $cond : array();
510  }
511 
512  function __showButtons()
513  {
514  if(!$this->getBackButtons())
515  {
516  return false;
517  }
518 
519  $this->tpl->addBlockfile("BUTTONS", "buttons", "tpl.buttons.html");
520  foreach($this->getBackButtons() as $name => $link)
521  {
522  $this->tpl->setCurrentBlock("btn_cell");
523  $this->tpl->setVariable("BTN_LINK",$link);
524  $this->tpl->setVariable("BTN_TXT",$this->lng->txt($name));
525  $this->tpl->parseCurrentBlock();
526  }
527  }
528 
536  private function initFormCondition($a_source_id,$a_condition_id = 0,$a_mode = 'add')
537  {
538  $trigger_obj_id = ilObject::_lookupObjId($a_source_id);
539  $trigger_type = ilObject::_lookupType($trigger_obj_id);
540 
541  $condition = ilConditionHandler::_getCondition($a_condition_id);
542 
543  if(is_object($this->form))
544  {
545  return true;
546  }
547  include_once('Services/Form/classes/class.ilPropertyFormGUI.php');
548  $this->form = new ilPropertyFormGUI();
549  $this->ctrl->setParameter($this,'source_id',$a_source_id);
550  $this->form->setFormAction($this->ctrl->getFormAction($this));
551 
552  $sel = new ilSelectInputGUI($this->lng->txt('condition'),'operator');
553  include_once "./classes/class.ilConditionHandler.php";
554  $ch_obj = new ilConditionHandler();
555  $operators[0] = $this->lng->txt('select_one');
556  foreach($ch_obj->getOperatorsByTargetType($trigger_type) as $operator)
557  {
558  $operators[$operator] = $this->lng->txt('condition_'.$operator);
559  }
560  $sel->setValue(isset($condition['operator']) ? $condition['operator'] : 0);
561  $sel->setOptions($operators);
562  $sel->setRequired(true);
563  $this->form->addItem($sel);
564 
566  {
567  $rad_opt = new ilRadioGroupInputGUI($this->lng->txt('cond_ref_handling'),'ref_handling');
568  $rad_opt->setValue(isset($condition['ref_handling']) ? $condition['ref_handling'] : ilConditionHandler::SHARED_CONDITIONS);
569 
570  $opt2 = new ilRadioOption($this->lng->txt('cond_ref_shared'),ilConditionHandler::SHARED_CONDITIONS);
571  $rad_opt->addOption($opt2);
572 
573  $opt1 = new ilRadioOption($this->lng->txt('cond_ref_unique'),ilConditionHandler::UNIQUE_CONDITIONS);
574  $rad_opt->addOption($opt1);
575 
576  $this->form->addItem($rad_opt);
577  }
578 
579  // Additional settings for SCO's
580  if($trigger_type == 'sahs')
581  {
582  $this->lng->loadLanguageModule('trac');
583  include_once 'Services/Tracking/classes/class.ilLPCollections.php';
584  $lp_collections = new ilLPCollections($trigger_obj_id);
585 
586  $cus = new ilCustomInputGUI($this->lng->txt('trac_sahs_relevant_items'),'item_ids[]');
587  $cus->setRequired(true);
588 
589  $tpl = new ilTemplate('tpl.condition_handler_sco_row.html',true,true);
590  $counter = 0;
591 
592  foreach(ilLPCollections::_getPossibleSAHSItems($trigger_obj_id) as $item_id => $sahs_item)
593  {
594  $tpl->setCurrentBlock("sco_row");
595  $tpl->setVariable('SCO_ID',$item_id);
596  $tpl->setVariable('SCO_TITLE',$sahs_item['title']);
597  $tpl->setVariable('CHECKED',$lp_collections->isAssigned($item_id) ? 'checked="checked"' : '');
598  $tpl->parseCurrentBlock();
599  $counter++;
600  }
601  $tpl->setVariable('INFO_SEL',$this->lng->txt('trac_lp_determination_info_sco'));
602  $cus->setHTML($tpl->get());
603  $this->form->addItem($cus);
604  }
605  switch($a_mode)
606  {
607  case 'edit':
608  $this->form->setTitleIcon(ilUtil::getImagePath('icon_'.$this->getTargetType().'.gif'));
609  $this->form->setTitle($this->lng->txt('precondition').' ('.
610  $this->getTargetTitle().' -> '.
612  $this->form->addCommandButton('updateCondition',$this->lng->txt('save'));
613  $this->form->addCommandButton('listConditions',$this->lng->txt('cancel'));
614  break;
615 
616 
617  case 'add':
618  $this->form->setTitleIcon(ilUtil::getImagePath('icon_'.$this->getTargetType().'.gif'));
619  $this->form->setTitle($this->lng->txt('add_condition').' ('.
620  $this->getTargetTitle().' -> '.
622  $this->form->addCommandButton('assign',$this->lng->txt('save'));
623  $this->form->addCommandButton('selector',$this->lng->txt('back'));
624  break;
625  }
626  return true;
627  }
628 }
629 ?>