ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 public function getComponentType()
22  {
23  return IL_COMP_SERVICE;
24  }
25 
26  final public function getComponentName()
27  {
28  return "User";
29  }
30 
31  final public function getSlot()
32  {
33  return "UDFClaiming";
34  }
35 
36  final public function getSlotId()
37  {
38  return "udfc";
39  }
40 
41  final protected 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 $DIC;
77 
78  $ilDB = $DIC['ilDB'];
79 
80  $set = $ilDB->query("SELECT field_id FROM udf_definition" .
81  " WHERE field_id = " . $ilDB->quote($a_field_id, "integer"));
82  return (bool) $ilDB->numRows($set);
83  }
84 
91  protected static function getDBField($a_field_id)
92  {
93  global $DIC;
94 
95  $ilDB = $DIC['ilDB'];
96 
97  $set = $ilDB->query("SELECT * FROM udf_definition" .
98  " WHERE field_id = " . $ilDB->quote($a_field_id, "integer"));
99  return $ilDB->fetchAssoc($set);
100  }
101 
108  protected static function isValidFieldType($a_field_type)
109  {
110  // needed for the type constants
111  require_once "Services/User/classes/class.ilUserDefinedFields.php";
112 
114 
115  return in_array($a_field_type, $valid);
116  }
117 
124  protected static function handleAccesss(array &$fields, array $a_access = null, array $a_existing = null)
125  {
126  $map = array("visible", "changeable", "searchable", "required", "export",
127  "course_export", "group_export", "registration_visible", "visible_lua",
128  "changeable_lua", "certificate");
129  foreach ($map as $prop) {
130  if (isset($a_access[$prop])) {
131  $fields[$prop] = array("integer", (int) $a_access[$prop]);
132  } elseif (isset($a_existing[$prop])) {
133  $fields[$prop] = array("integer", (int) $a_existing[$prop]);
134  } else {
135  $fields[$prop] = array("integer", 0);
136  }
137  }
138  }
139 
149  public static function createDBField($a_type, $a_title, array $a_access = null, array $a_options = null)
150  {
151  global $DIC;
152 
153  $ilDB = $DIC['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  return;
161  }
162 
163  if ($a_type != UDF_TYPE_SELECT) {
164  $a_options = null;
165  }
166 
167  // :TODO: check unique title?
168 
169  $fields = array(
170  "field_id" => array("integer", $field_id),
171  "field_type" => array("integer", $a_type),
172  "field_name" => array("text", trim($a_title)),
173  "field_values" => array("text", serialize((array) $a_options))
174  );
175 
176  self::handleAccesss($fields, $a_access);
177 
178  $ilDB->insert("udf_definition", $fields);
179 
180  return $field_id;
181  }
182 
192  public static function updateDBField($a_field_id, $a_title, array $a_access = null, array $a_options = null)
193  {
194  global $DIC;
195 
196  $ilDB = $DIC['ilDB'];
197 
198  if (self::hasDBField($a_field_id)) {
199  $old = self::getDBField($a_field_id);
200 
201  if ($old["field_type"] != UDF_TYPE_SELECT) {
202  $a_options = null;
203  }
204 
205  $fields = array(
206  "field_name" => array("text", trim($a_title)),
207  "field_values" => array("text", serialize((array) $a_options))
208  );
209 
210  self::handleAccesss($fields, $a_access, $old);
211 
212  $ilDB->update(
213  "udf_definition",
214  $fields,
215  array("field_id" => array("integer", $a_field_id))
216  );
217  return true;
218  }
219 
220  return false;
221  }
222 
229  public static function deleteDBField($a_field_id)
230  {
231  global $DIC;
232 
233  $ilDB = $DIC['ilDB'];
234 
235  if (self::hasDBField($a_field_id)) {
236  // :TODO: we are not deleting any values here
237 
238  $ilDB->manipulate("DELETE FROM udf_definition" .
239  " WHERE field_id = " . $ilDB->quote($a_field_id, "integer"));
240  return true;
241  }
242 
243  return false;
244  }
245 }
const UDF_TYPE_SELECT
global $DIC
Definition: saml.php:7
static isValidFieldType($a_field_type)
Validate field type.
$valid
$a_context_id
Definition: workflow.php:97
checkPermission($a_user_id, $a_context_type, $a_context_id, $a_action_id, $a_action_sub_id)
Check permission.
static handleAccesss(array &$fields, array $a_access=null, array $a_existing=null)
Convert access array to DB columns.
static updateDBField($a_field_id, $a_title, array $a_access=null, array $a_options=null)
Update field db entry.
static createDBField($a_type, $a_title, array $a_access=null, array $a_options=null)
Create field db entry.
static getDBField($a_field_id)
Get existing field values.
$a_type
Definition: workflow.php:92
const UDF_TYPE_TEXT
const UDF_TYPE_WYSIWYG
$a_context_type
Definition: workflow.php:96
static deleteDBField($a_field_id)
Delete field db entry.
static hasDBField($a_field_id)
Check if field has db entry.
global $ilDB
Abstract parent class for all udf claiming plugin classes.
const IL_COMP_SERVICE