ILIAS  release_7 Revision v7.30-3-g800a261c036
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 $DIC;
49
50 $ilDB = $DIC['ilDB'];
51
52 $this->db = &$ilDB;
53
54 $this->course_id = $crs_id;
55 $this->user_id = $user_id;
56 }
57
58 public function getUserId()
59 {
60 return $this->user_id;
61 }
62 public function getCourseRefId()
63 {
64 return $this->course_id;
65 }
66
67 public static function _updateLastAccess($a_user_id, $a_lm_ref_id, $a_page_id)
68 {
69 global $DIC;
70
71 $tree = $DIC['tree'];
72 $ilDB = $DIC['ilDB'];
73
74 if (!$crs_ref_id = $tree->checkForParentType($a_lm_ref_id, 'crs')) {
75 return true;
76 }
77
78 $ilDB->replace("crs_lm_history", [
79 "crs_ref_id" => ["integer", $crs_ref_id],
80 "lm_ref_id" => ["integer", $a_lm_ref_id],
81 "usr_id" => ["integer", $a_user_id]
82 ], [
83 "lm_page_id" => ["integer", $a_page_id],
84 "last_access" => ["integer", time()]
85 ]
86 );
87
88 return true;
89 }
90
91 public function getLastLM()
92 {
93 global $DIC;
94
95 $ilDB = $DIC['ilDB'];
96
97 $query = "SELECT * FROM crs_lm_history " .
98 "WHERE usr_id = " . $ilDB->quote($this->getUserId(), 'integer') . " " .
99 "AND crs_ref_id = " . $ilDB->quote($this->getCourseRefId(), 'integer') . " " .
100 "ORDER BY last_access ";
101
102 $res = $this->db->query($query);
103 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
104 return $row->lm_ref_id;
105 }
106 return false;
107 }
108
109 public function getLMHistory()
110 {
111 global $DIC;
112
113 $ilDB = $DIC['ilDB'];
114
115 $query = "SELECT * FROM crs_lm_history " .
116 "WHERE usr_id = " . $ilDB->quote($this->getUserId(), 'integer') . " " .
117 "AND crs_ref_id = " . $ilDB->quote($this->getCourseRefId(), 'integer') . "";
118
119 $res = $this->db->query($query);
120 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
121 $lm[$row->lm_ref_id]['lm_ref_id'] = $row->lm_ref_id;
122 $lm[$row->lm_ref_id]['lm_page_id'] = $row->lm_page_id;
123 $lm[$row->lm_ref_id]['last_access'] = $row->last_access;
124 }
125 return $lm ? $lm : array();
126 }
127
134 public static function _deleteUser($a_usr_id)
135 {
136 global $DIC;
137
138 $ilDB = $DIC['ilDB'];
139
140 $query = "DELETE FROM crs_lm_history WHERE usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " ";
141 $res = $ilDB->manipulate($query);
142
143 return true;
144 }
145}
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 $DIC
Definition: goto.php:24
$query
foreach($_POST as $key=> $value) $res
global $ilDB