mirror of
https://github.com/Karaka-Management/oms-Media.git
synced 2026-02-16 17:28:41 +00:00
update
This commit is contained in:
parent
ff5cad292c
commit
d332790d4c
43
Admin/Install/Search.php
Normal file
43
Admin/Install/Search.php
Normal 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']);
|
||||||
|
}
|
||||||
|
}
|
||||||
32
Admin/Install/SearchCommands.php
Normal file
32
Admin/Install/SearchCommands.php
Normal 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,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
76
Controller/SearchController.php
Normal file
76
Controller/SearchController.php
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
9
Models/Elastic/Media.json
Normal file
9
Models/Elastic/Media.json
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"id": "{id}",
|
||||||
|
"title": "{title}",
|
||||||
|
"content": "{content}",
|
||||||
|
"extension": "{extension}",
|
||||||
|
"path": "{path}",
|
||||||
|
"types": ["{types}"],
|
||||||
|
"tags": ["{tags}"]
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user