• 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 $lng;
00040         var $tpl;
00041         var $tree;
00042 
00043         var $ch_obj;
00044         var $target_obj;
00045         var $client_obj;
00046         var $target_id;
00047         var $target_type;
00048         var $target_title;
00049         var $target_ref_id;
00050 
00051         function ilConditionHandlerInterface(&$gui_obj,$a_ref_id = null)
00052         {
00053                 global $lng,$tpl,$tree;
00054 
00055                 include_once "./classes/class.ilConditionHandler.php";
00056 
00057                 $this->ch_obj =& new ilConditionHandler();
00058 
00059                 $this->gui_obj =& $gui_obj;
00060                 $this->lng =& $lng;
00061                 $this->tpl =& $tpl;
00062                 $this->tree =& $tree;
00063                 
00064                 if($a_ref_id)
00065                 {
00066                         $this->target_obj =& ilObjectFactory::getInstanceByRefId($a_ref_id);
00067                 }
00068                 else
00069                 {
00070                         $this->target_obj =& $this->gui_obj->object;
00071                 }
00072 
00073                 // this only works for ilObject derived objects (other objects
00074                 // should call set() methods manually   
00075                 if (is_object($this->target_obj))
00076                 {
00077                         $this->setTargetId($this->target_obj->getId());
00078                         $this->setTargetRefId($this->target_obj->getRefId());
00079                         $this->setTargetType($this->target_obj->getType());
00080                         $this->setTargetTitle($this->target_obj->getTitle());
00081                 }
00082                 
00083         }
00084         
00088         function setTargetId($a_target_id)
00089         {
00090                 $this->target_id = $a_target_id;
00091         }
00092         
00096         function getTargetId()
00097         {
00098                 return $this->target_id;
00099         }
00100 
00104         function setTargetRefId($a_target_ref_id)
00105         {
00106                 $this->target_ref_id = $a_target_ref_id;
00107         }
00108         
00112         function getTargetRefId()
00113         {
00114                 return $this->target_ref_id;
00115         }
00116 
00120         function setTargetType($a_target_type)
00121         {
00122                 $this->target_type = $a_target_type;
00123         }
00124         
00128         function getTargetType()
00129         {
00130                 return $this->target_type;
00131         }
00132 
00136         function setTargetTitle($a_target_title)
00137         {
00138                 $this->target_title = $a_target_title;
00139         }
00140         
00144         function getTargetTitle()
00145         {
00146                 return $this->target_title;
00147         }
00148 
00149         function chi_init(&$chi_target_obj,$a_ref_id = null)
00150         {
00151                 echo 'deprecated';
00152                 
00153                 include_once "./classes/class.ilConditionHandler.php";
00154 
00155                 $this->ch_obj =& new ilConditionHandler();
00156 
00157                 if($a_ref_id)
00158                 {
00159                         $this->target_obj =& ilObjectFactory::getInstanceByRefId($a_ref_id);
00160                 }
00161                 else
00162                 {
00163                         $this->target_obj =& $this->object;
00164                 }
00165 
00166                 return true;
00167         }
00168 
00172         function &chi_list()
00173         {
00174                 global $rbacsystem;
00175 
00176                 $operators = array(''                   => $this->lng->txt('condition_select_one'),
00177                                                    'passed'             => $this->lng->txt('condition_passed'));
00178 
00179                 $tpl =& new ilTemplate("tpl.table.html", true, true);
00180 
00181 
00182                 $tpl->setCurrentBlock("tbl_form_header");
00183                 $tpl->setVariable("FORMACTION",$this->gui_obj->ctrl->getFormAction($this->gui_obj));
00184                 $tpl->parseCurrentBlock();
00185 
00186                 $tpl->setCurrentBlock("tbl_action_row");
00187                 $tpl->setVariable("COLUMN_COUNTS",4);
00188                 $tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.gif"));
00189 
00190                 if(count(ilConditionHandler::_getConditionsOfTarget($this->getTargetId(), $this->getTargetType())))
00191                 {
00192 
00193                         $tpl->setCurrentBlock("tbl_action_btn");
00194                         $tpl->setVariable("BTN_NAME","chi_delete");
00195                         $tpl->setVariable("BTN_VALUE",$this->lng->txt("delete"));
00196                         $tpl->parseCurrentBlock();
00197 
00198                         $tpl->setCurrentBlock("plain_button");
00199                         $tpl->setVariable("PBTN_NAME","chi_update");
00200                         $tpl->setVariable("PBTN_VALUE",$this->lng->txt("condition_update"));
00201                         $tpl->parseCurrentBlock();
00202                 }
00203 
00204                 $tpl->setCurrentBlock("plain_button");
00205                 $tpl->setVariable("PBTN_NAME","chi_selector");
00206                 $tpl->setVariable("PBTN_VALUE",$this->lng->txt("add_condition"));
00207                 $tpl->parseCurrentBlock();
00208 
00209                 $tpl->setCurrentBlock("tbl_action_row");
00210                 $tpl->setVariable("TPLPATH",$this->tpl->tplPath);
00211                 $tpl->parseCurrentBlock();
00212 
00213                 $tpl->setCurrentBlock("tbl_action_row");
00214 
00215                 $tpl->addBlockfile("TBL_CONTENT", "tbl_content", "tpl.condition_handler_row.html");
00216 
00217                 $counter = 0;
00218                 foreach(ilConditionHandler::_getConditionsOfTarget($this->getTargetId(), $this->getTargetType()) as $condition)
00219                 {
00220                         $tmp_obj =& ilObjectFactory::getInstanceByRefId($condition['trigger_ref_id']);
00221 
00222                         $tpl->setCurrentBlock("tbl_content");
00223                         $tpl->setVariable("CHECKBOX",ilUtil::formCheckbox(0,"conditions[]",$condition['id']));
00224                         $tpl->setVariable("OBJ_TITLE",$tmp_obj->getTitle());
00225                         $tpl->setVariable("OBJ_DESCRIPTION",$tmp_obj->getDescription());
00226                         $tpl->setVariable("ROWCOL", ilUtil::switchColor($counter++,"tblrow2","tblrow1"));
00227 
00228                         $tpl->setVariable("OBJ_CONDITION",ilUtil::formSelect($condition['operator'],
00229                                                                                                                                  "operator[".$condition['id']."]",
00230                                                                                                                                  $operators,
00231                                                                                                                                  false,
00232                                                                                                                                  true));
00233 
00234                         $tpl->setVariable("OBJ_VALUE_NAME","value[".$condition['id']."]");
00235                         $tpl->setVariable("OBJ_VALUE_VALUE",$condition['value']); 
00236 
00237                         $tpl->parseCurrentBlock();
00238                 }
00239 
00240 
00241                 // create table
00242                 include_once './classes/class.ilTableGUI.php';
00243 
00244                 $tbl =& new ilTableGUI();
00245 
00246                 // title & header columns
00247                 $tbl->setTitle($this->getTargetTitle()." ".$this->lng->txt("preconditions"),"icon_".$this->getTargetType().".gif",
00248                                            $this->lng->txt("preconditions"));
00249 
00250                 $tbl->setHeaderNames(array("",$this->lng->txt("title"),$this->lng->txt("condition"),
00251                                                                    $this->lng->txt("value")));
00252                 $tbl->setHeaderVars(array("","title","condition","value"), 
00253                                                         array("ref_id" => $this->getTargetRefId(),
00254                                                                   "cmdClass" => "ilobjcoursegui",
00255                                                                   "cmdNode" => $_GET["cmdNode"],
00256                                                                   "cmd" => "cci_edit"));
00257                 $tbl->setColumnWidth(array("1%","40%","30%","30%"));
00258 
00259                 $tbl->setLimit($_GET["limit"]);
00260                 $tbl->setOffset($_GET["offset"]);
00261                 $tbl->setMaxCount(10);
00262 
00263                 // footer
00264                 $tbl->disable("footer");
00265                 $tbl->disable('sort');
00266 
00267                 // render table
00268                 $tbl->setTemplate($tpl);
00269                 $tbl->render();
00270 
00271                 return $tpl->get();
00272         }
00273 
00274         function chi_delete()
00275         {
00276                 if(!count($_POST['conditions']))
00277                 {
00278                         sendInfo('no_condition_selected');
00279 
00280                         return true;
00281                 }
00282 
00283                 foreach($_POST['conditions'] as $condition_id)
00284                 {
00285                         $this->ch_obj->deleteCondition($condition_id);
00286                 }
00287                 sendInfo($this->lng->txt('condition_deleted'));
00288                 return true;
00289         }
00290         
00291         function chi_selector($a_tpl_block = "content", $a_tpl_var = "OBJECTS")
00292         {
00293                 include_once ("classes/class.ilConditionSelector.php");
00294 
00295                 $this->tpl->setCurrentBlock($a_tpl_block);
00296                 $this->tpl->addBlockFile($a_tpl_var, "objects", "tpl.condition_selector.html");
00297 
00298                 sendInfo($this->lng->txt("condition_select_object"));
00299 
00300                 $exp = new ilConditionSelector($this->gui_obj->ctrl->getLinkTarget($this->gui_obj,'copySelector'));
00301                 $exp->setExpand($_GET["condition_selector_expand"] ? $_GET["condition_selector_expand"] : $this->tree->readRootId());
00302                 $exp->setExpandTarget($this->gui_obj->ctrl->getLinkTarget($this->gui_obj,'chi_selector'));
00303                 $exp->setTargetGet("ref_id");
00304                 $exp->setRefId($this->getTargetRefId());
00305                 $exp->addFilter('crs');
00306                 $exp->setSelectableTypes($this->ch_obj->getTriggerTypes());
00307                 $exp->setControlClass($this->gui_obj);
00308                 // build html-output
00309                 $exp->setOutput(0);
00310 
00311                 $this->tpl->setCurrentBlock("objects");
00312                 $this->tpl->setVariable("EXPLORER",$exp->getOutput());
00313                 $this->tpl->parseCurrentBlock();
00314         }
00315 
00319         function chi_assign($a_automatic_validation = true)
00320         {
00321                 if(!isset($_GET['source_id']))
00322                 {
00323                         echo "class.ilConditionHandlerInterface: no source_id given";
00324 
00325                         return false;
00326                 }
00327 
00328                 // automatic determination of obj id and type works only for
00329                 // referenced objects
00330                 if ($this->getTargetRefId() > 0)
00331                 {
00332                         if(!$target_obj =& ilObjectFactory::getInstanceByRefId($this->getTargetRefId(),false))
00333                         {
00334                                 echo 'ilConditionHandler: Target object does not exist';
00335                         }
00336                         $this->ch_obj->setTargetObjId($target_obj->getId());
00337                         $this->ch_obj->setTargetType($target_obj->getType());
00338                 }
00339                 $this->ch_obj->setTargetRefId($this->getTargetRefId());
00340                 $this->ch_obj->setTargetObjId($this->getTargetId());
00341                 $this->ch_obj->setTargetType($this->getTargetType());
00342                 
00343                 // this has to be changed, if non referenced trigger are implemted
00344                 if(!$trigger_obj =& ilObjectFactory::getInstanceByRefId((int) $_GET['source_id'],false))
00345                 {
00346                         echo 'ilConditionHandler: Trigger object does not exist';
00347                 }
00348                 $this->ch_obj->setTriggerRefId($trigger_obj->getRefId());
00349                 $this->ch_obj->setTriggerObjId($trigger_obj->getId());
00350                 $this->ch_obj->setTriggerType($trigger_obj->getType());
00351                 $this->ch_obj->setOperator('');
00352                 $this->ch_obj->setValue('');
00353 
00354                 $this->ch_obj->enableAutomaticValidation($a_automatic_validation);
00355                 if(!$this->ch_obj->storeCondition())
00356                 {
00357                         sendInfo($this->ch_obj->getErrorMessage());
00358                 }
00359                 else
00360                 {
00361                         sendInfo($this->lng->txt('added_new_condition'));
00362                 }
00363                 return true;
00364         }
00365 
00366         function chi_update()
00367         {
00368                 #if(in_array('',$_POST['operator']))
00369                 #{
00370                 #       sendInfo($this->lng->txt('select_one_operator'));
00371 
00372                 #       return false;
00373                 #}
00374                 foreach(ilConditionHandler::_getConditionsOfTarget($this->getTargetId(), $this->getTargetType()) as $condition)
00375                 {
00376                         $this->ch_obj->setOperator($_POST['operator'][$condition["id"]]);
00377                         $this->ch_obj->setValue($_POST['value'][$condition["id"]]);
00378                         $this->ch_obj->updateCondition($condition['id']);
00379 
00380                 }
00381                 sendInfo($this->lng->txt('conditions_updated'));
00382 
00383                 return true;
00384         }
00385 
00386 }
00387 ?>

Generated on Fri Dec 13 2013 08:00:14 for ILIAS Release_3_3_x_branch .rev 46803 by  doxygen 1.7.1