ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 $ilDB;
21 
22  $this->db = $ilDB;
23  $this->usr_id = $a_usr_id;
24 
25  $this->__read();
26  }
27 
34  public static function lookupData($a_user_ids, $a_field_ids)
35  {
36  global $ilDB;
37 
38  $query = "SELECT * FROM udf_text " .
39  "WHERE " . $ilDB->in('usr_id', $a_user_ids, false, 'integer') . ' ' .
40  'AND ' . $ilDB->in('field_id', $a_field_ids, false, 'integer');
41  $res = $ilDB->query($query);
42 
43  $udfd = array();
44  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
45  $udfd[$row['usr_id']][$row['field_id']] = $row['value'];
46  }
47  return $udfd;
48  }
49 
50  public function getUserId()
51  {
52  return $this->usr_id;
53  }
54 
55  public function set($a_field, $a_value)
56  {
57  $this->user_data[$a_field] = $a_value;
58  }
59  public function get($a_field)
60  {
61  return isset($this->user_data[$a_field]) ? $this->user_data[$a_field] : '';
62  }
63 
67  public function getAll()
68  {
69  return $this->user_data;
70  }
71 
75  public function update()
76  {
77  global $ilDB;
78 
79  include_once './Services/User/classes/class.ilUserDefinedFields.php';
81 
82  $sql = '';
83  $field_def = array();
84  foreach ($udf_obj->getDefinitions() as $definition) {
85  // $field_def['f_'.$definition['field_id']] = array('text',$this->get($definition['field_id']));
86 
87  // $sql .= ("`".(int) $definition['field_id']."` = ".$this->db->quote($this->get($definition['field_id'])).", ");
88 
89  if ($definition["field_type"] == UDF_TYPE_WYSIWYG) {
90  $ilDB->replace(
91  "udf_clob",
92  array(
93  "usr_id" => array("integer", $this->getUserId()),
94  "field_id" => array("integer", $definition['field_id'])),
95  array(
96  "value" => array("clob", $this->get("f_" . $definition['field_id']))
97  )
98  );
99  } else {
100  $ilDB->replace(
101  "udf_text",
102  array(
103  "usr_id" => array("integer", $this->getUserId()),
104  "field_id" => array("integer", $definition['field_id'])),
105  array(
106  "value" => array("text", $this->get("f_" . $definition['field_id']))
107  )
108  );
109  }
110  }
111  /* if(!$field_def)
112  {
113  return true;
114  }
115 
116  $query = "SELECT usr_id FROM udf_data WHERE usr_id = ".$ilDB->quote($this->getUserId(),'integer');
117  $res = $ilDB->query($query);
118 
119  if($res->numRows())
120  {
121  $ilDB->update('udf_data',$field_def,array('usr_id' => array('integer',$this->getUserId())));
122  }
123  else
124  {
125  $field_def['usr_id'] = array('integer',$this->getUserId());
126  $ilDB->insert('udf_data',$field_def);
127  }*/
128  return true;
129  }
130 
136  public static function deleteEntriesOfUser($a_user_id)
137  {
138  global $ilDB;
139 
140  $ilDB->manipulate(
141  "DELETE FROM udf_text WHERE "
142  . " usr_id = " . $ilDB->quote($a_user_id, "integer")
143  );
144  $ilDB->manipulate(
145  "DELETE FROM udf_clob WHERE "
146  . " usr_id = " . $ilDB->quote($a_user_id, "integer")
147  );
148  }
149 
155  public static function deleteEntriesOfField($a_field_id)
156  {
157  global $ilDB;
158 
159  $ilDB->manipulate(
160  "DELETE FROM udf_text WHERE "
161  . " field_id = " . $ilDB->quote($a_field_id, "integer")
162  );
163  $ilDB->manipulate(
164  "DELETE FROM udf_clob WHERE "
165  . " field_id = " . $ilDB->quote($a_field_id, "integer")
166  );
167  }
168 
175  public static function deleteFieldValue($a_field_id, $a_value)
176  {
177  global $ilDB;
178 
179  $ilDB->manipulate(
180  "UPDATE udf_text SET value = " . $ilDB->quote("", "text") . " WHERE "
181  . " field_id = " . $ilDB->quote($a_field_id, "integer")
182  . " AND value = " . $ilDB->quote($a_value, "text")
183  );
184  }
185 
186  public function toXML()
187  {
188  include_once './Services/Xml/classes/class.ilXmlWriter.php';
189  $xml_writer = new ilXmlWriter();
190 
191  $this->addToXML($xml_writer);
192 
193  return $xml_writer->xmlDumpMem(false);
194  }
195 
200  public function addToXML($xml_writer)
201  {
202  include_once './Services/User/classes/class.ilUserDefinedFields.php';
204 
205  foreach ($udf_obj->getDefinitions() as $definition) {
206  if ($definition["export"] != false) {
207  $xml_writer->xmlElement(
208  'UserDefinedField',
209  array('Id' => $definition['il_id'],
210  'Name' => $definition['field_name']),
211  (string) $this->user_data['f_' . (int) $definition['field_id']]
212  );
213  }
214  }
215  }
216 
217  // Private
218  public function __read()
219  {
220  $this->user_data = array();
221  $query = "SELECT * FROM udf_text " .
222  "WHERE usr_id = " . $this->db->quote($this->usr_id, 'integer') . "";
223  $res = $this->db->query($query);
224  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
225  $this->user_data["f_" . $row["field_id"]] = $row["value"];
226  }
227  $query = "SELECT * FROM udf_clob " .
228  "WHERE usr_id = " . $this->db->quote($this->usr_id, 'integer') . "";
229  $res = $this->db->query($query);
230  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
231  $this->user_data["f_" . $row["field_id"]] = $row["value"];
232  }
233  }
234 }
static _getInstance()
Get instance.
Class ilUserDefinedData.
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
Create styles array
The data for the language used.
static deleteEntriesOfUser($a_user_id)
Delete data of user.
global $ilDB
static deleteFieldValue($a_field_id, $a_value)
Delete data of particular value of a (selection) field.