ILIAS  release_7 Revision v7.30-3-g800a261c036
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 $DIC;
51
52 $ilDB = $DIC['ilDB'];
53
54 $this->db = $ilDB;
55 $this->user_id = $a_user_id;
56 $this->field_id = $a_field_id;
57
58 if ($this->field_id) {
59 $this->read();
60 }
61 }
62
71 public static function _getValuesByObjId($a_obj_id)
72 {
73 global $DIC;
74
75 $ilDB = $DIC['ilDB'];
76
77 include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
79 if (!count($field_ids)) {
80 return array();
81 }
82
83 $where = "WHERE " . $ilDB->in('field_id', $field_ids, false, 'integer');
84 $query = "SELECT * FROM crs_user_data " .
85 $where;
86
87 $res = $ilDB->query($query);
88 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
89 $user_data[$row->usr_id][$row->field_id] = $row->value;
90 }
91
92 return $user_data ? $user_data : array();
93 }
94
106 public static function _checkRequired($a_usr_id, $a_obj_id)
107 {
108 global $DIC;
109
110 $ilDB = $DIC['ilDB'];
111
112 include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
114 if (!count($required)) {
115 return true;
116 }
117
118 //$and = ("AND field_id IN (".implode(",",ilUtil::quoteArray($required)).")");
119 $and = "AND " . $ilDB->in('field_id', $required, false, 'integer');
120
121 $query = "SELECT COUNT(*) num_entries FROM crs_user_data " .
122 "WHERE usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " " .
123 "AND value != '' AND value IS NOT NULL " .
124 $and . " " .
125 " ";
126 $res = $ilDB->query($query);
127 $row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT);
128
129 return $row->num_entries == count($required);
130 }
131
140 public static function _deleteByUser($a_user_id)
141 {
142 global $DIC;
143
144 $ilDB = $DIC['ilDB'];
145
146 $query = "DELETE FROM crs_user_data " .
147 "WHERE usr_id = " . $ilDB->quote($a_user_id, 'integer');
148 $res = $ilDB->manipulate($query);
149 }
150
158 public static function _deleteByField($a_field_id)
159 {
160 global $DIC;
161
162 $ilDB = $DIC['ilDB'];
163
164 $query = "DELETE FROM crs_user_data " .
165 "WHERE field_id = " . $ilDB->quote($a_field_id, 'integer');
166 $res = $ilDB->manipulate($query);
167 }
168
169 public function setValue($a_value)
170 {
171 $this->value = $a_value;
172 }
173 public function getValue()
174 {
175 return $this->value;
176 }
177
184 public function update()
185 {
186 $this->delete();
187 $this->create();
188 }
189
196 public function delete()
197 {
198 global $DIC;
199
200 $ilDB = $DIC['ilDB'];
201
202 $query = "DELETE FROM crs_user_data " .
203 "WHERE usr_id = " . $this->db->quote($this->user_id, 'integer') . " " .
204 "AND field_id = " . $this->db->quote($this->field_id, 'integer');
205 $res = $ilDB->manipulate($query);
206 }
207
214 public function create()
215 {
216 global $DIC;
217
218 $ilDB = $DIC['ilDB'];
219
220 $query = "INSERT INTO crs_user_data (value,usr_id,field_id) " .
221 "VALUES( " .
222 $this->db->quote($this->getValue(), 'text') . ", " .
223 $this->db->quote($this->user_id, 'integer') . ", " .
224 $this->db->quote($this->field_id, 'integer') . " " .
225 ")";
226
227 $res = $ilDB->manipulate($query);
228 }
229
235 private function read()
236 {
237 global $DIC;
238
239 $ilDB = $DIC['ilDB'];
240
241 $query = "SELECT * FROM crs_user_data " .
242 "WHERE usr_id = " . $this->db->quote($this->user_id, 'integer') . " " .
243 "AND field_id = " . $this->db->quote($this->field_id, 'integer');
244 $res = $this->db->query($query);
245 $row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT);
246
247 $this->setValue($row->value);
248 }
249}
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.
global $DIC
Definition: goto.php:24
$query
foreach($_POST as $key=> $value) $res
global $ilDB