ILIAS  release_8 Revision v8.24
class.ilUDFClaimingPlugin.php
Go to the documentation of this file.
1<?php
2
23abstract class ilUDFClaimingPlugin extends ilPlugin
24{
25 //
26 // permission
27 //
28
32 abstract public function checkPermission(
33 int $a_user_id,
34 int $a_context_type,
35 int $a_context_id,
36 int $a_action_id,
37 int $a_action_sub_id
38 ): bool;
39
40
41 //
42 // db update helper
43 //
44
48 public static function hasDBField(string $a_field_id): bool
49 {
50 global $DIC;
51
52 $ilDB = $DIC['ilDB'];
53
54 $set = $ilDB->query("SELECT field_id FROM udf_definition" .
55 " WHERE field_id = " . $ilDB->quote($a_field_id, "integer"));
56 return (bool) $ilDB->numRows($set);
57 }
58
62 protected static function getDBField(string $a_field_id): array // Missing array type.
63 {
64 global $DIC;
65
66 $ilDB = $DIC['ilDB'];
67
68 $set = $ilDB->query("SELECT * FROM udf_definition" .
69 " WHERE field_id = " . $ilDB->quote($a_field_id, "integer"));
70 return $ilDB->fetchAssoc($set);
71 }
72
76 protected static function isValidFieldType(int $a_field_type): bool
77 {
79 return in_array($a_field_type, $valid);
80 }
81
85 protected static function handleAccesss(
86 array &$fields,
87 ?array $a_access = null,
88 ?array $a_existing = null
89 ): void {
90 $map = array("visible", "changeable", "searchable", "required", "export",
91 "course_export", "group_export", "registration_visible", "visible_lua",
92 "changeable_lua", "certificate");
93 foreach ($map as $prop) {
94 if (isset($a_access[$prop])) {
95 $fields[$prop] = array("integer", (int) $a_access[$prop]);
96 } elseif (isset($a_existing[$prop])) {
97 $fields[$prop] = array("integer", (int) $a_existing[$prop]);
98 } else {
99 $fields[$prop] = array("integer", 0);
100 }
101 }
102 }
103
107 public static function createDBField(
108 int $a_type,
109 string $a_title,
110 array $a_access = null,
111 array $a_options = null
112 ): ?int {
113 global $DIC;
114
115 $ilDB = $DIC['ilDB'];
116
117 $field_id = $ilDB->nextId("udf_definition");
118
119 // validating type
120 if (!self::isValidFieldType($a_type)) {
121 return null;
122 }
123
124 if ($a_type != UDF_TYPE_SELECT) {
125 $a_options = null;
126 }
127
128 // :TODO: check unique title?
129
130 $fields = array(
131 "field_id" => array("integer", $field_id),
132 "field_type" => array("integer", $a_type),
133 "field_name" => array("text", trim($a_title)),
134 "field_values" => array("text", serialize((array) $a_options))
135 );
136
137 self::handleAccesss($fields, $a_access);
138
139 $ilDB->insert("udf_definition", $fields);
140
141 return $field_id;
142 }
143
147 public static function updateDBField(
148 int $a_field_id,
149 string $a_title,
150 array $a_access = null,
151 array $a_options = null
152 ): bool {
153 global $DIC;
154
155 $ilDB = $DIC['ilDB'];
156
157 if (self::hasDBField($a_field_id)) {
158 $old = self::getDBField($a_field_id);
159
160 if ($old["field_type"] != UDF_TYPE_SELECT) {
161 $a_options = null;
162 }
163
164 $fields = array(
165 "field_name" => array("text", trim($a_title)),
166 "field_values" => array("text", serialize((array) $a_options))
167 );
168
169 self::handleAccesss($fields, $a_access, $old);
170
171 $ilDB->update(
172 "udf_definition",
173 $fields,
174 array("field_id" => array("integer", $a_field_id))
175 );
176 return true;
177 }
178
179 return false;
180 }
181
185 public static function deleteDBField(int $a_field_id): bool
186 {
187 global $DIC;
188
189 $ilDB = $DIC['ilDB'];
190
191 if (self::hasDBField($a_field_id)) {
192 // :TODO: we are not deleting any values here
193
194 $ilDB->manipulate("DELETE FROM udf_definition" .
195 " WHERE field_id = " . $ilDB->quote($a_field_id, "integer"));
196 return true;
197 }
198
199 return false;
200 }
201}
const UDF_TYPE_SELECT
const UDF_TYPE_WYSIWYG
const UDF_TYPE_TEXT
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static createDBField(int $a_type, string $a_title, array $a_access=null, array $a_options=null)
Create field db entry.
static deleteDBField(int $a_field_id)
Delete field db entry.
checkPermission(int $a_user_id, int $a_context_type, int $a_context_id, int $a_action_id, int $a_action_sub_id)
Check permission.
static getDBField(string $a_field_id)
Get existing field values.
static handleAccesss(array &$fields, ?array $a_access=null, ?array $a_existing=null)
Convert access array to DB columns.
static updateDBField(int $a_field_id, string $a_title, array $a_access=null, array $a_options=null)
Update field db entry.
static isValidFieldType(int $a_field_type)
Validate field type.
static hasDBField(string $a_field_id)
Check if field has db entry.
$valid
global $DIC
Definition: feed.php:28