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

Services/Tracking/classes/class.ilLearningProgress.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 
00036 class ilLearningProgress
00037 {
00038         var $db = null;
00039 
00040         function ilLearningProgress()
00041         {
00042                 global $ilDB;
00043                 
00044                 $this->db = $ilDB;
00045         }
00046 
00047         // Static
00048         function _tracProgress($a_user_id,$a_obj_id, $a_obj_type = '')
00049         {
00050                 global $ilDB,$ilObjDataCache;
00051 
00052                 if(!strlen($a_obj_type))
00053                 {
00054                         $a_obj_type = $ilObjDataCache->lookupType($a_obj_id);
00055                 }
00056 
00057                 if($progress = ilLearningProgress::_getProgress($a_user_id,$a_obj_id))
00058                 {
00059                         ilLearningProgress::_updateProgress($progress);
00060                         return true;
00061                 }
00062                 $query = "INSERT INTO ut_learning_progress ".
00063                         "SET user_id = '".$a_user_id."', ".
00064                         "obj_type = '".$a_obj_type."', ".
00065                         "obj_id = '".$a_obj_id."', ".
00066                         "spent_time = '0',".
00067                         "access_time = '".time()."', ".
00068                         "visits = '1'";
00069 
00070                 $ilDB->query($query);
00071                 return true;
00072         }
00073 
00074         function _getProgress($a_user_id,$a_obj_id)
00075         {
00076                 global $ilDB;
00077 
00078                 $query = "SELECT * FROM ut_learning_progress ".
00079                         "WHERE user_id = '".$a_user_id."' ".
00080                         "AND obj_id = '".$a_obj_id."'";
00081                 $res = $ilDB->query($query);
00082 
00083                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00084                 {
00085                         $progress['lp_id'] = $row->lp_id;
00086                         $progress['obj_id'] = $row->obj_id;
00087                         $progress['obj_type'] = $row->obj_type;
00088                         $progress['user_id'] = $row->user_id;
00089                         $progress['spent_time'] = $row->spent_time;
00090                         $progress['access_time'] = $row->access_time;
00091                         $progress['visits'] = $row->visits;
00092                 }
00093                 return $progress ? $progress : array();
00094         }
00095 
00096         function _updateProgress($data)
00097         {
00098                 global $ilDB;
00099 
00100                 $spent = $data['spent_time'];
00101                 
00102                 include_once('Services/Tracking/classes/class.ilObjUserTracking.php');
00103                 if((time() - $data['access_time']) <= ilObjUserTracking::_getValidTimeSpan())
00104                 {
00105                         $spent = $data['spent_time'] + time() - $data['access_time'];
00106                 }
00107                 $visits = $data['visits'] + 1;
00108                 
00109                 $query = "UPDATE ut_learning_progress ".
00110                         "SET visits = visits + 1, ".
00111                         "spent_time = '".$spent."', ".
00112                         "access_time = '".time()."' ". 
00113                         "WHERE lp_id = '".$data['lp_id']."'";
00114 
00115                 $ilDB->query($query);
00116         }
00117 }
00118 ?>

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