ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilLPMarks.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 
36 class ilLPMarks
37 {
38  public $db = null;
39 
40  public $obj_id = null;
41  public $usr_id = null;
42  public $obj_type = null;
43 
44  public $completed = false;
45  public $comment = '';
46  public $mark = '';
47  public $status_changed = '';
48 
49  public $has_entry = false;
50 
51 
52 
53  public function __construct($a_obj_id, $a_usr_id)
54  {
55  global $DIC;
56 
57  $ilObjDataCache = $DIC['ilObjDataCache'];
58  $ilDB = $DIC['ilDB'];
59 
60  $this->db = $ilDB;
61 
62  $this->obj_id = $a_obj_id;
63  $this->usr_id = $a_usr_id;
64  $this->obj_type = $ilObjDataCache->lookupType($this->obj_id);
65 
66  $this->__read();
67  }
68 
74  public static function deleteObject($a_obj_id)
75  {
76  global $DIC;
77 
78  $ilDB = $DIC['ilDB'];
79 
80  $query = "DELETE FROM ut_lp_marks " .
81  "WHERE obj_id = " . $ilDB->quote($a_obj_id, 'integer');
82  $res = $ilDB->manipulate($query);
83  return true;
84  }
85 
86  public function getUserId()
87  {
88  return $this->usr_id;
89  }
90 
91  public function setMark($a_mark)
92  {
93  $this->mark = $a_mark;
94  }
95  public function getMark()
96  {
97  return $this->mark;
98  }
99  public function setComment($a_comment)
100  {
101  $this->comment = $a_comment;
102  }
103  public function getComment()
104  {
105  return $this->comment;
106  }
107  public function setCompleted($a_status)
108  {
109  $this->completed = (bool) $a_status;
110  }
111  public function getCompleted()
112  {
113  return $this->completed;
114  }
115  public function getStatusChanged()
116  {
117  return $this->status_changed;
118  }
119 
120  public function getObjId()
121  {
122  return (int) $this->obj_id;
123  }
124 
125  public function update()
126  {
127  global $DIC;
128 
129  $ilDB = $DIC['ilDB'];
130 
131  if (!$this->has_entry) {
132  $this->__add();
133  }
134  $query = "UPDATE ut_lp_marks " .
135  "SET mark = " . $ilDB->quote($this->getMark(), 'text') . ", " .
136  "u_comment = " . $ilDB->quote($this->getComment(), 'text') . ", " .
137  "completed = " . $ilDB->quote($this->getCompleted(), 'integer') . " " .
138  "WHERE obj_id = " . $ilDB->quote($this->getObjId(), 'integer') . " " .
139  "AND usr_id = " . $ilDB->quote($this->getUserId(), 'integer');
140  $res = $ilDB->manipulate($query);
141  return true;
142  }
143 
144  // Static
145  public static function _hasCompleted($a_usr_id, $a_obj_id)
146  {
147  global $DIC;
148 
149  $ilDB = $DIC['ilDB'];
150 
151  $query = "SELECT * FROM ut_lp_marks " .
152  "WHERE usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " " .
153  "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer');
154 
155  $res = $ilDB->query($query);
156  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
157  return (bool) $row->completed;
158  }
159  return false;
160  }
161 
169  public static function getCompletionsOfUser($user_id, $from, $to)
170  {
171  global $DIC;
172 
173  $ilDB = $DIC['ilDB'];
174 
175  $query = "SELECT * FROM ut_lp_marks " .
176  "WHERE usr_id = " . $ilDB->quote($user_id, 'integer') .
177  " AND status = " . $ilDB->quote(ilLPStatus::LP_STATUS_COMPLETED_NUM, 'integer') .
178  " AND status_changed >= " . $ilDB->quote($from, "timestamp") .
179  " AND status_changed <= " . $ilDB->quote($to, "timestamp");
180 
181  $set = $ilDB->query($query);
182  $completions = array();
183  while ($rec = $ilDB->fetchAssoc($set)) {
184  $completions[] = $rec;
185  }
186 
187  return $completions;
188  }
189 
190 
191  public static function _lookupMark($a_usr_id, $a_obj_id)
192  {
193  global $DIC;
194 
195  $ilDB = $DIC['ilDB'];
196 
197  $query = "SELECT * FROM ut_lp_marks " .
198  "WHERE usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " " .
199  "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer');
200 
201  $res = $ilDB->query($query);
202  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
203  return $row->mark;
204  }
205  return '';
206  }
207 
208 
209  public static function _lookupComment($a_usr_id, $a_obj_id)
210  {
211  global $DIC;
212 
213  $ilDB = $DIC['ilDB'];
214 
215  $query = "SELECT * FROM ut_lp_marks " .
216  "WHERE usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " " .
217  "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer');
218 
219  $res = $ilDB->query($query);
220  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
221  return $row->u_comment;
222  }
223  return '';
224  }
225 
226  // Private
227  public function __read()
228  {
229  global $DIC;
230 
231  $ilDB = $DIC['ilDB'];
232 
233  $res = $this->db->query("SELECT * FROM ut_lp_marks " .
234  "WHERE obj_id = " . $this->db->quote($this->obj_id, 'integer') . " " .
235  "AND usr_id = " . $ilDB->quote($this->usr_id, 'integer'));
236  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
237  $this->has_entry = true;
238  $this->completed = (int) $row->completed;
239  $this->comment = $row->u_comment;
240  $this->mark = $row->mark;
241  $this->status_changed = $row->status_changed;
242 
243  return true;
244  }
245 
246  return false;
247  }
248 
249  public function __add()
250  {
251  global $DIC;
252 
253  $ilDB = $DIC['ilDB'];
254 
255  $query = "INSERT INTO ut_lp_marks (mark,u_comment, completed,obj_id,usr_id) " .
256  "VALUES( " .
257  $ilDB->quote($this->getMark(), 'text') . ", " .
258  $ilDB->quote($this->getComment(), 'text') . ", " .
259  $ilDB->quote($this->getCompleted(), 'integer') . ", " .
260  $ilDB->quote($this->getObjId(), 'integer') . ", " .
261  $ilDB->quote($this->getUserId(), 'integer') . " " .
262  ")";
263  $res = $ilDB->manipulate($query);
264  $this->has_entry = true;
265 
266  return true;
267  }
268 
269  public static function _deleteForUsers($a_obj_id, array $a_user_ids)
270  {
271  global $DIC;
272 
273  $ilDB = $DIC['ilDB'];
274 
275  $ilDB->manipulate("DELETE FROM ut_lp_marks" .
276  " WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer") .
277  " AND " . $ilDB->in("usr_id", $a_user_ids, "", "integer"));
278  }
279 
280  public static function _getAllUserIds($a_obj_id)
281  {
282  global $DIC;
283 
284  $ilDB = $DIC['ilDB'];
285 
286  $res = array();
287 
288  $set = $ilDB->query("SELECT usr_id FROM ut_lp_marks" .
289  " WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer"));
290  while ($row = $ilDB->fetchAssoc($set)) {
291  $res[] = $row["usr_id"];
292  }
293 
294  return $res;
295  }
296 }
const LP_STATUS_COMPLETED_NUM
static _hasCompleted($a_usr_id, $a_obj_id)
setMark($a_mark)
global $DIC
Definition: saml.php:7
$from
static _getAllUserIds($a_obj_id)
foreach($_POST as $key=> $value) $res
comment()
Definition: comment.php:2
static _deleteForUsers($a_obj_id, array $a_user_ids)
$query
$row
static getCompletionsOfUser($user_id, $from, $to)
Get completions of user.
static deleteObject($a_obj_id)
Delete object.
__construct($a_obj_id, $a_usr_id)
global $ilDB
setComment($a_comment)
static _lookupMark($a_usr_id, $a_obj_id)
static _lookupComment($a_usr_id, $a_obj_id)
setCompleted($a_status)