ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilCourseLMHistory.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 
35 {
36  var $db;
37 
39  var $user_id;
40 
41  function ilCourseLMHistory($crs_id,$user_id)
42  {
43  global $ilDB;
44 
45  $this->db =& $ilDB;
46 
47  $this->course_id = $crs_id;
48  $this->user_id = $user_id;
49  }
50 
51  function getUserId()
52  {
53  return $this->user_id;
54  }
55  function getCourseRefId()
56  {
57  return $this->course_id;
58  }
59 
60  function _updateLastAccess($a_user_id,$a_lm_ref_id,$a_page_id)
61  {
62  global $tree,$ilDB;
63 
64  if(!$crs_ref_id = $tree->checkForParentType($a_lm_ref_id,'crs'))
65  {
66  return true;
67  }
68 
69  // Delete old entries
70  $query = "DELETE FROM crs_lm_history ".
71  "WHERE lm_ref_id = ".$ilDB->quote($a_lm_ref_id,'integer')." ".
72  "AND usr_id = ".$ilDB->quote($a_user_id,'integer')."";
73  $res = $ilDB->manipulate($query);
74 
75  // Add new entry
76  $fields = array("usr_id" => array("integer", $a_user_id),
77  "crs_ref_id" => array("integer", $crs_ref_id),
78  "lm_ref_id" => array("integer", $a_lm_ref_id),
79  "lm_page_id" => array("integer", $a_page_id),
80  "last_access" => array("integer", time()));
81  $ilDB->insert("crs_lm_history", $fields);
82  return true;
83  }
84 
85  function getLastLM()
86  {
87  global $ilDB;
88 
89  $query = "SELECT * FROM crs_lm_history ".
90  "WHERE usr_id = ".$ilDB->quote($this->getUserId(),'integer')." ".
91  "AND crs_ref_id = ".$ilDB->quote($this->getCourseRefId(),'integer')." ".
92  "ORDER BY last_access ";
93 
94  $res = $this->db->query($query);
95  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
96  {
97  return $row->lm_ref_id;
98  }
99  return false;
100  }
101 
102  function getLMHistory()
103  {
104  global $ilDB;
105 
106  $query = "SELECT * FROM crs_lm_history ".
107  "WHERE usr_id = ".$ilDB->quote($this->getUserId(),'integer')." ".
108  "AND crs_ref_id = ".$ilDB->quote($this->getCourseRefId(),'integer')."";
109 
110  $res = $this->db->query($query);
111  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
112  {
113  $lm[$row->lm_ref_id]['lm_ref_id'] = $row->lm_ref_id;
114  $lm[$row->lm_ref_id]['lm_page_id'] = $row->lm_page_id;
115  $lm[$row->lm_ref_id]['last_access'] = $row->last_access;
116  }
117  return $lm ? $lm : array();
118  }
119 
120  function _deleteUser($a_usr_id)
121  {
122  global $ilDB;
123 
124  $query = "DELETE FROM crs_lm_history WHERE usr_id = ".$ilDB->quote($a_usr_id,'integer')." ";
125  $res = $ilDB->manipulate($query);
126 
127  return true;
128  }
129 
130 }
131 ?>