ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilExportUserSettings.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 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 
32 {
33  private $db;
34  private $user_id;
35  private $obj_id;
36  private $settings = array();
37 
44  public function __construct($a_user_id,$a_obj_id)
45  {
46  global $ilDB;
47 
48  $this->user_id = $a_user_id;
49  $this->obj_id = $a_obj_id;
50  $this->db = $ilDB;
51 
52  $this->read();
53  }
54 
61  public static function _delete($a_usr_id)
62  {
63  global $ilDB;
64 
65  $query = "DELETE FROM member_export_settings WHERE user_id = ".$ilDB->quote($a_usr_id);
66  $ilDB->query($query);
67  return true;
68  }
69 
77  public function set($a_data)
78  {
79  $this->settings = $a_data;
80  }
81 
89  public function enabled($a_option)
90  {
91  if(array_key_exists($a_option,(array) $this->settings) and $this->settings[$a_option])
92  {
93  return true;
94  }
95  return false;
96  }
97 
105  public function getOrderedExportableFields()
106  {
107  include_once('Services/PrivacySecurity/classes/class.ilPrivacySettings.php');
108  include_once('Services/PrivacySecurity/classes/class.ilExportFieldsInfo.php');
109  include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
110  include_once('Services/User/classes/class.ilUserDefinedFields.php');
111 
113 
114  $fields[] = 'role';
115  // Append agreement info
116  $privacy = ilPrivacySettings::_getInstance();
117  if($privacy->courseConfirmationRequired() or ilCourseDefinedFieldDefinition::_hasFields($this->obj_id))
118  {
119  $fields[] = 'agreement';
120  }
121 
122  foreach($field_info->getExportableFields() as $field)
123  {
124  if($this->enabled($field))
125  {
126  $fields[] = $field;
127  }
128  }
129 
131  foreach($udf->getCourseExportableFields() as $field_id => $udf_data)
132  {
133  $fields[] = 'udf_'.$field_id;
134  }
135 
136  // Add course specific fields
137  foreach(ilCourseDefinedFieldDefinition::_getFields($this->obj_id) as $field_obj)
138  {
139  if($this->enabled('cdf_'.$field_obj->getId()))
140  {
141  $fields[] = 'cdf_'.$field_obj->getId();
142  }
143  }
144  return $fields ? $fields : array();
145  }
146 
153  public function store()
154  {
155  global $ilDB;
156 
157  $query = "DELETE FROM member_usr_settings WHERE user_id = ".$this->db->quote($this->user_id ,'integer');
158  $res = $ilDB->manipulate($query);
159 
160  $query = "INSERT INTO member_usr_settings (user_id,settings) ".
161  "VALUES( ".
162  $this->db->quote($this->user_id ,'integer').", ".
163  $ilDB->quote(serialize($this->settings) ,'text')." ".
164  ")";
165  $res = $ilDB->manipulate($query);
166  $this->read();
167  }
168 
176  private function read()
177  {
178  $query = "SELECT * FROM member_usr_settings WHERE user_id = ".$this->db->quote($this->user_id ,'integer');
179  $res = $this->db->query($query);
180 
181  $this->settings = array();
182  if($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
183  {
184  $this->settings = unserialize($row->settings);
185  }
186  return true;
187  }
188 }
189 
190 ?>