Skip to content

Commit

Permalink
Fix/7/99 (opencast-ilias#214)
Browse files Browse the repository at this point in the history
* [FIX] activate column owner depending on settings

* [FIX] sort column speaker (and other metadata based)
  • Loading branch information
chfsx authored Nov 13, 2023
1 parent e1a8b5c commit 20b22ab
Showing 1 changed file with 43 additions and 63 deletions.
106 changes: 43 additions & 63 deletions classes/Event/class.xoctEventTableGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class xoctEventTableGUI extends ilTable2GUI
/**
* @var ObjectSettings
*/
protected $objectSettings;
protected $object_settings;
/**
* @var xoctEventGUI
*/
Expand Down Expand Up @@ -70,14 +70,10 @@ class xoctEventTableGUI extends ilTable2GUI
*/
private $user;

/**
* @throws DICException
* @throws xoctException
*/
public function __construct(
xoctEventGUI $a_parent_obj,
string $a_parent_cmd,
ObjectSettings $objectSettings,
ObjectSettings $object_settings,
array $md_fields,
array $data,
string $lang_key
Expand All @@ -89,7 +85,7 @@ public function __construct(
$this->parent_obj = $a_parent_obj;
$this->md_fields = $md_fields;
$this->lang_key = $lang_key;
$this->objectSettings = $objectSettings;
$this->object_settings = $object_settings;
$this->container = OpencastDIC::getInstance();
$this->plugin = $this->container->plugin();
$a_val = static::getGeneratedPrefix($a_parent_obj->getObjId());
Expand Down Expand Up @@ -137,21 +133,23 @@ public static function getGeneratedPrefix(int $obj_id): string
return self::TBL_ID . '_' . substr($obj_id, 0, 5);
}

/**
* @param $column
*/
public function isColumsSelected($column): bool
public function isColumnSelected($a_col): bool
{
if (!array_key_exists($column, $this->getSelectableColumns())) {
if (!array_key_exists($a_col, $this->getSelectableColumns())) {
return true;
}

return in_array($column, $this->getSelectedColumns());
if (isset($this->getSelectedColumns()[$a_col])) {
return true;
}

$column_settings = $this->getSelectableColumns()[$a_col] ?? [];

return $column_settings['default'] ?? false;
}

/**
* @param array $a_set
* @throws DICException
* @throws ilTemplateException
* @throws xoctException
*/
Expand All @@ -162,22 +160,22 @@ protected function fillRow($a_set)
* @var $xoctUser xoctUser
*/
$event = $a_set['object'] ?: $this->event_repository->find($a_set['identifier']);
$renderer = new xoctEventRenderer($event, $this->objectSettings);
$renderer = new xoctEventRenderer($event, $this->object_settings);

$renderer->insertPreviewImage($this->tpl, null);
$renderer->insertPlayerLink($this->tpl);

if (!$this->objectSettings->getStreamingOnly()) {
if (!$this->object_settings->getStreamingOnly()) {
$renderer->insertDownloadLink($this->tpl);
}

if ($this->objectSettings->getUseAnnotations()) {
if ($this->object_settings->getUseAnnotations()) {
$renderer->insertAnnotationLink($this->tpl);
}

$first = true;
foreach ($this->md_fields as $md_field) {
if ($this->isColumsSelected($md_field->getFieldId())) {
if ($this->isColumnSelected($md_field->getFieldId())) {
$this->tpl->setCurrentBlock('generic' . ($first ? '_w_state' : ''));
if ($first) {
$this->tpl->setVariable('STATE', $renderer->getStateHTML());
Expand All @@ -188,7 +186,7 @@ protected function fillRow($a_set)
}
}

if ($this->isColumsSelected('event_owner')) {
if ($this->isColumnSelected('event_owner')) {
$renderer->insertOwner($this->tpl, 'generic', 'VALUE', $a_set['owner_username']);
}

Expand All @@ -203,7 +201,7 @@ protected function fillRow($a_set)
/**
* @return array{selectable: true, sort_field: string, text: string}[]|array{selectable: false, sort_field: null, width: string, lang_var: string}[]|array{selectable: false, sort_field: null, lang_var: string}[]|array{selectable: true, sort_field: string, default: bool, lang_var: string}[]|array{selectable: false, sort_field: string, lang_var: string}[]|array{selectable: false, lang_var: string}[]
*/
protected function getAllColums(): array
protected function getAllColumns(): array
{
$columns = [
'event_preview' => [
Expand All @@ -220,9 +218,10 @@ protected function getAllColums(): array
];

foreach ($this->md_fields as $md_field) {
$columns[$md_field->getFieldId()] = [
$field_id = $md_field->getFieldId();
$columns[$field_id] = [
'selectable' => true,
'sort_field' => $md_field->getFieldId() . '_s',
'sort_field' => $field_id,
'text' => $md_field->getTitle($this->lang_key)
];
}
Expand All @@ -245,19 +244,16 @@ protected function getAllColums(): array
],
];

if (!(new PublicationUsageRepository())->exists(PublicationUsage::USAGE_UNPROTECTED_LINK)
|| !$this->has_unprotected_links
|| !ilObjOpenCastAccess::checkAction(ilObjOpenCastAccess::ACTION_VIEW_UNPROTECTED_LINK)) {
if (!$this->has_unprotected_links
|| !ilObjOpenCastAccess::checkAction(ilObjOpenCastAccess::ACTION_VIEW_UNPROTECTED_LINK)
|| !(new PublicationUsageRepository())->exists(PublicationUsage::USAGE_UNPROTECTED_LINK)) {
unset($columns['unprotected_link']);
}

return $columns;
}

/**
* @return bool
*/
protected function getOwnerColDefault()
protected function getOwnerColDefault(): bool
{
static $owner_visible;
if ($owner_visible !== null) {
Expand All @@ -266,35 +262,28 @@ protected function getOwnerColDefault()
$owner_visible = (ilObjOpenCastAccess::isActionAllowedForRole(
'upload',
'member'
) || $this->objectSettings->getPermissionPerClip());
) || $this->object_settings->getPermissionPerClip());

return $owner_visible;
}

/**
* @throws DICException
*/
protected function initColumns()
protected function initColumns(): void
{
$selected_columns = $this->getSelectedColumns();

foreach ($this->getAllColums() as $key => $col) {
if (!$this->isColumsSelected($key)) {
foreach ($this->getAllColumns() as $key => $col) {
if (!$this->isColumnSelected($key)) {
continue;
}
if ($col['selectable'] == false || in_array($key, $selected_columns)) {
$col_title = isset($col['lang_var']) ? $this->plugin->txt($col['lang_var']) : $col['text'];
$this->addColumn($col_title, $col['sort_field'], $col['width']);
}
$this->addColumn(
isset($col['lang_var']) ? $this->plugin->txt($col['lang_var']) : $col['text'],
$col['sort_field'],
$col['width']
);
}
}

/**
* @throws DICException
*/
protected function addActionMenu(Event $event)
protected function addActionMenu(Event $event): void
{
$renderer = new xoctEventRenderer($event, $this->objectSettings);
$renderer = new xoctEventRenderer($event, $this->object_settings);
$actions = $renderer->getActions();
if ($actions === []) {
return;
Expand All @@ -312,7 +301,7 @@ protected function addActionMenu(Event $event)
/**
* @return Closure => $value) {
*/
protected function filterArray()
protected function filterArray(): Closure
{
return function ($array): bool {
$return = true;
Expand Down Expand Up @@ -344,25 +333,19 @@ protected function filterArray()
};
}

/**
* @return Closure
*/
protected function filterPermissions()
protected function filterPermissions(): Closure
{
return function ($array): bool {
$xoctUser = xoctUser::getInstance($this->user);
$event = $array['object'] instanceof Event ? $array['object'] : $this->event_repository->find(
$array['identifier']
);

return ilObjOpenCastAccess::hasReadAccessOnEvent($event, $xoctUser, $this->objectSettings);
return ilObjOpenCastAccess::hasReadAccessOnEvent($event, $xoctUser, $this->object_settings);
};
}

/**
* @param $item
*/
protected function addAndReadFilterItem(ilFormPropertyGUI $item)
protected function addAndReadFilterItem(ilFormPropertyGUI $item): void
{
$this->addFilterItem($item);
$item->readFromSession();
Expand Down Expand Up @@ -434,18 +417,15 @@ protected function fillRowCSV($a_csv, $a_set)
parent::fillRowCSV($a_csv, $set);
}

/**
* @return array
*/
public function getSelectableColumns()
public function getSelectableColumns(): array
{
static $selectable_columns;
if ($selectable_columns !== null) {
return $selectable_columns;
}
$selectable_columns = [];
foreach ($this->getAllColums() as $key => $col) {
if ($col['selectable']) {
foreach ($this->getAllColumns() as $key => $col) {
if ((bool) ($col['selectable'] ?? false)) {
$col_title = isset($col['lang_var']) ? $this->plugin->txt($col['lang_var']) : $col['text'];
$selectable_columns[$key] = [
'txt' => $col_title,
Expand Down

0 comments on commit 20b22ab

Please sign in to comment.