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

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