|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of Jitamin. |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright (C) Jitamin Team |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Jitamin\Http\Controllers; |
|
13
|
|
|
|
|
14
|
|
|
use Jitamin\Filter\TaskProjectsFilter; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Search Controller. |
|
18
|
|
|
*/ |
|
19
|
|
|
class SearchController extends Controller |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* Shows the search view. |
|
23
|
|
|
*/ |
|
24
|
|
|
public function index() |
|
25
|
|
|
{ |
|
26
|
|
|
$projects = $this->projectUserRoleModel->getActiveProjectsByUser($this->userSession->getId()); |
|
|
|
|
|
|
27
|
|
|
$query = urldecode($this->request->getStringParam('q')); |
|
|
|
|
|
|
28
|
|
|
$nb_tasks = 0; |
|
29
|
|
|
|
|
30
|
|
|
$paginator = $this->paginator |
|
|
|
|
|
|
31
|
|
|
->setUrl('SearchController', 'index', ['q' => $query]) |
|
32
|
|
|
->setMax(30) |
|
33
|
|
|
->setOrder('tasks.id') |
|
34
|
|
|
->setDirection('DESC'); |
|
35
|
|
|
|
|
36
|
|
|
if ($query !== '' && !empty($projects)) { |
|
37
|
|
|
$paginator |
|
38
|
|
|
->setQuery($this->taskLexer |
|
|
|
|
|
|
39
|
|
|
->build($query) |
|
40
|
|
|
->withFilter(new TaskProjectsFilter(array_keys($projects))) |
|
41
|
|
|
->getQuery() |
|
42
|
|
|
) |
|
43
|
|
|
->calculate(); |
|
44
|
|
|
|
|
45
|
|
|
$nb_tasks = $paginator->getTotal(); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
$this->response->html($this->helper->layout->dashboard('search/index', [ |
|
|
|
|
|
|
49
|
|
|
'values' => [ |
|
50
|
|
|
'q' => $query, |
|
51
|
|
|
'controller' => 'SearchController', |
|
52
|
|
|
'action' => 'index', |
|
53
|
|
|
], |
|
54
|
|
|
'paginator' => $paginator, |
|
55
|
|
|
'title' => t('Search tasks').($nb_tasks > 0 ? ' ('.$nb_tasks.')' : ''), |
|
56
|
|
|
], 'search/_partials/nav')); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Shows the search view of activity. |
|
61
|
|
|
*/ |
|
62
|
|
|
public function activity() |
|
63
|
|
|
{ |
|
64
|
|
|
$query = urldecode($this->request->getStringParam('q')); |
|
|
|
|
|
|
65
|
|
|
$events = $this->helper->projectActivity->searchEvents($query); |
|
|
|
|
|
|
66
|
|
|
$nb_events = count($events); |
|
67
|
|
|
|
|
68
|
|
|
$this->response->html($this->helper->layout->dashboard('search/activity', [ |
|
|
|
|
|
|
69
|
|
|
'values' => [ |
|
70
|
|
|
'q' => $query, |
|
71
|
|
|
'controller' => 'SearchController', |
|
72
|
|
|
'action' => 'activity', |
|
73
|
|
|
], |
|
74
|
|
|
'title' => t('Search in activities').($nb_events > 0 ? ' ('.$nb_events.')' : ''), |
|
75
|
|
|
'nb_events' => $nb_events, |
|
76
|
|
|
'events' => $events, |
|
77
|
|
|
], 'search/_partials/nav')); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
Since your code implements the magic getter
_get, this function will be called for any read access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.