• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

classes/class.ilConditionHandlerInterface.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00024 
00037 class ilConditionHandlerInterface
00038 {
00039         var $ctrl = null;
00040 
00041         var $lng;
00042         var $tpl;
00043         var $tree;
00044 
00045         var $ch_obj;
00046         var $target_obj;
00047         var $client_obj;
00048         var $target_id;
00049         var $target_type;
00050         var $target_title;
00051         var $target_ref_id;
00052 
00053         var $automatic_validation = true;
00054 
00055         function ilConditionHandlerInterface(&$gui_obj,$a_ref_id = null)
00056         {
00057                 global $lng,$tpl,$tree,$ilCtrl;
00058 
00059                 include_once "./classes/class.ilConditionHandler.php";
00060 
00061                 $this->ch_obj =& new ilConditionHandler();
00062 
00063                 $this->ctrl =& $ilCtrl;
00064                 $this->gui_obj =& $gui_obj;
00065                 $this->lng =& $lng;
00066                 $this->tpl =& $tpl;
00067                 $this->tree =& $tree;
00068                 
00069                 if($a_ref_id)
00070                 {
00071                         $this->target_obj =& ilObjectFactory::getInstanceByRefId($a_ref_id);
00072                 }
00073                 else
00074                 {
00075                         $this->target_obj =& $this->gui_obj->object;
00076                 }
00077 
00078                 // this only works for ilObject derived objects (other objects
00079                 // should call set() methods manually   
00080                 if (is_object($this->target_obj))
00081                 {
00082                         $this->setTargetId($this->target_obj->getId());
00083                         $this->setTargetRefId($this->target_obj->getRefId());
00084                         $this->setTargetType($this->target_obj->getType());
00085                         $this->setTargetTitle($this->target_obj->getTitle());
00086                 }
00087                 
00088         }
00089 
00090         function setBackButtons($a_btn_arr)
00091         {
00092                 $_SESSION['precon_btn'] = $a_btn_arr;
00093         }
00094         function getBackButtons()
00095         {
00096                 return $_SESSION['precon_btn'] ? $_SESSION['precon_btn'] : array();
00097         }
00098 
00099         function &executeCommand()
00100         {
00101                 $next_class = $this->ctrl->getNextClass($this);
00102                 $cmd = $this->ctrl->getCmd();
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                 // Table header
00223                 $this->tpl->setVariable("HEAD_TITLE",$this->lng->txt('title'));
00224                 $this->tpl->setVariable("HEAD_CONDITION",$this->lng->txt('condition'));
00225                 
00226                 // Table footer
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->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                         $this->tpl->setVariable("ROWCOL", ilUtil::switchColor($counter++,"tblrow1","tblrow2"));
00243                         $this->tpl->setVariable("CHECKBOX",ilUtil::formCheckbox(0,"conditions[]",$condition['id']));
00244                         $this->tpl->setVariable("TITLE",$ilObjDataCache->lookupTitle($condition['trigger_obj_id']));
00245                         if(strlen($desc = $ilObjDataCache->lookupDescription($condition['trigger_obj_id'])))
00246                         {
00247                                 $this->tpl->setVariable("DESCRIPTION",$desc);
00248                         }
00249                         $this->tpl->setVariable("OBJ_CONDITION",$this->lng->txt('condition_'.$condition['operator']));
00250 
00251                         // Edit link
00252                         $this->tpl->setVariable("EDIT",$this->lng->txt('edit'));
00253 
00254                         $this->ctrl->setParameter($this,'condition_id',$condition['id']);
00255                         $this->tpl->setVariable("EDIT_LINK",$this->ctrl->getLinkTarget($this,'edit'));
00256                         $this->ctrl->clearParameters($this);
00257                         $this->tpl->parseCurrentBlock();
00258                 }
00259                 return true;
00260         }
00261 
00262         function edit()
00263         {
00264                 global $ilObjDataCache;
00265 
00266                 if(!$_GET['condition_id'])
00267                 {
00268                         sendInfo("Missing id: condition_id");
00269                         $this->listConditions();
00270                         return false;
00271                 }
00272                 $condition = ilConditionHandler::_getCondition((int) $_GET['condition_id']);
00273 
00274                 $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.condition_handler_edit_condition.html');
00275                 $this->ctrl->setParameter($this,'condition_id',(int) $_GET['condition_id']);
00276                 $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
00277 
00278                 // Table header
00279                 $this->tpl->setVariable("COLL_TITLE_IMG",ilUtil::getImagePath('icon_'.$this->getTargetType().'.gif'));
00280                 $this->tpl->setVariable("COLL_TITLE_IMG_ALT",$this->lng->txt('obj_'.$this->getTargetType()));
00281                 $this->tpl->setVariable("TABLE_TITLE",$this->getTargetTitle());
00282                 $this->tpl->setVariable("TRIGGER_TITLE",$ilObjDataCache->lookupTitle($condition['trigger_obj_id']));
00283 
00284                 // Condition selector
00285                 $this->tpl->setVariable("CONDITION",$this->lng->txt('condition'));
00286 
00287                 include_once "./classes/class.ilConditionHandler.php";
00288                 $ch_obj =& new ilConditionHandler();
00289                 foreach($ch_obj->getOperatorsByTargetType($condition['trigger_type']) as $operator)
00290                 {
00291                         $operators[$operator] = $this->lng->txt('condition_'.$operator);
00292                 }
00293                 $this->tpl->setVariable("SEL_CONDITION",ilUtil::formSelect($condition['operator'],
00294                                                                                                                                    "operator",
00295                                                                                                                                    $operators,
00296                                                                                                                                    false,
00297                                                                                                                                    true));
00298                 // Additional settings for SCO's
00299                 if($condition['trigger_type'] == 'sahs')
00300                 {
00301                         $this->lng->loadLanguageModule('trac');
00302                         include_once 'Services/Tracking/classes/class.ilLPCollections.php';
00303                         $lp_collections = new ilLPCollections($condition['trigger_obj_id']);
00304 
00305                         $counter = 0;
00306                         $this->tpl->setVariable("INFO_SCO",$this->lng->txt('trac_lp_determination_info_sco'));
00307                         $this->tpl->setVariable("ROWCOL_INFO",ilUtil::switchColor(++$counter,'tblrow1','tblrow2'));
00308                         foreach(ilLPCollections::_getPossibleSAHSItems($condition['trigger_obj_id']) as $item_id => $sahs_item)
00309                         {
00310                                 $this->tpl->setCurrentBlock("sco_row");
00311                                 $this->tpl->setVariable("CHECK_SCO",ilUtil::formCheckbox($lp_collections->isAssigned($item_id),
00312                                                                                                                                                  'item_ids[]',
00313                                                                                                                                                  $item_id));
00314                                 $this->tpl->setVariable("SCO_TITLE",$sahs_item['title']);
00315                                 $this->tpl->setVariable("ROWCOL",ilUtil::switchColor(++$counter,'tblrow1','tblrow2'));
00316                                 $this->tpl->parseCurrentBlock();
00317                         }
00318                 }
00319                 
00320                 // Table footer
00321                 $this->tpl->setVariable("DOWNRIGHT",ilUtil::getImagePath('arrow_downright.gif'));
00322                 $this->tpl->setVariable("BTN_SAVE",$this->lng->txt('save'));
00323                 $this->tpl->setVariable("BTN_CANCEL",$this->lng->txt('cancel'));
00324         }
00325 
00326         function updateCondition()
00327         {
00328                 global $ilObjDataCache;
00329 
00330                 if(!$_GET['condition_id'])
00331                 {
00332                         sendInfo("Missing id: condition_id");
00333                         $this->listConditions();
00334                         return false;
00335                 }
00336 
00337                 // Update condition
00338                 include_once 'classes/class.ilConditionHandler.php';
00339                 $condition_handler = new ilConditionHandler();
00340 
00341                 $condition = ilConditionHandler::_getCondition((int) $_GET['condition_id']);
00342                 $condition_handler->setOperator($_POST['operator']);
00343                 $condition_handler->setValue('');
00344                 $condition_handler->updateCondition($condition['id']);
00345 
00346                 // Update relevant sco's
00347                 if($condition['trigger_type'] == 'sahs')
00348                 {
00349                         include_once 'Services/Tracking/classes/class.ilLPCollections.php';
00350                         $lp_collection = new ilLPCollections($condition['trigger_obj_id']);
00351                         $lp_collection->deleteAll();
00352 
00353                         $items = is_array($_POST['item_ids']) ? $_POST['item_ids'] : array();
00354                         foreach($items as $item_id)
00355                         {
00356                                 $lp_collection->add($item_id);
00357                         }
00358                 }
00359 
00360                 sendInfo($this->lng->txt('settings_saved'));
00361                 $this->edit();
00362         }
00363                 
00364 
00365         function delete()
00366         {
00367                 if(!count($_POST['conditions']))
00368                 {
00369                         sendInfo('no_condition_selected');
00370                         $this->listConditions();
00371                         return true;
00372                 }
00373 
00374                 foreach($_POST['conditions'] as $condition_id)
00375                 {
00376                         $this->ch_obj->deleteCondition($condition_id);
00377                 }
00378                 sendInfo($this->lng->txt('condition_deleted'));
00379                 $this->listConditions();
00380 
00381                 return true;
00382         }
00383         
00384         function selector()
00385         {
00386                 include_once ("classes/class.ilConditionSelector.php");
00387 
00388                 $this->tpl->addBlockFile('ADM_CONTENT', "adm_content", "tpl.condition_selector.html");
00389 
00390                 sendInfo($this->lng->txt("condition_select_object"));
00391 
00392                 $exp = new ilConditionSelector($this->ctrl->getLinkTarget($this,'copySelector'));
00393                 $exp->setExpand($_GET["condition_selector_expand"] ? $_GET["condition_selector_expand"] : $this->tree->readRootId());
00394                 $exp->setExpandTarget($this->ctrl->getLinkTarget($this,'selector'));
00395                 $exp->setTargetGet("ref_id");
00396                 $exp->setRefId($this->getTargetRefId());
00397 
00398                 $exp->addFilter('crs');
00399                 $exp->addFilter('tst');
00400                 $exp->addFilter('sahs');
00401 
00402                 $exp->setSelectableTypes($this->ch_obj->getTriggerTypes());
00403                 $exp->setControlClass($this);
00404                 // build html-output
00405                 $exp->setOutput(0);
00406 
00407                 $this->tpl->setCurrentBlock("adm_content");
00408                 $this->tpl->setVariable("EXPLORER",$exp->getOutput());
00409                 $this->tpl->parseCurrentBlock();
00410         }
00411 
00412         function add()
00413         {
00414                 global $ilObjDataCache;
00415 
00416                 if(!$_GET['source_id'])
00417                 {
00418                         sendInfo("Missing id: condition_id");
00419                         $this->selector();
00420                         return false;
00421                 }
00422                 $trigger_obj_id = $ilObjDataCache->lookupObjId((int) $_GET['source_id']);
00423                 $trigger_type = $ilObjDataCache->lookupType($trigger_obj_id);
00424                 $trigger_title = $ilObjDataCache->lookupTitle($trigger_obj_id);
00425 
00426                 $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.condition_handler_add.html');
00427                 $this->ctrl->setParameter($this,'source_id',(int) $_GET['source_id']);
00428                 $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
00429 
00430                 // Table header
00431                 $this->tpl->setVariable("COLL_TITLE_IMG",ilUtil::getImagePath('icon_'.$this->getTargetType().'.gif'));
00432                 $this->tpl->setVariable("COLL_TITLE_IMG_ALT",$this->lng->txt('obj_'.$this->getTargetType()));
00433                 $this->tpl->setVariable("ADD_CONDITION",$this->lng->txt('add_condition'));
00434                 $this->tpl->setVariable("TABLE_TITLE",$this->getTargetTitle());
00435                 $this->tpl->setVariable("TRIGGER_TITLE",$trigger_title);
00436 
00437                 // Condition selector
00438                 $this->tpl->setVariable("CONDITION",$this->lng->txt('condition'));
00439 
00440                 include_once "./classes/class.ilConditionHandler.php";
00441                 $ch_obj =& new ilConditionHandler();
00442                 foreach($ch_obj->getOperatorsByTargetType($trigger_type) as $operator)
00443                 {
00444                         $operators[$operator] = $this->lng->txt('condition_'.$operator);
00445                 }
00446                 $this->tpl->setVariable("SEL_CONDITION",ilUtil::formSelect(0,
00447                                                                                                                                    "operator",
00448                                                                                                                                    $operators,
00449                                                                                                                                    false,
00450                                                                                                                                    true));
00451                 // Additional settings for SCO's
00452                 if($trigger_type == 'sahs')
00453                 {
00454                         $this->lng->loadLanguageModule('trac');
00455                         include_once 'Services/Tracking/classes/class.ilLPCollections.php';
00456                         $lp_collections = new ilLPCollections($trigger_obj_id);
00457 
00458                         $counter = 0;
00459                         $this->tpl->setVariable("INFO_SCO",$this->lng->txt('trac_lp_determination_info_sco'));
00460                         $this->tpl->setVariable("ROWCOL_INFO",ilUtil::switchColor(++$counter,'tblrow1','tblrow2'));
00461                         foreach(ilLPCollections::_getPossibleSAHSItems($trigger_obj_id) as $item_id => $sahs_item)
00462                         {
00463                                 $this->tpl->setCurrentBlock("sco_row");
00464                                 $this->tpl->setVariable("CHECK_SCO",ilUtil::formCheckbox($lp_collections->isAssigned($item_id),
00465                                                                                                                                                  'item_ids[]',
00466                                                                                                                                                  $item_id));
00467                                 $this->tpl->setVariable("SCO_TITLE",$sahs_item['title']);
00468                                 $this->tpl->setVariable("ROWCOL",ilUtil::switchColor(++$counter,'tblrow1','tblrow2'));
00469                                 $this->tpl->parseCurrentBlock();
00470                         }
00471                 }
00472                 
00473                 // Table footer
00474                 $this->tpl->setVariable("DOWNRIGHT",ilUtil::getImagePath('arrow_downright.gif'));
00475                 $this->tpl->setVariable("BTN_SAVE",$this->lng->txt('save'));
00476                 $this->tpl->setVariable("BTN_CANCEL",$this->lng->txt('cancel'));
00477         }
00478 
00479 
00483         function assign()
00484         {
00485                 if(!isset($_GET['source_id']))
00486                 {
00487                         echo "class.ilConditionHandlerInterface: no source_id given";
00488 
00489                         return false;
00490                 }
00491                 if(!strlen($_POST['operator']))
00492                 {
00493                         sendInfo($this->lng->txt('no_operator_selected'));
00494                         $this->add();
00495 
00496                         return false;
00497                 }
00498 
00499 
00500                 $this->ch_obj->setTargetRefId($this->getTargetRefId());
00501                 $this->ch_obj->setTargetObjId($this->getTargetId());
00502                 $this->ch_obj->setTargetType($this->getTargetType());
00503                 
00504                 // this has to be changed, if non referenced trigger are implemted
00505                 if(!$trigger_obj =& ilObjectFactory::getInstanceByRefId((int) $_GET['source_id'],false))
00506                 {
00507                         echo 'ilConditionHandler: Trigger object does not exist';
00508                 }
00509                 $this->ch_obj->setTriggerRefId($trigger_obj->getRefId());
00510                 $this->ch_obj->setTriggerObjId($trigger_obj->getId());
00511                 $this->ch_obj->setTriggerType($trigger_obj->getType());
00512                 $this->ch_obj->setOperator($_POST['operator']);
00513                 $this->ch_obj->setValue('');
00514 
00515                 // Save assigned sco's
00516                 if($this->ch_obj->getTriggerType() == 'sahs')
00517                 {
00518                         include_once 'Services/Tracking/classes/class.ilLPCollections.php';
00519                         $lp_collection = new ilLPCollections($this->ch_obj->getTriggerObjId());
00520                         $lp_collection->deleteAll();
00521 
00522                         $items = is_array($_POST['item_ids']) ? $_POST['item_ids'] : array();
00523                         foreach($items as $item_id)
00524                         {
00525                                 $lp_collection->add($item_id);
00526                         }
00527                 }
00528 
00529                 $this->ch_obj->enableAutomaticValidation($this->getAutomaticValidation());
00530                 if(!$this->ch_obj->storeCondition())
00531                 {
00532                         sendInfo($this->ch_obj->getErrorMessage());
00533                 }
00534                 else
00535                 {
00536                         sendInfo($this->lng->txt('added_new_condition'));
00537                 }
00538 
00539                 $this->listConditions();
00540 
00541                 return true;
00542         }
00543 
00544         function chi_update()
00545         {
00546                 #if(in_array('',$_POST['operator']))
00547                 #{
00548                 #       sendInfo($this->lng->txt('select_one_operator'));
00549 
00550                 #       return false;
00551                 #}
00552                 foreach($this->__getConditionsOfTarget() as $condition)
00553                 {
00554                         $this->ch_obj->setOperator($_POST['operator'][$condition["id"]]);
00555                         $this->ch_obj->setValue($_POST['value'][$condition["id"]]);
00556                         $this->ch_obj->updateCondition($condition['id']);
00557 
00558                 }
00559                 sendInfo($this->lng->txt('conditions_updated'));
00560                 
00561                 $this->ctrl->returnToParent($this);
00562 
00563                 return true;
00564         }
00565         function __getConditionsOfTarget()
00566         {
00567                 include_once './classes/class.ilConditionHandler.php';
00568 
00569                 foreach(ilConditionHandler::_getConditionsOfTarget($this->getTargetId(), $this->getTargetType()) as $condition)
00570                 {
00571                         if($condition['operator'] == 'not_member')
00572                         {
00573                                 continue;
00574                         }
00575                         else
00576                         {
00577                                 $cond[] = $condition;
00578                         }
00579                 }
00580                 return $cond ? $cond : array();
00581         }
00582 
00583         function __showButtons()
00584         {
00585                 if(!$this->getBackButtons())
00586                 {
00587                         return false;
00588                 }
00589 
00590                 $this->tpl->addBlockfile("BUTTONS", "buttons", "tpl.buttons.html");
00591                 foreach($this->getBackButtons() as $name => $link)
00592                 {
00593                         $this->tpl->setCurrentBlock("btn_cell");
00594                         $this->tpl->setVariable("BTN_LINK",$link);
00595                         $this->tpl->setVariable("BTN_TXT",$this->lng->txt($name));
00596                         $this->tpl->parseCurrentBlock();
00597                 }
00598         }
00599 
00600 }
00601 ?>

Generated on Fri Dec 13 2013 13:52:06 for ILIAS Release_3_7_x_branch .rev 46817 by  doxygen 1.7.1