This commit is contained in:
Dennis Eichhorn 2024-02-04 20:34:12 +00:00
parent ff5cad292c
commit d332790d4c
5 changed files with 162 additions and 1 deletions

43
Admin/Install/Search.php Normal file
View File

@ -0,0 +1,43 @@
<?php
/**
* Jingga
*
* PHP Version 8.1
*
* @package Modules\Media\Admin\Install
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace Modules\Media\Admin\Install;
use phpOMS\Application\ApplicationAbstract;
/**
* Search class.
*
* @package Modules\Media\Admin\Install
* @license OMS License 2.0
* @link https://jingga.app
* @since 1.0.0
*/
final class Search
{
/**
* Install navigation providing
*
* @param ApplicationAbstract $app Application
* @param string $path Module path
*
* @return void
*
* @since 1.0.0
*/
public static function install(ApplicationAbstract $app, string $path) : void
{
\Modules\Search\Admin\Installer::installExternal($app, ['path' => __DIR__ . '/SearchCommands.php']);
}
}

View File

@ -0,0 +1,32 @@
<?php
/**
* Jingga
*
* PHP Version 8.1
*
* @package Modules\Media
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
use Modules\Media\Controller\SearchController;
use Modules\Media\Models\PermissionCategory;
use phpOMS\Account\PermissionType;
use phpOMS\Router\RouteVerb;
return [
'^(?!:).+.*?' => [
[
'dest' => '\Modules\Media\Controller\SearchController:searchGeneral',
'verb' => RouteVerb::ANY,
'permission' => [
'module' => SearchController::NAME,
'type' => PermissionType::READ,
'state' => PermissionCategory::MEDIA,
],
],
],
];

View File

@ -0,0 +1,76 @@
<?php
/**
* Jingga
*
* PHP Version 8.1
*
* @package Modules\Media
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace Modules\Media\Controller;
use Modules\Media\Models\MediaMapper;
use phpOMS\DataStorage\Database\Query\OrderType;
use phpOMS\Message\RequestAbstract;
use phpOMS\Message\ResponseAbstract;
use phpOMS\System\MimeType;
/**
* Search class.
*
* @package Modules\Media
* @license OMS License 2.0
* @link https://jingga.app
* @since 1.0.0
*/
final class SearchController extends Controller
{
/**
* Api method to search for tags
*
* @param RequestAbstract $request Request
* @param ResponseAbstract $response Response
* @param array $data Generic data
*
* @return void
*
* @api
*
* @since 1.0.0
*/
public function searchGeneral(RequestAbstract $request, ResponseAbstract $response, array $data = []) : void
{
/** @var \Modules\Media\Models\Media[] $media */
$media = MediaMapper::getAll()
->with('tags')
->with('tags/title')
->where('name', '%' . ($request->getDataString('search') ?? '') . '%', 'LIKE')
->where('tags/title/language', $response->header->l11n->language)
->sort('createdAt', OrderType::DESC)
->limit(8)
->execute();
$results = [];
foreach ($media as $file) {
$results[] = [
'title' => $file->name . ' (' . $file->extension . ')',
'summary' => '',
'link' => '{/base}/media/view?id=' . $file->id,
'account' => '',
'createdAt' => $file->createdAt,
'image' => '',
'tags' => $file->tags,
'type' => 'list_links',
'module' => 'Media',
];
}
$response->header->set('Content-Type', MimeType::M_JSON . '; charset=utf-8', true);
$response->add($request->uri->__toString(), $results);
}
}

View File

@ -0,0 +1,9 @@
{
"id": "{id}",
"title": "{title}",
"content": "{content}",
"extension": "{extension}",
"path": "{path}",
"types": ["{types}"],
"tags": ["{tags}"]
}

View File

@ -24,7 +24,8 @@
},
"providing": {
"Navigation": "*",
"Media": "*"
"Media": "*",
"Search": "*"
},
"load": [
{