ILIAS  Release_3_10_x_branch Revision 61812
 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 
65  function getUserId()
66  {
67  return $this->usr_id;
68  }
69 
70  function setMark($a_mark)
71  {
72  $this->mark = $a_mark;
73  }
74  function getMark()
75  {
76  return $this->mark;
77  }
78  function setComment($a_comment)
79  {
80  $this->comment = $a_comment;
81  }
82  function getComment()
83  {
84  return $this->comment;
85  }
86  function setCompleted($a_status)
87  {
88  $this->completed = (bool) $a_status;
89  }
90  function getCompleted()
91  {
92  return $this->completed;
93  }
94 
95  function getObjId()
96  {
97  return (int) $this->obj_id;
98  }
99 
100  function update()
101  {
102  if(!$this->has_entry)
103  {
104  $this->__add();
105  }
106  $query = "UPDATE ut_lp_marks ".
107  "SET mark = '".ilUtil::prepareDBString($this->getMark())."', ".
108  "comment = '".ilUtil::prepareDBString($this->getComment())."', ".
109  "completed = '".(int) $this->getCompleted()."' ".
110  "WHERE obj_id = '".$this->getObjId()."' ".
111  "AND usr_id = '".$this->getUserId()."'";
112 
113  $this->db->query($query);
114 
115  return true;
116  }
117 
118  // Static
119  function _hasCompleted($a_usr_id,$a_obj_id)
120  {
121  global $ilDB;
122 
123  $query = "SELECT * FROM ut_lp_marks ".
124  "WHERE usr_id = '".$a_usr_id."' ".
125  "AND obj_id = '".$a_obj_id."'";
126 
127  $res = $ilDB->query($query);
128  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
129  {
130  return (bool) $row->completed;
131  }
132  return false;
133  }
134 
135  function _lookupMark($a_usr_id,$a_obj_id)
136  {
137  global $ilDB;
138 
139  $query = "SELECT * FROM ut_lp_marks ".
140  "WHERE usr_id = '".$a_usr_id."' ".
141  "AND obj_id = '".$a_obj_id."'";
142 
143  $res = $ilDB->query($query);
144  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
145  {
146  return $row->mark;
147  }
148  return '';
149  }
150 
151 
152  function _lookupComment($a_usr_id,$a_obj_id)
153  {
154  global $ilDB;
155 
156  $query = "SELECT * FROM ut_lp_marks ".
157  "WHERE usr_id = '".$a_usr_id."' ".
158  "AND obj_id = '".$a_obj_id."'";
159 
160  $res = $ilDB->query($query);
161  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
162  {
163  return $row->comment;
164  }
165  return '';
166  }
167 
168  // Private
169  function __read()
170  {
171  $res = $this->db->query("SELECT * FROM ut_lp_marks ".
172  "WHERE obj_id = ".$this->db->quote($this->obj_id)." ".
173  "AND usr_id = '".(int) $this->usr_id."'");
174  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
175  {
176  $this->has_entry = true;
177  $this->completed = (int) $row->completed;
178  $this->comment = $row->comment;
179  $this->mark = $row->mark;
180 
181  return true;
182  }
183 
184  return false;
185  }
186 
187  function __add()
188  {
189  $query = "INSERT INTO ut_lp_marks ".
190  "SET mark = '".ilUtil::prepareDBString($this->getMark())."', ".
191  "comment = '".ilUtil::prepareDBString($this->getComment())."', ".
192  "completed = '".(int) $this->getCompleted()."', ".
193  "obj_id = '".$this->getObjId()."', ".
194  "usr_id = '".$this->getUserId()."'";
195 
196  $this->db->query($query);
197 
198  $this->has_entry = true;
199 
200  return true;
201  }
202 }
203 ?>