Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
boardcomponentbutton.php
1<?php
2
4
5
6
7use Bitrix\Main\Page\Asset;
9
11{
12 private $componentName;
13 private $componentTemplateName = '';
14 private $componentParams = [];
15 private $jsPathList = array();
16 private $cssPathList = array();
17 private $processed = false;
18
19
20 public function __construct($componentName, $componentTemplateName = '', $componentParams = [])
21 {
22 $this->setComponentName($componentName);
23 $this->setComponentTemplateName($componentTemplateName);
24 $this->setComponentParams($componentParams);
25 }
26
30 public function getComponentName()
31 {
32 return $this->componentName;
33 }
34
38 public function setComponentName($componentName)
39 {
40 $this->componentName = $componentName;
41 }
42
46 public function getComponentTemplateName()
47 {
48 return $this->componentTemplateName;
49 }
50
54 public function setComponentTemplateName($componentTemplateName)
55 {
56 $this->componentTemplateName = $componentTemplateName;
57 }
58
62 public function getComponentParams()
63 {
64 return $this->componentParams;
65 }
66
70 public function setComponentParams($componentParams)
71 {
72 $this->componentParams = $componentParams;
73 }
74
78 public function process()
79 {
80 if ($this->isProcessed())
81 {
82 return $this;
83 }
84
85 ob_start();
86 $this->flush();
87 $componentContent = ob_get_clean();
88
89 //$this->collectAssetsPathList();
90
91
92 $this->setHtml($componentContent);
93 $this->setJsList($this->getComponentJsList());
94 $this->setCssList($this->getComponentCssList());
95 $this->setStringList($this->getComponentstringList());
96
97 $this->setProcessed(true);
98 return $this;
99 }
100
101
102 public function flush()
103 {
104 global $APPLICATION;
105 $APPLICATION->IncludeComponent(
106 $this->getComponentName(),
108 $this->getComponentParams()
109 );
110 }
111
112 private function collectAssetsPathList()
113 {
114 Asset::getInstance()->getJs();
115 Asset::getInstance()->getCss();
116
117 $this->jsPathList = Asset::getInstance()->getTargetList('JS');
118 $this->cssPathList = Asset::getInstance()->getTargetList('CSS');
119 }
120
121
125 private function getComponentJsList()
126 {
127 $jsList = array();
128
129 foreach($this->jsPathList as $targetAsset)
130 {
131 $assetInfo = Asset::getInstance()->getAssetInfo($targetAsset['NAME'], AssetMode::ALL);
132 if (!empty($assetInfo['JS']))
133 {
134 $jsList = array_merge($jsList, $assetInfo['JS']);
135 }
136 }
137
138 return $jsList;
139 }
140
144 private function getComponentCssList()
145 {
146 $cssList = array();
147
148 foreach($this->cssPathList as $targetAsset)
149 {
150 $assetInfo = Asset::getInstance()->getAssetInfo($targetAsset['NAME'], AssetMode::ALL);
151 if (!empty($assetInfo['CSS']))
152 {
153 $cssList = array_merge($cssList, $assetInfo['CSS']);
154 }
155 }
156
157 return $cssList;
158 }
159
163 private function getComponentStringList()
164 {
165 $stringList = array();
166 foreach($this->cssPathList as $targetAsset)
167 {
168 $assetInfo = Asset::getInstance()->getAssetInfo($targetAsset['NAME'], AssetMode::ALL);
169 if (!empty($assetInfo['STRINGS']))
170 {
171 $stringList = array_merge($stringList, $assetInfo['STRINGS']);
172 }
173 }
174
175 foreach($this->jsPathList as $targetAsset)
176 {
177 $assetInfo = Asset::getInstance()->getAssetInfo($targetAsset['NAME'], AssetMode::ALL);
178 if (!empty($assetInfo['STRINGS']))
179 {
180 $stringList = array_merge($stringList, $assetInfo['STRINGS']);
181 }
182 }
183 return $stringList;
184 }
185
189 public function isProcessed()
190 {
191 return $this->processed;
192 }
193
197 public function setProcessed($processed)
198 {
199 $this->processed = $processed;
200 }
201
202}
203
__construct($componentName, $componentTemplateName='', $componentParams=[])