ILIAS  Release_4_0_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 
48  var $has_entry = false;
49 
50 
51 
52  function ilLPMarks($a_obj_id,$a_usr_id)
53  {
54  global $ilObjDataCache,$ilDB;
55 
56  $this->db =& $ilDB;
57 
58  $this->obj_id = $a_obj_id;
59  $this->usr_id = $a_usr_id;
60  $this->obj_type = $ilObjDataCache->lookupType($this->obj_id);
61 
62  $this->__read();
63  }
64 
70  public static function deleteObject($a_obj_id)
71  {
72  global $ilDB;
73 
74  $query = "DELETE FROM ut_lp_marks ".
75  "WHERE obj_id = ".$ilDB->quote($a_obj_id,'integer');
76  $res = $ilDB->manipulate($query);
77  return true;
78  }
79 
80  function getUserId()
81  {
82  return $this->usr_id;
83  }
84 
85  function setMark($a_mark)
86  {
87  $this->mark = $a_mark;
88  }
89  function getMark()
90  {
91  return $this->mark;
92  }
93  function setComment($a_comment)
94  {
95  $this->comment = $a_comment;
96  }
97  function getComment()
98  {
99  return $this->comment;
100  }
101  function setCompleted($a_status)
102  {
103  $this->completed = (bool) $a_status;
104  }
105  function getCompleted()
106  {
107  return $this->completed;
108  }
109 
110  function getObjId()
111  {
112  return (int) $this->obj_id;
113  }
114 
115  function update()
116  {
117  global $ilDB;
118 
119  if(!$this->has_entry)
120  {
121  $this->__add();
122  }
123  $query = "UPDATE ut_lp_marks ".
124  "SET mark = ".$ilDB->quote($this->getMark(), 'text').", ".
125  "u_comment = ".$ilDB->quote($this->getComment() ,'text').", ".
126  "completed = ".$ilDB->quote($this->getCompleted() ,'integer')." ".
127  "WHERE obj_id = ".$ilDB->quote($this->getObjId() ,'integer')." ".
128  "AND usr_id = ".$ilDB->quote($this->getUserId(), 'integer');
129  $res = $ilDB->manipulate($query);
130  return true;
131  }
132 
133  // Static
134  function _hasCompleted($a_usr_id,$a_obj_id)
135  {
136  global $ilDB;
137 
138  $query = "SELECT * FROM ut_lp_marks ".
139  "WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ".
140  "AND obj_id = ".$ilDB->quote($a_obj_id ,'integer');
141 
142  $res = $ilDB->query($query);
143  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
144  {
145  return (bool) $row->completed;
146  }
147  return false;
148  }
149 
150  function _lookupMark($a_usr_id,$a_obj_id)
151  {
152  global $ilDB;
153 
154  $query = "SELECT * FROM ut_lp_marks ".
155  "WHERE usr_id = ".$ilDB->quote($a_usr_id, 'integer')." ".
156  "AND obj_id = ".$ilDB->quote($a_obj_id ,'integer');
157 
158  $res = $ilDB->query($query);
159  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
160  {
161  return $row->mark;
162  }
163  return '';
164  }
165 
166 
167  function _lookupComment($a_usr_id,$a_obj_id)
168  {
169  global $ilDB;
170 
171  $query = "SELECT * FROM ut_lp_marks ".
172  "WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ".
173  "AND obj_id = ".$ilDB->quote($a_obj_id ,'integer');
174 
175  $res = $ilDB->query($query);
176  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
177  {
178  return $row->u_comment;
179  }
180  return '';
181  }
182 
183  // Private
184  function __read()
185  {
186  global $ilDB;
187 
188  $res = $this->db->query("SELECT * FROM ut_lp_marks ".
189  "WHERE obj_id = ".$this->db->quote($this->obj_id ,'integer')." ".
190  "AND usr_id = ".$ilDB->quote($this->usr_id ,'integer'));
191  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
192  {
193  $this->has_entry = true;
194  $this->completed = (int) $row->completed;
195  $this->comment = $row->u_comment;
196  $this->mark = $row->mark;
197 
198  return true;
199  }
200 
201  return false;
202  }
203 
204  function __add()
205  {
206  global $ilDB;
207 
208  $query = "INSERT INTO ut_lp_marks (mark,u_comment, completed,obj_id,usr_id) ".
209  "VALUES( ".
210  $ilDB->quote($this->getMark(),'text').", ".
211  $ilDB->quote($this->getComment() ,'text').", ".
212  $ilDB->quote($this->getCompleted() ,'integer').", ".
213  $ilDB->quote($this->getObjId() ,'integer').", ".
214  $ilDB->quote($this->getUserId() ,'integer')." ".
215  ")";
216  $res = $ilDB->manipulate($query);
217  $this->has_entry = true;
218 
219  return true;
220  }
221 }
222 ?>