• 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 define("LP_MODE_MANUAL_BY_TUTOR",11);
00047 define("LP_MODE_SCORM_PACKAGE",12);
00048 
00049 define("LP_DEFAULT_VISITS",30);
00050 
00051 
00052 class ilLPObjSettings
00053 {
00054         var $db = null;
00055 
00056         var $obj_id = null;
00057         var $obj_type = null;
00058         var $obj_mode = null;
00059         var $visits = null;
00060 
00061         var $is_stored = false;
00062 
00063         function ilLPObjSettings($a_obj_id)
00064         {
00065                 global $ilObjDataCache,$ilDB;
00066 
00067                 $this->db =& $ilDB;
00068 
00069                 $this->obj_id = $a_obj_id;
00070 
00071                 if(!$this->__read())
00072                 {
00073                         $this->obj_type = $ilObjDataCache->lookupType($this->obj_id);
00074                         $this->obj_mode = $this->__getDefaultMode($this->obj_id,$this->obj_type);
00075                 }
00076         }
00077         
00085         public function cloneSettings($a_new_obj_id)
00086         {
00087                 $query = "INSERT INTO ut_lp_settings ".
00088                         "SET obj_id = ".$this->db->quote($a_new_obj_id).", ".
00089                         "obj_type = ".$this->db->quote($this->getObjType()).", ".
00090                         "mode = ".$this->db->quote($this->getMode()).", ".
00091                         "visits = ".$this->db->quote($this->getVisits());
00092                         
00093                 $this->db->query($query);
00094                 return true;
00095         }
00096 
00097         function getVisits()
00098         {
00099                 return (int) $this->visits ? $this->visits : LP_DEFAULT_VISITS;
00100         }
00101 
00102         function setVisits($a_visits)
00103         {
00104                 $this->visits = $a_visits;
00105         }
00106 
00107         function setMode($a_mode)
00108         {
00109                 $this->obj_mode = $a_mode;
00110         }
00111         function getMode()
00112         {
00113                 return $this->obj_mode;
00114         }
00115 
00116         function getObjId()
00117         {
00118                 return (int) $this->obj_id;
00119         }
00120         function getObjType()
00121         {
00122                 return $this->obj_type;
00123         }
00124 
00125         function update()
00126         {
00127                 if(!$this->is_stored)
00128                 {
00129                         return $this->insert();
00130                 }
00131                 $query = "UPDATE ut_lp_settings SET mode = '".$this->obj_mode.
00132                         "', visits = '".$this->visits."' ".
00133                         "WHERE obj_id = '".$this->getObjId()."'";
00134                 $this->db->query($query);
00135                 $this->__read();
00136                 return true;
00137         }
00138 
00139         function insert()
00140         {
00141                 $query = "INSERT INTO ut_lp_settings SET obj_id = '".$this->obj_id."', ".
00142                         "obj_type = '".$this->obj_type."', ".
00143                         "mode = '".$this->obj_mode."'";
00144                 $this->db->query($query);
00145                 $this->__read();
00146                 return true;
00147         }
00148 
00149 
00150         // Static
00151         function _lookupVisits($a_obj_id)
00152         {
00153                 global $ilDB;
00154 
00155                 #echo $a_obj_id;
00156 
00157                 $query = "SELECT visits FROM ut_lp_settings ".
00158                         "WHERE obj_id = '".$a_obj_id."'";
00159 
00160                 $res = $ilDB->query($query);
00161                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00162                 {
00163                         return $row->visits;
00164                 }
00165                 return LP_DEFAULT_VISITS;
00166         }
00167 
00168         function _isContainer($a_mode)
00169         {
00170                 return $a_mode == LP_MODE_COLLECTION or
00171                         $a_mode == LP_MODE_SCORM or
00172                         $a_mode == LP_MODE_OBJECTIVES or
00173                         $a_mode == LP_MODE_MANUAL_BY_TUTOR;
00174         }
00175                 
00176 
00177         function _delete($a_obj_id)
00178         {
00179                 global $ilDB;
00180 
00181                 $query = "DELETE FROM ut_lp_settings WHERE obj_id = '".$a_obj_id."'";
00182                 $ilDB->query($query);
00183 
00184                 return true;
00185         }
00186 
00187         function _lookupMode($a_obj_id)
00188         {
00189                 global $ilDB,$ilObjDataCache;
00190 
00191                 if(ilLPObjSettings::_checkObjectives($a_obj_id))
00192                 {
00193                         return LP_MODE_OBJECTIVES;
00194                 }
00195                 if(ilLPObjSettings::_checkSCORMPreconditions($a_obj_id))
00196                 {
00197                         return LP_MODE_SCORM;
00198                 }
00199 
00200                 $query = "SELECT mode FROM ut_lp_settings ".
00201                         "WHERE obj_id = '".$a_obj_id."'";
00202 
00203                 $res = $ilDB->query($query);
00204                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00205                 {
00206                         return $row->mode;
00207                 }
00208                 
00209                 // no db entry exists => return default mode by type
00210                 return ilLPObjSettings::__getDefaultMode($a_obj_id,$ilObjDataCache->lookupType($a_obj_id));
00211         }
00212 
00213         function getValidModes()
00214         {
00215                 global $lng;
00216 
00217                 switch($this->obj_type)
00218                 {
00219                         case 'crs':
00220                                 if(ilLPObjSettings::_checkObjectives($this->getObjId()))
00221                                 {
00222                                         return array(LP_MODE_OBJECTIVES => $lng->txt('trac_mode_objectives'));
00223                                 }
00224 
00225                                 return array(LP_MODE_DEACTIVATED => $lng->txt('trac_mode_deactivated'),
00226                                                          LP_MODE_MANUAL_BY_TUTOR => $lng->txt('trac_mode_manual_by_tutor'),
00227                                                          LP_MODE_COLLECTION => $lng->txt('trac_mode_collection'));
00228 
00229                                 break;
00230 
00231                         case 'dbk':
00232                         case 'lm':
00233                                 return array(LP_MODE_MANUAL => $lng->txt('trac_mode_manual'),
00234                                                          LP_MODE_VISITS => $lng->txt('trac_mode_visits'),
00235                                                          LP_MODE_TLT => $lng->txt('trac_mode_tlt'),
00236                                                          LP_MODE_DEACTIVATED => $lng->txt('trac_mode_deactivated'));
00237 
00238                         case 'htlm':
00239                                 return array(LP_MODE_DEACTIVATED => $lng->txt('trac_mode_deactivated'),
00240                                                          LP_MODE_MANUAL => $lng->txt('trac_mode_manual'));
00241 
00242                         case 'sahs':
00243                                 include_once './Services/Tracking/classes/class.ilLPCollections.php';
00244                                 include_once "./Modules/ScormAicc/classes/class.ilObjSAHSLearningModule.php";
00245                                 $subtype = ilObjSAHSLearningModule::_lookupSubType($this->getObjId());
00246                                 
00247                                 if ($subtype != "scorm2004")
00248                                 {
00249                                         if(ilLPObjSettings::_checkSCORMPreconditions($this->getObjId()))
00250                                         {
00251                                                 return array(LP_MODE_SCORM => $lng->txt('trac_mode_scorm_aicc'));
00252                                         }
00253                                         if(ilLPCollections::_getCountPossibleSAHSItems($this->getObjId()))
00254                                         {
00255                                                 return array(LP_MODE_DEACTIVATED => $lng->txt('trac_mode_deactivated'),
00256                                                                          LP_MODE_SCORM => $lng->txt('trac_mode_scorm_aicc'));
00257                                         }
00258                                         return array(LP_MODE_DEACTIVATED => $lng->txt('trac_mode_deactivated'));
00259                                 }
00260                                 else
00261                                 {
00262                                         if(ilLPObjSettings::_checkSCORMPreconditions($this->getObjId()))
00263                                         {
00264                                                 return array(LP_MODE_SCORM => $lng->txt('trac_mode_scorm_aicc'),
00265                                                         LP_MODE_SCORM_PACKAGE => $lng->txt('trac_mode_scorm_package'));
00266                                         }
00267                                         if(ilLPCollections::_getCountPossibleSAHSItems($this->getObjId()))
00268                                         {
00269                                                 return array(LP_MODE_DEACTIVATED => $lng->txt('trac_mode_deactivated'),
00270                                                         LP_MODE_SCORM_PACKAGE => $lng->txt('trac_mode_scorm_package'),
00271                                                         LP_MODE_SCORM => $lng->txt('trac_mode_scorm_aicc'));
00272                                         }
00273                                         return array(LP_MODE_DEACTIVATED => $lng->txt('trac_mode_deactivated'),
00274                                                 LP_MODE_SCORM_PACKAGE => $lng->txt('trac_mode_scorm_package'));
00275                                 }
00276                                 break;
00277 
00278                         case 'tst':
00279                                 return array(LP_MODE_TEST_FINISHED => $lng->txt('trac_mode_test_finished'),
00280                                                          LP_MODE_TEST_PASSED => $lng->txt('trac_mode_test_passed'),
00281                                                          LP_MODE_DEACTIVATED => $lng->txt('trac_mode_deactivated'));
00282 
00283                         case 'exc':
00284                                 return array(LP_MODE_DEACTIVATED => $lng->txt('trac_mode_deactivated'),
00285                                                          LP_MODE_EXERCISE_RETURNED => $lng->txt('trac_mode_exercise_returned'));
00286 
00287                         case 'grp':
00288                                 return array(LP_MODE_DEACTIVATED => $lng->txt('trac_mode_deactivated'),
00289                                                          LP_MODE_MANUAL_BY_TUTOR => $lng->txt('trac_mode_manual_by_tutor'),
00290                                                          LP_MODE_COLLECTION => $lng->txt('trac_mode_collection'));
00291 
00292                         case 'fold':
00293                                 return array(LP_MODE_DEACTIVATED => $lng->txt('trac_mode_deactivated'),
00294                                                          LP_MODE_COLLECTION => $lng->txt('trac_mode_collection'));
00295 
00296                         default:
00297                                 return array();
00298                 }
00299         }
00300 
00301         function _mode2Text($a_mode)
00302         {
00303                 global $lng;
00304 
00305                 switch($a_mode)
00306                 {
00307                         case LP_MODE_DEACTIVATED:
00308                                 return $lng->txt('trac_mode_deactivated');
00309 
00310                         case LP_MODE_TLT:
00311                                 return $lng->txt('trac_mode_tlt');
00312 
00313                         case LP_MODE_VISITS:
00314                                 return $lng->txt('trac_mode_visits');
00315                                 
00316                         case LP_MODE_MANUAL:
00317                                 return $lng->txt('trac_mode_manual');
00318 
00319                         case LP_MODE_MANUAL_BY_TUTOR:
00320                                 return $lng->txt('trac_mode_manual_by_tutor');
00321 
00322                         case LP_MODE_OBJECTIVES:
00323                                 return $lng->txt('trac_mode_objectives');
00324 
00325                         case LP_MODE_COLLECTION:
00326                                 return $lng->txt('trac_mode_collection');
00327 
00328                         case LP_MODE_SCORM:
00329                                 return $lng->txt('trac_mode_scorm');
00330 
00331                         case LP_MODE_TEST_FINISHED:
00332                                 return $lng->txt('trac_mode_test_finished');
00333 
00334                         case LP_MODE_TEST_PASSED:
00335                                 return $lng->txt('trac_mode_test_passed');
00336 
00337                         case LP_MODE_EXERCISE_RETURNED:
00338                                 return $lng->txt('trac_mode_exercise_returned');
00339                         
00340                         case LP_MODE_SCORM_PACKAGE:
00341                                 return $lng->txt('trac_mode_scorm_package');
00342                                 
00343 
00344                 }
00345         }
00346         
00355         public static function _mode2InfoText($a_mode)
00356         {
00357                 global $lng;
00358                 
00359                 switch($a_mode)
00360                 {
00361                         case LP_MODE_DEACTIVATED:
00362                                 return $lng->txt('trac_mode_deactivated_info');
00363 
00364                         case LP_MODE_TLT:
00365                                 return $lng->txt('trac_mode_tlt_info');
00366 
00367                         case LP_MODE_VISITS:
00368                                 return $lng->txt('trac_mode_visits_info');
00369                                 
00370                         case LP_MODE_MANUAL:
00371                                 return $lng->txt('trac_mode_manual_info');
00372                                 
00373                         case LP_MODE_MANUAL_BY_TUTOR:
00374                                 return $lng->txt('trac_mode_manual_by_tutor_info');
00375 
00376                         case LP_MODE_OBJECTIVES:
00377                                 return $lng->txt('trac_mode_objectives_info');
00378 
00379                         case LP_MODE_COLLECTION:
00380                                 return $lng->txt('trac_mode_collection_info');
00381 
00382                         case LP_MODE_SCORM:
00383                                 return $lng->txt('trac_mode_scorm_info');
00384 
00385                         case LP_MODE_TEST_FINISHED:
00386                                 return $lng->txt('trac_mode_test_finished_info');
00387 
00388                         case LP_MODE_TEST_PASSED:
00389                                 return $lng->txt('trac_mode_test_passed_info');
00390 
00391                         case LP_MODE_EXERCISE_RETURNED:
00392                                 return $lng->txt('trac_mode_exercise_returned_info');
00393 
00394                         case LP_MODE_SCORM_PACKAGE:
00395                                 return $lng->txt('trac_mode_scorm_package_info');
00396                 }
00397                 
00398         }
00399                                                          
00400                                 
00401 
00402 
00403         // Private
00404         function _checkObjectives($a_obj_id)
00405         {
00406                 global $ilDB,$ilObjDataCache;
00407 
00408                 // Return deactivate for course with objective view
00409                 if($ilObjDataCache->lookupType($a_obj_id) == 'crs')
00410                 {
00411                         include_once 'Modules/Course/classes/class.ilObjCourse.php';
00412 
00413                         if(ilObjCourse::_lookupViewMode($a_obj_id) == IL_CRS_VIEW_OBJECTIVE)
00414                         {
00415                                 return true;
00416                         }
00417                 }
00418                 return false;
00419         }
00420         
00421         function _checkSCORMPreconditions($a_obj_id)
00422         {
00423                 global $ilObjDataCache;
00424                 
00425                 if($ilObjDataCache->lookupType($a_obj_id) != 'sahs')
00426                 {
00427                         return false;
00428                 }
00429                 include_once('classes/class.ilConditionHandler.php');
00430                 if(count($conditions = ilConditionHandler::_getConditionsOfTrigger('sahs',$a_obj_id)))
00431                 {
00432                         return true;
00433                 }
00434                 return false;
00435         }
00436                 
00437 
00438 
00439         function __read()
00440         {
00441                 $res = $this->db->query("SELECT * FROM ut_lp_settings WHERE obj_id = ".$this->db->quote($this->obj_id)." ");
00442                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00443                 {
00444                         $this->is_stored = true;
00445                         $this->obj_type = $row->obj_type;
00446                         $this->obj_mode = $row->mode;
00447                         $this->visits = $row->visits;
00448 
00449                         if(ilLPObjSettings::_checkObjectives($this->obj_id))
00450                         {
00451                                 $this->obj_mode = LP_MODE_OBJECTIVES;
00452                         }
00453                         if(ilLPObjSettings::_checkSCORMPreconditions($this->obj_id))
00454                         {
00455                                 $this->obj_mode = LP_MODE_SCORM;
00456                         }
00457 
00458                         return true;
00459                 }
00460 
00461                 return false;
00462         }
00463 
00464         function __getDefaultMode($a_obj_id,$a_type)
00465         {
00466                 global $ilDB;
00467 
00468                 #$type = strlen($a_type) ? $a_type : $this->obj_type;
00469 
00470                 switch($a_type)
00471                 {
00472                         case 'crs':
00473                                 // If objectives are enabled return deactivated
00474                                 if(ilLPObjSettings::_checkObjectives($a_obj_id))
00475                                 {
00476                                         return LP_MODE_OBJECTIVES;
00477                                 }
00478                                 return LP_MODE_MANUAL_BY_TUTOR;
00479 
00480                         case 'dbk':
00481                         case 'lm':
00482                         case 'htlm':
00483                                 return LP_MODE_MANUAL;
00484 
00485                         case 'sahs':
00486                                 return LP_MODE_DEACTIVATED;
00487 
00488                         case 'dbk':
00489                                 return LP_MODE_MANUAL;
00490 
00491                         case 'tst':
00492                                 return LP_MODE_TEST_PASSED;
00493 
00494                         case 'exc':
00495                                 return LP_MODE_EXERCISE_RETURNED;
00496 
00497                         case 'grp':
00498                                 return LP_MODE_DEACTIVATED;
00499 
00500                         case 'fold':
00501                                 return LP_MODE_DEACTIVATED;
00502                                         
00503                         default:
00504                                 return LP_MODE_UNDEFINED;
00505                 }
00506         }
00507 }
00508 ?>

Generated on Fri Dec 13 2013 17:57:01 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1