• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

classes/class.ilUserDefinedData.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00035 class ilUserDefinedData
00036 {
00037         var $db = null;
00038         var $user_data = array();
00039         var $usr_id = null;
00040 
00041         function ilUserDefinedData($a_usr_id)
00042         {
00043                 global $ilDB;
00044 
00045                 $this->db =& $ilDB;
00046                 $this->usr_id = $a_usr_id;
00047 
00048                 $this->__read();
00049         }
00050 
00051         function getUserId()
00052         {
00053                 return $this->usr_id;
00054         }
00055 
00056         function set($a_field,$a_value)
00057         {
00058                 $this->user_data[$a_field] = $a_value;
00059         }
00060         function get($a_field)
00061         {
00062                 return isset($this->user_data[$a_field]) ? $this->user_data[$a_field] : '';
00063         }
00064 
00065         function update()
00066         {
00067                 include_once 'classes/class.ilUserDefinedFields.php';
00068                 $udf_obj =& ilUserDefinedFields::_getInstance();
00069 
00070                 $sql = '';
00071 
00072                 foreach($udf_obj->getDefinitions() as $definition)
00073                 {
00074                         $sql .= ("`".$definition['field_id']."` = '".$this->get($definition['field_id'])."', ");
00075                 }
00076 
00077                 $query = "REPLACE INTO usr_defined_data ".
00078                         "SET ".$sql." ".
00079                         "usr_id = '".$this->getUserId()."'";
00080                 $this->db->query($query);
00081                 return true;
00082         }
00083 
00084         function toXML()
00085         {
00086                 include_once 'classes/class.ilXmlWriter.php';
00087                 $xml_writer = new ilXmlWriter();
00088                 
00089                 $this->addToXML ($xml_writer);
00090 
00091                 return $xml_writer->xmlDumpMem(false);
00092         }
00093         
00098         function addToXML($xml_writer) 
00099         {
00100                 include_once 'classes/class.ilUserDefinedFields.php';
00101                 $udf_obj =& ilUserDefinedFields::_getInstance();
00102 
00103                 foreach($udf_obj->getDefinitions() as $definition)
00104                 {
00105                         $xml_writer->xmlElement('UserDefinedField',
00106                                                                         array('Id' => $definition['il_id'],
00107                                                                                   'Name' => $definition['field_name']),
00108                                                                         $this->user_data["$definition[field_id]"]);
00109                 }               
00110         }
00111 
00112         // Private
00113         function __read()
00114         {
00115                 $this->user_data = array();
00116                 $query = "SELECT * FROM usr_defined_data ".
00117                         "WHERE usr_id = '".$this->usr_id."'";
00118                 $res = $this->db->query($query);
00119                 while($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
00120                 {
00121                         foreach($row as $field => $data)
00122                         {
00123                                 if($field != 'usr_id')
00124                                 {
00125                                         $this->user_data[$field] = $data;
00126                                 }
00127                         }
00128                 }
00129         }
00130 
00131 }
00132 ?>

Generated on Fri Dec 13 2013 13:52:08 for ILIAS Release_3_7_x_branch .rev 46817 by  doxygen 1.7.1