ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilUDFClaimingPlugin.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 include_once("./Services/Component/classes/class.ilPlugin.php");
6 
15 abstract class ilUDFClaimingPlugin extends ilPlugin
16 {
17  //
18  // plugin slot
19  //
20 
21  final function getComponentType()
22  {
23  return IL_COMP_SERVICE;
24  }
25 
26  final function getComponentName()
27  {
28  return "User";
29  }
30 
31  final function getSlot()
32  {
33  return "UDFClaiming";
34  }
35 
36  final function getSlotId()
37  {
38  return "udfc";
39  }
40 
41  protected final function slotInit()
42  {
43  require_once "Services/User/classes/class.ilUDFPermissionHelper.php";
44  }
45 
46 
47  //
48  // permission
49  //
50 
61  abstract public function checkPermission($a_user_id, $a_context_type, $a_context_id, $a_action_id, $a_action_sub_id);
62 
63 
64  //
65  // db update helper
66  //
67 
74  public static function hasDBField($a_field_id)
75  {
76  global $ilDB;
77 
78  $set = $ilDB->query("SELECT field_id FROM udf_definition".
79  " WHERE field_id = ".$ilDB->quote($a_field_id, "integer"));
80  return (bool)$ilDB->numRows($set);
81  }
82 
89  protected static function getDBField($a_field_id)
90  {
91  global $ilDB;
92 
93  $set = $ilDB->query("SELECT * FROM udf_definition".
94  " WHERE field_id = ".$ilDB->quote($a_field_id, "integer"));
95  return $ilDB->fetchAssoc($set);
96  }
97 
104  protected static function isValidFieldType($a_field_type)
105  {
106  // needed for the type constants
107  require_once "Services/User/classes/class.ilUserDefinedFields.php";
108 
110 
111  return in_array($a_field_type, $valid);
112  }
113 
120  protected static function handleAccesss(array &$fields, array $a_access = null, array $a_existing = null)
121  {
122  $map = array("visible", "changeable", "searchable", "required", "export",
123  "course_export", "group_export", "registration_visible", "visible_lua",
124  "changeable_lua", "certificate");
125  foreach($map as $prop)
126  {
127  if(isset($a_access[$prop]))
128  {
129  $fields[$prop] = array("integer", (int)$a_access[$prop]);
130  }
131  else if(isset($a_existing[$prop]))
132  {
133  $fields[$prop] = array("integer", (int)$a_existing[$prop]);
134  }
135  else
136  {
137  $fields[$prop] = array("integer", 0);
138  }
139  }
140  }
141 
151  public static function createDBField($a_type, $a_title, array $a_access = null, array $a_options = null)
152  {
153  global $ilDB;
154 
155  $field_id = $ilDB->nextId("udf_definition");
156 
157  // validating type
158  $a_type = (int)$a_type;
159  if(!self::isValidFieldType($a_type))
160  {
161  return;
162  }
163 
164  if($a_type != UDF_TYPE_SELECT)
165  {
166  $a_options = null;
167  }
168 
169  // :TODO: check unique title?
170 
171  $fields = array(
172  "field_id" => array("integer", $field_id),
173  "field_type" => array("integer", $a_type),
174  "field_name" => array("text", trim($a_title)),
175  "field_values" => array("text", serialize((array)$a_options))
176  );
177 
178  self::handleAccesss($fields, $a_access);
179 
180  $ilDB->insert("udf_definition", $fields);
181 
182  return $field_id;
183  }
184 
194  public static function updateDBField($a_field_id, $a_title, array $a_access = null, array $a_options = null)
195  {
196  global $ilDB;
197 
198  if(self::hasDBField($a_field_id))
199  {
200  $old = self::getDBField($a_field_id);
201 
202  if($old["field_type"] != UDF_TYPE_SELECT)
203  {
204  $a_options = null;
205  }
206 
207  $fields = array(
208  "field_name" => array("text", trim($a_title)),
209  "field_values" => array("text", serialize((array)$a_options))
210  );
211 
212  self::handleAccesss($fields, $a_access, $old);
213 
214  $ilDB->update("udf_definition", $fields,
215  array("field_id" => array("integer", $a_field_id)));
216  return true;
217  }
218 
219  return false;
220  }
221 
228  public static function deleteDBField($a_field_id)
229  {
230  global $ilDB;
231 
232  if(self::hasDBField($a_field_id))
233  {
234  // :TODO: we are not deleting any values here
235 
236  $ilDB->manipulate("DELETE FROM udf_definition".
237  " WHERE field_id = ".$ilDB->quote($a_field_id, "integer"));
238  return true;
239  }
240 
241  return false;
242  }
243 }
244 
245 ?>