From f6a19bab0200ecace8f7a92df455d5d0712b117e Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sun, 10 Mar 2024 02:24:57 +0000 Subject: [PATCH] bump --- Controller/SearchController.php | 70 ++++++++++++++++++++++++++++ Theme/Backend/task-dashboard.tpl.php | 4 +- Theme/Backend/task-list.tpl.php | 2 +- Theme/Backend/task-view.tpl.php | 3 +- 4 files changed, 75 insertions(+), 4 deletions(-) diff --git a/Controller/SearchController.php b/Controller/SearchController.php index 64c32e0..3bfff4f 100755 --- a/Controller/SearchController.php +++ b/Controller/SearchController.php @@ -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 * diff --git a/Theme/Backend/task-dashboard.tpl.php b/Theme/Backend/task-dashboard.tpl.php index 8c6b27f..451965b 100755 --- a/Theme/Backend/task-dashboard.tpl.php +++ b/Theme/Backend/task-dashboard.tpl.php @@ -76,7 +76,7 @@ echo $this->data['nav']->render(); ?> tags as $tag) : ?> - icon) ? '' : ''; ?> + icon) ? '' : '' . $this->printHtml($tag->icon) . ''; ?> printHtml($tag->getL11n()); ?> @@ -150,7 +150,7 @@ echo $this->data['nav']->render(); ?> tags as $tag) : ?> - icon) ? '' : ''; ?> + icon) ? '' : '' . $this->printHtml($tag->icon) . ''; ?> printHtml($tag->getL11n()); ?> diff --git a/Theme/Backend/task-list.tpl.php b/Theme/Backend/task-list.tpl.php index 15fbc22..05343e0 100644 --- a/Theme/Backend/task-list.tpl.php +++ b/Theme/Backend/task-list.tpl.php @@ -77,7 +77,7 @@ echo $this->data['nav']->render(); ?> tags as $tag) : ?> - icon) ? '' : ''; ?> + icon) ? '' : '' . $this->printHtml($tag->icon) . ''; ?> printHtml($tag->getL11n()); ?> diff --git a/Theme/Backend/task-view.tpl.php b/Theme/Backend/task-view.tpl.php index 6c17049..3c5346e 100644 --- a/Theme/Backend/task-view.tpl.php +++ b/Theme/Backend/task-view.tpl.php @@ -87,7 +87,8 @@ echo $this->data['nav']->render(); ?> tags as $tag) : ?> - icon) ? '' : ''; ?>printHtml($tag->getL11n()); ?> + icon) ? '' : '' . $this->printHtml($tag->icon) . ''; ?> + printHtml($tag->getL11n()); ?>