• Main Page
  • Related Pages
  • 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 
00212         function listConditions()
00213         {
00214                 global $rbacsystem;
00215 
00216                 $this->lng->loadLanguageModule('crs');
00217 
00218                 $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.condition_handler_edit.html');
00219 
00220                 // No conditions => show add button and exit
00221                 if(!count($conditions = $this->__getConditionsOfTarget()))
00222                 {
00223                         $this->tpl->addBlockfile("BUTTONS", "buttons", "tpl.buttons.html");
00224                         $this->tpl->setCurrentBlock("btn_cell");
00225                         $this->tpl->setVariable("BTN_LINK",$this->ctrl->getLinkTarget($this,'selector'));
00226                         $this->tpl->setVariable("BTN_TXT",$this->lng->txt("add_condition"));
00227                         $this->tpl->parseCurrentBlock();
00228 
00229                         sendInfo($this->lng->txt('no_conditions_found'));
00230                         return true;
00231                 }
00232 
00233                 $tpl =& new ilTemplate("tpl.table.html", true, true);
00234                 $tpl->setCurrentBlock("tbl_form_header");
00235                 $tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
00236 
00237                 $tpl->setVariable("WIDTH",'width="60%"');
00238                 $tpl->parseCurrentBlock();
00239 
00240                 $tpl->setCurrentBlock("tbl_action_row");
00241                 $tpl->setVariable("COLUMN_COUNTS",4);
00242                 $tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.gif"));
00243 
00244                 
00245                 $tpl->setCurrentBlock("tbl_action_btn");
00246                 $tpl->setVariable("BTN_NAME","delete");
00247                 $tpl->setVariable("BTN_VALUE",$this->lng->txt("delete"));
00248                 $tpl->parseCurrentBlock();
00249                 
00250                 $tpl->setCurrentBlock("plain_button");
00251                 $tpl->setVariable("PBTN_NAME","selector");
00252                 $tpl->setVariable("PBTN_VALUE",$this->lng->txt("add_condition"));
00253                 $tpl->parseCurrentBlock();
00254 
00255                 $tpl->setCurrentBlock("tbl_action_row");
00256                 $tpl->setVariable("TPLPATH",$this->tpl->tplPath);
00257                 $tpl->parseCurrentBlock();
00258 
00259                 $tpl->setCurrentBlock("tbl_action_row");
00260 
00261                 $tpl->addBlockfile("TBL_CONTENT", "tbl_content", "tpl.condition_handler_row.html");
00262 
00263                 $counter = 0;
00264                 #foreach(ilConditionHandler::_getConditionsOfTarget($this->getTargetId(), $this->getTargetType()) as $condition)
00265                 foreach($conditions as $condition)
00266                 {
00267                         $tmp_obj =& ilObjectFactory::getInstanceByRefId($condition['trigger_ref_id']);
00268 
00269                         $tpl->setCurrentBlock("tbl_content");
00270                         $tpl->setVariable("CHECKBOX",ilUtil::formCheckbox(0,"conditions[]",$condition['id']));
00271                         $tpl->setVariable("OBJ_TITLE",$tmp_obj->getTitle());
00272                         $tpl->setVariable("OBJ_DESCRIPTION",$tmp_obj->getDescription());
00273                         $tpl->setVariable("ROWCOL", ilUtil::switchColor($counter++,"tblrow2","tblrow1"));
00274 
00275                         $tpl->setVariable("OBJ_CONDITION",$this->lng->txt('condition_'.$condition['operator']));
00276                         $tpl->setVariable("OBJ_CONDITION_VALUE",$condition['value'] ? $condition['value'] : $this->lng->txt('crs_not_available')); 
00277 
00278                         $tpl->parseCurrentBlock();
00279                 }
00280 
00281 
00282                 // create table
00283                 include_once './classes/class.ilTableGUI.php';
00284 
00285                 $tbl =& new ilTableGUI();
00286                 $tbl->setStyle('table','std');
00287 
00288                 // title & header columns
00289                 $tbl->setTitle($this->getTargetTitle()." ".$this->lng->txt("preconditions"),"icon_".$this->getTargetType().".gif",
00290                                            $this->lng->txt("preconditions"));
00291 
00292                 $tbl->setHeaderNames(array("",$this->lng->txt("title"),$this->lng->txt("condition"),
00293                                                                    $this->lng->txt("value")));
00294                 $tbl->setHeaderVars(array("","title","condition","value"), 
00295                                                         array("ref_id" => $this->getTargetRefId(),
00296                                                                   "cmdClass" => "ilobjcoursegui",
00297                                                                   "cmdNode" => $_GET["cmdNode"],
00298                                                                   "cmd" => "cci_edit"));
00299                 $tbl->setColumnWidth(array("1%","40%","30%","30%"));
00300 
00301                 $tbl->setLimit($_GET["limit"]);
00302                 $tbl->setOffset($_GET["offset"]);
00303                 $tbl->setMaxCount(10);
00304 
00305                 // footer
00306                 $tbl->disable("footer");
00307                 $tbl->disable('sort');
00308 
00309                 // render table
00310                 $tbl->setTemplate($tpl);
00311                 $tbl->render();
00312 
00313                 $this->tpl->setVariable("PRECONDITION_TABLE",$tpl->get());
00314 
00315                 return true;
00316         }
00317 
00318         function delete()
00319         {
00320                 if(!count($_POST['conditions']))
00321                 {
00322                         sendInfo('no_condition_selected');
00323                         $this->listConditions();
00324                         return true;
00325                 }
00326 
00327                 foreach($_POST['conditions'] as $condition_id)
00328                 {
00329                         $this->ch_obj->deleteCondition($condition_id);
00330                 }
00331                 sendInfo($this->lng->txt('condition_deleted'));
00332                 $this->listConditions();
00333 
00334                 return true;
00335         }
00336         
00337         function selector()
00338         {
00339                 include_once ("classes/class.ilConditionSelector.php");
00340 
00341                 $this->tpl->addBlockFile('ADM_CONTENT', "adm_content", "tpl.condition_selector.html");
00342 
00343                 sendInfo($this->lng->txt("condition_select_object"));
00344 
00345                 $exp = new ilConditionSelector($this->ctrl->getLinkTarget($this,'copySelector'));
00346                 $exp->setExpand($_GET["condition_selector_expand"] ? $_GET["condition_selector_expand"] : $this->tree->readRootId());
00347                 $exp->setExpandTarget($this->ctrl->getLinkTarget($this,'selector'));
00348                 $exp->setTargetGet("ref_id");
00349                 $exp->setRefId($this->getTargetRefId());
00350 
00351                 $exp->addFilter('crs');
00352                 $exp->addFilter('tst');
00353 
00354                 $exp->setSelectableTypes($this->ch_obj->getTriggerTypes());
00355                 $exp->setControlClass($this);
00356                 // build html-output
00357                 $exp->setOutput(0);
00358 
00359                 $this->tpl->setCurrentBlock("adm_content");
00360                 $this->tpl->setVariable("EXPLORER",$exp->getOutput());
00361                 $this->tpl->parseCurrentBlock();
00362         }
00363 
00364         function add()
00365         {
00366                 // TODO: ONLY FOR REFERENCED OBJECTS
00367                 $tmp_source_obj =& ilObjectFactory::getInstanceByRefId((int) $_GET['source_id']);
00368 
00369                 include_once "./classes/class.ilConditionHandler.php";
00370 
00371                 $ch_obj =& new ilConditionHandler();
00372                 
00373                 $operators[] = $this->lng->txt('condition_select_one');
00374                 foreach($ch_obj->getOperatorsByTargetType($tmp_source_obj->getType()) as $operator)
00375                 {
00376                         $operators[$operator] = $this->lng->txt('condition_'.$operator);
00377                 } 
00378 
00379                 $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.condition_handler_add.html');
00380 
00381                 // does not work in the moment
00382                 #this->tpl->setCurrentBlock("btn_cell");
00383                 #this->tpl->setVariable("BTN_LINK",$this->ctrl->getLinkTarget($this,'selector'));
00384                 #this->tpl->setVariable("BTN_TXT",$this->lng->txt('new_selection'));
00385                 #this->tpl->parseCurrentBlock();
00386 
00387                 $this->ctrl->setParameter($this,'source_id',(int) $_GET['source_id']);
00388                 $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
00389                 $this->tpl->setVariable("CSS_TABLE",'std');
00390                 $this->tpl->setVariable("WIDTH",'50%');
00391                 $this->tpl->setVariable("TBL_TITLE_IMG",ilUtil::getImagePath('icon_'.$this->getTargetType().'.gif'));
00392                 $this->tpl->setVariable("TBL_TITLE_ALT",$this->lng->txt('obj_',$this->getTargetType()));
00393                 
00394 
00395                 $this->tpl->setVariable("CONDITION_SELECT",ilUtil::formSelect('',
00396                                                                                                                                           "operator",
00397                                                                                                                                           $operators,
00398                                                                                                                                           false,
00399                                                                                                                                           true));
00400 
00401                 $title = $this->lng->txt('add_condition').' ('.$tmp_source_obj->getTitle().')';
00402                 unset($tmp_source_obj);
00403 
00404                 $this->tpl->setVariable("TBL_TITLE",$title);
00405                 
00406                 $this->tpl->setVariable("TXT_ADD",$this->lng->txt('add_condition'));
00407                 $this->tpl->setVariable("CMD_ADD",'assign');
00408 
00409                 return true;
00410         }
00411 
00412 
00416         function assign()
00417         {
00418                 if(!isset($_GET['source_id']))
00419                 {
00420                         echo "class.ilConditionHandlerInterface: no source_id given";
00421 
00422                         return false;
00423                 }
00424                 if(!strlen($_POST['operator']))
00425                 {
00426                         sendInfo($this->lng->txt('no_operator_selected'));
00427                         $this->add();
00428 
00429                         return false;
00430                 }
00431 
00432 
00433                 $this->ch_obj->setTargetRefId($this->getTargetRefId());
00434                 $this->ch_obj->setTargetObjId($this->getTargetId());
00435                 $this->ch_obj->setTargetType($this->getTargetType());
00436                 
00437                 // this has to be changed, if non referenced trigger are implemted
00438                 if(!$trigger_obj =& ilObjectFactory::getInstanceByRefId((int) $_GET['source_id'],false))
00439                 {
00440                         echo 'ilConditionHandler: Trigger object does not exist';
00441                 }
00442                 $this->ch_obj->setTriggerRefId($trigger_obj->getRefId());
00443                 $this->ch_obj->setTriggerObjId($trigger_obj->getId());
00444                 $this->ch_obj->setTriggerType($trigger_obj->getType());
00445                 $this->ch_obj->setOperator($_POST['operator']);
00446                 $this->ch_obj->setValue('');
00447 
00448                 $this->ch_obj->enableAutomaticValidation($this->getAutomaticValidation());
00449                 if(!$this->ch_obj->storeCondition())
00450                 {
00451                         sendInfo($this->ch_obj->getErrorMessage());
00452                 }
00453                 else
00454                 {
00455                         sendInfo($this->lng->txt('added_new_condition'));
00456                 }
00457 
00458                 $this->listConditions();
00459 
00460                 return true;
00461         }
00462 
00463         function chi_update()
00464         {
00465                 #if(in_array('',$_POST['operator']))
00466                 #{
00467                 #       sendInfo($this->lng->txt('select_one_operator'));
00468 
00469                 #       return false;
00470                 #}
00471                 foreach($this->__getConditionsOfTarget() as $condition)
00472                 {
00473                         $this->ch_obj->setOperator($_POST['operator'][$condition["id"]]);
00474                         $this->ch_obj->setValue($_POST['value'][$condition["id"]]);
00475                         $this->ch_obj->updateCondition($condition['id']);
00476 
00477                 }
00478                 sendInfo($this->lng->txt('conditions_updated'));
00479                 
00480                 $this->ctrl->returnToParent($this);
00481 
00482                 return true;
00483         }
00484         function __getConditionsOfTarget()
00485         {
00486                 include_once './classes/class.ilConditionHandler.php';
00487 
00488                 foreach(ilConditionHandler::_getConditionsOfTarget($this->getTargetId(), $this->getTargetType()) as $condition)
00489                 {
00490                         if($condition['operator'] == 'not_member')
00491                         {
00492                                 continue;
00493                         }
00494                         else
00495                         {
00496                                 $cond[] = $condition;
00497                         }
00498                 }
00499                 return $cond ? $cond : array();
00500         }
00501 
00502         function __showButtons()
00503         {
00504                 if(!$this->getBackButtons())
00505                 {
00506                         return false;
00507                 }
00508 
00509                 $this->tpl->addBlockfile("BUTTONS", "buttons", "tpl.buttons.html");
00510                 foreach($this->getBackButtons() as $name => $link)
00511                 {
00512                         $this->tpl->setCurrentBlock("btn_cell");
00513                         $this->tpl->setVariable("BTN_LINK",$link);
00514                         $this->tpl->setVariable("BTN_TXT",$this->lng->txt($name));
00515                         $this->tpl->parseCurrentBlock();
00516                 }
00517         }
00518 
00519 }
00520 ?>

Generated on Fri Dec 13 2013 11:57:53 for ILIAS Release_3_6_x_branch .rev 46809 by  doxygen 1.7.1