ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 $ilObjDataCache,$ilDB;
56 
57  $this->db = $ilDB;
58 
59  $this->obj_id = $a_obj_id;
60  $this->usr_id = $a_usr_id;
61  $this->obj_type = $ilObjDataCache->lookupType($this->obj_id);
62 
63  $this->__read();
64  }
65 
71  public static function deleteObject($a_obj_id)
72  {
73  global $ilDB;
74 
75  $query = "DELETE FROM ut_lp_marks " .
76  "WHERE obj_id = " . $ilDB->quote($a_obj_id, 'integer');
77  $res = $ilDB->manipulate($query);
78  return true;
79  }
80 
81  public function getUserId()
82  {
83  return $this->usr_id;
84  }
85 
86  public function setMark($a_mark)
87  {
88  $this->mark = $a_mark;
89  }
90  public function getMark()
91  {
92  return $this->mark;
93  }
94  public function setComment($a_comment)
95  {
96  $this->comment = $a_comment;
97  }
98  public function getComment()
99  {
100  return $this->comment;
101  }
102  public function setCompleted($a_status)
103  {
104  $this->completed = (bool) $a_status;
105  }
106  public function getCompleted()
107  {
108  return $this->completed;
109  }
110  public function getStatusChanged()
111  {
112  return $this->status_changed;
113  }
114 
115  public function getObjId()
116  {
117  return (int) $this->obj_id;
118  }
119 
120  public function update()
121  {
122  global $ilDB;
123 
124  if (!$this->has_entry) {
125  $this->__add();
126  }
127  $query = "UPDATE ut_lp_marks " .
128  "SET mark = " . $ilDB->quote($this->getMark(), 'text') . ", " .
129  "u_comment = " . $ilDB->quote($this->getComment(), 'text') . ", " .
130  "completed = " . $ilDB->quote($this->getCompleted(), 'integer') . " " .
131  "WHERE obj_id = " . $ilDB->quote($this->getObjId(), 'integer') . " " .
132  "AND usr_id = " . $ilDB->quote($this->getUserId(), 'integer');
133  $res = $ilDB->manipulate($query);
134  return true;
135  }
136 
137  // Static
138  public static function _hasCompleted($a_usr_id, $a_obj_id)
139  {
140  global $ilDB;
141 
142  $query = "SELECT * FROM ut_lp_marks " .
143  "WHERE usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " " .
144  "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer');
145 
146  $res = $ilDB->query($query);
147  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
148  return (bool) $row->completed;
149  }
150  return false;
151  }
152 
153  public static function _lookupMark($a_usr_id, $a_obj_id)
154  {
155  global $ilDB;
156 
157  $query = "SELECT * FROM ut_lp_marks " .
158  "WHERE usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " " .
159  "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer');
160 
161  $res = $ilDB->query($query);
162  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
163  return $row->mark;
164  }
165  return '';
166  }
167 
168 
169  public static function _lookupComment($a_usr_id, $a_obj_id)
170  {
171  global $ilDB;
172 
173  $query = "SELECT * FROM ut_lp_marks " .
174  "WHERE usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " " .
175  "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer');
176 
177  $res = $ilDB->query($query);
178  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
179  return $row->u_comment;
180  }
181  return '';
182  }
183 
184  // Private
185  public function __read()
186  {
187  global $ilDB;
188 
189  $res = $this->db->query("SELECT * FROM ut_lp_marks " .
190  "WHERE obj_id = " . $this->db->quote($this->obj_id, 'integer') . " " .
191  "AND usr_id = " . $ilDB->quote($this->usr_id, 'integer'));
192  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
193  $this->has_entry = true;
194  $this->completed = (int) $row->completed;
195  $this->comment = $row->u_comment;
196  $this->mark = $row->mark;
197  $this->status_changed = $row->status_changed;
198 
199  return true;
200  }
201 
202  return false;
203  }
204 
205  public function __add()
206  {
207  global $ilDB;
208 
209  $query = "INSERT INTO ut_lp_marks (mark,u_comment, completed,obj_id,usr_id) " .
210  "VALUES( " .
211  $ilDB->quote($this->getMark(), 'text') . ", " .
212  $ilDB->quote($this->getComment(), 'text') . ", " .
213  $ilDB->quote($this->getCompleted(), 'integer') . ", " .
214  $ilDB->quote($this->getObjId(), 'integer') . ", " .
215  $ilDB->quote($this->getUserId(), 'integer') . " " .
216  ")";
217  $res = $ilDB->manipulate($query);
218  $this->has_entry = true;
219 
220  return true;
221  }
222 
223  public static function _deleteForUsers($a_obj_id, array $a_user_ids)
224  {
225  global $ilDB;
226 
227  $ilDB->manipulate("DELETE FROM ut_lp_marks" .
228  " WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer") .
229  " AND " . $ilDB->in("usr_id", $a_user_ids, "", "integer"));
230  }
231 
232  public static function _getAllUserIds($a_obj_id)
233  {
234  global $ilDB;
235 
236  $res = array();
237 
238  $set = $ilDB->query("SELECT usr_id FROM ut_lp_marks" .
239  " WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer"));
240  while ($row = $ilDB->fetchAssoc($set)) {
241  $res[] = $row["usr_id"];
242  }
243 
244  return $res;
245  }
246 }
static _hasCompleted($a_usr_id, $a_obj_id)
setMark($a_mark)
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
Create styles array
The data for the language used.
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)