ILIAS  trunk Revision v11.0_alpha-1769-g99a433fe2dc
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilMDControlledVocabsUpdateSteps.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
23 
25 {
26  protected \ilDBInterface $db;
27 
28  public function prepare(\ilDBInterface $db): void
29  {
30  $this->db = $db;
31  }
32 
36  public function step_1(): void
37  {
38  if (!$this->db->tableExists('il_md_vocab_inactive')) {
39  $this->db->createTable(
40  'il_md_vocab_inactive',
41  [
42  'slot' => [
43  'type' => ilDBConstants::T_TEXT,
44  'notnull' => true,
45  'length' => 64
46  ]
47  ]
48  );
49  $this->db->addPrimaryKey('il_md_vocab_inactive', ['slot']);
50  }
51  }
52 
56  public function step_2(): void
57  {
58  if (!$this->db->tableExists('il_md_vocab_contr')) {
59  $this->db->createTable(
60  'il_md_vocab_contr',
61  [
62  'id' => [
63  'type' => ilDBConstants::T_INTEGER,
64  'notnull' => true,
65  'length' => 4
66  ],
67  'slot' => [
68  'type' => ilDBConstants::T_TEXT,
69  'notnull' => true,
70  'length' => 64
71  ],
72  'source' => [
73  'type' => ilDBConstants::T_TEXT,
74  'notnull' => true,
75  'length' => 64
76  ],
77  'active' => [
78  'type' => ilDBConstants::T_INTEGER,
79  'notnull' => true,
80  'length' => 1,
81  'default' => 1
82  ],
83  'custom_input' => [
84  'type' => ilDBConstants::T_INTEGER,
85  'notnull' => true,
86  'length' => 1,
87  'default' => 1
88  ],
89  ]
90  );
91  $this->db->addPrimaryKey('il_md_vocab_contr', ['id']);
92  $this->db->createSequence('il_md_vocab_contr');
93  }
94  }
95 
99  public function step_3(): void
100  {
101  if (!$this->db->tableExists('il_md_vocab_contr_vals')) {
102  $this->db->createTable(
103  'il_md_vocab_contr_vals',
104  [
105  'vocab_id' => [
106  'type' => ilDBConstants::T_INTEGER,
107  'notnull' => true,
108  'length' => 4
109  ],
110  'value' => [
111  'type' => ilDBConstants::T_TEXT,
112  'notnull' => true,
113  'length' => 255
114  ],
115  'label' => [
116  'type' => ilDBConstants::T_TEXT,
117  'notnull' => true,
118  'length' => 255
119  ]
120  ]
121  );
122  $this->db->addPrimaryKey('il_md_vocab_contr_vals', ['vocab_id', 'value']);
123  }
124  }
125 
129  public function step_4(): void
130  {
131  foreach ($this->getAllVocabSlots() as $slot) {
132  $table = $this->getTableForVocabSlot($slot);
133  $src_column = $this->getSourceColumnNameForVocabSlot($slot);
134 
135  if ($this->db->tableColumnExists($table, $src_column)) {
136  continue;
137  }
138  $this->db->addTableColumn(
139  $table,
140  $src_column,
141  [
142  'type' => ilDBConstants::T_TEXT,
143  'notnull' => true,
144  'length' => 64
145  ]
146  );
147  }
148  }
149 
153  public function step_5(): void
154  {
155  foreach ($this->getAllVocabSlots() as $slot) {
156  $table = $this->getTableForVocabSlot($slot);
157  $value_column = $this->getValueColumnNameForVocabSlot($slot);
158 
159  if (!$this->db->tableColumnExists($table, $value_column)) {
160  continue;
161  }
162  $this->db->modifyTableColumn(
163  $table,
164  $value_column,
165  [
166  'type' => ilDBConstants::T_TEXT,
167  'length' => 255
168  ]
169  );
170  }
171  }
172 
176  public function step_6(): void
177  {
178  foreach ($this->getAllVocabSlots() as $slot) {
179  $table = $this->getTableForVocabSlot($slot);
180  $value_column = $this->getValueColumnNameForVocabSlot($slot);
181 
182  foreach ($this->getTranslationsForVocabSlot($slot) as $new_value => $old_value) {
183  if ($new_value === $old_value) {
184  continue;
185  }
186  $this->db->update(
187  $table,
188  [$value_column => [ilDBConstants::T_TEXT, $new_value]],
189  [$value_column => [ilDBConstants::T_TEXT, $old_value]]
190  );
191  }
192  }
193  }
194 
198  public function step_7(): void
199  {
200  foreach ($this->getAllVocabSlots() as $slot) {
201  $table = $this->getTableForVocabSlot($slot);
202  $src_column = $this->getSourceColumnNameForVocabSlot($slot);
203  $value_column = $this->getValueColumnNameForVocabSlot($slot);
204  $standard_values = array_keys($this->getTranslationsForVocabSlot($slot));
205 
206  $this->db->manipulate(
207  'UPDATE ' . $this->db->quoteIdentifier($table) . ' SET ' .
208  $this->db->quoteIdentifier($src_column) . ' = ' .
209  $this->db->quote(VocabFactory::STANDARD_SOURCE, ilDBConstants::T_TEXT) .
210  ' WHERE ' . $this->db->in($value_column, $standard_values, false, ilDBConstants::T_TEXT)
211  );
212  }
213  }
214 
215  public function step_8(): void
216  {
217  foreach ($this->getAllVocabSlots() as $slot) {
218  $table = $this->getTableForVocabSlot($slot);
219  $src_column = $this->getSourceColumnNameForVocabSlot($slot);
220  if (!$this->db->tableColumnExists($table, $src_column)) {
221  continue;
222  }
223  $this->db->modifyTableColumn(
224  $table,
225  $src_column,
226  [
227  'default' => ""
228  ]
229  );
230  }
231  }
232 
236  protected function getAllVocabSlots(): \Generator
237  {
238  // Some slots are persisted in the same column and table, so only return one of them.
239  yield from [
240  SlotIdentifier::GENERAL_STRUCTURE,
241  SlotIdentifier::GENERAL_AGGREGATION_LEVEL,
242  SlotIdentifier::LIFECYCLE_STATUS,
243  SlotIdentifier::LIFECYCLE_CONTRIBUTE_ROLE,
244  //SlotIdentifier::METAMETADATA_CONTRIBUTE_ROLE,
245  SlotIdentifier::TECHNICAL_REQUIREMENT_TYPE,
246  SlotIdentifier::TECHNICAL_REQUIREMENT_BROWSER,
247  //SlotIdentifier::TECHNICAL_REQUIREMENT_OS,
248  SlotIdentifier::EDUCATIONAL_INTERACTIVITY_TYPE,
249  SlotIdentifier::EDUCATIONAL_INTERACTIVITY_LEVEL,
250  SlotIdentifier::EDUCATIONAL_SEMANTIC_DENSITY,
251  SlotIdentifier::EDUCATIONAL_DIFFICULTY,
252  SlotIdentifier::EDUCATIONAL_LEARNING_RESOURCE_TYPE,
253  SlotIdentifier::EDCUCATIONAL_INTENDED_END_USER_ROLE,
254  SlotIdentifier::EDUCATIONAL_CONTEXT,
255  SlotIdentifier::RIGHTS_COST,
256  SlotIdentifier::RIGHTS_CP_AND_OTHER_RESTRICTIONS,
257  SlotIdentifier::RELATION_KIND,
258  SlotIdentifier::CLASSIFICATION_PURPOSE
259  ];
260  }
261 
262  protected function getTableForVocabSlot(SlotIdentifier $slot): string
263  {
264  return match ($slot) {
265  SlotIdentifier::GENERAL_STRUCTURE,
266  SlotIdentifier::GENERAL_AGGREGATION_LEVEL => 'il_meta_general',
267  SlotIdentifier::LIFECYCLE_STATUS => 'il_meta_lifecycle',
268  SlotIdentifier::LIFECYCLE_CONTRIBUTE_ROLE,
269  SlotIdentifier::METAMETADATA_CONTRIBUTE_ROLE => 'il_meta_contribute',
270  SlotIdentifier::TECHNICAL_REQUIREMENT_TYPE,
271  SlotIdentifier::TECHNICAL_REQUIREMENT_BROWSER,
272  SlotIdentifier::TECHNICAL_REQUIREMENT_OS => 'il_meta_or_composite',
273  SlotIdentifier::EDUCATIONAL_INTERACTIVITY_TYPE,
274  SlotIdentifier::EDUCATIONAL_INTERACTIVITY_LEVEL,
275  SlotIdentifier::EDUCATIONAL_SEMANTIC_DENSITY,
276  SlotIdentifier::EDUCATIONAL_DIFFICULTY => 'il_meta_educational',
277  SlotIdentifier::EDUCATIONAL_LEARNING_RESOURCE_TYPE => 'il_meta_lr_type',
278  SlotIdentifier::EDCUCATIONAL_INTENDED_END_USER_ROLE => 'il_meta_end_usr_role',
279  SlotIdentifier::EDUCATIONAL_CONTEXT => 'il_meta_context',
280  SlotIdentifier::RIGHTS_COST,
281  SlotIdentifier::RIGHTS_CP_AND_OTHER_RESTRICTIONS => 'il_meta_rights',
282  SlotIdentifier::RELATION_KIND => 'il_meta_relation',
283  SlotIdentifier::CLASSIFICATION_PURPOSE => 'il_meta_classification',
284  default => ''
285  };
286  }
287 
288  protected function getValueColumnNameForVocabSlot(SlotIdentifier $slot): string
289  {
290  return match ($slot) {
291  SlotIdentifier::GENERAL_STRUCTURE => 'general_structure',
292  SlotIdentifier::GENERAL_AGGREGATION_LEVEL => 'general_aggl',
293  SlotIdentifier::LIFECYCLE_STATUS => 'lifecycle_status',
294  SlotIdentifier::LIFECYCLE_CONTRIBUTE_ROLE,
295  SlotIdentifier::METAMETADATA_CONTRIBUTE_ROLE => 'role',
296  SlotIdentifier::TECHNICAL_REQUIREMENT_TYPE => 'type',
297  SlotIdentifier::TECHNICAL_REQUIREMENT_BROWSER,
298  SlotIdentifier::TECHNICAL_REQUIREMENT_OS => 'name',
299  SlotIdentifier::EDUCATIONAL_INTERACTIVITY_TYPE => 'interactivity_type',
300  SlotIdentifier::EDUCATIONAL_LEARNING_RESOURCE_TYPE => 'learning_resource_type',
301  SlotIdentifier::EDUCATIONAL_INTERACTIVITY_LEVEL => 'interactivity_level',
302  SlotIdentifier::EDUCATIONAL_SEMANTIC_DENSITY => 'semantic_density',
303  SlotIdentifier::EDCUCATIONAL_INTENDED_END_USER_ROLE => 'intended_end_user_role',
304  SlotIdentifier::EDUCATIONAL_CONTEXT => 'context',
305  SlotIdentifier::EDUCATIONAL_DIFFICULTY => 'difficulty',
306  SlotIdentifier::RIGHTS_COST => 'costs',
307  SlotIdentifier::RIGHTS_CP_AND_OTHER_RESTRICTIONS => 'cpr_and_or',
308  SlotIdentifier::RELATION_KIND => 'kind',
309  SlotIdentifier::CLASSIFICATION_PURPOSE => 'purpose',
310  default => ''
311  };
312  }
313 
314  protected function getSourceColumnNameForVocabSlot(SlotIdentifier $slot): string
315  {
316  return match ($slot) {
317  SlotIdentifier::GENERAL_STRUCTURE => 'general_structure_src',
318  SlotIdentifier::GENERAL_AGGREGATION_LEVEL => 'general_aggl_src',
319  SlotIdentifier::LIFECYCLE_STATUS => 'lifecycle_status_src',
320  SlotIdentifier::LIFECYCLE_CONTRIBUTE_ROLE,
321  SlotIdentifier::METAMETADATA_CONTRIBUTE_ROLE => 'role_src',
322  SlotIdentifier::TECHNICAL_REQUIREMENT_TYPE => 'type_src',
323  SlotIdentifier::TECHNICAL_REQUIREMENT_BROWSER,
324  SlotIdentifier::TECHNICAL_REQUIREMENT_OS => 'name_src',
325  SlotIdentifier::EDUCATIONAL_INTERACTIVITY_TYPE => 'interactivity_type_src',
326  SlotIdentifier::EDUCATIONAL_LEARNING_RESOURCE_TYPE => 'learning_resource_type_src',
327  SlotIdentifier::EDUCATIONAL_INTERACTIVITY_LEVEL => 'interactivity_level_src',
328  SlotIdentifier::EDUCATIONAL_SEMANTIC_DENSITY => 'semantic_density_src',
329  SlotIdentifier::EDCUCATIONAL_INTENDED_END_USER_ROLE => 'intended_end_user_role_src',
330  SlotIdentifier::EDUCATIONAL_CONTEXT => 'context_src',
331  SlotIdentifier::EDUCATIONAL_DIFFICULTY => 'difficulty_src',
332  SlotIdentifier::RIGHTS_COST => 'costs_src',
333  SlotIdentifier::RIGHTS_CP_AND_OTHER_RESTRICTIONS => 'cpr_and_or_src',
334  SlotIdentifier::RELATION_KIND => 'kind_src',
335  SlotIdentifier::CLASSIFICATION_PURPOSE => 'purpose_src',
336  default => ''
337  };
338  }
339 
340  protected function getTranslationsForVocabSlot(SlotIdentifier $slot): array
341  {
342  return match ($slot) {
343  SlotIdentifier::GENERAL_AGGREGATION_LEVEL => [
344  '1' => '1',
345  '2' => '2',
346  '3' => '3',
347  '4' => '4'
348  ],
349  SlotIdentifier::TECHNICAL_REQUIREMENT_TYPE => [
350  'browser' => 'browser',
351  'operating system' => 'operating system'
352  ],
353  SlotIdentifier::GENERAL_STRUCTURE => [
354  'atomic' => 'Atomic',
355  'collection' => 'Collection',
356  'networked' => 'Networked',
357  'hierarchical' => 'Hierarchical',
358  'linear' => 'Linear'
359  ],
360  SlotIdentifier::LIFECYCLE_STATUS => [
361  'draft' => 'Draft',
362  'final' => 'Final',
363  'revised' => 'Revised',
364  'unavailable' => 'Unavailable'
365  ],
366  SlotIdentifier::LIFECYCLE_CONTRIBUTE_ROLE,
367  SlotIdentifier::METAMETADATA_CONTRIBUTE_ROLE => [
368  'author' => 'Author',
369  'publisher' => 'Publisher',
370  'unknown' => 'Unknown',
371  'initiator' => 'Initiator',
372  'terminator' => 'Terminator',
373  'editor' => 'Editor',
374  'graphical designer' => 'GraphicalDesigner',
375  'technical implementer' => 'TechnicalImplementer',
376  'content provider' => 'ContentProvider',
377  'technical validator' => 'TechnicalValidator',
378  'educational validator' => 'EducationalValidator',
379  'script writer' => 'ScriptWriter',
380  'instructional designer' => 'InstructionalDesigner',
381  'subject matter expert' => 'SubjectMatterExpert',
382  'creator' => 'Creator',
383  'validator' => 'Validator'
384  ],
385  SlotIdentifier::TECHNICAL_REQUIREMENT_BROWSER,
386  SlotIdentifier::TECHNICAL_REQUIREMENT_OS => [
387  'pc-dos' => 'PC-DOS',
388  'ms-windows' => 'MS-Windows',
389  'macos' => 'MacOS',
390  'unix' => 'Unix',
391  'multi-os' => 'Multi-OS',
392  'none' => 'None',
393  'any' => 'Any',
394  'netscape communicator' => 'NetscapeCommunicator',
395  'ms-internet explorer' => 'MS-InternetExplorer',
396  'opera' => 'Opera',
397  'amaya' => 'Amaya'
398  ],
399  SlotIdentifier::EDUCATIONAL_INTERACTIVITY_TYPE => [
400  'active' => 'Active',
401  'expositive' => 'Expositive',
402  'mixed' => 'Mixed'
403  ],
404  SlotIdentifier::EDUCATIONAL_LEARNING_RESOURCE_TYPE => [
405  'exercise' => 'Exercise',
406  'simulation' => 'Simulation',
407  'questionnaire' => 'Questionnaire',
408  'diagram' => 'Diagram',
409  'figure' => 'Figure',
410  'graph' => 'Graph',
411  'index' => 'Index',
412  'slide' => 'Slide',
413  'table' => 'Table',
414  'narrative text' => 'NarrativeText',
415  'exam' => 'Exam',
416  'experiment' => 'Experiment',
417  'problem statement' => 'ProblemStatement',
418  'self assessment' => 'SelfAssessment',
419  'lecture' => 'Lecture'
420  ],
421  SlotIdentifier::EDUCATIONAL_INTERACTIVITY_LEVEL,
422  SlotIdentifier::EDUCATIONAL_SEMANTIC_DENSITY => [
423  'very low' => 'VeryLow',
424  'low' => 'Low',
425  'medium' => 'Medium',
426  'high' => 'High',
427  'very high' => 'VeryHigh'
428  ],
429  SlotIdentifier::EDCUCATIONAL_INTENDED_END_USER_ROLE => [
430  'teacher' => 'Teacher',
431  'author' => 'Author',
432  'learner' => 'Learner',
433  'manager' => 'Manager'
434  ],
435  SlotIdentifier::EDUCATIONAL_CONTEXT => [
436  'school' => 'School',
437  'higher education' => 'HigherEducation',
438  'training' => 'Training',
439  'other' => 'Other'
440  ],
441  SlotIdentifier::EDUCATIONAL_DIFFICULTY => [
442  'very easy' => 'VeryEasy',
443  'easy' => 'Easy',
444  'medium' => 'Medium',
445  'difficult' => 'Difficult',
446  'very difficult' => 'VeryDifficult'
447  ],
448  SlotIdentifier::RIGHTS_COST,
449  SlotIdentifier::RIGHTS_CP_AND_OTHER_RESTRICTIONS => [
450  'yes' => 'Yes',
451  'no' => 'No'
452  ],
453  SlotIdentifier::RELATION_KIND => [
454  'ispartof' => 'IsPartOf',
455  'haspart' => 'HasPart',
456  'isversionof' => 'IsVersionOf',
457  'hasversion' => 'HasVersion',
458  'isformatof' => 'IsFormatOf',
459  'hasformat' => 'HasFormat',
460  'references' => 'References',
461  'isreferencedby' => 'IsReferencedBy',
462  'isbasedon' => 'IsBasedOn',
463  'isbasisfor' => 'IsBasisFor',
464  'requires' => 'Requires',
465  'isrequiredby' => 'IsRequiredBy'
466  ],
467  SlotIdentifier::CLASSIFICATION_PURPOSE => [
468  'discipline' => 'Discipline',
469  'idea' => 'Idea',
470  'prerequisite' => 'Prerequisite',
471  'educational objective' => 'EducationalObjective',
472  'accessibility restrictions' => 'AccessibilityRestrictions',
473  'educational level' => 'EducationalLevel',
474  'skill level' => 'SkillLevel',
475  'security level' => 'SecurityLevel',
476  'competency' => 'Competency'
477  ],
478  default => []
479  };
480  }
481 }
step_3()
Add a new table to store values and labels of controlled vocabularies.
step_4()
Add columns for the sources of all vocab values.
step_2()
Add a new table to store controlled vocabularies.
step_5()
Make more space in the columns of vocab values to hold controlled values.
step_1()
Add a new table to store deactivated standard vocabularies.
prepare(\ilDBInterface $db)
Prepare the execution of the steps.
step_7()
Fill source columns with the default value.