Skip to content

Commit

Permalink
MetaData: add db tables, some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
schmitz-ilias committed Sep 26, 2024
1 parent 0c2ef02 commit 86ed6c4
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class ilMDCopyrightTableGUI extends ilTable2GUI
{
protected UIFactory $ui_factory;
protected UIRenderer $ui_renderer;
protected ilMDSettingsModalService $modal_service;

protected bool $has_write;

Expand All @@ -49,9 +48,6 @@ public function __construct(

$this->ui_factory = $DIC->ui()->factory();
$this->ui_renderer = $DIC->ui()->renderer();
$this->modal_service = new ilMDSettingsModalService(
$this->ui_factory
);

$this->has_write = $has_write;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,16 @@ public function __construct(
PresentationUtilities $presentation_utils,
VocabPresentation $vocab_presentation,
SlotHandler $slot_handler,
Structure $structure
Structure $structure,
NavigatorFactory $navigator_factory
) {
$this->vocab_manager = $vocab_manager;
$this->elements_presentation = $elements_presentation;
$this->presentation_utils = $presentation_utils;
$this->vocab_presentation = $vocab_presentation;
$this->slot_handler = $slot_handler;
$this->structure = $structure;
$this->navigator_factory = $navigator_factory;
}

public function getRows(
Expand Down Expand Up @@ -102,7 +104,7 @@ public function getRows(
$vocab->isActive() && !$infos->isDeactivatable($vocab)
)->withDisabledAction(
'toggle_custom_input',
$infos->canDisallowCustomInput($vocab)
!$infos->canDisallowCustomInput($vocab)
);
};
}
Expand Down Expand Up @@ -150,7 +152,7 @@ protected function translateSlot(SlotIdentifier $slot): string
$element
);
$condition_element_name = $this->elements_presentation->nameWithParents(
$element,
$condition_element,
$this->findFirstCommonParent($element, $condition_element)->getSuperElement(),
false,
in_array($element->getDefinition()->dataType(), $skip_data),
Expand Down Expand Up @@ -211,6 +213,14 @@ protected function buildValuesPreview(VocabularyInterface $vocabulary): string
break;
}

if (
$vocabulary->type() === VocabType::STANDARD ||
$vocabulary->type() === VocabType::COPYRIGHT
) {
$presentable_values[] = $labelled_value->label();
continue;
}

$presentable_value = $labelled_value->value();
if ($labelled_value->label() !== '') {
$presentable_value = $labelled_value->label() . ' (' . $presentable_value . ')';
Expand All @@ -227,7 +237,7 @@ protected function getVocabs(Range $range = null): array
return $this->vocabs;
}

$vocabs = iterator_to_array($this->vocab_manager->getAllVocabularies());
$vocabs = iterator_to_array($this->vocab_manager->getAllVocabularies(), false);
if ($range) {
$vocabs = array_slice($vocabs, $range->getStart(), $range->getLength());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
use ILIAS\MetaData\Paths\FactoryInterface as PathFactory;
use ILIAS\MetaData\Settings\Vocabularies\Import\Importer;
use ILIAS\MetaData\Vocabularies\Slots\HandlerInterface as SlotHandler;
use ILIAS\MetaData\Presentation\ElementsInterface as ElementsPresentation;
use ILIAS\MetaData\Presentation\UtilitiesInterface as PresentationUtilities;
use ILIAS\MetaData\Vocabularies\Dispatch\Presentation\PresentationInterface as VocabPresentation;
use ILIAS\MetaData\Elements\Structure\StructureSetInterface as Structure;
use ILIAS\MetaData\Paths\Navigator\NavigatorFactoryInterface as NavigatorFactory;
use ILIAS\MetaData\Services\InternalServices;

/**
* @ilCtrl_Calls ilMDVocabulariesGUI: ilMDVocabularyUploadHandlerGUI
Expand All @@ -44,7 +50,12 @@ class ilMDVocabulariesGUI
protected Filesystem $temp_files;
protected VocabManager $vocab_manager;
protected PathFactory $path_factory;
protected NavigatorFactory $navigator_factory;
protected Structure $structure;
protected SlotHandler $slot_handler;
protected ElementsPresentation $elements_presentation;
protected PresentationUtilities $presentation_utils;
protected VocabPresentation $vocab_presentation;
protected ilGlobalTemplateInterface $tpl;
protected ilLanguage $lng;
protected ilToolbarGUI $toolbar;
Expand All @@ -57,6 +68,17 @@ public function __construct(ilObjMDSettingsGUI $parent_obj_gui)
{
global $DIC;

$services = new InternalServices($DIC);

$this->vocab_manager = $services->vocabularies()->manager();
$this->elements_presentation = $services->presentation()->elements();
$this->presentation_utils = $services->presentation()->utilities();
$this->vocab_presentation = $services->vocabularies()->presentation();
$this->slot_handler = $services->vocabularies()->slotHandler();
$this->structure = $services->structure()->structure();
$this->path_factory = $services->paths()->pathFactory();
$this->navigator_factory = $services->paths()->navigatorFactory();

$this->ctrl = $DIC->ctrl();
$this->http = $DIC->http();
$this->temp_files = $DIC->filesystem()->temp();
Expand Down Expand Up @@ -245,7 +267,15 @@ protected function getTable(): DataTable
return $this->ui_factory->table()->data(
$this->lng->txt('md_vocab_table_title'),
$columns,
new ilMDVocabulariesDataRetrieval()
new ilMDVocabulariesDataRetrieval(
$this->vocab_manager,
$this->elements_presentation,
$this->presentation_utils,
$this->vocab_presentation,
$this->slot_handler,
$this->structure,
$this->navigator_factory
)
)->withActions($actions)->withRequest($this->http->request());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,77 @@ public function step_1(): void
$this->db->addPrimaryKey('il_md_vocab_inactive', ['slot']);
}
}

/**
* Add a new table to store controlled vocabularies.
*/
public function step_2(): void
{
if (!$this->db->tableExists('il_md_vocab_contr')) {
$this->db->createTable(
'il_md_vocab_contr',
[
'id' => [
'type' => ilDBConstants::T_INTEGER,
'notnull' => true,
'length' => 4
],
'slot' => [
'type' => ilDBConstants::T_TEXT,
'notnull' => true,
'length' => 64
],
'source' => [
'type' => ilDBConstants::T_TEXT,
'notnull' => true,
'length' => 64
],
'active' => [
'type' => ilDBConstants::T_INTEGER,
'notnull' => true,
'length' => 1,
'default' => 1
],
'custom_input' => [
'type' => ilDBConstants::T_INTEGER,
'notnull' => true,
'length' => 1,
'default' => 1
],
]
);
$this->db->addPrimaryKey('il_md_vocab_contr', ['id']);
$this->db->createSequence('il_md_vocab_contr');
}
}

/**
* Add a new table to store values and labels of controlled vocabularies.
*/
public function step_3(): void
{
if (!$this->db->tableExists('il_md_vocab_contr_vals')) {
$this->db->createTable(
'il_md_vocab_contr_vals',
[
'vocab_id' => [
'type' => ilDBConstants::T_INTEGER,
'notnull' => true,
'length' => 4
],
'value' => [
'type' => ilDBConstants::T_TEXT,
'notnull' => true,
'length' => 300
],
'label' => [
'type' => ilDBConstants::T_TEXT,
'notnull' => true,
'length' => 300
]
]
);
$this->db->addPrimaryKey('il_md_vocab_contr_vals', ['vocab_id', 'value']);
}
}
}
10 changes: 5 additions & 5 deletions Services/MetaData/classes/Vocabularies/Controlled/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function addValueToVocabulary(
return;
}
$this->db->insert(
'il_md_vocab_contr_values',
'il_md_vocab_contr_vals',
[
'vocab_id' => [\ilDBConstants::T_INTEGER, $vocab_id],
'value' => [\ilDBConstants::T_TEXT, $value],
Expand All @@ -106,7 +106,7 @@ public function findAlreadyExistingValues(
string ...$values
): \Generator {
$result = $this->db->query(
'SELECT value FROM il_md_vocab_contr_values JOIN il_md_vocab_contr ON vocab_id
'SELECT value FROM il_md_vocab_contr_vals JOIN il_md_vocab_contr ON vocab_id
WHERE slot = ' . $this->db->quoteAsString($slot->value) . ' AND ' .
$this->db->in('value', ...$values)
);
Expand Down Expand Up @@ -171,7 +171,7 @@ public function getLabelsForValues(
}

$result = $this->db->query(
'SELECT value, label FROM il_md_vocab_contr_values JOIN il_md_vocab_contr ON vocab_id
'SELECT value, label FROM il_md_vocab_contr_vals JOIN il_md_vocab_contr ON vocab_id
WHERE slot = ' . $this->db->quoteAsString($slot->value) . ' AND ' .
$this->db->in('value', ...$values)
);
Expand Down Expand Up @@ -209,7 +209,7 @@ public function setCustomInputsAllowedForVocabulary(
public function deleteVocabulary(string $vocab_id): void
{
$this->db->manipulate(
'DELETE FROM il_md_vocab_contr_values WHERE vocab_id = ' .
'DELETE FROM il_md_vocab_contr_vals WHERE vocab_id = ' .
$this->db->quoteAsString($vocab_id)
);
$this->db->manipulate(
Expand Down Expand Up @@ -274,7 +274,7 @@ protected function getVocabularyFromRow(array $row): VocabularyInterface
protected function readVocabularyValues(string $vocab_id): \Generator
{
$result = $this->db->query(
'SELECT value FROM il_md_vocab_contr_values WHERE vocab_id = ' .
'SELECT value FROM il_md_vocab_contr_vals WHERE vocab_id = ' .
$this->db->quoteAsInteger($vocab_id)
);
foreach ($result as $row) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public function vocabulary(SlotIdentifier $slot): ?VocabularyInterface
foreach ($this->copyright_repository->getAllEntries() as $copyright) {
$values[] = $this->identifier_handler->buildIdentifierFromEntryID($copyright->id());
}

if (empty($values)) {
return null;
}
Expand Down
3 changes: 2 additions & 1 deletion Services/MetaData/classes/Vocabularies/Slots/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function pathForSlot(Identifier $identifier): PathInterface

public function isSlotConditional(Identifier $identifier): bool
{
return is_null($this->conditionForSlot($identifier));
return !is_null($this->conditionForSlot($identifier));
}

public function conditionForSlot(Identifier $identifier): ?ConditionInterface
Expand Down Expand Up @@ -177,6 +177,7 @@ protected function buildCondition(
foreach ($steps_to_condition as $step) {
if ($step === StepToken::SUPER) {
$builder = $builder->withNextStepToSuperElement();
continue;
}
$builder = $builder->withNextStep($step);
}
Expand Down
14 changes: 7 additions & 7 deletions Services/MetaData/classes/Vocabularies/Slots/Identifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,20 @@ enum Identifier: string
case GENERAL_COVERAGE = 'general_coverage';
case GENERAL_IDENTIFIER_CATALOG = 'general_identifier_catalog';
case LIFECYCLE_STATUS = 'lifecycle_status';
case LIFECYCLE_CONTRIBUTE_ROLE = 'lifecycle_contribution_role';
case LIFECYCLE_CONTRIBUTE_PUBLISHER = 'lifecycle_contribution_publisher';
case LIFECYCLE_CONTRIBUTE_ROLE = 'lifecycle_contribute_role';
case LIFECYCLE_CONTRIBUTE_PUBLISHER = 'lifecycle_contribute_publisher';
case METAMETADATA_IDENTIFIER_CATALOG = 'metametadata_identifier_catalog';
case METAMETADATA_CONTRIBUTE_ROLE = 'metametadata_contribution_role';
case METAMETADATA_CONTRIBUTE_ROLE = 'metametadata_contribute_role';
case METAMETADATA_SCHEMA = 'metametadata_schema';
case TECHNICAL_REQUIREMENT_TYPE = 'technical_requiment_type';
case TECHNICAL_REQUIREMENT_BROWSER = 'technical_requiment_browser';
case TECHNICAL_REQUIREMENT_OS = 'technical_requiment_os';
case TECHNICAL_OTHER_PLATFORM_REQUIREMENTS = 'technical_other_platform_requiments';
case TECHNICAL_OTHER_PLATFORM_REQUIREMENTS = 'technical_other_platform_requirements';
case TECHNICAL_FORMAT = 'technical_format';
case EDUCATIONAL_INTERACTIVITY_TYPE = 'educational_activity_type';
case EDUCATIONAL_INTERACTIVITY_TYPE = 'educational_interactivity_type';
case EDUCATIONAL_LEARNING_RESOURCE_TYPE = 'educational_learning_resource_type';
case EDUCATIONAL_INTERACTIVITY_LEVEL = 'educational_activity_level';
case EDUCATIONAL_SEMANTIC_DENSITY = 'educational_semantic_denition';
case EDUCATIONAL_INTERACTIVITY_LEVEL = 'educational_interactivity_level';
case EDUCATIONAL_SEMANTIC_DENSITY = 'educational_semantic_density';
case EDCUCATIONAL_INTENDED_END_USER_ROLE = 'educational_intended_end_user_role';
case EDUCATIONAL_CONTEXT = 'educational_context';
case EDUCATIONAL_DIFFICULTY = 'educational_difficulty';
Expand Down

0 comments on commit 86ed6c4

Please sign in to comment.