ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
ilAdvancedMDClaimingPlugin Class Reference

Abstract parent class for all advanced md claiming plugin classes. More...

+ Inheritance diagram for ilAdvancedMDClaimingPlugin:
+ Collaboration diagram for ilAdvancedMDClaimingPlugin:

Public Member Functions

 checkPermission (int $a_user_id, int $a_context_type, int $a_context_id, int $a_action_id, int $a_action_sub_id)
 
- Public Member Functions inherited from ilPlugin
 getMessage ()
 
 __construct (\ilDBInterface $db, \ilComponentRepositoryWrite $component_repository, string $id)
 
 getPluginName ()
 
 getId ()
 
 getVersion ()
 Only very little classes seem to care about this: More...
 
 getDirectory ()
 Only very little classes seem to care about this: More...
 
 isActive ()
 Only very little classes seem to care about this: More...
 
 needsUpdate ()
 
 install ()
 
 uninstall ()
 
 activate ()
 This will update (if required) and activate the plugin. More...
 
 deactivate ()
 
 update ()
 
 loadLanguageModule ()
 Load language module for plugin. More...
 
 txt (string $a_var)
 Get Language Variable (prefix will be prepended automatically) More...
 
 getTemplate (string $a_template, bool $a_par1=true, bool $a_par2=true)
 ILIAS is moving towards UI components and plugins are expected to use these components. More...
 
 getStyleSheetLocation (string $a_css_file)
 ILIAS is moving towards UI components and plugins are expected to use these components. More...
 
 addBlockFile ($a_tpl, $a_var, $a_block, $a_tplname)
 ILIAS is moving towards UI components and plugins are expected to use these components. More...
 
 getGlobalScreenProviderCollection ()
 
 exchangeUIRendererAfterInitialization (\ILIAS\DI\Container $dic)
 This methods allows to replace the UI Renderer (see src/UI) of ILIAS after initialization by returning a closure returning a custom renderer. More...
 
 exchangeUIFactoryAfterInitialization (string $dic_key, \ILIAS\DI\Container $dic)
 This methods allows to replace some factory for UI Components (see src/UI) of ILIAS after initialization by returning a closure returning a custom factory. More...
 

Static Public Member Functions

static hasDBRecord (int $a_record_id)
 
static createDBRecord (string $a_title, string $a_description, bool $a_active, array $a_obj_types)
 
static updateDBRecord (int $a_record_id, string $a_title, string $a_description, bool $a_active, array $a_obj_types)
 Update record db entry. More...
 
static deleteDBRecord (int $a_record_id)
 
static hasDBField (int $a_field_id)
 
static createDBField (int $a_record_id, int $a_type, string $a_title, ?string $a_description=null, bool $a_searchable=false, array $a_definition=null)
 
static updateDBField (int $a_field_id, string $a_title, ?string $a_description=null, bool $a_searchable=false, ?array $a_definition=null)
 
static deleteDBField (int $a_field_id)
 
static setDBSubstitution (string $a_obj_type, bool $a_show_description, bool $a_show_field_names)
 
static hasDBFieldSubstitution (string $a_obj_type, int $a_field_id)
 
static setDBFieldSubstitution (string $a_obj_type, int $a_field_id, bool $a_bold=false, bool $a_newline=false)
 
static removeDBFieldSubstitution (string $a_obj_type, int $a_field_id)
 

Static Protected Member Functions

static isValidObjType (string $a_obj_type, bool $a_is_substitution=false)
 Validate object type. More...
 
static saveRecordObjTypes (int $a_record_id, array $a_obj_types)
 Save object type assignments for record. More...
 
static getDBFieldLastPosition (int $a_record_id)
 
static getDBSubstitution (string $a_obj_type, bool $a_include_field_data=false)
 

Additional Inherited Members

- Protected Member Functions inherited from ilPlugin
 init ()
 Object initialization. More...
 
 getPluginInfo ()
 
 getComponentInfo ()
 
 getPluginSlotInfo ()
 
 afterInstall ()
 If you cannot get rid of the requirement to use this, adjust the install method in your subclass instead. More...
 
 beforeUninstall ()
 If you cannot get rid of the requirement to use this, adjust the uninstall method in your subclass instead. More...
 
 afterUninstall ()
 If you cannot get rid of the requirement to use this, adjust the uninstall method in your subclass instead. More...
 
 beforeActivation ()
 If you cannot get rid of the requirement to use this, adjust the activate method in your subclass instead. More...
 
 afterActivation ()
 If you cannot get rid of the requirement to use this, adjust the activate method in your subclass instead. More...
 
 afterDeactivation ()
 If you cannot get rid of the requirement to use this, adjust the activate method in your subclass instead. More...
 
 updateDatabase ()
 
 beforeUpdate ()
 If you cannot get rid of the requirement to use this, adjust the update method in your subclass instead. More...
 
 afterUpdate ()
 
 getLanguageHandler ()
 
 buildLanguageHandler ()
 
- Protected Attributes inherited from ilPlugin
ilDBInterface $db
 
ilComponentRepositoryWrite $component_repository
 
string $id
 
ilPluginLanguage $language_handler = null
 
bool $lang_initialised = false
 
ProviderCollection $provider_collection
 
string $message = ''
 

Detailed Description

Abstract parent class for all advanced md claiming plugin classes.

Author
Jörg Lützenkirchen luetz.nosp@m.enki.nosp@m.rchen.nosp@m.@lei.nosp@m.fos.c.nosp@m.om

Definition at line 12 of file class.ilAdvancedMDClaimingPlugin.php.

Member Function Documentation

◆ checkPermission()

ilAdvancedMDClaimingPlugin::checkPermission ( int  $a_user_id,
int  $a_context_type,
int  $a_context_id,
int  $a_action_id,
int  $a_action_sub_id 
)
abstract

◆ createDBField()

static ilAdvancedMDClaimingPlugin::createDBField ( int  $a_record_id,
int  $a_type,
string  $a_title,
?string  $a_description = null,
bool  $a_searchable = false,
array  $a_definition = null 
)
static

Definition at line 197 of file class.ilAdvancedMDClaimingPlugin.php.

References $DIC, $ilDB, $res, IL_INST_ID, ilAdvancedMDFieldDefinition\isValidType(), ilDBConstants\T_INTEGER, ilDBConstants\T_TEXT, ilAdvancedMDFieldDefinition\TYPE_SELECT, and ilAdvancedMDFieldDefinition\TYPE_SELECT_MULTI.

204  : ?int {
205  global $DIC;
206 
207  $ilDB = $DIC->database();
208 
209  if (!self::hasDBRecord($a_record_id)) {
210  return null;
211  }
212 
213  $field_id = $ilDB->nextId("adv_mdf_definition");
214 
215  // validating type
217  return null;
218  }
219 
220  $options_in_different_table = $a_definition &&
223 
224  $pos = self::getDBFieldLastPosition($a_record_id) + 1;
225 
226  $fields = array(
227  "record_id" => array("integer", $a_record_id),
228  "field_id" => array("integer", $field_id),
229  "import_id" => array("text", "il_" . IL_INST_ID . "_adv_md_field_" . $field_id),
230  "field_type" => array("integer", $a_type),
231  "position" => array("integer", $pos),
232  "title" => array("text", trim($a_title)),
233  "description" => array("text", trim((string) $a_description)),
234  "searchable" => array("integer", (int) $a_searchable)
235  );
236  if ($a_definition && !$options_in_different_table) {
237  $fields["field_values"] = array("text", serialize($a_definition));
238  }
239  $ilDB->insert("adv_mdf_definition", $fields);
240 
241  if ($options_in_different_table) {
242  $ilDB->manipulate(
243  'DELETE FROM adv_mdf_enum WHERE field_id = ' .
244  $ilDB->quote($field_id, ilDBConstants::T_INTEGER)
245  );
246 
247  $default_language = '';
248  $res = $ilDB->query(
249  'SELECT lang_default FROM adv_md_record WHERE record_id = ' .
250  $ilDB->quote($a_record_id, 'integer')
251  );
252  if ($row = $res->fetchAssoc()) {
253  $default_language = (string) $row['lang_default'];
254  }
255 
256  $idx = 0;
257  foreach ($a_definition as $option) {
258  if (!is_string($option)) {
259  continue;
260  }
261  $ilDB->insert(
262  'adv_mdf_enum',
263  [
264  'field_id' => [ilDBConstants::T_INTEGER, $field_id],
265  'lang_code' => [ilDBConstants::T_TEXT, $default_language],
266  'idx' => [ilDBConstants::T_INTEGER, $idx],
267  'value' => [ilDBConstants::T_TEXT, $option],
268  'position' => [ilDBConstants::T_INTEGER, $idx]
269  ]
270  );
271  $idx++;
272  }
273  }
274 
275  return $field_id;
276  }
$res
Definition: ltiservices.php:69
const IL_INST_ID
Definition: constants.php:40
const TYPE_SELECT
TODO: put this in when minimum php version is set to 8.2.
global $DIC
Definition: shib_login.php:25
+ Here is the call graph for this function:

◆ createDBRecord()

static ilAdvancedMDClaimingPlugin::createDBRecord ( string  $a_title,
string  $a_description,
bool  $a_active,
array  $a_obj_types 
)
static
Parameters
string$a_title
string$a_description
bool$a_active
string[]$a_obj_types
Returns
int

Definition at line 39 of file class.ilAdvancedMDClaimingPlugin.php.

References $DIC, $ilDB, and IL_INST_ID.

44  : int {
45  global $DIC;
46 
47  $ilDB = $DIC->database();
48 
49  $record_id = $ilDB->nextId("adv_md_record");
50 
51  $fields = array(
52  "record_id" => array("integer", $record_id),
53  "import_id" => array("text", 'il_' . IL_INST_ID . '_adv_md_record_' . $record_id),
54  "title" => array("text", trim($a_title)),
55  "description" => array("text", trim($a_description)),
56  "active" => array("integer", (int) $a_active)
57  );
58  $ilDB->insert("adv_md_record", $fields);
59  self::saveRecordObjTypes($record_id, $a_obj_types);
60  return $record_id;
61  }
const IL_INST_ID
Definition: constants.php:40
global $DIC
Definition: shib_login.php:25

◆ deleteDBField()

static ilAdvancedMDClaimingPlugin::deleteDBField ( int  $a_field_id)
static

Definition at line 310 of file class.ilAdvancedMDClaimingPlugin.php.

References $DIC, and $ilDB.

310  : bool
311  {
312  global $DIC;
313 
314  $ilDB = $DIC['ilDB'];
315 
316  if (self::hasDBField($a_field_id)) {
317  $ilDB->manipulate("DELETE FROM adv_mdf_definition" .
318  " WHERE field_id = " . $ilDB->quote($a_field_id, "integer"));
319  return true;
320  }
321 
322  return false;
323  }
global $DIC
Definition: shib_login.php:25

◆ deleteDBRecord()

static ilAdvancedMDClaimingPlugin::deleteDBRecord ( int  $a_record_id)
static

Definition at line 152 of file class.ilAdvancedMDClaimingPlugin.php.

References $DIC, and $ilDB.

152  : bool
153  {
154  global $DIC;
155 
156  $ilDB = $DIC->database();
157 
158  if (self::hasDBRecord($a_record_id)) {
159  $ilDB->manipulate("DELETE FROM adv_md_record" .
160  " WHERE record_id = " . $ilDB->quote($a_record_id, "integer"));
161  return true;
162  }
163 
164  return false;
165  }
global $DIC
Definition: shib_login.php:25

◆ getDBFieldLastPosition()

static ilAdvancedMDClaimingPlugin::getDBFieldLastPosition ( int  $a_record_id)
staticprotected
See also
ilAdvancedMDFieldDefinition::getLastPosition()

Definition at line 180 of file class.ilAdvancedMDClaimingPlugin.php.

References $DIC, and $ilDB.

180  : int
181  {
182  global $DIC;
183 
184  $ilDB = $DIC->database();
185 
186  $sql = "SELECT max(position) pos" .
187  " FROM adv_mdf_definition" .
188  " WHERE record_id = " . $ilDB->quote($a_record_id, "integer");
189  $set = $ilDB->query($sql);
190  if ($ilDB->numRows($set)) {
191  $pos = $ilDB->fetchAssoc($set);
192  return (int) $pos["pos"];
193  }
194  return 0;
195  }
global $DIC
Definition: shib_login.php:25

◆ getDBSubstitution()

static ilAdvancedMDClaimingPlugin::getDBSubstitution ( string  $a_obj_type,
bool  $a_include_field_data = false 
)
staticprotected

Definition at line 325 of file class.ilAdvancedMDClaimingPlugin.php.

References $DIC, $ilDB, and $res.

325  : array
326  {
327  global $DIC;
328 
329  $ilDB = $DIC->database();
330 
331  $set = $ilDB->query("SELECT * FROM adv_md_substitutions" .
332  " WHERE obj_type = " . $ilDB->quote($a_obj_type, "text"));
333  if ($ilDB->numRows($set)) {
334  $res = $ilDB->fetchAssoc($set);
335  $res["hide_description"] = array("integer", (bool) $res["hide_description"]);
336  $res["hide_field_names"] = array("integer", (bool) $res["hide_field_names"]);
337 
338  if ($a_include_field_data) {
339  $res["substitution"] = array("text", (array) unserialize($res["substitution"]));
340  } else {
341  unset($res["substitution"]);
342  }
343  unset($res["obj_type"]);
344 
345  return $res;
346  }
347  return [];
348  }
$res
Definition: ltiservices.php:69
global $DIC
Definition: shib_login.php:25

◆ hasDBField()

static ilAdvancedMDClaimingPlugin::hasDBField ( int  $a_field_id)
static

Definition at line 167 of file class.ilAdvancedMDClaimingPlugin.php.

References $DIC, and $ilDB.

167  : bool
168  {
169  global $DIC;
170  $ilDB = $DIC->database();
171 
172  $set = $ilDB->query("SELECT field_id FROM adv_mdf_definition" .
173  " WHERE field_id = " . $ilDB->quote($a_field_id, "integer"));
174  return (bool) $ilDB->numRows($set);
175  }
global $DIC
Definition: shib_login.php:25

◆ hasDBFieldSubstitution()

static ilAdvancedMDClaimingPlugin::hasDBFieldSubstitution ( string  $a_obj_type,
int  $a_field_id 
)
static

Definition at line 386 of file class.ilAdvancedMDClaimingPlugin.php.

386  : bool
387  {
388  if (self::isValidObjType($a_obj_type, true)) {
389  $fields = self::getDBSubstitution($a_obj_type, true);
390  $fields = $fields["substitution"][1];
391  foreach ($fields as $field) {
392  if ($field["field_id"] == $a_field_id) {
393  return true;
394  }
395  }
396  }
397  return false;
398  }

◆ hasDBRecord()

static ilAdvancedMDClaimingPlugin::hasDBRecord ( int  $a_record_id)
static

Definition at line 22 of file class.ilAdvancedMDClaimingPlugin.php.

References $DIC, and $ilDB.

22  : bool
23  {
24  global $DIC;
25  $ilDB = $DIC->database();
26 
27  $set = $ilDB->query("SELECT record_id FROM adv_md_record" .
28  " WHERE record_id = " . $ilDB->quote($a_record_id, "integer"));
29  return (bool) $ilDB->numRows($set);
30  }
global $DIC
Definition: shib_login.php:25

◆ isValidObjType()

static ilAdvancedMDClaimingPlugin::isValidObjType ( string  $a_obj_type,
bool  $a_is_substitution = false 
)
staticprotected

Validate object type.

Todo:
support ecs type

Definition at line 67 of file class.ilAdvancedMDClaimingPlugin.php.

References $valid.

67  : bool
68  {
69  // ecs not supported yet
70  $valid = ["crs", "cat", "book", "wiki", "glo", "orgu", "prg", 'grp', 'iass'];
71 
72  if (!$a_is_substitution) {
73  $valid[] = "orgu";
74  $valid[] = "prg";
75  }
76 
77  return in_array($a_obj_type, $valid);
78  }
$valid

◆ removeDBFieldSubstitution()

static ilAdvancedMDClaimingPlugin::removeDBFieldSubstitution ( string  $a_obj_type,
int  $a_field_id 
)
static

Definition at line 448 of file class.ilAdvancedMDClaimingPlugin.php.

References $DIC, and $ilDB.

448  : bool
449  {
450  global $DIC;
451 
452  $ilDB = $DIC->database();
453 
454  if (self::isValidObjType($a_obj_type, true)) {
455  $fields = self::getDBSubstitution($a_obj_type, true);
456  if (!$fields) {
457  return true;
458  } else {
459  $fields = $fields["substitution"][1];
460  }
461 
462  $found = false;
463  foreach ($fields as $idx => $field) {
464  if ($field["field_id"] == $a_field_id) {
465  unset($fields[$idx]);
466  $found = true;
467  break;
468  }
469  }
470  if ($found) {
471  $fields = array("substitution" => array("text", serialize($fields)));
472  $ilDB->update(
473  "adv_md_substitutions",
474  $fields,
475  array("obj_type" => array("text", $a_obj_type))
476  );
477  }
478  return true;
479  }
480  return false;
481  }
global $DIC
Definition: shib_login.php:25

◆ saveRecordObjTypes()

static ilAdvancedMDClaimingPlugin::saveRecordObjTypes ( int  $a_record_id,
array  $a_obj_types 
)
staticprotected

Save object type assignments for record.

Parameters
int$a_record_id
string[]$a_obj_types

Definition at line 85 of file class.ilAdvancedMDClaimingPlugin.php.

References $DIC, and $ilDB.

85  : void
86  {
87  global $DIC;
88  $ilDB = $DIC->database();
89 
90  foreach ($a_obj_types as $type) {
91  if (!is_array($type)) {
92  $type = strtolower(trim($type));
93  $subtype = "-";
94  } else {
95  $subtype = strtolower(trim($type[1]));
96  $type = strtolower(trim($type[0]));
97  }
98 
99  if (self::isValidObjType($type)) {
100  $fields = array(
101  "record_id" => array("integer", $a_record_id),
102  "obj_type" => array("text", $type),
103  "sub_type" => array("text", $subtype)
104  );
105  $ilDB->insert("adv_md_record_objs", $fields);
106  }
107  }
108  }
global $DIC
Definition: shib_login.php:25

◆ setDBFieldSubstitution()

static ilAdvancedMDClaimingPlugin::setDBFieldSubstitution ( string  $a_obj_type,
int  $a_field_id,
bool  $a_bold = false,
bool  $a_newline = false 
)
static

Definition at line 400 of file class.ilAdvancedMDClaimingPlugin.php.

References $DIC, and $ilDB.

405  : bool {
406  global $DIC;
407 
408  $ilDB = $DIC->database();
409 
410  if (self::isValidObjType($a_obj_type, true)) {
411  $fields = self::getDBSubstitution($a_obj_type, true);
412  if (!$fields) {
413  self::setDBSubstitution($a_obj_type, true, true);
414  $fields = array();
415  } else {
416  $fields = $fields["substitution"][1];
417  }
418 
419  $found = false;
420  foreach ($fields as $idx => $field) {
421  if ($field["field_id"] == $a_field_id) {
422  $fields[$idx]["bold"] = $a_bold;
423  $fields[$idx]["newline"] = $a_newline;
424  $found = true;
425  break;
426  }
427  }
428  if (!$found) {
429  $fields[] = array(
430  "field_id" => $a_field_id
431  ,
432  "bold" => $a_bold
433  ,
434  "newline" => $a_newline
435  );
436  }
437 
438  $fields = array("substitution" => array("text", serialize($fields)));
439  $ilDB->update(
440  "adv_md_substitutions",
441  $fields,
442  array("obj_type" => array("text", $a_obj_type))
443  );
444  }
445  return false;
446  }
global $DIC
Definition: shib_login.php:25

◆ setDBSubstitution()

static ilAdvancedMDClaimingPlugin::setDBSubstitution ( string  $a_obj_type,
bool  $a_show_description,
bool  $a_show_field_names 
)
static

Definition at line 350 of file class.ilAdvancedMDClaimingPlugin.php.

References $DIC, and $ilDB.

354  : bool {
355  global $DIC;
356 
357  $ilDB = $DIC->database();
358 
359  if (self::isValidObjType($a_obj_type, true)) {
360  $fields = self::getDBSubstitution($a_obj_type);
361 
362  $create = false;
363  if (!$fields) {
364  $create = true;
365  $fields = array("obj_type" => array("text", $a_obj_type));
366  }
367 
368  $fields["hide_description"] = array("integer", !$a_show_description);
369  $fields["hide_field_names"] = array("integer", !$a_show_field_names);
370 
371  if ($create) {
372  $ilDB->insert("adv_md_substitutions", $fields);
373  } else {
374  $ilDB->update(
375  "adv_md_substitutions",
376  $fields,
377  array("obj_type" => array("text", $a_obj_type))
378  );
379  }
380 
381  return true;
382  }
383  return false;
384  }
global $DIC
Definition: shib_login.php:25

◆ updateDBField()

static ilAdvancedMDClaimingPlugin::updateDBField ( int  $a_field_id,
string  $a_title,
?string  $a_description = null,
bool  $a_searchable = false,
?array  $a_definition = null 
)
static

Definition at line 278 of file class.ilAdvancedMDClaimingPlugin.php.

References $DIC, and $ilDB.

284  : bool {
285  global $DIC;
286 
287  $ilDB = $DIC->database();
288 
289  if (self::hasDBField($a_field_id)) {
290  $fields = array(
291  "field_id" => array("integer", $a_field_id),
292  "title" => array("text", trim($a_title)),
293  "description" => array("text", trim($a_description)),
294  "searchable" => array("integer", (int) $a_searchable)
295  );
296  if ($a_definition) {
297  $fields["field_values"] = array("text", serialize($a_definition));
298  }
299  $ilDB->update(
300  "adv_mdf_definition",
301  $fields,
302  array("field_id" => array("integer", $a_field_id))
303  );
304  return true;
305  }
306 
307  return false;
308  }
global $DIC
Definition: shib_login.php:25

◆ updateDBRecord()

static ilAdvancedMDClaimingPlugin::updateDBRecord ( int  $a_record_id,
string  $a_title,
string  $a_description,
bool  $a_active,
array  $a_obj_types 
)
static

Update record db entry.

Parameters
int$a_record_id
string$a_title
string$a_description
bool$a_active
string[]$a_obj_types
Returns
bool

Definition at line 119 of file class.ilAdvancedMDClaimingPlugin.php.

References $DIC, and $ilDB.

125  : bool {
126  global $DIC;
127 
128  $ilDB = $DIC->database();
129 
130  if (self::hasDBRecord($a_record_id)) {
131  $fields = array(
132  "title" => array("text", trim($a_title)),
133  "description" => array("text", trim($a_description)),
134  "active" => array("integer", (int) $a_active)
135  );
136  $ilDB->update(
137  "adv_md_record",
138  $fields,
139  array("record_id" => array("integer", $a_record_id))
140  );
141 
142  $ilDB->manipulate("DELETE FROM adv_md_record_objs" .
143  " WHERE record_id = " . $ilDB->quote($a_record_id, "integer"));
144 
145  self::saveRecordObjTypes($a_record_id, $a_obj_types);
146 
147  return true;
148  }
149  return false;
150  }
global $DIC
Definition: shib_login.php:25

The documentation for this class was generated from the following file: