|
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\Helper; |
|
13
|
|
|
|
|
14
|
|
|
use Jitamin\Foundation\Base; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Navbar Search Helper. |
|
18
|
|
|
*/ |
|
19
|
|
|
class NavbarSearchHelper extends Base |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* Get current query. |
|
23
|
|
|
* |
|
24
|
|
|
* @param array $project |
|
25
|
|
|
* |
|
26
|
|
|
* @return string |
|
27
|
|
|
*/ |
|
28
|
|
|
public function getSearchQuery(array $project) |
|
29
|
|
|
{ |
|
30
|
|
|
$project_id = !empty($project) ? $project['id'] : 0; |
|
31
|
|
|
$query = $this->request->getStringParam('q', $this->userSession->getFilters($project_id)); |
|
|
|
|
|
|
32
|
|
|
$this->userSession->setFilters($project_id, $query); |
|
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
return urldecode($query); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Render project header (views switcher and search box). |
|
39
|
|
|
* |
|
40
|
|
|
* @param array $project |
|
41
|
|
|
* |
|
42
|
|
|
* @return string |
|
43
|
|
|
*/ |
|
44
|
|
|
public function render(array $project) |
|
45
|
|
|
{ |
|
46
|
|
|
if (empty($project)) { |
|
47
|
|
|
return; |
|
48
|
|
|
} |
|
49
|
|
|
$controller = $this->helper->app->getRouterController(); |
|
|
|
|
|
|
50
|
|
|
$action = $this->helper->app->getRouterAction(); |
|
|
|
|
|
|
51
|
|
|
|
|
52
|
|
|
if (!$this->canShowNavbarSearch($controller.'@'.$action)) { |
|
53
|
|
|
return; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
$filters = [ |
|
57
|
|
|
'controller' => $controller, |
|
58
|
|
|
'action' => $action, |
|
59
|
|
|
'project_id' => $project['id'], |
|
60
|
|
|
'q' => $this->getSearchQuery($project), |
|
61
|
|
|
]; |
|
62
|
|
|
|
|
63
|
|
|
return $this->template->render('_partials/navbar_search', [ |
|
|
|
|
|
|
64
|
|
|
'project' => $project, |
|
65
|
|
|
'filters' => $filters, |
|
66
|
|
|
'categories_list' => $this->categoryModel->getList($project['id'], false), |
|
|
|
|
|
|
67
|
|
|
'users_list' => $this->projectUserRoleModel->getAssignableUsersList($project['id'], false), |
|
|
|
|
|
|
68
|
|
|
'custom_filters_list' => $this->customFilterModel->getAll($project['id'], $this->userSession->getId()), |
|
|
|
|
|
|
69
|
|
|
]); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Determin if shows header search bar. |
|
74
|
|
|
* |
|
75
|
|
|
* @param string $path |
|
76
|
|
|
* |
|
77
|
|
|
* @return bool |
|
78
|
|
|
*/ |
|
79
|
|
|
protected function canShowNavbarSearch($path = '') |
|
80
|
|
|
{ |
|
81
|
|
|
$whiteList = ['Project/ProjectController@overview', 'Project/ProjectController@show', 'Project/Board/BoardController@show', 'CalendarController@show', 'Task/TaskController@index', 'Task/TaskController@gantt']; |
|
82
|
|
|
|
|
83
|
|
|
return in_array($path, $whiteList); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|
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.