This commit is contained in:
Dennis Eichhorn 2024-03-10 02:24:57 +00:00
parent 421f0743d1
commit f6a19bab02
4 changed files with 75 additions and 4 deletions

View File

@ -30,6 +30,76 @@ 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\Tasks\Models\Task[] $tasks */
$tasks = TaskMapper::getAll()
->with('tags')
->with('tags/title')
->with('taskElements')
->where('tags/title/language', $response->header->l11n->language)
->where('tags/title/content', $pattern)
->sort('createdAt', OrderType::DESC)
->sort('taskElements/createdAt', OrderType::ASC)
->limit(8)
//->limit(1, 'taskElements')
->execute();
$results = [];
$count = 0;
foreach ($tasks as $task) {
if ($count >= 8) {
break;
}
// @performance Check if this can be combined with the above getAll()
// https://github.com/Karaka-Management/oms-Tasks/issues/41
if (!TaskMapper::hasReadingPermission($request->header->account, $task->id)) {
continue;
}
++$count;
$results[] = [
'title' => $task->title,
'summary' => \substr(\trim($task->description), 0, 500),
'link' => '{/base}/task/view?id=' . $task->id,
'account' => '',
'createdAt' => $task->createdAt,
'image' => '',
'tags' => $task->tags,
'type' => 'list_links',
'module' => 'Tasks',
];
}
$response->header->set('Content-Type', MimeType::M_JSON . '; charset=utf-8', true);
$response->add($request->uri->__toString(), $results);
}
/**
* Api method to search for tags
*

View File

@ -76,7 +76,7 @@ echo $this->data['nav']->render(); ?>
<?php foreach ($task->tags as $tag) : ?>
<a href="<?= $url; ?>">
<span class="tag" style="background: <?= $this->printHtml($tag->color); ?>">
<?= empty($tag->icon) ? '' : ''; ?>
<?= empty($tag->icon) ? '' : '<i class="g-icon">' . $this->printHtml($tag->icon) . '</i>'; ?>
<?= $this->printHtml($tag->getL11n()); ?>
</span>
</a>
@ -150,7 +150,7 @@ echo $this->data['nav']->render(); ?>
<?php foreach ($task->tags as $tag) : ?>
<a href="<?= $url; ?>">
<span class="tag" style="background: <?= $this->printHtml($tag->color); ?>">
<?= empty($tag->icon) ? '' : ''; ?>
<?= empty($tag->icon) ? '' : '<i class="g-icon">' . $this->printHtml($tag->icon) . '</i>'; ?>
<?= $this->printHtml($tag->getL11n()); ?>
</span>
</a>

View File

@ -77,7 +77,7 @@ echo $this->data['nav']->render(); ?>
<?php foreach ($task->tags as $tag) : ?>
<a href="<?= $url; ?>">
<span class="tag" style="background: <?= $this->printHtml($tag->color); ?>">
<?= empty($tag->icon) ? '' : ''; ?>
<?= empty($tag->icon) ? '' : '<i class="g-icon">' . $this->printHtml($tag->icon) . '</i>'; ?>
<?= $this->printHtml($tag->getL11n()); ?>
</span>
</a>

View File

@ -87,7 +87,8 @@ echo $this->data['nav']->render(); ?>
<?php
foreach ($task->tags as $tag) : ?>
<span class="tag" style="background: <?= $this->printHtml($tag->color); ?>">
<?= empty($tag->icon) ? '' : ''; ?><?= $this->printHtml($tag->getL11n()); ?>
<?= empty($tag->icon) ? '' : '<i class="g-icon">' . $this->printHtml($tag->icon) . '</i>'; ?>
<?= $this->printHtml($tag->getL11n()); ?>
</span>
<?php endforeach; ?>
<?php if (!empty($taskMedia)) : ?>