ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
MediaCastTableBuilder.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\MediaCast;
22
26
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
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) {
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}
__construct(protected InternalDomainService $domain, protected InternalGUIService $gui, protected \ilObjMediaCast $media_cast, protected bool $edit_order, object $parent_gui, string $parent_cmd)
getPreview(\ilObjMediaObject $mob, string $title)
transformRow(array $data_row)
transform raw data array to table row data array
activeAction(string $action, array $data_row)
textColumn(string $key, string $title, bool $sortable=false)
singleAction(string $action, string $title, bool $async=false)
const IL_CAL_DATETIME
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
@classDescription Date and time handling
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getVideoPreviewPic(bool $a_filename_only=false)
static _lookupItemPath(int $a_mob_id, bool $a_url_encode=false, bool $a_web=true, string $a_purpose="")
Get path for item with specific purpose.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $lng
Definition: privfeed.php:26
$data
Definition: storeScorm.php:45