ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilCourseUserData.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 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 
33 {
34  private $db;
35  private $user_id;
36  private $field_id;
37  private $value;
38 
39 
48  public function __construct($a_user_id,$a_field_id = 0)
49  {
50  global $ilDB;
51 
52  $this->db = $ilDB;
53  $this->user_id = $a_user_id;
54  $this->field_id = $a_field_id;
55 
56  if($this->field_id)
57  {
58  $this->read();
59  }
60  }
61 
70  public static function _getValuesByObjId($a_obj_id)
71  {
72  global $ilDB;
73 
74  include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
75  $field_ids = ilCourseDefinedFieldDefinition::_getFieldIds($a_obj_id);
76  if(!count($field_ids))
77  {
78  return array();
79  }
80  $where = ("WHERE field_id IN (".implode(",",ilUtil::quoteArray($field_ids)).") ");
81 
82  $query = "SELECT * FROM crs_user_data ".
83  $where;
84 
85  $res = $ilDB->query($query);
86  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
87  {
88  $user_data[$row->usr_id][$row->field_id] = $row->value;
89  }
90 
91  return $user_data ? $user_data : array();
92  }
93 
105  public static function _checkRequired($a_usr_id,$a_obj_id)
106  {
107  global $ilDB;
108 
109  include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
111  if(!count($required))
112  {
113  return true;
114  }
115 
116  $and = ("AND field_id IN (".implode(",",ilUtil::quoteArray($required)).")");
117  $query = "SELECT COUNT(*) as num_entries FROM crs_user_data ".
118  "WHERE usr_id = ".$ilDB->quote($a_usr_id)." ".
119  "AND value != '' ".
120  $and;
121  $res = $ilDB->query($query);
122  $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
123 
124  return $row->num_entries == count($required);
125  }
126 
135  public static function _deleteByUser($a_user_id)
136  {
137  global $ilDB;
138 
139  $query = "DELETE FROM crs_user_data ".
140  "WHERE usr_id = ".$ilDB->quote($a_user_id);
141  $ilDB->query($query);
142 
143  }
144 
152  public static function _deleteByField($a_field_id)
153  {
154  global $ilDB;
155 
156  $query = "DELETE FROM crs_user_data ".
157  "WHERE field_id = ".$ilDB->quote($a_field_id);
158  $ilDB->query($query);
159  }
160 
161  public function setValue($a_value)
162  {
163  $this->value = $a_value;
164  }
165  public function getValue()
166  {
167  return $this->value;
168  }
169 
176  public function update()
177  {
178  $this->delete();
179  $this->create();
180  }
181 
188  public function delete()
189  {
190  $query = "DELETE FROM crs_user_data ".
191  "WHERE usr_id = ".$this->db->quote($this->user_id)." ".
192  "AND field_id = ".$this->db->quote($this->field_id);
193  $this->db->query($query);
194  }
195 
202  public function create()
203  {
204  $query = "INSERT INTO crs_user_data SET ".
205  "value = ".$this->db->quote($this->getValue()).", ".
206  "usr_id = ".$this->db->quote($this->user_id).", ".
207  "field_id = ".$this->db->quote($this->field_id)." ";
208  $this->db->query($query);
209  }
210 
216  private function read()
217  {
218  $query = "SELECT * FROM crs_user_data ".
219  "WHERE usr_id = ".$this->db->quote($this->user_id)." ".
220  "AND field_id = ".$this->db->quote($this->field_id);
221  $res = $this->db->query($query);
222  $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
223 
224  $this->setValue($row->value);
225 
226  }
227 }
228 
229 
230 ?>