1 | <?php |
||||
2 | |||||
3 | namespace SleepingOwl\Admin\Navigation; |
||||
4 | |||||
5 | use SleepingOwl\Admin\Contracts\ModelConfigurationInterface; |
||||
6 | use SleepingOwl\Admin\Contracts\Navigation\PageInterface; |
||||
7 | |||||
8 | class Page extends \KodiComponents\Navigation\Page implements PageInterface |
||||
9 | { |
||||
10 | /** |
||||
11 | * Menu item related model class. |
||||
12 | * @var string |
||||
13 | */ |
||||
14 | protected $model; |
||||
15 | |||||
16 | /** |
||||
17 | * Menu item by url id. |
||||
18 | * @var string |
||||
19 | */ |
||||
20 | protected $aliasId; |
||||
21 | |||||
22 | /** |
||||
23 | * @param string|null $modelClass |
||||
24 | */ |
||||
25 | 1 | public function __construct($modelClass = null) |
|||
26 | { |
||||
27 | 1 | parent::__construct(); |
|||
28 | |||||
29 | 1 | $this->setModel($modelClass); |
|||
30 | |||||
31 | 1 | if ($this->hasModel()) { |
|||
32 | 1 | $this->setIcon($this->getModelConfiguration()->getIcon()); |
|||
33 | 1 | } |
|||
34 | 1 | } |
|||
35 | |||||
36 | /** |
||||
37 | * Set Alias Id. |
||||
38 | */ |
||||
39 | public function setAliasId() |
||||
40 | { |
||||
41 | $url = parse_url($this->getUrl(), PHP_URL_PATH); |
||||
42 | if ($url) { |
||||
43 | $this->aliasId = md5($url); |
||||
44 | } |
||||
45 | } |
||||
46 | |||||
47 | /** |
||||
48 | * @return string |
||||
49 | */ |
||||
50 | public function getAliasId() |
||||
51 | { |
||||
52 | return $this->aliasId; |
||||
53 | } |
||||
54 | |||||
55 | /** |
||||
56 | * @return ModelConfigurationInterface |
||||
57 | */ |
||||
58 | 1 | public function getModelConfiguration() |
|||
59 | { |
||||
60 | 1 | if (! $this->hasModel()) { |
|||
61 | return; |
||||
62 | } |
||||
63 | |||||
64 | 1 | return app('sleeping_owl')->getModel($this->model); |
|||
0 ignored issues
–
show
|
|||||
65 | } |
||||
66 | |||||
67 | /** |
||||
68 | * @return bool |
||||
69 | */ |
||||
70 | 1 | public function hasModel() |
|||
71 | { |
||||
72 | 1 | return ! is_null($this->model) && class_exists($this->model); |
|||
73 | } |
||||
74 | |||||
75 | /** |
||||
76 | * @return string |
||||
77 | */ |
||||
78 | public function getId() |
||||
79 | { |
||||
80 | if (is_null($this->id) && $this->hasModel()) { |
||||
0 ignored issues
–
show
|
|||||
81 | return $this->model; |
||||
82 | } |
||||
83 | |||||
84 | return parent::getId(); |
||||
85 | } |
||||
86 | |||||
87 | /** |
||||
88 | * @return string |
||||
89 | */ |
||||
90 | public function getTitle() |
||||
91 | { |
||||
92 | if (is_null($this->title) && $this->hasModel()) { |
||||
0 ignored issues
–
show
|
|||||
93 | return $this->getModelConfiguration()->getTitle(); |
||||
94 | } |
||||
95 | |||||
96 | return parent::getTitle(); |
||||
97 | } |
||||
98 | |||||
99 | /** |
||||
100 | * @return string |
||||
101 | */ |
||||
102 | public function getUrl() |
||||
103 | { |
||||
104 | if (is_null($this->url) && $this->hasModel()) { |
||||
0 ignored issues
–
show
|
|||||
105 | return $this->getModelConfiguration()->getDisplayUrl(); |
||||
106 | } |
||||
107 | |||||
108 | return parent::getUrl(); |
||||
109 | } |
||||
110 | |||||
111 | /** |
||||
112 | * @return \Closure |
||||
113 | */ |
||||
114 | public function getAccessLogic() |
||||
115 | { |
||||
116 | if (! is_callable($this->accessLogic)) { |
||||
117 | if ($this->hasModel()) { |
||||
118 | return function () { |
||||
119 | return $this->getModelConfiguration()->isDisplayable(); |
||||
120 | }; |
||||
121 | } |
||||
122 | } |
||||
123 | |||||
124 | return parent::getAccessLogic(); |
||||
125 | } |
||||
126 | |||||
127 | /** |
||||
128 | * @param string|null $view |
||||
129 | * |
||||
130 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
||||
131 | */ |
||||
132 | public function render($view = null) |
||||
133 | { |
||||
134 | if ($this->hasChild() && ! $this->hasClassProperty($class = config('navigation.class.has_child', 'treeview'))) { |
||||
135 | $this->setHtmlAttribute('class', $class); |
||||
136 | } |
||||
137 | |||||
138 | $data = $this->toArray(); |
||||
139 | |||||
140 | if (! is_null($view)) { |
||||
141 | return view($view, $data)->render(); |
||||
0 ignored issues
–
show
|
|||||
142 | } |
||||
143 | |||||
144 | return app('sleeping_owl.template')->view('_partials.navigation.page', $data)->render(); |
||||
0 ignored issues
–
show
The method
view() does not exist on Illuminate\Contracts\Foundation\Application .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||
145 | } |
||||
146 | |||||
147 | /** |
||||
148 | 1 | * @param string $model |
|||
149 | * |
||||
150 | 1 | * @return $this |
|||
151 | */ |
||||
152 | 1 | protected function setModel($model) |
|||
153 | { |
||||
154 | $this->model = $model; |
||||
155 | |||||
156 | return $this; |
||||
157 | } |
||||
158 | } |
||||
159 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.