1 | <?php |
||||||
2 | namespace Inji; |
||||||
3 | /** |
||||||
4 | * Materials module |
||||||
5 | * |
||||||
6 | * @author Alexey Krupskiy <[email protected]> |
||||||
7 | * @link http://inji.ru/ |
||||||
8 | * @copyright 2015 Alexey Krupskiy |
||||||
9 | * @license https://github.com/injitools/cms-Inji/blob/master/LICENSE |
||||||
10 | */ |
||||||
11 | class Materials extends \Inji\Module { |
||||||
12 | public $name = 'Materials'; |
||||||
13 | |||||||
14 | public function viewsList() { |
||||||
15 | $return = [ |
||||||
16 | 'inherit' => 'Как у родителя', |
||||||
17 | 'default' => 'Стандартная страница', |
||||||
18 | 'main_page' => 'Главная страница', |
||||||
19 | 'materialWithCategorys' => 'Страница со списком категорий', |
||||||
20 | ]; |
||||||
21 | $conf = App::$primary->view->template->config; |
||||||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||||||
22 | |||||||
23 | if (!empty($conf['files']['modules']['Materials'])) { |
||||||
24 | |||||||
25 | foreach ($conf['files']['modules']['Materials'] as $file) { |
||||||
26 | if (!empty($file['type']) && $file['type'] == 'Material') { |
||||||
27 | $return[$file['file']] = $file['name']; |
||||||
28 | } |
||||||
29 | } |
||||||
30 | } |
||||||
31 | return $return; |
||||||
32 | } |
||||||
33 | |||||||
34 | public function templatesList() { |
||||||
35 | $return = [ |
||||||
36 | 'inherit' => 'Как у родителя', |
||||||
37 | 'current' => 'Текущая тема' |
||||||
38 | ]; |
||||||
39 | |||||||
40 | $conf = App::$primary->view->template->config; |
||||||
0 ignored issues
–
show
The property
view does not exist on Inji\App . Since you implemented __get , consider adding a @property annotation.
![]() |
|||||||
41 | |||||||
42 | if (!empty($conf['files']['aditionTemplateFiels'])) { |
||||||
43 | foreach ($conf['files']['aditionTemplateFiels'] as $file) { |
||||||
44 | $return[$file['file']] = '- ' . $file['name']; |
||||||
45 | } |
||||||
46 | } |
||||||
47 | return $return; |
||||||
48 | } |
||||||
49 | |||||||
50 | public function viewsCategoryList() { |
||||||
51 | $return = [ |
||||||
52 | 'inherit' => 'Как у родителя', |
||||||
53 | 'category' => 'Стандартная категория', |
||||||
54 | ]; |
||||||
55 | $conf = App::$primary->view->template->config; |
||||||
0 ignored issues
–
show
The property
view does not exist on Inji\App . Since you implemented __get , consider adding a @property annotation.
![]() |
|||||||
56 | |||||||
57 | if (!empty($conf['files']['modules']['Materials'])) { |
||||||
58 | |||||||
59 | foreach ($conf['files']['modules']['Materials'] as $file) { |
||||||
60 | if ($file['type'] == 'Category') { |
||||||
61 | $return[$file['file']] = $file['name']; |
||||||
62 | } |
||||||
63 | } |
||||||
64 | } |
||||||
65 | return $return; |
||||||
66 | } |
||||||
67 | |||||||
68 | public function templatesCategoryList() { |
||||||
69 | $return = [ |
||||||
70 | 'inherit' => 'Как у родителя', |
||||||
71 | 'current' => 'Текущая тема' |
||||||
72 | ]; |
||||||
73 | |||||||
74 | $conf = App::$primary->view->template->config; |
||||||
0 ignored issues
–
show
The property
view does not exist on Inji\App . Since you implemented __get , consider adding a @property annotation.
![]() |
|||||||
75 | |||||||
76 | if (!empty($conf['files']['aditionTemplateFiels'])) { |
||||||
77 | foreach ($conf['files']['aditionTemplateFiels'] as $file) { |
||||||
78 | $return[$file['file']] = '- ' . $file['name']; |
||||||
79 | } |
||||||
80 | } |
||||||
81 | return $return; |
||||||
82 | } |
||||||
83 | |||||||
84 | public function sitemap() { |
||||||
85 | $map = []; |
||||||
86 | $zeroMaterials = \Materials\Material::getList(['where' => ['category_id', 0]]); |
||||||
87 | foreach ($zeroMaterials as $mat) { |
||||||
88 | $map[] = [ |
||||||
89 | 'name' => $mat->name, |
||||||
90 | 'url' => [ |
||||||
91 | 'loc' => (!empty($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . INJI_DOMAIN_NAME . ($mat->getHref()) |
||||||
92 | ], |
||||||
93 | ]; |
||||||
94 | } |
||||||
95 | |||||||
96 | $categorys = \Materials\Category::getList(['where' => ['parent_id', 0]]); |
||||||
0 ignored issues
–
show
The type
Materials\Category was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||||||
97 | $scan = function ($category, $scan) { |
||||||
98 | $map = []; |
||||||
99 | |||||||
100 | foreach ($category->items as $mat) { |
||||||
101 | $map[] = [ |
||||||
102 | 'name' => $mat->name, |
||||||
103 | 'url' => [ |
||||||
104 | 'loc' => (!empty($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . INJI_DOMAIN_NAME . ($mat->getHref()) |
||||||
105 | ], |
||||||
106 | ]; |
||||||
107 | } |
||||||
108 | foreach ($category->childs as $child) { |
||||||
109 | $map = array_merge($map, $scan($child, $scan)); |
||||||
110 | } |
||||||
111 | return $map; |
||||||
112 | }; |
||||||
113 | foreach ($categorys as $category) { |
||||||
114 | $map = array_merge($map, $scan($category, $scan)); |
||||||
115 | } |
||||||
116 | return $map; |
||||||
117 | } |
||||||
118 | |||||||
119 | function search($search) { |
||||||
0 ignored issues
–
show
|
|||||||
120 | $query = 'select material_id from ' . App::$cur->db->table_prefix . \Materials\Material::table() . ' where MATCH (material_name,material_text,material_keywords,material_description) AGAINST (\'' . $search . '\')'; |
||||||
0 ignored issues
–
show
The property
db does not exist on Inji\App . Since you implemented __get , consider adding a @property annotation.
![]() |
|||||||
121 | $ids = array_keys(App::$cur->db->query($query)->getArray('material_id')); |
||||||
0 ignored issues
–
show
The method
query() does not exist on Inji\Module . It seems like you code against a sub-type of Inji\Module such as Inji\Db .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() The method
query() does not exist on null .
(
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. ![]() |
|||||||
122 | $count = count($ids); |
||||||
123 | $pages = new \Ui\Pages($_GET, ['count' => $count]); |
||||||
0 ignored issues
–
show
The type
Ui\Pages was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||||||
124 | //items |
||||||
125 | //items |
||||||
126 | $items = \Materials\Material::getList([ |
||||||
127 | 'where' => ['id', $ids, 'IN'], |
||||||
128 | 'start' => $pages->params['start'], |
||||||
129 | 'limit' => $pages->params['limit'] |
||||||
130 | ]); |
||||||
131 | return ['count' => $count, 'items' => $items, 'pages' => $pages]; |
||||||
132 | } |
||||||
133 | |||||||
134 | public function siteSearch($search) { |
||||||
135 | $result = $this->search($search); |
||||||
136 | $searchResult = []; |
||||||
137 | foreach ($result['items'] as $item) { |
||||||
138 | $details = '<div>'; |
||||||
139 | $shortdes = mb_substr(strip_tags($item->text), 0, 300); |
||||||
140 | $shortdes = mb_substr($shortdes, 0, mb_strrpos($shortdes, ' ')); |
||||||
141 | $details .= $shortdes; |
||||||
142 | if (mb_strlen($item->description) > $shortdes) { |
||||||
143 | $details .= '...'; |
||||||
144 | } |
||||||
145 | $details .= '</div>'; |
||||||
146 | $searchResult[] = [ |
||||||
147 | 'title' => $item->name(), |
||||||
148 | 'details' => $details, |
||||||
149 | 'href' => '/materials/view/' . $item->id |
||||||
150 | ]; |
||||||
151 | } |
||||||
152 | return ['name' => 'Материалы', 'count' => $result['count'], 'result' => $searchResult, 'detailSearch' => ' / materials / detailSearch ? search = ' . $search]; |
||||||
153 | } |
||||||
154 | } |
||||||
155 |