|
1
|
|
|
<?php |
|
2
|
|
|
|
|
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 Module |
|
12
|
|
|
{ |
|
13
|
|
|
public function viewsList() |
|
14
|
|
|
{ |
|
15
|
|
|
$return = [ |
|
16
|
|
|
'inherit' => 'Как у родителя', |
|
17
|
|
|
'default' => 'Стандартная страница', |
|
18
|
|
|
'materialWithCategorys' => 'Страница со списком категорий', |
|
19
|
|
|
]; |
|
20
|
|
|
$conf = App::$primary->view->template->config; |
|
21
|
|
|
|
|
22
|
|
|
if (!empty($conf['files']['modules']['Materials'])) { |
|
23
|
|
|
|
|
24
|
|
|
foreach ($conf['files']['modules']['Materials'] as $file) { |
|
25
|
|
|
if (!empty($file['type']) && $file['type'] == 'Material') { |
|
26
|
|
|
$return[$file['file']] = $file['name']; |
|
27
|
|
|
} |
|
28
|
|
|
} |
|
29
|
|
|
} |
|
30
|
|
|
return $return; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
View Code Duplication |
public function templatesList() |
|
34
|
|
|
{ |
|
35
|
|
|
$return = [ |
|
36
|
|
|
'inherit' => 'Как у родителя', |
|
37
|
|
|
'current' => 'Текущая тема' |
|
38
|
|
|
]; |
|
39
|
|
|
|
|
40
|
|
|
$conf = App::$primary->view->template->config; |
|
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
|
|
|
{ |
|
52
|
|
|
$return = [ |
|
53
|
|
|
'inherit' => 'Как у родителя', |
|
54
|
|
|
'category' => 'Стандартная категория', |
|
55
|
|
|
]; |
|
56
|
|
|
$conf = App::$primary->view->template->config; |
|
57
|
|
|
|
|
58
|
|
|
if (!empty($conf['files']['modules']['Materials'])) { |
|
59
|
|
|
|
|
60
|
|
|
foreach ($conf['files']['modules']['Materials'] as $file) { |
|
61
|
|
|
if ($file['type'] == 'Category') { |
|
62
|
|
|
$return[$file['file']] = $file['name']; |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
return $return; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
View Code Duplication |
public function templatesCategoryList() |
|
70
|
|
|
{ |
|
71
|
|
|
$return = [ |
|
72
|
|
|
'inherit' => 'Как у родителя', |
|
73
|
|
|
'current' => 'Текущая тема' |
|
74
|
|
|
]; |
|
75
|
|
|
|
|
76
|
|
|
$conf = App::$primary->view->template->config; |
|
77
|
|
|
|
|
78
|
|
|
if (!empty($conf['files']['aditionTemplateFiels'])) { |
|
79
|
|
|
foreach ($conf['files']['aditionTemplateFiels'] as $file) { |
|
80
|
|
|
$return[$file['file']] = '- ' . $file['name']; |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
return $return; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
View Code Duplication |
function sitemap() |
|
|
|
|
|
|
87
|
|
|
{ |
|
88
|
|
|
$map = []; |
|
89
|
|
|
$zeroMaterials = \Materials\Material::getList(['where' => ['category_id', 0]]); |
|
90
|
|
|
foreach ($zeroMaterials as $mat) { |
|
91
|
|
|
$map[] = [ |
|
92
|
|
|
'name' => $mat->name, |
|
93
|
|
|
'url' => [ |
|
94
|
|
|
'loc' => (!empty($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . INJI_DOMAIN_NAME . ($mat->getHref()) |
|
95
|
|
|
], |
|
96
|
|
|
]; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
$categorys = \Materials\Category::getList(['where' => ['parent_id', 0]]); |
|
100
|
|
|
$scan = function($category, $scan) { |
|
101
|
|
|
$map = []; |
|
102
|
|
|
|
|
103
|
|
|
foreach ($category->items as $mat) { |
|
104
|
|
|
$map[] = [ |
|
105
|
|
|
'name' => $mat->name, |
|
106
|
|
|
'url' => [ |
|
107
|
|
|
'loc' => (!empty($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . INJI_DOMAIN_NAME . ($mat->getHref()) |
|
108
|
|
|
], |
|
109
|
|
|
]; |
|
110
|
|
|
} |
|
111
|
|
|
foreach ($category->childs as $child) { |
|
112
|
|
|
$map = array_merge($map, $scan($child, $scan)); |
|
113
|
|
|
} |
|
114
|
|
|
return $map; |
|
115
|
|
|
}; |
|
116
|
|
|
foreach ($categorys as $category) { |
|
117
|
|
|
$map = array_merge($map, $scan($category, $scan)); |
|
118
|
|
|
} |
|
119
|
|
|
return $map; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
} |
|
123
|
|
|
|
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.