ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilUserDefinedData.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
13 {
14  public $db = null;
15  public $user_data = array();
16  public $usr_id = null;
17 
18  public function __construct($a_usr_id)
19  {
20  global $DIC;
21 
22  $ilDB = $DIC['ilDB'];
23 
24  $this->db = $ilDB;
25  $this->usr_id = $a_usr_id;
26 
27  $this->__read();
28  }
29 
36  public static function lookupData($a_user_ids, $a_field_ids)
37  {
38  global $DIC;
39 
40  $ilDB = $DIC['ilDB'];
41 
42  $query = "SELECT * FROM udf_text " .
43  "WHERE " . $ilDB->in('usr_id', $a_user_ids, false, 'integer') . ' ' .
44  'AND ' . $ilDB->in('field_id', $a_field_ids, false, 'integer');
45  $res = $ilDB->query($query);
46 
47  $udfd = array();
48  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
49  $udfd[$row['usr_id']][$row['field_id']] = $row['value'];
50  }
51 
52  include_once './Services/User/classes/class.ilCustomUserFieldsHelper.php';
54  foreach ($def_helper->getActivePlugins() as $plugin) {
55  foreach ($plugin->lookupUserData($a_user_ids, $a_field_ids) as $user_id => $usr_data) {
56  foreach ($usr_data as $field_id => $value) {
57  $udfd[$user_id][$field_id] = $value;
58  }
59  }
60  }
61 
62  return $udfd;
63  }
64 
65  public function getUserId()
66  {
67  return $this->usr_id;
68  }
69 
70  public function set($a_field, $a_value)
71  {
72  $this->user_data[$a_field] = $a_value;
73  }
74  public function get($a_field)
75  {
76  return isset($this->user_data[$a_field]) ? $this->user_data[$a_field] : '';
77  }
78 
82  public function getAll()
83  {
84  return $this->user_data;
85  }
86 
90  public function update()
91  {
92  global $DIC;
93 
94  $ilDB = $DIC['ilDB'];
95 
96  include_once './Services/User/classes/class.ilUserDefinedFields.php';
98 
99  $sql = '';
100  $field_def = array();
101  foreach ($udf_obj->getDefinitions() as $definition) {
102  // $field_def['f_'.$definition['field_id']] = array('text',$this->get($definition['field_id']));
103 
104  // $sql .= ("`".(int) $definition['field_id']."` = ".$this->db->quote($this->get($definition['field_id'])).", ");
105 
106  if ($definition["field_type"] == UDF_TYPE_WYSIWYG) {
107  $ilDB->replace(
108  "udf_clob",
109  array(
110  "usr_id" => array("integer", $this->getUserId()),
111  "field_id" => array("integer", $definition['field_id'])),
112  array(
113  "value" => array("clob", $this->get("f_" . $definition['field_id']))
114  )
115  );
116  } else {
117  $ilDB->replace(
118  "udf_text",
119  array(
120  "usr_id" => array("integer", $this->getUserId()),
121  "field_id" => array("integer", $definition['field_id'])),
122  array(
123  "value" => array("text", $this->get("f_" . $definition['field_id']))
124  )
125  );
126  }
127  }
128  /* if(!$field_def)
129  {
130  return true;
131  }
132 
133  $query = "SELECT usr_id FROM udf_data WHERE usr_id = ".$ilDB->quote($this->getUserId(),'integer');
134  $res = $ilDB->query($query);
135 
136  if($res->numRows())
137  {
138  $ilDB->update('udf_data',$field_def,array('usr_id' => array('integer',$this->getUserId())));
139  }
140  else
141  {
142  $field_def['usr_id'] = array('integer',$this->getUserId());
143  $ilDB->insert('udf_data',$field_def);
144  }*/
145  return true;
146  }
147 
153  public static function deleteEntriesOfUser($a_user_id)
154  {
155  global $DIC;
156 
157  $ilDB = $DIC['ilDB'];
158 
159  $ilDB->manipulate(
160  "DELETE FROM udf_text WHERE "
161  . " usr_id = " . $ilDB->quote($a_user_id, "integer")
162  );
163  $ilDB->manipulate(
164  "DELETE FROM udf_clob WHERE "
165  . " usr_id = " . $ilDB->quote($a_user_id, "integer")
166  );
167  }
168 
174  public static function deleteEntriesOfField($a_field_id)
175  {
176  global $DIC;
177 
178  $ilDB = $DIC['ilDB'];
179 
180  $ilDB->manipulate(
181  "DELETE FROM udf_text WHERE "
182  . " field_id = " . $ilDB->quote($a_field_id, "integer")
183  );
184  $ilDB->manipulate(
185  "DELETE FROM udf_clob WHERE "
186  . " field_id = " . $ilDB->quote($a_field_id, "integer")
187  );
188  }
189 
196  public static function deleteFieldValue($a_field_id, $a_value)
197  {
198  global $DIC;
199 
200  $ilDB = $DIC['ilDB'];
201 
202  $ilDB->manipulate(
203  "UPDATE udf_text SET value = " . $ilDB->quote("", "text") . " WHERE "
204  . " field_id = " . $ilDB->quote($a_field_id, "integer")
205  . " AND value = " . $ilDB->quote($a_value, "text")
206  );
207  }
208 
209  public function toXML()
210  {
211  include_once './Services/Xml/classes/class.ilXmlWriter.php';
212  $xml_writer = new ilXmlWriter();
213 
214  $this->addToXML($xml_writer);
215 
216  return $xml_writer->xmlDumpMem(false);
217  }
218 
223  public function addToXML($xml_writer)
224  {
225  include_once './Services/User/classes/class.ilUserDefinedFields.php';
226  $udf_obj = &ilUserDefinedFields::_getInstance();
227 
228  foreach ($udf_obj->getDefinitions() as $definition) {
229  if ($definition["export"] != false) {
230  $xml_writer->xmlElement(
231  'UserDefinedField',
232  array('Id' => $definition['il_id'],
233  'Name' => $definition['field_name']),
234  (string) $this->user_data['f_' . (int) $definition['field_id']]
235  );
236  }
237  }
238  }
239 
240  // Private
241  public function __read()
242  {
243  $this->user_data = array();
244  $query = "SELECT * FROM udf_text " .
245  "WHERE usr_id = " . $this->db->quote($this->usr_id, 'integer') . "";
246  $res = $this->db->query($query);
247  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
248  $this->user_data["f_" . $row["field_id"]] = $row["value"];
249  }
250  $query = "SELECT * FROM udf_clob " .
251  "WHERE usr_id = " . $this->db->quote($this->usr_id, 'integer') . "";
252  $res = $this->db->query($query);
253  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
254  $this->user_data["f_" . $row["field_id"]] = $row["value"];
255  }
256  }
257 }
static _getInstance()
Get instance.
Class ilUserDefinedData.
global $DIC
Definition: saml.php:7
static deleteEntriesOfField($a_field_id)
Delete data of particular field.
getAll()
Get all fields.
XML writer class.
static lookupData($a_user_ids, $a_field_ids)
Lookup data.
foreach($_POST as $key=> $value) $res
addToXML($xml_writer)
add user defined field data to xml (using usr dtd)
$query
const UDF_TYPE_WYSIWYG
static deleteEntriesOfUser($a_user_id)
Delete data of user.
$row
global $ilDB
static deleteFieldValue($a_field_id, $a_value)
Delete data of particular value of a (selection) field.