Skip to content

Commit

Permalink
Clean table params in DC queries
Browse files Browse the repository at this point in the history
  • Loading branch information
iszmais committed Jun 10, 2024
1 parent 5d218cc commit 491eb44
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 79 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
Expand All @@ -13,8 +14,7 @@
* https://www.ilias.de
* https://github.com/ILIAS-eLearning
*
********************************************************************
*/
*********************************************************************/

/**
* Class ilDclBaseFieldModel
Expand Down Expand Up @@ -181,6 +181,7 @@ private function buildData(): void
}

$this->ctrl->setParameterByClass("ildclfieldeditgui", "record_id", $record->getId());
$this->ctrl->setParameterByClass(ilDclDetailedViewGUI::class, "table_id", $record->getTableId());
$this->ctrl->setParameterByClass("ilDclDetailedViewGUI", "record_id", $record->getId());
$this->ctrl->setParameterByClass("ilDclDetailedViewGUI", "tableview_id", $this->tableview->getId());
$this->ctrl->setParameterByClass("ildclrecordeditgui", "record_id", $record->getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
* https://www.ilias.de
* https://github.com/ILIAS-eLearning
*
********************************************************************
*/
*********************************************************************/

/**
* Class ilDclBaseRecordRepresentation
Expand Down Expand Up @@ -143,30 +142,4 @@ public function getRecord(): ilDclBaseRecordModel
{
return $this->record_field->getRecord();
}

/**
* Note this should be properly injected from ilObjDataCollection GUI.
*/
protected function getTableViewId(): int
{
$tableview_id = null;
if ($this->http->wrapper()->query()->has('tableview_id')) {
$tableview_id = $this->http->wrapper()->query()->retrieve(
'tableview_id',
$this->refinery->kindlyTo()->int()
);
}
if ($this->http->wrapper()->post()->has('tableview_id')) {
$tableview_id = $this->http->wrapper()->post()->retrieve(
'tableview_id',
$this->refinery->kindlyTo()->int()
);
}
if (!$tableview_id) {
$table_obj = ilDclCache::getTableCache($this->getRecordField()->getRecord()->getTableId());
$ref_id = $this->http->wrapper()->query()->retrieve('ref_id', $this->refinery->kindlyTo()->int());
$tableview_id = $table_obj->getFirstTableViewId($ref_id);
}
return $tableview_id;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
Expand All @@ -13,8 +14,7 @@
* https://www.ilias.de
* https://github.com/ILIAS-eLearning
*
********************************************************************
*/
*********************************************************************/

/**
* Class ilDclReferenceRecordRepresentation
Expand All @@ -36,7 +36,7 @@ public function getHTML(bool $link = true, array $options = []): string
$value = [$value];
}

$html = "";
$items = [];

foreach ($value as $k => $v) {
$ref_record = ilDclCache::getRecordCache($v);
Expand All @@ -50,50 +50,35 @@ public function getHTML(bool $link = true, array $options = []): string
} else {
$field = $this->getRecordField()->getField();
if ($field->getProperty(ilDclBaseFieldModel::PROP_REFERENCE_LINK)) {
$ref_record = ilDclCache::getRecordCache($v);
$ref_table = $ref_record->getTable();

$ref_id = $this->http->wrapper()->query()->retrieve('ref_id', $this->refinery->kindlyTo()->int());

if ($ref_table->getVisibleTableViews($ref_id, true)) {
$html .= $this->getLinkHTML(null, $v);
} else {
$html .= $ref_record->getRecordFieldHTML($field->getProperty(ilDclBaseFieldModel::PROP_REFERENCE));
if ($v !== null && $v !== '' && $v !== '-') {
$view = $ref_record->getTable()->getFirstTableViewId($ref_id, $this->user->getId(), true);
if ($view) {
$items[] = $this->getLinkHTML($ref_record, $view);
continue;
}
}
} else {
$html .= $ref_record->getRecordFieldHTML($field->getProperty(ilDclBaseFieldModel::PROP_REFERENCE));
}
$items[] = $ref_record->getRecordFieldHTML($field->getProperty(ilDclBaseFieldModel::PROP_REFERENCE));
}
$html .= '<br>';
}

$html = substr($html, 0, -4); // cut away last <br>

return $html;
return implode('<br>', $items);
}

/**
* @param string|null|int $value
*/
protected function getLinkHTML(?string $link_name = null, $value): string
protected function getLinkHTML(ilDclBaseRecordModel $record, int $view): string
{
if (!$value || $value == "-") {
return "";
}
$record_field = $this;
$ref_record = ilDclCache::getRecordCache($value);
if (!$link_name) {
$link_name = $ref_record->getRecordFieldHTML($record_field->getField()->getProperty(ilDclBaseFieldModel::PROP_REFERENCE));
}
$this->ctrl->clearParametersByClass(ilDclDetailedViewGUI::class);
$this->ctrl->setParameterByClass(ilDclDetailedViewGUI::class, "record_id", $ref_record->getId());
$table_obj = ilDclCache::getTableCache($ref_record->getTableId());
$ref_id = $this->http->wrapper()->query()->retrieve('ref_id', $this->refinery->kindlyTo()->int());
$this->ctrl->setParameterByClass(ilDclDetailedViewGUI::class, "tableview_id", $table_obj->getFirstTableViewId($ref_id));
$html = $this->factory->link()->standard($link_name, $this->ctrl->getLinkTargetByClass(
ilDclDetailedViewGUI::class,
"renderRecord"
));
$this->ctrl->setParameterByClass(ilDclDetailedViewGUI::class, "table_id", $record->getTableId());
$this->ctrl->setParameterByClass(ilDclDetailedViewGUI::class, "record_id", $record->getId());
$this->ctrl->setParameterByClass(ilDclDetailedViewGUI::class, "tableview_id", $view);
$html = $this->factory->link()->standard(
$record->getRecordFieldValue($this->getField()->getProperty(ilDclBaseFieldModel::PROP_REFERENCE)),
$this->ctrl->getLinkTargetByClass(
ilDclDetailedViewGUI::class,
"renderRecord"
)
);

return $this->renderer->render($html);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
Expand Down Expand Up @@ -28,6 +29,9 @@ public function getHTML(bool $link = true, array $options = []): string
{
$value = $this->getRecordField()->getValue();

$ref_id = $this->http->wrapper()->query()->retrieve('ref_id', $this->refinery->kindlyTo()->int());
$views = $this->getRecord()->getTable()->getVisibleTableViews($ref_id, true, $this->user->getId());

//Property URL
$field = $this->getField();
if ($field->hasProperty(ilDclBaseFieldModel::PROP_URL)) {
Expand Down Expand Up @@ -56,16 +60,26 @@ public function getHTML(bool $link = true, array $options = []): string
$link,
ENT_QUOTES
) . "'>" . htmlspecialchars($link_value, ENT_QUOTES) . "</a>";
} elseif ($field->hasProperty(
ilDclBaseFieldModel::PROP_LINK_DETAIL_PAGE_TEXT
) && $link && ilDclDetailedViewDefinition::isActive($this->getTableViewId())) {
} elseif ($field->hasProperty(ilDclBaseFieldModel::PROP_LINK_DETAIL_PAGE_TEXT) && $link && $views !== []) {
$view = array_shift($views);
if ($this->http->wrapper()->query()->has('tableview_id')) {
$tableview_id = $this->http->wrapper()->query()->retrieve('tableview_id', $this->refinery->kindlyTo()->int());
foreach ($views as $v) {
if ($v->getId() === $tableview_id) {
$view = $tableview_id;
break;
}
}
}

$this->ctrl->clearParametersByClass("ilDclDetailedViewGUI");
$this->ctrl->setParameterByClass(
'ilDclDetailedViewGUI',
'record_id',
$this->getRecordField()->getRecord()->getId()
);
$this->ctrl->setParameterByClass('ilDclDetailedViewGUI', 'tableview_id', $this->getTableViewId());

$this->ctrl->setParameterByClass('ilDclDetailedViewGUI', 'tableview_id', $view->getId());
$html = '<a href="' . $this->ctrl->getLinkTargetByClass(
"ilDclDetailedViewGUI",
'renderRecord'
Expand Down
8 changes: 3 additions & 5 deletions Modules/DataCollection/classes/Table/class.ilDclTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
* https://www.ilias.de
* https://github.com/ILIAS-eLearning
*
********************************************************************
*/
*********************************************************************/

/**
* Class ilDclBaseFieldModel
Expand Down Expand Up @@ -521,12 +520,11 @@ public function getVisibleTableViews(int $ref_id, bool $with_active_detailedview

/**
* get id of first (for current user) available view
* @return bool|int|null
*/
public function getFirstTableViewId(int $ref_id, int $user_id = 0)
public function getFirstTableViewId(int $ref_id, int $user_id = 0, bool $with_deteiled_view = false): ?int
{
$uid = $user_id;
$array = $this->getVisibleTableViews($ref_id, false, $uid);
$array = $this->getVisibleTableViews($ref_id, $with_deteiled_view, $uid);
$tableview = array_shift($array);

return $tableview ? $tableview->getId() : false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
* https://www.ilias.de
* https://github.com/ILIAS-eLearning
*
********************************************************************
*/
*********************************************************************/

/**
* Class ilObjDataCollectionGUI
Expand Down Expand Up @@ -449,7 +448,7 @@ protected function setTabs(): void
// read permission
if ($this->dclAccess->hasReadPermission($refId) === true) {
// list records
$this->addTab(self::TAB_CONTENT, $this->dclEndPoint->getListRecordsLink($this->getTableViewId()));
$this->addTab(self::TAB_CONTENT, $this->dclEndPoint->getListRecordsLink());
}

// visible permission
Expand Down

0 comments on commit 491eb44

Please sign in to comment.