00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00036 class ilConditionHandlerInterface
00037 {
00038 var $ctrl = null;
00039
00040 var $lng;
00041 var $tpl;
00042 var $tree;
00043
00044 var $ch_obj;
00045 var $target_obj;
00046 var $client_obj;
00047 var $target_id;
00048 var $target_type;
00049 var $target_title;
00050 var $target_ref_id;
00051
00052 var $automatic_validation = true;
00053
00054 function ilConditionHandlerInterface(&$gui_obj,$a_ref_id = null)
00055 {
00056 global $lng,$tpl,$tree,$ilCtrl;
00057
00058 include_once "./classes/class.ilConditionHandler.php";
00059
00060 $this->ch_obj =& new ilConditionHandler();
00061
00062 $this->ctrl =& $ilCtrl;
00063 $this->gui_obj =& $gui_obj;
00064 $this->lng =& $lng;
00065 $this->tpl =& $tpl;
00066 $this->tree =& $tree;
00067
00068 if($a_ref_id)
00069 {
00070 $this->target_obj =& ilObjectFactory::getInstanceByRefId($a_ref_id);
00071 }
00072 else
00073 {
00074 $this->target_obj =& $this->gui_obj->object;
00075 }
00076
00077
00078
00079 if (is_object($this->target_obj))
00080 {
00081 $this->setTargetId($this->target_obj->getId());
00082 $this->setTargetRefId($this->target_obj->getRefId());
00083 $this->setTargetType($this->target_obj->getType());
00084 $this->setTargetTitle($this->target_obj->getTitle());
00085 }
00086
00087 }
00088
00089 function setBackButtons($a_btn_arr)
00090 {
00091 $_SESSION['precon_btn'] = $a_btn_arr;
00092 }
00093 function getBackButtons()
00094 {
00095 return $_SESSION['precon_btn'] ? $_SESSION['precon_btn'] : array();
00096 }
00097
00098 function &executeCommand()
00099 {
00100 $next_class = $this->ctrl->getNextClass($this);
00101 $cmd = $this->ctrl->getCmd();
00102
00103 switch ($next_class)
00104 {
00105 default:
00106 if (empty($cmd))
00107 {
00108 $cmd = "view";
00109 }
00110 $this->$cmd();
00111 break;
00112 }
00113 }
00114
00115 function setAutomaticValidation($a_status)
00116 {
00117 $this->automatic_validation = $a_status;
00118 }
00119 function getAutomaticValidation()
00120 {
00121 return $this->automatic_validation;
00122 }
00123
00124
00128 function setTargetId($a_target_id)
00129 {
00130 $this->target_id = $a_target_id;
00131 }
00132
00136 function getTargetId()
00137 {
00138 return $this->target_id;
00139 }
00140
00144 function setTargetRefId($a_target_ref_id)
00145 {
00146 $this->target_ref_id = $a_target_ref_id;
00147 }
00148
00152 function getTargetRefId()
00153 {
00154 return $this->target_ref_id;
00155 }
00156
00160 function setTargetType($a_target_type)
00161 {
00162 $this->target_type = $a_target_type;
00163 }
00164
00168 function getTargetType()
00169 {
00170 return $this->target_type;
00171 }
00172
00176 function setTargetTitle($a_target_title)
00177 {
00178 $this->target_title = $a_target_title;
00179 }
00180
00184 function getTargetTitle()
00185 {
00186 return $this->target_title;
00187 }
00188
00189 function chi_init(&$chi_target_obj,$a_ref_id = null)
00190 {
00191 echo 'deprecated';
00192
00193 include_once "./classes/class.ilConditionHandler.php";
00194
00195 $this->ch_obj =& new ilConditionHandler();
00196
00197 if($a_ref_id)
00198 {
00199 $this->target_obj =& ilObjectFactory::getInstanceByRefId($a_ref_id);
00200 }
00201 else
00202 {
00203 $this->target_obj =& $this->object;
00204 }
00205
00206 return true;
00207 }
00208
00209
00210 function listConditions()
00211 {
00212 global $ilObjDataCache;
00213
00214 $this->lng->loadLanguageModule('crs');
00215
00216 $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.condition_handler_edit.html');
00217 $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
00218 $this->tpl->setVariable("COLL_TITLE_IMG",ilUtil::getImagePath('icon_'.$this->getTargetType().'.gif'));
00219 $this->tpl->setVariable("COLL_TITLE_IMG_ALT",$this->lng->txt('obj_'.$this->getTargetType()));
00220 $this->tpl->setVariable("TABLE_TITLE",$this->getTargetTitle().' ('.$this->lng->txt('preconditions').')');
00221
00222
00223 $this->tpl->setVariable("HEAD_TITLE",$this->lng->txt('title'));
00224 $this->tpl->setVariable("HEAD_CONDITION",$this->lng->txt('condition'));
00225
00226
00227 $this->tpl->setVariable("BTN_DELETE",$this->lng->txt('delete'));
00228 $this->tpl->setVariable("BTN_ADD",$this->lng->txt('add_condition'));
00229 $this->tpl->setVariable("DOWNRIGHT",ilUtil::getImagePath('arrow_downright.gif'));
00230
00231
00232 if(!count($conditions = ilConditionHandler::_getConditionsOfTarget($this->getTargetRefId(),$this->getTargetId(), $this->getTargetType())))
00233 {
00234 $this->tpl->setVariable("EMPTY_TXT",$this->lng->txt('no_conditions_found'));
00235 return true;
00236 }
00237
00238 $counter = 0;
00239 foreach($conditions as $condition)
00240 {
00241 $this->tpl->setCurrentBlock("table_content");
00242
00243 $this->tpl->setVariable('TRIGGER_SRC',ilUtil::getImagePath('icon_'.$condition['trigger_type'].'_s.gif'));
00244 $this->tpl->setVariable('TRIGGER_ALT',$this->lng->txt('obj_'.$condition['trigger_type']));
00245 $this->tpl->setVariable("ROWCOL", ilUtil::switchColor($counter++,"tblrow1","tblrow2"));
00246 $this->tpl->setVariable("CHECKBOX",ilUtil::formCheckbox(0,"conditions[]",$condition['id']));
00247 $this->tpl->setVariable("TITLE",$ilObjDataCache->lookupTitle($condition['trigger_obj_id']));
00248 if(strlen($desc = $ilObjDataCache->lookupDescription($condition['trigger_obj_id'])))
00249 {
00250 $this->tpl->setVariable("DESCRIPTION",$desc);
00251 }
00252 $this->tpl->setVariable("OBJ_CONDITION",$this->lng->txt('condition_'.$condition['operator']));
00253
00254
00255 $this->tpl->setVariable("EDIT",$this->lng->txt('edit'));
00256
00257 $this->ctrl->setParameter($this,'condition_id',$condition['id']);
00258 $this->tpl->setVariable("EDIT_LINK",$this->ctrl->getLinkTarget($this,'edit'));
00259 $this->ctrl->clearParameters($this);
00260 $this->tpl->parseCurrentBlock();
00261 }
00262 return true;
00263 }
00264
00265 function edit()
00266 {
00267 global $ilObjDataCache;
00268
00269 if(!$_GET['condition_id'])
00270 {
00271 ilUtil::sendInfo("Missing id: condition_id");
00272 $this->listConditions();
00273 return false;
00274 }
00275 $condition = ilConditionHandler::_getCondition((int) $_GET['condition_id']);
00276
00277 $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.condition_handler_edit_condition.html');
00278 $this->ctrl->setParameter($this,'condition_id',(int) $_GET['condition_id']);
00279
00280 $this->initFormCondition($condition['trigger_ref_id'],(int) $_GET['condition_id'],'edit');
00281 $this->tpl->setVariable('CONDITION_TABLE',$this->form->getHTML());
00282 }
00283
00284 function updateCondition()
00285 {
00286 global $ilObjDataCache;
00287
00288 if(!$_GET['condition_id'])
00289 {
00290 ilUtil::sendInfo("Missing id: condition_id");
00291 $this->listConditions();
00292 return false;
00293 }
00294
00295
00296 include_once 'classes/class.ilConditionHandler.php';
00297 $condition_handler = new ilConditionHandler();
00298
00299 $condition = ilConditionHandler::_getCondition((int) $_GET['condition_id']);
00300 $condition_handler->setOperator($_POST['operator']);
00301 $condition_handler->setTargetRefId($this->getTargetRefId());
00302 $condition_handler->setValue('');
00303 switch($this->getTargetType())
00304 {
00305 case 'st':
00306 $condition_handler->setReferenceHandlingType($_POST['ref_handling']);
00307 break;
00308
00309 default:
00310 $condition_handler->setReferenceHandlingType(ilConditionHandler::UNIQUE_CONDITIONS);
00311 break;
00312 }
00313 $condition_handler->updateCondition($condition['id']);
00314
00315
00316 if($condition['trigger_type'] == 'sahs')
00317 {
00318 include_once 'Services/Tracking/classes/class.ilLPCollections.php';
00319 $lp_collection = new ilLPCollections($condition['trigger_obj_id']);
00320 $lp_collection->deleteAll();
00321
00322 $items = is_array($_POST['item_ids']) ? $_POST['item_ids'] : array();
00323 foreach($items as $item_id)
00324 {
00325 $lp_collection->add($item_id);
00326 }
00327 }
00328
00329 ilUtil::sendInfo($this->lng->txt('settings_saved'));
00330 $this->listConditions();
00331 }
00332
00333
00334 function delete()
00335 {
00336 if(!count($_POST['conditions']))
00337 {
00338 ilUtil::sendInfo('no_condition_selected');
00339 $this->listConditions();
00340 return true;
00341 }
00342
00343 foreach($_POST['conditions'] as $condition_id)
00344 {
00345 $this->ch_obj->deleteCondition($condition_id);
00346 }
00347 ilUtil::sendInfo($this->lng->txt('condition_deleted'));
00348 $this->listConditions();
00349
00350 return true;
00351 }
00352
00353 function selector()
00354 {
00355 include_once ("classes/class.ilConditionSelector.php");
00356
00357 $this->tpl->addBlockFile('ADM_CONTENT', "adm_content", "tpl.condition_selector.html");
00358
00359 ilUtil::sendInfo($this->lng->txt("condition_select_object"));
00360
00361 $exp = new ilConditionSelector($this->ctrl->getLinkTarget($this,'copySelector'));
00362 $exp->setExpand($_GET["condition_selector_expand"] ? $_GET["condition_selector_expand"] : $this->tree->readRootId());
00363 $exp->setExpandTarget($this->ctrl->getLinkTarget($this,'selector'));
00364 $exp->setTargetGet("ref_id");
00365 $exp->setRefId($this->getTargetRefId());
00366
00367 $exp->addFilter('crs');
00368 $exp->addFilter('tst');
00369 $exp->addFilter('sahs');
00370 $exp->addFilter('svy');
00371
00372 $exp->setSelectableTypes($this->ch_obj->getTriggerTypes());
00373 $exp->setControlClass($this);
00374
00375 $exp->setOutput(0);
00376
00377 $this->tpl->setCurrentBlock("adm_content");
00378 $this->tpl->setVariable("EXPLORER",$exp->getOutput());
00379 $this->tpl->parseCurrentBlock();
00380 }
00381
00382 function add()
00383 {
00384 global $ilObjDataCache;
00385
00386 if(!$_GET['source_id'])
00387 {
00388 ilUtil::sendInfo("Missing id: condition_id");
00389 $this->selector();
00390 return false;
00391 }
00392
00393 $this->initFormCondition((int) $_GET['source_id'],0,'add');
00394 $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.condition_handler_add.html');
00395 $this->tpl->setVariable('CONDITION_TABLE',$this->form->getHTML());
00396 }
00397
00398
00402 function assign()
00403 {
00404 if(!isset($_GET['source_id']))
00405 {
00406 echo "class.ilConditionHandlerInterface: no source_id given";
00407
00408 return false;
00409 }
00410 if(!strlen($_POST['operator']))
00411 {
00412 ilUtil::sendInfo($this->lng->txt('no_operator_selected'));
00413 $this->add();
00414
00415 return false;
00416 }
00417
00418
00419 $this->ch_obj->setTargetRefId($this->getTargetRefId());
00420 $this->ch_obj->setTargetObjId($this->getTargetId());
00421 $this->ch_obj->setTargetType($this->getTargetType());
00422
00423 switch($this->getTargetType())
00424 {
00425 case 'st':
00426 $this->ch_obj->setReferenceHandlingType($_POST['ref_handling']);
00427 break;
00428
00429 default:
00430 $this->ch_obj->setReferenceHandlingType(ilConditionHandler::UNIQUE_CONDITIONS);
00431 break;
00432 }
00433
00434 if(!$trigger_obj =& ilObjectFactory::getInstanceByRefId((int) $_GET['source_id'],false))
00435 {
00436 echo 'ilConditionHandler: Trigger object does not exist';
00437 }
00438 $this->ch_obj->setTriggerRefId($trigger_obj->getRefId());
00439 $this->ch_obj->setTriggerObjId($trigger_obj->getId());
00440 $this->ch_obj->setTriggerType($trigger_obj->getType());
00441 $this->ch_obj->setOperator($_POST['operator']);
00442 $this->ch_obj->setValue('');
00443
00444
00445 if($this->ch_obj->getTriggerType() == 'sahs')
00446 {
00447 include_once 'Services/Tracking/classes/class.ilLPCollections.php';
00448 $lp_collection = new ilLPCollections($this->ch_obj->getTriggerObjId());
00449 $lp_collection->deleteAll();
00450
00451 $items = is_array($_POST['item_ids']) ? $_POST['item_ids'] : array();
00452 foreach($items as $item_id)
00453 {
00454 $lp_collection->add($item_id);
00455 }
00456 }
00457
00458 $this->ch_obj->enableAutomaticValidation($this->getAutomaticValidation());
00459 if(!$this->ch_obj->storeCondition())
00460 {
00461 ilUtil::sendInfo($this->ch_obj->getErrorMessage());
00462 }
00463 else
00464 {
00465 ilUtil::sendInfo($this->lng->txt('added_new_condition'));
00466 }
00467
00468 $this->listConditions();
00469
00470 return true;
00471 }
00472
00473 function chi_update()
00474 {
00475 #if(in_array('',$_POST['operator']))
00476 #{
00477 # ilUtil::sendInfo($this->lng->txt('select_one_operator'));
00478
00479 # return false;
00480 #}
00481 foreach($this->__getConditionsOfTarget() as $condition)
00482 {
00483 $this->ch_obj->setOperator($_POST['operator'][$condition["id"]]);
00484 $this->ch_obj->setValue($_POST['value'][$condition["id"]]);
00485 $this->ch_obj->updateCondition($condition['id']);
00486
00487 }
00488 ilUtil::sendInfo($this->lng->txt('conditions_updated'));
00489
00490 $this->ctrl->returnToParent($this);
00491
00492 return true;
00493 }
00494 function __getConditionsOfTarget()
00495 {
00496 include_once './classes/class.ilConditionHandler.php';
00497
00498 foreach(ilConditionHandler::_getConditionsOfTarget($this->getTargetRefId(),$this->getTargetId(), $this->getTargetType()) as $condition)
00499 {
00500 if($condition['operator'] == 'not_member')
00501 {
00502 continue;
00503 }
00504 else
00505 {
00506 $cond[] = $condition;
00507 }
00508 }
00509 return $cond ? $cond : array();
00510 }
00511
00512 function __showButtons()
00513 {
00514 if(!$this->getBackButtons())
00515 {
00516 return false;
00517 }
00518
00519 $this->tpl->addBlockfile("BUTTONS", "buttons", "tpl.buttons.html");
00520 foreach($this->getBackButtons() as $name => $link)
00521 {
00522 $this->tpl->setCurrentBlock("btn_cell");
00523 $this->tpl->setVariable("BTN_LINK",$link);
00524 $this->tpl->setVariable("BTN_TXT",$this->lng->txt($name));
00525 $this->tpl->parseCurrentBlock();
00526 }
00527 }
00528
00536 private function initFormCondition($a_source_id,$a_condition_id = 0,$a_mode = 'add')
00537 {
00538 $trigger_obj_id = ilObject::_lookupObjId($a_source_id);
00539 $trigger_type = ilObject::_lookupType($trigger_obj_id);
00540
00541 $condition = ilConditionHandler::_getCondition($a_condition_id);
00542
00543 if(is_object($this->form))
00544 {
00545 return true;
00546 }
00547 include_once('Services/Form/classes/class.ilPropertyFormGUI.php');
00548 $this->form = new ilPropertyFormGUI();
00549 $this->ctrl->setParameter($this,'source_id',$a_source_id);
00550 $this->form->setFormAction($this->ctrl->getFormAction($this));
00551
00552 $sel = new ilSelectInputGUI($this->lng->txt('condition'),'operator');
00553 include_once "./classes/class.ilConditionHandler.php";
00554 $ch_obj = new ilConditionHandler();
00555 $operators[0] = $this->lng->txt('select_one');
00556 foreach($ch_obj->getOperatorsByTargetType($trigger_type) as $operator)
00557 {
00558 $operators[$operator] = $this->lng->txt('condition_'.$operator);
00559 }
00560 $sel->setValue(isset($condition['operator']) ? $condition['operator'] : 0);
00561 $sel->setOptions($operators);
00562 $sel->setRequired(true);
00563 $this->form->addItem($sel);
00564
00565 if(ilConditionHandler::_isReferenceHandlingOptional($this->getTargetType()))
00566 {
00567 $rad_opt = new ilRadioGroupInputGUI($this->lng->txt('cond_ref_handling'),'ref_handling');
00568 $rad_opt->setValue(isset($condition['ref_handling']) ? $condition['ref_handling'] : ilConditionHandler::SHARED_CONDITIONS);
00569
00570 $opt2 = new ilRadioOption($this->lng->txt('cond_ref_shared'),ilConditionHandler::SHARED_CONDITIONS);
00571 $rad_opt->addOption($opt2);
00572
00573 $opt1 = new ilRadioOption($this->lng->txt('cond_ref_unique'),ilConditionHandler::UNIQUE_CONDITIONS);
00574 $rad_opt->addOption($opt1);
00575
00576 $this->form->addItem($rad_opt);
00577 }
00578
00579
00580 if($trigger_type == 'sahs')
00581 {
00582 $this->lng->loadLanguageModule('trac');
00583 include_once 'Services/Tracking/classes/class.ilLPCollections.php';
00584 $lp_collections = new ilLPCollections($trigger_obj_id);
00585
00586 $cus = new ilCustomInputGUI($this->lng->txt('trac_sahs_relevant_items'),'item_ids[]');
00587 $cus->setRequired(true);
00588
00589 $tpl = new ilTemplate('tpl.condition_handler_sco_row.html',true,true);
00590 $counter = 0;
00591
00592 foreach(ilLPCollections::_getPossibleSAHSItems($trigger_obj_id) as $item_id => $sahs_item)
00593 {
00594 $tpl->setCurrentBlock("sco_row");
00595 $tpl->setVariable('SCO_ID',$item_id);
00596 $tpl->setVariable('SCO_TITLE',$sahs_item['title']);
00597 $tpl->setVariable('CHECKED',$lp_collections->isAssigned($item_id) ? 'checked="checked"' : '');
00598 $tpl->parseCurrentBlock();
00599 $counter++;
00600 }
00601 $tpl->setVariable('INFO_SEL',$this->lng->txt('trac_lp_determination_info_sco'));
00602 $cus->setHTML($tpl->get());
00603 $this->form->addItem($cus);
00604 }
00605 switch($a_mode)
00606 {
00607 case 'edit':
00608 $this->form->setTitleIcon(ilUtil::getImagePath('icon_'.$this->getTargetType().'.gif'));
00609 $this->form->setTitle($this->lng->txt('precondition').' ('.
00610 $this->getTargetTitle().' -> '.
00611 ilObject::_lookupTitle(ilObject::_lookupObjId($a_source_id)).')');
00612 $this->form->addCommandButton('updateCondition',$this->lng->txt('save'));
00613 $this->form->addCommandButton('listConditions',$this->lng->txt('cancel'));
00614 break;
00615
00616
00617 case 'add':
00618 $this->form->setTitleIcon(ilUtil::getImagePath('icon_'.$this->getTargetType().'.gif'));
00619 $this->form->setTitle($this->lng->txt('add_condition').' ('.
00620 $this->getTargetTitle().' -> '.
00621 ilObject::_lookupTitle(ilObject::_lookupObjId($a_source_id)).')');
00622 $this->form->addCommandButton('assign',$this->lng->txt('save'));
00623 $this->form->addCommandButton('selector',$this->lng->txt('back'));
00624 break;
00625 }
00626 return true;
00627 }
00628 }
00629 ?>