ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5
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 
81  $where = "WHERE ".$ilDB->in('field_id',$field_ids,false,'integer');
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  $and = "AND ".$ilDB->in('field_id',$required,false,'integer');
118 
119  $query = "SELECT COUNT(*) num_entries FROM crs_user_data ".
120  "WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ".
121  "AND value != '' AND value IS NOT NULL ".
122  $and." ".
123  " ";
124  $res = $ilDB->query($query);
125  $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
126 
127  return $row->num_entries == count($required);
128  }
129 
138  public static function _deleteByUser($a_user_id)
139  {
140  global $ilDB;
141 
142  $query = "DELETE FROM crs_user_data ".
143  "WHERE usr_id = ".$ilDB->quote($a_user_id ,'integer');
144  $res = $ilDB->manipulate($query);
145 
146  }
147 
155  public static function _deleteByField($a_field_id)
156  {
157  global $ilDB;
158 
159  $query = "DELETE FROM crs_user_data ".
160  "WHERE field_id = ".$ilDB->quote($a_field_id ,'integer');
161  $res = $ilDB->manipulate($query);
162  }
163 
164  public function setValue($a_value)
165  {
166  $this->value = $a_value;
167  }
168  public function getValue()
169  {
170  return $this->value;
171  }
172 
179  public function update()
180  {
181  $this->delete();
182  $this->create();
183  }
184 
191  public function delete()
192  {
193  global $ilDB;
194 
195  $query = "DELETE FROM crs_user_data ".
196  "WHERE usr_id = ".$this->db->quote($this->user_id ,'integer')." ".
197  "AND field_id = ".$this->db->quote($this->field_id ,'integer');
198  $res = $ilDB->manipulate($query);
199  }
200 
207  public function create()
208  {
209  global $ilDB;
210 
211  $query = "INSERT INTO crs_user_data (value,usr_id,field_id) ".
212  "VALUES( ".
213  $this->db->quote($this->getValue() ,'text').", ".
214  $this->db->quote($this->user_id ,'integer').", ".
215  $this->db->quote($this->field_id ,'integer')." ".
216  ")";
217 
218  $res = $ilDB->manipulate($query);
219  }
220 
226  private function read()
227  {
228  global $ilDB;
229 
230  $query = "SELECT * FROM crs_user_data ".
231  "WHERE usr_id = ".$this->db->quote($this->user_id ,'integer')." ".
232  "AND field_id = ".$this->db->quote($this->field_id ,'integer');
233  $res = $this->db->query($query);
234  $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
235 
236  $this->setValue($row->value);
237 
238  }
239 }
240 
241 
242 ?>
__construct($a_user_id, $a_field_id=0)
Contructor.
static _getValuesByObjId($a_obj_id)
Get values by obj_id (for all users)
static _getFieldIds($a_container_id, $a_sort=IL_CDF_SORT_ID)
Get all field ids of a container.
static _getRequiredFieldIds($a_obj_id)
Get required filed id&#39;s.
static _deleteByField($a_field_id)
Delete by field.
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
static _checkRequired($a_usr_id, $a_obj_id)
Check required fields.
static _deleteByUser($a_user_id)
Delete all entries of an user.
global $ilDB