mirror of
https://github.com/Karaka-Management/oms-Media.git
synced 2026-02-17 17:58:40 +00:00
bug fixes and subscription improvements
This commit is contained in:
parent
44095561e2
commit
744b771463
|
|
@ -1241,6 +1241,8 @@ final class ApiController extends Controller
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$response->header->set('Content-Type', MimeType::M_BIN, true);
|
$response->header->set('Content-Type', MimeType::M_BIN, true);
|
||||||
|
$response->header->set('Content-Disposition', 'attachment; filename="' . \addslashes($media->name) . '"', true);
|
||||||
|
$response->header->set('Content-Transfer-Encoding', 'binary', true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,9 @@ use phpOMS\DataStorage\Database\Mapper\ReadMapper;
|
||||||
* @license OMS License 2.0
|
* @license OMS License 2.0
|
||||||
* @link https://jingga.app
|
* @link https://jingga.app
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
*
|
||||||
|
* @template T of Collection
|
||||||
|
* @extends MediaMapper<T>
|
||||||
*/
|
*/
|
||||||
final class CollectionMapper extends MediaMapper
|
final class CollectionMapper extends MediaMapper
|
||||||
{
|
{
|
||||||
|
|
|
||||||
143
Models/MediaListTrait.php
Normal file
143
Models/MediaListTrait.php
Normal file
|
|
@ -0,0 +1,143 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Karaka
|
||||||
|
*
|
||||||
|
* PHP Version 8.1
|
||||||
|
*
|
||||||
|
* @package Modules\Media\Models
|
||||||
|
* @copyright Dennis Eichhorn
|
||||||
|
* @license OMS License 2.0
|
||||||
|
* @version 1.0.0
|
||||||
|
* @link https://jingga.app
|
||||||
|
*/
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Modules\Media\Models;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Media class.
|
||||||
|
*
|
||||||
|
* @package Modules\Media\Models
|
||||||
|
* @license OMS License 2.0
|
||||||
|
* @link https://jingga.app
|
||||||
|
* @since 1.0.0
|
||||||
|
*
|
||||||
|
* @property \Modules\Media\Models\Media[] $files
|
||||||
|
*/
|
||||||
|
trait MediaListTrait
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Files.
|
||||||
|
*
|
||||||
|
* @var Media[]
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
private array $files = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get files
|
||||||
|
*
|
||||||
|
* @return Media[]
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function getFiles() : array
|
||||||
|
{
|
||||||
|
return $this->files;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get media file by type
|
||||||
|
*
|
||||||
|
* @param int $type Media type
|
||||||
|
*
|
||||||
|
* @return Media
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function getFileByType(int $type) : Media
|
||||||
|
{
|
||||||
|
foreach ($this->files as $file) {
|
||||||
|
if ($file->hasMediaTypeId($type)) {
|
||||||
|
return $file;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new NullMedia();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all media files by type name
|
||||||
|
*
|
||||||
|
* @param string $type Media type
|
||||||
|
*
|
||||||
|
* @return Media
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function getFileByTypeName(string $type) : Media
|
||||||
|
{
|
||||||
|
foreach ($this->files as $file) {
|
||||||
|
if ($file->hasMediaTypeName($type)) {
|
||||||
|
return $file;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new NullMedia();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all media files by type name
|
||||||
|
*
|
||||||
|
* @param string $type Media type
|
||||||
|
*
|
||||||
|
* @return Media[]
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function getFilesByTypeName(string $type) : array
|
||||||
|
{
|
||||||
|
$files = [];
|
||||||
|
foreach ($this->files as $file) {
|
||||||
|
if ($file->hasMediaTypeName($type)) {
|
||||||
|
$files[] = $file;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $files;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if file with a certain type name exists
|
||||||
|
*
|
||||||
|
* @param string $type Type name
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function hasFileTypeName(string $type) : bool
|
||||||
|
{
|
||||||
|
foreach ($this->files as $file) {
|
||||||
|
if ($file->hasMediaTypeName($type)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add media to item
|
||||||
|
*
|
||||||
|
* @param Media $media Media
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function addFile(Media $media) : void
|
||||||
|
{
|
||||||
|
$this->files[] = $media;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user