|
| 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 | +} |
0 commit comments