ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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  var $db = null;
39 
40  var $obj_id = null;
41  var $usr_id = null;
42  var $obj_type = null;
43 
44  var $completed = false;
45  var $comment = '';
46  var $mark = '';
47  var $status_changed = '';
48 
49  var $has_entry = false;
50 
51 
52 
53  function ilLPMarks($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  function getUserId()
82  {
83  return $this->usr_id;
84  }
85 
86  function setMark($a_mark)
87  {
88  $this->mark = $a_mark;
89  }
90  function getMark()
91  {
92  return $this->mark;
93  }
94  function setComment($a_comment)
95  {
96  $this->comment = $a_comment;
97  }
98  function getComment()
99  {
100  return $this->comment;
101  }
102  function setCompleted($a_status)
103  {
104  $this->completed = (bool) $a_status;
105  }
106  function getCompleted()
107  {
108  return $this->completed;
109  }
110  function getStatusChanged()
111  {
112  return $this->status_changed;
113  }
114 
115  function getObjId()
116  {
117  return (int) $this->obj_id;
118  }
119 
120  function update()
121  {
122  global $ilDB;
123 
124  if(!$this->has_entry)
125  {
126  $this->__add();
127  }
128  $query = "UPDATE ut_lp_marks ".
129  "SET mark = ".$ilDB->quote($this->getMark(), 'text').", ".
130  "u_comment = ".$ilDB->quote($this->getComment() ,'text').", ".
131  "completed = ".$ilDB->quote($this->getCompleted() ,'integer')." ".
132  "WHERE obj_id = ".$ilDB->quote($this->getObjId() ,'integer')." ".
133  "AND usr_id = ".$ilDB->quote($this->getUserId(), 'integer');
134  $res = $ilDB->manipulate($query);
135  return true;
136  }
137 
138  // Static
139  function _hasCompleted($a_usr_id,$a_obj_id)
140  {
141  global $ilDB;
142 
143  $query = "SELECT * FROM ut_lp_marks ".
144  "WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ".
145  "AND obj_id = ".$ilDB->quote($a_obj_id ,'integer');
146 
147  $res = $ilDB->query($query);
148  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
149  {
150  return (bool) $row->completed;
151  }
152  return false;
153  }
154 
155  function _lookupMark($a_usr_id,$a_obj_id)
156  {
157  global $ilDB;
158 
159  $query = "SELECT * FROM ut_lp_marks ".
160  "WHERE usr_id = ".$ilDB->quote($a_usr_id, 'integer')." ".
161  "AND obj_id = ".$ilDB->quote($a_obj_id ,'integer');
162 
163  $res = $ilDB->query($query);
164  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
165  {
166  return $row->mark;
167  }
168  return '';
169  }
170 
171 
172  function _lookupComment($a_usr_id,$a_obj_id)
173  {
174  global $ilDB;
175 
176  $query = "SELECT * FROM ut_lp_marks ".
177  "WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ".
178  "AND obj_id = ".$ilDB->quote($a_obj_id ,'integer');
179 
180  $res = $ilDB->query($query);
181  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
182  {
183  return $row->u_comment;
184  }
185  return '';
186  }
187 
188  // Private
189  function __read()
190  {
191  global $ilDB;
192 
193  $res = $this->db->query("SELECT * FROM ut_lp_marks ".
194  "WHERE obj_id = ".$this->db->quote($this->obj_id ,'integer')." ".
195  "AND usr_id = ".$ilDB->quote($this->usr_id ,'integer'));
196  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
197  {
198  $this->has_entry = true;
199  $this->completed = (int) $row->completed;
200  $this->comment = $row->u_comment;
201  $this->mark = $row->mark;
202  $this->status_changed = $row->status_changed;
203 
204  return true;
205  }
206 
207  return false;
208  }
209 
210  function __add()
211  {
212  global $ilDB;
213 
214  $query = "INSERT INTO ut_lp_marks (mark,u_comment, completed,obj_id,usr_id) ".
215  "VALUES( ".
216  $ilDB->quote($this->getMark(),'text').", ".
217  $ilDB->quote($this->getComment() ,'text').", ".
218  $ilDB->quote($this->getCompleted() ,'integer').", ".
219  $ilDB->quote($this->getObjId() ,'integer').", ".
220  $ilDB->quote($this->getUserId() ,'integer')." ".
221  ")";
222  $res = $ilDB->manipulate($query);
223  $this->has_entry = true;
224 
225  return true;
226  }
227 
228  public static function _deleteForUsers($a_obj_id, array $a_user_ids)
229  {
230  global $ilDB;
231 
232  $ilDB->manipulate("DELETE FROM ut_lp_marks".
233  " WHERE obj_id = ".$ilDB->quote($a_obj_id, "integer").
234  " AND ".$ilDB->in("usr_id", $a_user_ids, "", "integer"));
235  }
236 
237  public static function _getAllUserIds($a_obj_id)
238  {
239  global $ilDB;
240 
241  $res = array();
242 
243  $set = $ilDB->query("SELECT usr_id FROM ut_lp_marks".
244  " WHERE obj_id = ".$ilDB->quote($a_obj_id, "integer"));
245  while($row = $ilDB->fetchAssoc($set))
246  {
247  $res[] = $row["usr_id"];
248  }
249 
250  return $res;
251  }
252 }
253 
254 ?>