ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 $this->read();
58 }
59 }
60
69 public static function _getValuesByObjId($a_obj_id)
70 {
71 global $ilDB;
72
73 include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
75 if (!count($field_ids)) {
76 return array();
77 }
78
79 $where = "WHERE " . $ilDB->in('field_id', $field_ids, false, 'integer');
80 $query = "SELECT * FROM crs_user_data " .
81 $where;
82
83 $res = $ilDB->query($query);
84 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
85 $user_data[$row->usr_id][$row->field_id] = $row->value;
86 }
87
88 return $user_data ? $user_data : array();
89 }
90
102 public static function _checkRequired($a_usr_id, $a_obj_id)
103 {
104 global $ilDB;
105
106 include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
108 if (!count($required)) {
109 return true;
110 }
111
112 //$and = ("AND field_id IN (".implode(",",ilUtil::quoteArray($required)).")");
113 $and = "AND " . $ilDB->in('field_id', $required, false, 'integer');
114
115 $query = "SELECT COUNT(*) num_entries FROM crs_user_data " .
116 "WHERE usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " " .
117 "AND value != '' AND value IS NOT NULL " .
118 $and . " " .
119 " ";
120 $res = $ilDB->query($query);
122
123 return $row->num_entries == count($required);
124 }
125
134 public static function _deleteByUser($a_user_id)
135 {
136 global $ilDB;
137
138 $query = "DELETE FROM crs_user_data " .
139 "WHERE usr_id = " . $ilDB->quote($a_user_id, 'integer');
140 $res = $ilDB->manipulate($query);
141 }
142
150 public static function _deleteByField($a_field_id)
151 {
152 global $ilDB;
153
154 $query = "DELETE FROM crs_user_data " .
155 "WHERE field_id = " . $ilDB->quote($a_field_id, 'integer');
156 $res = $ilDB->manipulate($query);
157 }
158
159 public function setValue($a_value)
160 {
161 $this->value = $a_value;
162 }
163 public function getValue()
164 {
165 return $this->value;
166 }
167
174 public function update()
175 {
176 $this->delete();
177 $this->create();
178 }
179
186 public function delete()
187 {
188 global $ilDB;
189
190 $query = "DELETE FROM crs_user_data " .
191 "WHERE usr_id = " . $this->db->quote($this->user_id, 'integer') . " " .
192 "AND field_id = " . $this->db->quote($this->field_id, 'integer');
193 $res = $ilDB->manipulate($query);
194 }
195
202 public function create()
203 {
204 global $ilDB;
205
206 $query = "INSERT INTO crs_user_data (value,usr_id,field_id) " .
207 "VALUES( " .
208 $this->db->quote($this->getValue(), 'text') . ", " .
209 $this->db->quote($this->user_id, 'integer') . ", " .
210 $this->db->quote($this->field_id, 'integer') . " " .
211 ")";
212
213 $res = $ilDB->manipulate($query);
214 }
215
221 private function read()
222 {
223 global $ilDB;
224
225 $query = "SELECT * FROM crs_user_data " .
226 "WHERE usr_id = " . $this->db->quote($this->user_id, 'integer') . " " .
227 "AND field_id = " . $this->db->quote($this->field_id, 'integer');
228 $res = $this->db->query($query);
230
231 $this->setValue($row->value);
232 }
233}
An exception for terminatinating execution or to throw for unit testing.
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's.
static _deleteByField($a_field_id)
Delete by field.
static _deleteByUser($a_user_id)
Delete all entries of an user.
static _getValuesByObjId($a_obj_id)
Get values by obj_id (for all users)
__construct($a_user_id, $a_field_id=0)
Contructor.
static _checkRequired($a_usr_id, $a_obj_id)
Check required fields.
$query
foreach($_POST as $key=> $value) $res
global $ilDB