ILIAS  Release_4_1_x_branch Revision 61804
 All Data Structures Namespaces Files Functions Variables Groups Pages
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  var $db = null;
15  var $user_data = array();
16  var $usr_id = null;
17 
18  function ilUserDefinedData($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(DB_FETCHMODE_ASSOC))
45  {
46  $udfd[$row['usr_id']][$row['field_id']] = $row['value'];
47  }
48  return $udfd;
49  }
50 
51  function getUserId()
52  {
53  return $this->usr_id;
54  }
55 
56  function set($a_field,$a_value)
57  {
58  $this->user_data[$a_field] = $a_value;
59  }
60  function get($a_field)
61  {
62  return isset($this->user_data[$a_field]) ? $this->user_data[$a_field] : '';
63  }
64 
68  function getAll()
69  {
70  return $this->user_data;
71  }
72 
76  function update()
77  {
78  global $ilDB;
79 
80  include_once './Services/User/classes/class.ilUserDefinedFields.php';
82 
83  $sql = '';
84  $field_def = array();
85  foreach($udf_obj->getDefinitions() as $definition)
86  {
87 // $field_def['f_'.$definition['field_id']] = array('text',$this->get($definition['field_id']));
88 
89 // $sql .= ("`".(int) $definition['field_id']."` = ".$this->db->quote($this->get($definition['field_id'])).", ");
90 
91  if ($definition["field_type"] == UDF_TYPE_WYSIWYG)
92  {
93  $ilDB->replace("udf_clob", array(
94  "usr_id" => array("integer", $this->getUserId()),
95  "field_id" => array("integer", $definition['field_id'])),
96  array(
97  "value" => array("clob", $this->get("f_".$definition['field_id']))
98  ));
99  }
100  else
101  {
102  $ilDB->replace("udf_text", 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 /* if(!$field_def)
111  {
112  return true;
113  }
114 
115  $query = "SELECT usr_id FROM udf_data WHERE usr_id = ".$ilDB->quote($this->getUserId(),'integer');
116  $res = $ilDB->query($query);
117 
118  if($res->numRows())
119  {
120  $ilDB->update('udf_data',$field_def,array('usr_id' => array('integer',$this->getUserId())));
121  }
122  else
123  {
124  $field_def['usr_id'] = array('integer',$this->getUserId());
125  $ilDB->insert('udf_data',$field_def);
126  }*/
127  return true;
128  }
129 
135  static function deleteEntriesOfUser($a_user_id)
136  {
137  global $ilDB;
138 
139  $ilDB->manipulate("DELETE FROM udf_text WHERE "
140  ." usr_id = ".$ilDB->quote($a_user_id, "integer")
141  );
142  $ilDB->manipulate("DELETE FROM udf_clob WHERE "
143  ." usr_id = ".$ilDB->quote($a_user_id, "integer")
144  );
145  }
146 
152  static function deleteEntriesOfField($a_field_id)
153  {
154  global $ilDB;
155 
156  $ilDB->manipulate("DELETE FROM udf_text WHERE "
157  ." field_id = ".$ilDB->quote($a_field_id, "integer")
158  );
159  $ilDB->manipulate("DELETE FROM udf_clob WHERE "
160  ." field_id = ".$ilDB->quote($a_field_id, "integer")
161  );
162  }
163 
170  static function deleteFieldValue($a_field_id, $a_value)
171  {
172  global $ilDB;
173 
174  $ilDB->manipulate("UPDATE udf_text SET value = ".$ilDB->quote("", "text")." WHERE "
175  ." field_id = ".$ilDB->quote($a_field_id, "integer")
176  ." AND value = ".$ilDB->quote($a_value, "text")
177  );
178  }
179 
180  function toXML()
181  {
182  include_once './Services/Xml/classes/class.ilXmlWriter.php';
183  $xml_writer = new ilXmlWriter();
184 
185  $this->addToXML ($xml_writer);
186 
187  return $xml_writer->xmlDumpMem(false);
188  }
189 
194  function addToXML($xml_writer)
195  {
196  include_once './Services/User/classes/class.ilUserDefinedFields.php';
197  $udf_obj =& ilUserDefinedFields::_getInstance();
198 
199  foreach($udf_obj->getDefinitions() as $definition)
200  {
201  if ($definition["export"] != FALSE)
202  {
203  $xml_writer->xmlElement('UserDefinedField',
204  array('Id' => $definition['il_id'],
205  'Name' => $definition['field_name']),
206  (string) $this->user_data['f_'.(int) $definition['field_id']]);
207  }
208 
209  }
210  }
211 
212  // Private
213  function __read()
214  {
215  $this->user_data = array();
216  $query = "SELECT * FROM udf_text ".
217  "WHERE usr_id = ".$this->db->quote($this->usr_id,'integer')."";
218  $res = $this->db->query($query);
219  while($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
220  {
221  $this->user_data["f_".$row["field_id"]] = $row["value"];
222  }
223  $query = "SELECT * FROM udf_clob ".
224  "WHERE usr_id = ".$this->db->quote($this->usr_id,'integer')."";
225  $res = $this->db->query($query);
226  while($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
227  {
228  $this->user_data["f_".$row["field_id"]] = $row["value"];
229  }
230  }
231 
232 }
233 ?>