mirror of
https://github.com/Karaka-Management/oms-Search.git
synced 2026-01-11 18:48:41 +00:00
update
This commit is contained in:
parent
9bf6b2487d
commit
f901a40b1e
|
|
@ -20,7 +20,7 @@ use phpOMS\Router\RouteVerb;
|
|||
return [
|
||||
'^.*/search(\?.*|$)' => [
|
||||
[
|
||||
'dest' => '\Modules\Search\Controller\ApiController:routeSearch',
|
||||
'dest' => '\Modules\Search\Controller\ApiController:search',
|
||||
'verb' => RouteVerb::ANY,
|
||||
'permission' => [
|
||||
'module' => ApiController::NAME,
|
||||
|
|
|
|||
|
|
@ -12,4 +12,21 @@
|
|||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
return [];
|
||||
use Modules\Search\Controller\BackendController;
|
||||
use Modules\Search\Models\PermissionCategory;
|
||||
use phpOMS\Account\PermissionType;
|
||||
use phpOMS\Router\RouteVerb;
|
||||
|
||||
return [
|
||||
'^.*/search(\?.*|$)' => [
|
||||
[
|
||||
'dest' => '\Modules\Search\Controller\BackendController:search',
|
||||
'verb' => RouteVerb::ANY,
|
||||
'permission' => [
|
||||
'module' => BackendController::NAME,
|
||||
'type' => PermissionType::READ,
|
||||
'state' => PermissionCategory::SEARCH,
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
|
|
|||
|
|
@ -29,8 +29,6 @@ use phpOMS\Router\WebRouter;
|
|||
*/
|
||||
final class ApiController extends Controller
|
||||
{
|
||||
private $router = null;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
@ -49,28 +47,17 @@ final class ApiController extends Controller
|
|||
* @param ResponseAbstract $response Response
|
||||
* @param array $data Generic data
|
||||
*
|
||||
* @return void
|
||||
* @return array
|
||||
*
|
||||
* @api
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function routeSearch(HttpRequest $request, ResponseAbstract $response, mixed $data = null) : void
|
||||
public function search(HttpRequest $request, ResponseAbstract $response, mixed $data = null) : void
|
||||
{
|
||||
$this->app->dispatcher->dispatch(
|
||||
$this->router->route(
|
||||
$request->getDataString('search') ?? '',
|
||||
$request->getDataString('CSRF'),
|
||||
$request->getRouteVerb(),
|
||||
$this->app->appId,
|
||||
$this->app->unitId,
|
||||
$this->app->accountManager->get($request->header->account)
|
||||
),
|
||||
$request,
|
||||
$response
|
||||
);
|
||||
$data = $this->routeSearch($request, $response, $data);
|
||||
|
||||
if (empty($response->data)) {
|
||||
if (empty($data)) {
|
||||
$this->fillJsonRawResponse($request, $response, []);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
77
Controller/BackendController.php
Normal file
77
Controller/BackendController.php
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
/**
|
||||
* Jingga
|
||||
*
|
||||
* PHP Version 8.1
|
||||
*
|
||||
* @package Modules\Search
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 2.0
|
||||
* @version 1.0.0
|
||||
* @link https://jingga.app
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\Search\Controller;
|
||||
|
||||
use phpOMS\Application\ApplicationAbstract;
|
||||
use phpOMS\Contract\RenderableInterface;
|
||||
use phpOMS\Message\Http\HttpRequest;
|
||||
use phpOMS\Message\Http\HttpResponse;
|
||||
use phpOMS\Message\RequestAbstract;
|
||||
use phpOMS\Message\ResponseAbstract;
|
||||
use phpOMS\Views\View;
|
||||
use phpOMS\Router\WebRouter;
|
||||
|
||||
/**
|
||||
* Backend controller
|
||||
*
|
||||
* @package Modules\Search
|
||||
* @license OMS License 2.0
|
||||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class BackendController extends Controller
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(ApplicationAbstract $app)
|
||||
{
|
||||
parent::__construct($app);
|
||||
|
||||
$this->router = new WebRouter();
|
||||
$this->router->importFromFile(__DIR__ . '/../Admin/SearchCommands.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* Backend method to handle basic search request
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
* @param ResponseAbstract $response Response
|
||||
* @param array $data Generic data
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @api
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function search(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : RenderableInterface
|
||||
{
|
||||
$view = new View($this->app->l11nManager, $request, $response);
|
||||
$view->setTemplate('/Modules/Search/Theme/Backend/search-result');
|
||||
|
||||
$internalRequest = clone $request;
|
||||
$internalResponse = clone $response;
|
||||
|
||||
$internalResponse->header = clone $request->header;
|
||||
|
||||
$internalResponse->data = [];
|
||||
|
||||
$temp = empty($request->getDataString('search')) ? [] : $this->routeSearch($internalRequest, $internalResponse, $data);
|
||||
$view->data = empty($temp) ? [] : \reset($temp);
|
||||
|
||||
return $view;
|
||||
}
|
||||
}
|
||||
|
|
@ -15,7 +15,10 @@ declare(strict_types=1);
|
|||
namespace Modules\Search\Controller;
|
||||
|
||||
use Modules\Search\Models\Search;
|
||||
use phpOMS\Message\Http\HttpRequest;
|
||||
use phpOMS\Message\ResponseAbstract;
|
||||
use phpOMS\Module\ModuleAbstract;
|
||||
use phpOMS\Router\RouterInterface;
|
||||
|
||||
/**
|
||||
* Search class.
|
||||
|
|
@ -75,4 +78,37 @@ class Controller extends ModuleAbstract
|
|||
* @since 1.0.0
|
||||
*/
|
||||
public static array $dependencies = [];
|
||||
|
||||
protected ?RouterInterface $router = null;
|
||||
|
||||
/**
|
||||
* Api method to handle basic search request
|
||||
*
|
||||
* @param HttpRequest $request Request
|
||||
* @param ResponseAbstract $response Response
|
||||
* @param array $data Generic data
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @api
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function routeSearch(HttpRequest $request, ResponseAbstract $response, mixed $data = null) : array
|
||||
{
|
||||
$this->app->dispatcher->dispatch(
|
||||
$this->router->route(
|
||||
$request->getDataString('search') ?? '',
|
||||
$request->getDataString('CSRF'),
|
||||
$request->getRouteVerb(),
|
||||
$this->app->appId,
|
||||
$this->app->unitId,
|
||||
$this->app->accountManager->get($request->header->account)
|
||||
),
|
||||
$request,
|
||||
$response
|
||||
);
|
||||
|
||||
return $response->data;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
17
Theme/Backend/Lang/de.lang.php
Normal file
17
Theme/Backend/Lang/de.lang.php
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
/**
|
||||
* Jingga
|
||||
*
|
||||
* PHP Version 8.1
|
||||
*
|
||||
* @package Modules\Localization
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 2.0
|
||||
* @version 1.0.0
|
||||
* @link https://jingga.app
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
return ['Search' => [
|
||||
'NoResults' => 'Keine Surchergebnisse',
|
||||
]];
|
||||
17
Theme/Backend/Lang/en.lang.php
Normal file
17
Theme/Backend/Lang/en.lang.php
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
/**
|
||||
* Jingga
|
||||
*
|
||||
* PHP Version 8.1
|
||||
*
|
||||
* @package Modules\Localization
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 2.0
|
||||
* @version 1.0.0
|
||||
* @link https://jingga.app
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
return ['Search' => [
|
||||
'NoResults' => 'No search results',
|
||||
]];
|
||||
115
Theme/Backend/search-result.tpl.php
Normal file
115
Theme/Backend/search-result.tpl.php
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
<?php
|
||||
/**
|
||||
* Jingga
|
||||
*
|
||||
* PHP Version 8.1
|
||||
*
|
||||
* @package Modules\QA
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 2.0
|
||||
* @version 1.0.0
|
||||
* @link https://jingga.app
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use phpOMS\Uri\UriFactory;
|
||||
use phpOMS\Utils\Parser\Markdown\Markdown;
|
||||
|
||||
$isEmpty = true;
|
||||
?>
|
||||
<?php
|
||||
foreach ($this->data as $controller) :
|
||||
if (empty($controller)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$first = \reset($controller);
|
||||
?>
|
||||
<div class="row">
|
||||
<div class="box col-xs-12">
|
||||
<h1><?= $first['module']; ?></h1>
|
||||
</div>
|
||||
</div>
|
||||
<?php if ($first['type'] === 'list_links') : ?>
|
||||
<?php foreach ($controller as $data) :
|
||||
if (empty($data)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$isEmpty = false;
|
||||
|
||||
$summary = $data['summary'];
|
||||
$summary = \trim($summary, " #\n");
|
||||
?>
|
||||
<div class="row">
|
||||
<div class="col-xs-12">
|
||||
<section class="portlet">
|
||||
<?php if (!empty($data['title']) && !empty($summary)) : ?>
|
||||
<a href="<?= UriFactory::build($data['link']); ?>">
|
||||
<div class="portlet-head"><?= $this->printHtml(\trim($data['title'])); ?></div>
|
||||
</a>
|
||||
<?php elseif (!empty($data['title']) && empty($summary)) : ?>
|
||||
<a href="<?= UriFactory::build($data['link']); ?>">
|
||||
<div class="portlet-body"><?= $this->printHtml(\trim($data['title'])); ?></div>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
<?php if (!empty($summary)) : ?>
|
||||
<div class="portlet-body"><article><?= Markdown::parse($summary); ?></article></div>
|
||||
<?php endif; ?>
|
||||
<?php if (!empty($data['tags'])) : ?>
|
||||
<div class="portlet-foot">
|
||||
<?php foreach ($data['tags'] as $tag) : ?>
|
||||
<span class="tag" style="background: <?= $this->printHtml($tag->color); ?>">
|
||||
<?= empty($tag->icon) ? '' : ''; ?>
|
||||
<?= $this->printHtml($tag->getL11n()); ?>
|
||||
</span>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
<?php elseif ($first['type'] === 'list_accounts') : ?>
|
||||
<div class="row">
|
||||
<?php foreach ($controller as $data) :
|
||||
if (empty($data)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$isEmpty = false;
|
||||
?>
|
||||
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-3">
|
||||
<section class="portlet">
|
||||
<div class="portlet-head">
|
||||
<a style="display: flex; align-items: center;" href="<?= UriFactory::build($data['link']); ?>">
|
||||
<img class="profile-image" alt="account" loading="lazy"
|
||||
src="<?= UriFactory::build($data['image']); ?>">
|
||||
<span style="margin-left: .5rem;"><?= $this->printHtml($data['title']); ?></span>
|
||||
</a>
|
||||
</div>
|
||||
<div class="portlet-body">
|
||||
<div>
|
||||
<table class="wf-100" style="font-size: .9rem;">
|
||||
<?php if (!empty($data['email'])) : ?><tr><td><a href=""><?= $this->printHtml($data['email']); ?></a><?php endif; ?>
|
||||
<?php if (!empty($data['phone'])) : ?><tr><td><?= $this->printHtml($data['phone']); ?><?php endif; ?>
|
||||
<?php if (!empty($data['city'])) : ?><tr><td><?= $this->printHtml($data['city']); ?><?php endif; ?>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php endforeach; ?>
|
||||
|
||||
<?php if ($isEmpty) : ?>
|
||||
<div class="row">
|
||||
<div class="col-xs-12">
|
||||
<section class="portlet">
|
||||
<div class="portlet-body"><?= $this->getHtml('NoResults'); ?></div>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
Loading…
Reference in New Issue
Block a user