ILIAS  Release_4_0_x_branch Revision 61816
 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 
28  function getUserId()
29  {
30  return $this->usr_id;
31  }
32 
33  function set($a_field,$a_value)
34  {
35  $this->user_data[$a_field] = $a_value;
36  }
37  function get($a_field)
38  {
39  return isset($this->user_data[$a_field]) ? $this->user_data[$a_field] : '';
40  }
41 
45  function getAll()
46  {
47  return $this->user_data;
48  }
49 
53  function update()
54  {
55  global $ilDB;
56 
57  include_once './Services/User/classes/class.ilUserDefinedFields.php';
59 
60  $sql = '';
61  $field_def = array();
62  foreach($udf_obj->getDefinitions() as $definition)
63  {
64 // $field_def['f_'.$definition['field_id']] = array('text',$this->get($definition['field_id']));
65 
66 // $sql .= ("`".(int) $definition['field_id']."` = ".$this->db->quote($this->get($definition['field_id'])).", ");
67 
68  if ($definition["field_type"] == UDF_TYPE_WYSIWYG)
69  {
70  $ilDB->replace("udf_clob", array(
71  "usr_id" => array("integer", $this->getUserId()),
72  "field_id" => array("integer", $definition['field_id'])),
73  array(
74  "value" => array("clob", $this->get("f_".$definition['field_id']))
75  ));
76  }
77  else
78  {
79  $ilDB->replace("udf_text", array(
80  "usr_id" => array("integer", $this->getUserId()),
81  "field_id" => array("integer", $definition['field_id'])),
82  array(
83  "value" => array("text", $this->get("f_".$definition['field_id']))
84  ));
85  }
86  }
87 /* if(!$field_def)
88  {
89  return true;
90  }
91 
92  $query = "SELECT usr_id FROM udf_data WHERE usr_id = ".$ilDB->quote($this->getUserId(),'integer');
93  $res = $ilDB->query($query);
94 
95  if($res->numRows())
96  {
97  $ilDB->update('udf_data',$field_def,array('usr_id' => array('integer',$this->getUserId())));
98  }
99  else
100  {
101  $field_def['usr_id'] = array('integer',$this->getUserId());
102  $ilDB->insert('udf_data',$field_def);
103  }*/
104  return true;
105  }
106 
112  static function deleteEntriesOfUser($a_user_id)
113  {
114  global $ilDB;
115 
116  $ilDB->manipulate("DELETE FROM udf_text WHERE "
117  ." usr_id = ".$ilDB->quote($a_user_id, "integer")
118  );
119  $ilDB->manipulate("DELETE FROM udf_clob WHERE "
120  ." usr_id = ".$ilDB->quote($a_user_id, "integer")
121  );
122  }
123 
129  static function deleteEntriesOfField($a_field_id)
130  {
131  global $ilDB;
132 
133  $ilDB->manipulate("DELETE FROM udf_text WHERE "
134  ." field_id = ".$ilDB->quote($a_field_id, "integer")
135  );
136  $ilDB->manipulate("DELETE FROM udf_clob WHERE "
137  ." field_id = ".$ilDB->quote($a_field_id, "integer")
138  );
139  }
140 
147  static function deleteFieldValue($a_field_id, $a_value)
148  {
149  global $ilDB;
150 
151  $ilDB->manipulate("UPDATE udf_text SET value = ".$ilDB->quote("", "text")." WHERE "
152  ." field_id = ".$ilDB->quote($a_field_id, "integer")
153  ." AND value = ".$ilDB->quote($a_value, "text")
154  );
155  }
156 
157  function toXML()
158  {
159  include_once 'classes/class.ilXmlWriter.php';
160  $xml_writer = new ilXmlWriter();
161 
162  $this->addToXML ($xml_writer);
163 
164  return $xml_writer->xmlDumpMem(false);
165  }
166 
171  function addToXML($xml_writer)
172  {
173  include_once './Services/User/classes/class.ilUserDefinedFields.php';
174  $udf_obj =& ilUserDefinedFields::_getInstance();
175 
176  foreach($udf_obj->getDefinitions() as $definition)
177  {
178  if ($definition["export"] != FALSE)
179  {
180  $xml_writer->xmlElement('UserDefinedField',
181  array('Id' => $definition['il_id'],
182  'Name' => $definition['field_name']),
183  (string) $this->user_data['f_'.(int) $definition['field_id']]);
184  }
185 
186  }
187  }
188 
189  // Private
190  function __read()
191  {
192  $this->user_data = array();
193  $query = "SELECT * FROM udf_text ".
194  "WHERE usr_id = ".$this->db->quote($this->usr_id,'integer')."";
195  $res = $this->db->query($query);
196  while($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
197  {
198  $this->user_data["f_".$row["field_id"]] = $row["value"];
199  }
200  $query = "SELECT * FROM udf_clob ".
201  "WHERE usr_id = ".$this->db->quote($this->usr_id,'integer')."";
202  $res = $this->db->query($query);
203  while($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
204  {
205  $this->user_data["f_".$row["field_id"]] = $row["value"];
206  }
207  }
208 
209 }
210 ?>