Skip to content

Commit 67a8730

Browse files
committed
mediacast: fixed table issues; removed legacy one
1 parent 7253007 commit 67a8730

7 files changed

Lines changed: 304 additions & 804 deletions

File tree

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
/**
4+
* This file is part of ILIAS, a powerful learning management system
5+
* published by ILIAS open source e-Learning e.V.
6+
*
7+
* ILIAS is licensed with the GPL-3.0,
8+
* see https://www.gnu.org/licenses/gpl-3.0.en.html
9+
* You should have received a copy of said license along with
10+
* the source code, too.
11+
*
12+
* If this is not the case or you just want to try ILIAS, you'll find
13+
* us at:
14+
* https://www.ilias.de
15+
* https://github.com/ILIAS-eLearning
16+
*
17+
*********************************************************************/
18+
19+
declare(strict_types=1);
20+
21+
namespace ILIAS\MediaCast;
22+
23+
use Generator;
24+
use ILIAS\Data\Order;
25+
use ILIAS\Data\Range;
26+
use ILIAS\Repository\RetrievalBase;
27+
use ILIAS\Repository\RetrievalInterface;
28+
29+
class MediaCastRetrieval implements RetrievalInterface
30+
{
31+
use RetrievalBase;
32+
33+
public function __construct(
34+
protected \ilObjMediaCast $media_cast
35+
) {
36+
}
37+
38+
public function getData(
39+
array $fields,
40+
?Range $range = null,
41+
?Order $order = null,
42+
array $filter = [],
43+
array $parameters = []
44+
): Generator {
45+
$data = $this->media_cast->getSortedItemsArray();
46+
$data = $this->applyOrder($data, $order);
47+
$data = $this->applyRange($data, $range);
48+
49+
foreach ($data as $row) {
50+
$row['is_image'] = false;
51+
if (isset($row['mob_id'])) {
52+
$mob = new \ilObjMediaObject((int) $row['mob_id']);
53+
$med = $mob->getMediaItem('Standard');
54+
$row['is_image'] = $med !== null
55+
&& str_starts_with((string) $med->getFormat(), 'image/');
56+
}
57+
yield $row;
58+
}
59+
}
60+
61+
public function count(
62+
array $filter = [],
63+
array $parameters = []
64+
): int {
65+
return count($this->media_cast->getSortedItemsArray());
66+
}
67+
68+
public function isFieldNumeric(string $field): bool
69+
{
70+
return $field === 'id';
71+
}
72+
}
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
<?php
2+
3+
/**
4+
* This file is part of ILIAS, a powerful learning management system
5+
* published by ILIAS open source e-Learning e.V.
6+
*
7+
* ILIAS is licensed with the GPL-3.0,
8+
* see https://www.gnu.org/licenses/gpl-3.0.en.html
9+
* You should have received a copy of said license along with
10+
* the source code, too.
11+
*
12+
* If this is not the case or you just want to try ILIAS, you'll find
13+
* us at:
14+
* https://www.ilias.de
15+
* https://github.com/ILIAS-eLearning
16+
*
17+
*********************************************************************/
18+
19+
declare(strict_types=1);
20+
21+
namespace ILIAS\MediaCast;
22+
23+
use ILIAS\Repository\RetrievalInterface;
24+
use ILIAS\Repository\Table\CommonTableBuilder;
25+
use ILIAS\Repository\Table\TableAdapterGUI;
26+
27+
class MediaCastTableBuilder extends CommonTableBuilder
28+
{
29+
public function __construct(
30+
protected InternalDomainService $domain,
31+
protected InternalGUIService $gui,
32+
protected \ilObjMediaCast $media_cast,
33+
protected bool $edit_order,
34+
object $parent_gui,
35+
string $parent_cmd
36+
) {
37+
parent::__construct($parent_gui, $parent_cmd);
38+
}
39+
40+
protected function getId(): string
41+
{
42+
return 'mcst_items';
43+
}
44+
45+
protected function getTitle(): string
46+
{
47+
return $this->domain->lng()->txt($this->edit_order ? 'mcst_media_cast' : 'mcst_items');
48+
}
49+
50+
protected function getNamespace(): string
51+
{
52+
return 'mcst';
53+
}
54+
55+
protected function getRetrieval(): RetrievalInterface
56+
{
57+
return new MediaCastRetrieval($this->media_cast);
58+
}
59+
60+
protected function getOrderingCommand(): string
61+
{
62+
return $this->edit_order ? 'saveOrder' : '';
63+
}
64+
65+
protected function activeAction(string $action, array $data_row): bool
66+
{
67+
if ($action === 'determinePlaytimeObject') {
68+
return !($data_row['is_image'] ?? false);
69+
}
70+
71+
return true;
72+
}
73+
74+
protected function transformRow(array $data_row): array
75+
{
76+
$mob = new \ilObjMediaObject((int) $data_row['mob_id']);
77+
$med = $mob->getMediaItem('Standard');
78+
$format = $med?->getFormat() ?? '';
79+
80+
$data = [
81+
'id' => (int) $data_row['id'],
82+
'title' => (string) ($data_row['title'] ?? ''),
83+
'type' => $format !== '' ? $format : '-',
84+
'size' => $this->getSize($mob),
85+
'playtime' => ($data_row['playtime'] ?? '') !== '00:00:00'
86+
? (string) ($data_row['playtime'] ?? '')
87+
: '-',
88+
'creation_date' => \ilDatePresentation::formatDate(
89+
new \ilDateTime((string) ($data_row['creation_date'] ?? ''), IL_CAL_DATETIME)
90+
),
91+
'update_date' => $this->getUpdateDate($data_row),
92+
'preview' => $this->getPreview($mob, (string) ($data_row['title'] ?? '')),
93+
];
94+
95+
return $data;
96+
}
97+
98+
protected function build(TableAdapterGUI $table): TableAdapterGUI
99+
{
100+
$lng = $this->domain->lng();
101+
102+
$table = $table
103+
->textColumn('title', $lng->txt('title'))
104+
->textColumn('type', $lng->txt('type'))
105+
->textColumn('size', $lng->txt('size'))
106+
->textColumn('playtime', $lng->txt('mcst_play_time'))
107+
->textColumn('creation_date', $lng->txt('created'))
108+
->textColumn('update_date', $lng->txt('last_update'));
109+
110+
if ($this->media_cast->getViewMode() !== \ilObjMediaCast::VIEW_PODCAST) {
111+
$table = $table->textColumn('preview', $lng->txt('preview'));
112+
}
113+
114+
$table = $table
115+
->singleAction('editCastItemObject', $lng->txt('edit'))
116+
->singleAction('showCastItemObject', $lng->txt('show'), true);
117+
118+
if ($this->media_cast->getViewMode() !== \ilObjMediaCast::VIEW_IMG_GALLERY) {
119+
$table = $table->singleAction(
120+
'determinePlaytimeObject',
121+
$lng->txt('mcst_det_playtime')
122+
);
123+
}
124+
if ($this->media_cast->getDownloadable()) {
125+
$table = $table->singleAction('downloadItemObject', $lng->txt('download'));
126+
}
127+
128+
return $table->singleAction(
129+
'confirmItemDeletionObject',
130+
$lng->txt('delete'),
131+
true
132+
);
133+
}
134+
135+
protected function getSize(\ilObjMediaObject $mob): string
136+
{
137+
$file = \ilObjMediaObject::_lookupItemPath($mob->getId(), false, false, 'Standard');
138+
if (!is_file($file)) {
139+
return '-';
140+
}
141+
142+
return sprintf('%.1f MB', filesize($file) / 1024 / 1024);
143+
}
144+
145+
protected function getUpdateDate(array $data_row): string
146+
{
147+
if (($data_row['update_date'] ?? '') === ($data_row['creation_date'] ?? '')) {
148+
return '-';
149+
}
150+
151+
return \ilDatePresentation::formatDate(
152+
new \ilDateTime((string) ($data_row['update_date'] ?? ''), IL_CAL_DATETIME)
153+
);
154+
}
155+
156+
protected function getPreview(\ilObjMediaObject $mob, string $title): string
157+
{
158+
$preview = $mob->getVideoPreviewPic();
159+
if ($preview === '') {
160+
return '';
161+
}
162+
163+
$image = $this->gui->ui()->factory()->image()->responsive($preview, $title);
164+
return str_replace(
165+
'<img ',
166+
"<img style='max-width:150px;' ",
167+
$this->gui->ui()->renderer()->render($image)
168+
);
169+
}
170+
}

components/ILIAS/MediaCast/Service/class.InternalGUIService.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,20 @@ public function getObjMediaCastGUI(): \ilObjMediaCastGUI
7373
);
7474
}
7575

76-
public function getMediaCastManageTableGUI(\ilObjMediaCastGUI $gui, string $table_cmd): \ilMediaCastManageTableGUI
77-
{
78-
return new \ilMediaCastManageTableGUI($gui, $table_cmd);
76+
public function mediaCastTableBuilder(
77+
\ilObjMediaCast $media_cast,
78+
bool $edit_order,
79+
object $parent_gui,
80+
string $parent_cmd
81+
): MediaCastTableBuilder {
82+
return new MediaCastTableBuilder(
83+
$this->domain_service,
84+
$this,
85+
$media_cast,
86+
$edit_order,
87+
$parent_gui,
88+
$parent_cmd
89+
);
7990
}
8091

8192
public function comments(): Comments\GUIService

0 commit comments

Comments
 (0)