Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennis Eichhorn committed Feb 4, 2024
1 parent ff5cad2 commit d332790
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 1 deletion.
43 changes: 43 additions & 0 deletions Admin/Install/Search.php
Original file line number Diff line number Diff line change
@@ -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 changes: 32 additions & 0 deletions Admin/Install/SearchCommands.php
Original file line number Diff line number Diff line change
@@ -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 changes: 76 additions & 0 deletions Controller/SearchController.php
Original file line number Diff line number Diff line change
@@ -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 changes: 9 additions & 0 deletions Models/Elastic/Media.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"id": "{id}",
"title": "{title}",
"content": "{content}",
"extension": "{extension}",
"path": "{path}",
"types": ["{types}"],
"tags": ["{tags}"]
}
3 changes: 2 additions & 1 deletion info.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
},
"providing": {
"Navigation": "*",
"Media": "*"
"Media": "*",
"Search": "*"
},
"load": [
{
Expand Down

0 comments on commit d332790

Please sign in to comment.