mirror of
https://github.com/Karaka-Management/oms-News.git
synced 2026-01-11 08:08:42 +00:00
bump
This commit is contained in:
parent
f746af1495
commit
0f1632672c
|
|
@ -29,4 +29,15 @@ return [
|
|||
],
|
||||
],
|
||||
],
|
||||
'^:tag .*?' => [
|
||||
[
|
||||
'dest' => '\Modules\News\Controller\SearchController:searchTag',
|
||||
'verb' => RouteVerb::ANY,
|
||||
'permission' => [
|
||||
'module' => SearchController::NAME,
|
||||
'type' => PermissionType::READ,
|
||||
'state' => PermissionCategory::NEWS,
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
|
|
|||
|
|
@ -31,6 +31,62 @@ use phpOMS\System\MimeType;
|
|||
*/
|
||||
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 searchTag(RequestAbstract $request, ResponseAbstract $response, array $data = []) : void
|
||||
{
|
||||
$search = $request->getDataString('search') ?? '';
|
||||
|
||||
$searchIdStartPos = \stripos($search, ':');
|
||||
$patternStartPos = $searchIdStartPos === false
|
||||
? -1
|
||||
: \stripos($search, ' ', $searchIdStartPos);
|
||||
|
||||
$pattern = \substr($search, $patternStartPos + 1);
|
||||
|
||||
/** @var \Modules\News\Models\NewsArticle[] $news */
|
||||
$news = NewsArticleMapper::getAll()
|
||||
->with('tags')
|
||||
->with('tags/title')
|
||||
->where('status', NewsStatus::VISIBLE)
|
||||
->where('publish', new \DateTime('now'), '<=')
|
||||
->where('language', $response->header->l11n->language)
|
||||
->where('tags/title/language', $response->header->l11n->language)
|
||||
->where('tags/title/content', $pattern)
|
||||
->sort('publish', OrderType::DESC)
|
||||
->limit(8)
|
||||
->execute();
|
||||
|
||||
$results = [];
|
||||
foreach ($news as $article) {
|
||||
$results[] = [
|
||||
'title' => $article->title,
|
||||
'summary' => '',
|
||||
'link' => '{/base}/news/article?id=' . $article->id,
|
||||
'account' => '',
|
||||
'createdAt' => $article->createdAt,
|
||||
'image' => '',
|
||||
'tags' => $article->tags,
|
||||
'type' => 'list_links',
|
||||
'module' => 'News',
|
||||
];
|
||||
}
|
||||
|
||||
$response->header->set('Content-Type', MimeType::M_JSON . '; charset=utf-8', true);
|
||||
$response->add($request->uri->__toString(), $results);
|
||||
}
|
||||
|
||||
/**
|
||||
* Api method to search for tags
|
||||
*
|
||||
|
|
|
|||
|
|
@ -43,7 +43,10 @@ echo $this->data['nav']->render(); ?>
|
|||
<div class="portlet-body">
|
||||
<article><?= Markdown::parse(\substr($news->plain, 0, 500)); ?></article>
|
||||
<?php foreach ($news->tags as $tag) : ?>
|
||||
<span class="tag" style="background: <?= $this->printHtml($tag->color); ?>"><?= empty($tag->icon) ? '' : ''; ?><?= $this->printHtml($tag->getL11n()); ?></span>
|
||||
<span class="tag" style="background: <?= $this->printHtml($tag->color); ?>">
|
||||
<?= empty($tag->icon) ? '' : '<i class="g-icon">' . $this->printHtml($tag->icon) . '</i>'; ?>
|
||||
<?= $this->printHtml($tag->getL11n()); ?>
|
||||
</span>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<div class="portlet-foot">
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user