ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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
5include_once("./Services/Component/classes/class.ilPlugin.php");
6
15abstract 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 $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 if (isset($a_access[$prop])) {
127 $fields[$prop] = array("integer", (int) $a_access[$prop]);
128 } elseif (isset($a_existing[$prop])) {
129 $fields[$prop] = array("integer", (int) $a_existing[$prop]);
130 } else {
131 $fields[$prop] = array("integer", 0);
132 }
133 }
134 }
135
145 public static function createDBField($a_type, $a_title, array $a_access = null, array $a_options = null)
146 {
147 global $ilDB;
148
149 $field_id = $ilDB->nextId("udf_definition");
150
151 // validating type
152 $a_type = (int) $a_type;
153 if (!self::isValidFieldType($a_type)) {
154 return;
155 }
156
157 if ($a_type != UDF_TYPE_SELECT) {
158 $a_options = null;
159 }
160
161 // :TODO: check unique title?
162
163 $fields = array(
164 "field_id" => array("integer", $field_id),
165 "field_type" => array("integer", $a_type),
166 "field_name" => array("text", trim($a_title)),
167 "field_values" => array("text", serialize((array) $a_options))
168 );
169
170 self::handleAccesss($fields, $a_access);
171
172 $ilDB->insert("udf_definition", $fields);
173
174 return $field_id;
175 }
176
186 public static function updateDBField($a_field_id, $a_title, array $a_access = null, array $a_options = null)
187 {
188 global $ilDB;
189
190 if (self::hasDBField($a_field_id)) {
191 $old = self::getDBField($a_field_id);
192
193 if ($old["field_type"] != UDF_TYPE_SELECT) {
194 $a_options = null;
195 }
196
197 $fields = array(
198 "field_name" => array("text", trim($a_title)),
199 "field_values" => array("text", serialize((array) $a_options))
200 );
201
202 self::handleAccesss($fields, $a_access, $old);
203
204 $ilDB->update(
205 "udf_definition",
206 $fields,
207 array("field_id" => array("integer", $a_field_id))
208 );
209 return true;
210 }
211
212 return false;
213 }
214
221 public static function deleteDBField($a_field_id)
222 {
223 global $ilDB;
224
225 if (self::hasDBField($a_field_id)) {
226 // :TODO: we are not deleting any values here
227
228 $ilDB->manipulate("DELETE FROM udf_definition" .
229 " WHERE field_id = " . $ilDB->quote($a_field_id, "integer"));
230 return true;
231 }
232
233 return false;
234 }
235}
An exception for terminatinating execution or to throw for unit testing.
const IL_COMP_SERVICE
const UDF_TYPE_SELECT
const UDF_TYPE_WYSIWYG
const UDF_TYPE_TEXT
Abstract parent class for all udf claiming plugin classes.
static getDBField($a_field_id)
Get existing field values.
getComponentName()
Get Component Name.
static createDBField($a_type, $a_title, array $a_access=null, array $a_options=null)
Create field db entry.
static updateDBField($a_field_id, $a_title, array $a_access=null, array $a_options=null)
Update field db entry.
static deleteDBField($a_field_id)
Delete field db entry.
slotInit()
Object initialization done by slot.
static handleAccesss(array &$fields, array $a_access=null, array $a_existing=null)
Convert access array to DB columns.
static isValidFieldType($a_field_type)
Validate field type.
checkPermission($a_user_id, $a_context_type, $a_context_id, $a_action_id, $a_action_sub_id)
Check permission.
getComponentType()
Get Component Type.
static hasDBField($a_field_id)
Check if field has db entry.
$valid
$old
global $ilDB
$a_context_id
Definition: workflow.php:97
$a_type
Definition: workflow.php:92
$a_context_type
Definition: workflow.php:96