ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 public $db;
37
38 public $course_id;
39 public $user_id;
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 public function getUserId()
57 {
58 return $this->user_id;
59 }
60 public function getCourseRefId()
61 {
62 return $this->course_id;
63 }
64
65 public 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 return true;
71 }
72
73 // Delete old entries
74 $query = "DELETE FROM crs_lm_history " .
75 "WHERE lm_ref_id = " . $ilDB->quote($a_lm_ref_id, 'integer') . " " .
76 "AND usr_id = " . $ilDB->quote($a_user_id, 'integer') . "";
77 $res = $ilDB->manipulate($query);
78
79 // Add new entry
80 $fields = array("usr_id" => array("integer", $a_user_id),
81 "crs_ref_id" => array("integer", $crs_ref_id),
82 "lm_ref_id" => array("integer", $a_lm_ref_id),
83 "lm_page_id" => array("integer", $a_page_id),
84 "last_access" => array("integer", time()));
85 $ilDB->insert("crs_lm_history", $fields);
86 return true;
87 }
88
89 public function getLastLM()
90 {
91 global $ilDB;
92
93 $query = "SELECT * FROM crs_lm_history " .
94 "WHERE usr_id = " . $ilDB->quote($this->getUserId(), 'integer') . " " .
95 "AND crs_ref_id = " . $ilDB->quote($this->getCourseRefId(), 'integer') . " " .
96 "ORDER BY last_access ";
97
98 $res = $this->db->query($query);
99 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
100 return $row->lm_ref_id;
101 }
102 return false;
103 }
104
105 public function getLMHistory()
106 {
107 global $ilDB;
108
109 $query = "SELECT * FROM crs_lm_history " .
110 "WHERE usr_id = " . $ilDB->quote($this->getUserId(), 'integer') . " " .
111 "AND crs_ref_id = " . $ilDB->quote($this->getCourseRefId(), 'integer') . "";
112
113 $res = $this->db->query($query);
114 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
115 $lm[$row->lm_ref_id]['lm_ref_id'] = $row->lm_ref_id;
116 $lm[$row->lm_ref_id]['lm_page_id'] = $row->lm_page_id;
117 $lm[$row->lm_ref_id]['last_access'] = $row->last_access;
118 }
119 return $lm ? $lm : array();
120 }
121
128 public static function _deleteUser($a_usr_id)
129 {
130 global $ilDB;
131
132 $query = "DELETE FROM crs_lm_history WHERE usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " ";
133 $res = $ilDB->manipulate($query);
134
135 return true;
136 }
137}
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.
$query
foreach($_POST as $key=> $value) $res
global $ilDB