with('tags') ->with('tags/title') ->with('taskElements') ->where('title', '%' . ($request->getDataString('search') ?? '') . '%', 'LIKE') ->where('tags/title/language', $response->header->l11n->language) ->sort('createdAt', OrderType::DESC) ->sort('taskElements/createdAt', OrderType::ASC) ->limit(25) //->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); } }