ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilUserDefinedData.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 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 
35 {
36  var $db = null;
37  var $user_data = array();
38  var $usr_id = null;
39 
40  function ilUserDefinedData($a_usr_id)
41  {
42  global $ilDB;
43 
44  $this->db =& $ilDB;
45  $this->usr_id = $a_usr_id;
46 
47  $this->__read();
48  }
49 
50  function getUserId()
51  {
52  return $this->usr_id;
53  }
54 
55  function set($a_field,$a_value)
56  {
57  $this->user_data[$a_field] = $a_value;
58  }
59  function get($a_field)
60  {
61  return isset($this->user_data[$a_field]) ? $this->user_data[$a_field] : '';
62  }
63 
64  function update()
65  {
66  include_once './Services/User/classes/class.ilUserDefinedFields.php';
68 
69  $sql = '';
70 
71  foreach($udf_obj->getDefinitions() as $definition)
72  {
73  $sql .= ("`".(int) $definition['field_id']."` = ".$this->db->quote($this->get($definition['field_id'])).", ");
74  }
75 
76  $query = "REPLACE INTO usr_defined_data ".
77  "SET ".$sql." ".
78  "usr_id = '".$this->getUserId()."'";
79  $this->db->query($query);
80  return true;
81  }
82 
83  function toXML()
84  {
85  include_once 'classes/class.ilXmlWriter.php';
86  $xml_writer = new ilXmlWriter();
87 
88  $this->addToXML ($xml_writer);
89 
90  return $xml_writer->xmlDumpMem(false);
91  }
92 
97  function addToXML($xml_writer)
98  {
99  include_once './Services/User/classes/class.ilUserDefinedFields.php';
100  $udf_obj =& ilUserDefinedFields::_getInstance();
101 
102  foreach($udf_obj->getDefinitions() as $definition)
103  {
104  if ($definition["export"] != FALSE)
105  $xml_writer->xmlElement('UserDefinedField',
106  array('Id' => $definition['il_id'],
107  'Name' => $definition['field_name']),
108  $this->user_data["$definition[field_id]"]);
109  }
110  }
111 
112  // Private
113  function __read()
114  {
115  $this->user_data = array();
116  $query = "SELECT * FROM usr_defined_data ".
117  "WHERE usr_id = ".$this->db->quote($this->usr_id)."";
118  $res = $this->db->query($query);
119  while($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
120  {
121  foreach($row as $field => $data)
122  {
123  if($field != 'usr_id')
124  {
125  $this->user_data[$field] = $data;
126  }
127  }
128  }
129  }
130 
131 }
132 ?>