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

Services/Tracking/classes/class.ilLPObjSettings.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 
00035 define("LP_MODE_DEACTIVATED",0);
00036 define("LP_MODE_TLT",1);
00037 define("LP_MODE_VISITS",2);
00038 define("LP_MODE_MANUAL",3);
00039 define("LP_MODE_OBJECTIVES",4);
00040 define("LP_MODE_COLLECTION",5);
00041 define("LP_MODE_SCORM",6);
00042 define("LP_MODE_TEST_FINISHED",7);
00043 define("LP_MODE_TEST_PASSED",8);
00044 define("LP_MODE_EXERCISE_RETURNED",9);
00045 define("LP_MODE_EVENT",10);
00046 
00047 define("LP_DEFAULT_VISITS",30);
00048 
00049 
00050 class ilLPObjSettings
00051 {
00052         var $db = null;
00053 
00054         var $obj_id = null;
00055         var $obj_type = null;
00056         var $obj_mode = null;
00057         var $visits = null;
00058 
00059         var $is_stored = false;
00060 
00061         function ilLPObjSettings($a_obj_id)
00062         {
00063                 global $ilObjDataCache,$ilDB;
00064 
00065                 $this->db =& $ilDB;
00066 
00067                 $this->obj_id = $a_obj_id;
00068 
00069                 if(!$this->__read())
00070                 {
00071                         $this->obj_type = $ilObjDataCache->lookupType($this->obj_id);
00072                         $this->obj_mode = $this->__getDefaultMode($this->obj_id,$this->obj_type);
00073                 }
00074         }
00075 
00076         function getVisits()
00077         {
00078                 return (int) $this->visits ? $this->visits : LP_DEFAULT_VISITS;
00079         }
00080 
00081         function setVisits($a_visits)
00082         {
00083                 $this->visits = $a_visits;
00084         }
00085 
00086         function setMode($a_mode)
00087         {
00088                 $this->obj_mode = $a_mode;
00089         }
00090         function getMode()
00091         {
00092                 return $this->obj_mode;
00093         }
00094 
00095         function getObjId()
00096         {
00097                 return (int) $this->obj_id;
00098         }
00099         function getObjType()
00100         {
00101                 return $this->obj_type;
00102         }
00103 
00104         function update()
00105         {
00106                 if(!$this->is_stored)
00107                 {
00108                         return $this->insert();
00109                 }
00110                 $query = "UPDATE ut_lp_settings SET mode = '".$this->obj_mode.
00111                         "', visits = '".$this->visits."' ".
00112                         "WHERE obj_id = '".$this->getObjId()."'";
00113                 $this->db->query($query);
00114                 $this->__read();
00115                 return true;
00116         }
00117 
00118         function insert()
00119         {
00120                 $query = "INSERT INTO ut_lp_settings SET obj_id = '".$this->obj_id."', ".
00121                         "obj_type = '".$this->obj_type."', ".
00122                         "mode = '".$this->obj_mode."'";
00123                 $this->db->query($query);
00124                 $this->__read();
00125                 return true;
00126         }
00127 
00128 
00129         // Static
00130         function _lookupVisits($a_obj_id)
00131         {
00132                 global $ilDB;
00133 
00134                 #echo $a_obj_id;
00135 
00136                 $query = "SELECT visits FROM ut_lp_settings ".
00137                         "WHERE obj_id = '".$a_obj_id."'";
00138 
00139                 $res = $ilDB->query($query);
00140                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00141                 {
00142                         return $row->visits;
00143                 }
00144                 return LP_DEFAULT_VISITS;
00145         }
00146 
00147         function _isContainer($a_mode)
00148         {
00149                 return $a_mode == LP_MODE_COLLECTION or
00150                         $a_mode == LP_MODE_SCORM or
00151                         $a_mode == LP_MODE_OBJECTIVES;
00152         }
00153                 
00154 
00155         function _delete($a_obj_id)
00156         {
00157                 global $ilDB;
00158 
00159                 $query = "DELETE FROM ut_lp_settings WHERE obj_id = '".$a_obj_id."'";
00160                 $ilDB->query($query);
00161 
00162                 return true;
00163         }
00164 
00165         function _lookupMode($a_obj_id)
00166         {
00167                 global $ilDB,$ilObjDataCache;
00168 
00169                 if(ilLPObjSettings::_checkObjectives($a_obj_id))
00170                 {
00171                         return LP_MODE_OBJECTIVES;
00172                 }
00173                 if(ilLPObjSettings::_checkSCORMPreconditions($a_obj_id))
00174                 {
00175                         return LP_MODE_SCORM;
00176                 }
00177 
00178                 $query = "SELECT mode FROM ut_lp_settings ".
00179                         "WHERE obj_id = '".$a_obj_id."'";
00180 
00181                 $res = $ilDB->query($query);
00182                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00183                 {
00184                         return $row->mode;
00185                 }
00186                 
00187                 // no db entry exists => return default mode by type
00188                 return ilLPObjSettings::__getDefaultMode($a_obj_id,$ilObjDataCache->lookupType($a_obj_id));
00189         }
00190 
00191         function getValidModes()
00192         {
00193                 global $lng;
00194 
00195                 switch($this->obj_type)
00196                 {
00197                         case 'crs':
00198                                 if(ilLPObjSettings::_checkObjectives($this->getObjId()))
00199                                 {
00200                                         return array(LP_MODE_OBJECTIVES => $lng->txt('trac_mode_objectives'));
00201                                 }
00202 
00203                                 return array(LP_MODE_DEACTIVATED => $lng->txt('trac_mode_deactivated'),
00204                                                          LP_MODE_MANUAL => $lng->txt('trac_mode_manual'),
00205                                                          #LP_MODE_OBJECTIVES => $lng->txt('trac_mode_objectives'),
00206                                                          LP_MODE_COLLECTION => $lng->txt('trac_mode_collection'));
00207 
00208                                 break;
00209 
00210                         case 'dbk':
00211                         case 'lm':
00212                                 return array(LP_MODE_MANUAL => $lng->txt('trac_mode_manual'),
00213                                                          LP_MODE_VISITS => $lng->txt('trac_mode_visits'),
00214                                                          LP_MODE_TLT => $lng->txt('trac_mode_tlt'),
00215                                                          LP_MODE_DEACTIVATED => $lng->txt('trac_mode_deactivated'));
00216 
00217                         case 'htlm':
00218                                 return array(LP_MODE_DEACTIVATED => $lng->txt('trac_mode_deactivated'),
00219                                                          LP_MODE_MANUAL => $lng->txt('trac_mode_manual'));
00220 
00221                         case 'sahs':
00222                                 include_once './Services/Tracking/classes/class.ilLPCollections.php';
00223                                 
00224                                 if(ilLPObjSettings::_checkSCORMPreconditions($this->getObjId()))
00225                                 {
00226                                         return array(LP_MODE_SCORM => $lng->txt('trac_mode_scorm_aicc'));
00227                                 }
00228                                 if(ilLPCollections::_getCountPossibleSAHSItems($this->getObjId()))
00229                                 {
00230                                         return array(LP_MODE_DEACTIVATED => $lng->txt('trac_mode_deactivated'),
00231                                                                  LP_MODE_SCORM => $lng->txt('trac_mode_scorm_aicc'));
00232                                 }
00233                                 return array(LP_MODE_DEACTIVATED => $lng->txt('trac_mode_deactivated'));
00234 
00235                         case 'tst':
00236                                 return array(LP_MODE_TEST_FINISHED => $lng->txt('trac_mode_test_finished'),
00237                                                          LP_MODE_TEST_PASSED => $lng->txt('trac_mode_test_passed'),
00238                                                          LP_MODE_DEACTIVATED => $lng->txt('trac_mode_deactivated'));
00239 
00240                         case 'exc':
00241                                 return array(LP_MODE_DEACTIVATED => $lng->txt('trac_mode_deactivated'),
00242                                                          LP_MODE_EXERCISE_RETURNED => $lng->txt('trac_mode_exercise_returned'));
00243 
00244                         case 'grp':
00245                                 return array(LP_MODE_DEACTIVATED => $lng->txt('trac_mode_deactivated'),
00246                                                          LP_MODE_MANUAL => $lng->txt('trac_mode_manual'),
00247                                                          LP_MODE_COLLECTION => $lng->txt('trac_mode_collection'));
00248 
00249                         case 'fold':
00250                                 return array(LP_MODE_DEACTIVATED => $lng->txt('trac_mode_deactivated'),
00251                                                          LP_MODE_COLLECTION => $lng->txt('trac_mode_collection'));
00252 
00253                         default:
00254                                 return array();
00255                 }
00256         }
00257 
00258         function _mode2Text($a_mode)
00259         {
00260                 global $lng;
00261 
00262                 switch($a_mode)
00263                 {
00264                         case LP_MODE_DEACTIVATED:
00265                                 return $lng->txt('trac_mode_deactivated');
00266 
00267                         case LP_MODE_TLT:
00268                                 return $lng->txt('trac_mode_tlt');
00269 
00270                         case LP_MODE_VISITS:
00271                                 return $lng->txt('trac_mode_visits');
00272                                 
00273                         case LP_MODE_MANUAL:
00274                                 return $lng->txt('trac_mode_manual');
00275 
00276                         case LP_MODE_OBJECTIVES:
00277                                 return $lng->txt('trac_mode_objectives');
00278 
00279                         case LP_MODE_COLLECTION:
00280                                 return $lng->txt('trac_mode_collection');
00281 
00282                         case LP_MODE_SCORM:
00283                                 return $lng->txt('trac_mode_scorm');
00284 
00285                         case LP_MODE_TEST_FINISHED:
00286                                 return $lng->txt('trac_mode_test_finished');
00287 
00288                         case LP_MODE_TEST_PASSED:
00289                                 return $lng->txt('trac_mode_test_passed');
00290 
00291                         case LP_MODE_EXERCISE_RETURNED:
00292                                 return $lng->txt('trac_mode_exercise_returned');
00293 
00294                 }
00295         }
00296                                                          
00297                                 
00298 
00299 
00300         // Private
00301         function _checkObjectives($a_obj_id)
00302         {
00303                 global $ilDB,$ilObjDataCache;
00304 
00305                 // Return deactivate for course with objective view
00306                 if($ilObjDataCache->lookupType($a_obj_id) == 'crs')
00307                 {
00308                         include_once 'course/classes/class.ilObjCourse.php';
00309 
00310                         if(ilObjCourse::_lookupViewMode($a_obj_id) == IL_CRS_VIEW_OBJECTIVE)
00311                         {
00312                                 return true;
00313                         }
00314                 }
00315                 return false;
00316         }
00317         
00318         function _checkSCORMPreconditions($a_obj_id)
00319         {
00320                 global $ilObjDataCache;
00321                 
00322                 if($ilObjDataCache->lookupType($a_obj_id) != 'sahs')
00323                 {
00324                         return false;
00325                 }
00326                 include_once('classes/class.ilConditionHandler.php');
00327                 if(count($conditions = ilConditionHandler::_getConditionsOfTrigger('sahs',$a_obj_id)))
00328                 {
00329                         return true;
00330                 }
00331                 return false;
00332         }
00333                 
00334 
00335 
00336         function __read()
00337         {
00338                 $res = $this->db->query("SELECT * FROM ut_lp_settings WHERE obj_id = '".$this->db->quote($this->obj_id)."'");
00339                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00340                 {
00341                         $this->is_stored = true;
00342                         $this->obj_type = $row->obj_type;
00343                         $this->obj_mode = $row->mode;
00344                         $this->visits = $row->visits;
00345 
00346                         if(ilLPObjSettings::_checkObjectives($this->obj_id))
00347                         {
00348                                 $this->obj_mode = LP_MODE_OBJECTIVES;
00349                         }
00350                         if(ilLPObjSettings::_checkSCORMPreconditions($this->obj_id))
00351                         {
00352                                 $this->obj_mode = LP_MODE_SCORM;
00353                         }
00354 
00355                         return true;
00356                 }
00357 
00358                 return false;
00359         }
00360 
00361         function __getDefaultMode($a_obj_id,$a_type)
00362         {
00363                 global $ilDB;
00364 
00365                 #$type = strlen($a_type) ? $a_type : $this->obj_type;
00366 
00367                 switch($a_type)
00368                 {
00369                         case 'crs':
00370                                 // If objectives are enabled return deactivated
00371                                 if(ilLPObjSettings::_checkObjectives($a_obj_id))
00372                                 {
00373                                         return LP_MODE_OBJECTIVES;
00374                                 }
00375                                 return LP_MODE_MANUAL;
00376 
00377                         case 'dbk':
00378                         case 'lm':
00379                         case 'htlm':
00380                                 return LP_MODE_MANUAL;
00381 
00382                         case 'sahs':
00383                                 return LP_MODE_DEACTIVATED;
00384 
00385                         case 'dbk':
00386                                 return LP_MODE_MANUAL;
00387 
00388                         case 'tst':
00389                                 return LP_MODE_TEST_PASSED;
00390 
00391                         case 'exc':
00392                                 return LP_MODE_EXERCISE_RETURNED;
00393 
00394                         case 'grp':
00395                                 return LP_MODE_DEACTIVATED;
00396 
00397                         case 'fold':
00398                                 return LP_MODE_DEACTIVATED;
00399                                         
00400                         default:
00401                                 return LP_MODE_UNDEFINED;
00402                 }
00403         }
00404 }
00405 ?>

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