1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Alex19pov31\LinkedData\Loaders; |
4
|
|
|
|
5
|
|
|
use Alex19pov31\BitrixHelper\IblockHelper; |
6
|
|
|
use Alex19pov31\LinkedData\LoaderInterface; |
7
|
|
|
use Alex19pov31\LinkedData\Storage; |
8
|
|
|
|
9
|
|
|
class IblockLoader implements LoaderInterface |
10
|
|
|
{ |
11
|
|
|
use TraitBitrixLoader; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Код инфоблока |
15
|
|
|
* |
16
|
|
|
* @var string |
17
|
|
|
*/ |
18
|
|
|
private $iblockCode; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Идентификатор инфоблока |
22
|
|
|
* |
23
|
|
|
* @var integer |
24
|
|
|
*/ |
25
|
|
|
private $iblockId; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Менеджер данных |
29
|
|
|
* |
30
|
|
|
* @var \CIBlockElement|null |
|
|
|
|
31
|
|
|
*/ |
32
|
|
|
private $dataManager; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Хелпер инфоблоков |
36
|
|
|
* |
37
|
|
|
* @var IblockHelper|null |
38
|
|
|
*/ |
39
|
|
|
private $iblockHelper; |
40
|
|
|
|
41
|
|
|
public function __construct(string $iblockCode, $nameRepository = null, $dataManager = null, $storage = null, $iblockHelper = null) |
42
|
|
|
{ |
43
|
|
|
$this->iblockCode = $iblockCode; |
44
|
|
|
$this->iblockHelper = $iblockHelper; |
45
|
|
|
$this->iblockId = $this->getIblockId($iblockCode); |
46
|
|
|
$this->nameRepository = $nameRepository; |
47
|
|
|
$this->dataManager = !is_null($dataManager) ? $dataManager : \CIBlockElement::class; |
|
|
|
|
48
|
|
|
|
49
|
|
|
$storageClass = !is_null($storage) ? $storage : Storage::class; |
50
|
|
|
$storageClass::getRepository($this->repositoryName($iblockCode)) |
51
|
|
|
->setLoaderData($this); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
private function getIblockId(string $iblockCode): int |
55
|
|
|
{ |
56
|
|
|
if (!is_null($this->iblockHelper)) { |
57
|
|
|
return (int) $this->iblockHelper::getIblockID($iblockCode); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
IblockHelper::setCacheTime(60); |
61
|
|
|
$this->iblockHelper = new IblockHelper; |
62
|
|
|
return (int) $this->iblockHelper::getIblockID($iblockCode); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Имя репозитория по-умолчанию |
67
|
|
|
* |
68
|
|
|
* @param string $iblockCode |
69
|
|
|
* @return string |
70
|
|
|
*/ |
71
|
|
|
public static function getRepositoryName(string $iblockCode): string |
72
|
|
|
{ |
73
|
|
|
return 'iblock_' . $iblockCode; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Класс для получения данных |
78
|
|
|
* |
79
|
|
|
* @return \CIBlockElement |
80
|
|
|
*/ |
81
|
|
|
private function getDataManager() |
82
|
|
|
{ |
83
|
|
|
return $this->dataManager; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Возвращает данные |
88
|
|
|
* |
89
|
|
|
* @return array |
90
|
|
|
*/ |
91
|
|
|
public function getData(): array |
92
|
|
|
{ |
93
|
|
|
$data = []; |
94
|
|
|
$filter = $this->filter; |
95
|
|
|
$filter['IBLOCK_ID'] = $this->iblockId; |
96
|
|
|
$res = $this->getDataManager()::GetList( |
97
|
|
|
$this->sort, |
98
|
|
|
$filter, |
99
|
|
|
false, |
100
|
|
|
false, |
101
|
|
|
$this->select |
102
|
|
|
); |
103
|
|
|
|
104
|
|
|
while ($item = $res->Fetch()) { |
105
|
|
|
if (empty($item[$this->getKey()])) { |
106
|
|
|
$data[] = $item; |
107
|
|
|
continue; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
$key = $item[$this->getKey()]; |
111
|
|
|
$data[$key] = $item; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
return $data; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Возвращает элемент по ключу |
119
|
|
|
* |
120
|
|
|
* @param mixed $key |
121
|
|
|
* @return mixed |
122
|
|
|
*/ |
123
|
|
|
public function getItem($key) |
124
|
|
|
{ |
125
|
|
|
$filter = $this->filter; |
126
|
|
|
$filter[$this->getKey()] = $key; |
127
|
|
|
$filter['IBLOCK_ID'] = $this->iblockId; |
128
|
|
|
$data = $this->getDataManager()::GetList( |
129
|
|
|
$this->sort, |
130
|
|
|
$filter, |
131
|
|
|
false, |
132
|
|
|
false, |
133
|
|
|
$this->select |
134
|
|
|
)->Fetch(); |
135
|
|
|
|
136
|
|
|
return !empty($data) ? (array) $data : []; |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
|
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.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths