ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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
40
46 public function __construct($crs_id,$user_id)
47 {
48 global $ilDB;
49
50 $this->db =& $ilDB;
51
52 $this->course_id = $crs_id;
53 $this->user_id = $user_id;
54 }
55
56 function getUserId()
57 {
58 return $this->user_id;
59 }
60 function getCourseRefId()
61 {
62 return $this->course_id;
63 }
64
65 static function _updateLastAccess($a_user_id,$a_lm_ref_id,$a_page_id)
66 {
67 global $tree,$ilDB;
68
69 if(!$crs_ref_id = $tree->checkForParentType($a_lm_ref_id,'crs'))
70 {
71 return true;
72 }
73
74 // Delete old entries
75 $query = "DELETE FROM crs_lm_history ".
76 "WHERE lm_ref_id = ".$ilDB->quote($a_lm_ref_id,'integer')." ".
77 "AND usr_id = ".$ilDB->quote($a_user_id,'integer')."";
78 $res = $ilDB->manipulate($query);
79
80 // Add new entry
81 $fields = array("usr_id" => array("integer", $a_user_id),
82 "crs_ref_id" => array("integer", $crs_ref_id),
83 "lm_ref_id" => array("integer", $a_lm_ref_id),
84 "lm_page_id" => array("integer", $a_page_id),
85 "last_access" => array("integer", time()));
86 $ilDB->insert("crs_lm_history", $fields);
87 return true;
88 }
89
90 function getLastLM()
91 {
92 global $ilDB;
93
94 $query = "SELECT * FROM crs_lm_history ".
95 "WHERE usr_id = ".$ilDB->quote($this->getUserId(),'integer')." ".
96 "AND crs_ref_id = ".$ilDB->quote($this->getCourseRefId(),'integer')." ".
97 "ORDER BY last_access ";
98
99 $res = $this->db->query($query);
100 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
101 {
102 return $row->lm_ref_id;
103 }
104 return false;
105 }
106
107 function getLMHistory()
108 {
109 global $ilDB;
110
111 $query = "SELECT * FROM crs_lm_history ".
112 "WHERE usr_id = ".$ilDB->quote($this->getUserId(),'integer')." ".
113 "AND crs_ref_id = ".$ilDB->quote($this->getCourseRefId(),'integer')."";
114
115 $res = $this->db->query($query);
116 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
117 {
118 $lm[$row->lm_ref_id]['lm_ref_id'] = $row->lm_ref_id;
119 $lm[$row->lm_ref_id]['lm_page_id'] = $row->lm_page_id;
120 $lm[$row->lm_ref_id]['last_access'] = $row->last_access;
121 }
122 return $lm ? $lm : array();
123 }
124
131 public static function _deleteUser($a_usr_id)
132 {
133 global $ilDB;
134
135 $query = "DELETE FROM crs_lm_history WHERE usr_id = ".$ilDB->quote($a_usr_id,'integer')." ";
136 $res = $ilDB->manipulate($query);
137
138 return true;
139 }
140
141}
142?>
An exception for terminatinating execution or to throw for unit testing.
class ilCourseLMHistory
static _updateLastAccess($a_user_id, $a_lm_ref_id, $a_page_id)
static _deleteUser($a_usr_id)
Delete user @global type $ilDB.
__construct($crs_id, $user_id)
Constructor.
global $ilDB