Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
toloka.php
1<?php
9
17
18Loc::loadMessages(__FILE__);
19
24class Toloka
25{
26 const IMAGE_DIR = '/images/sender/preset/events/';
27 const LOCAL_DIR = '/modules/sender/preset/template_toloka/';
28
29 private static function getFileContent($fileName)
30 {
31 $pathTemplate = Loader::getLocal(self::LOCAL_DIR . bx_basename($fileName) . '.php');
32 $pathCSS = Loader::getLocal(self::LOCAL_DIR . bx_basename($fileName) . '.css');
33 $pathJS = Loader::getLocal(self::LOCAL_DIR . bx_basename($fileName) . '.js');
34
35 if (
36 self::fileExists($pathTemplate) &&
37 self::fileExists($pathCSS) &&
38 self::fileExists($pathJS)
39 )
40 {
41 return [
42 'template' => File::getFileContents($pathTemplate),
43 'css' => File::getFileContents($pathCSS),
44 'js' => File::getFileContents($pathJS),
45 ];
46 }
47
48 return [];
49 }
50 private static function fileExists($path):bool
51 {
52 if($path && File::isFileExists($path))
53 {
54 return true;
55 }
56
57 return false;
58 }
67 public static function onPresetTemplateList($templateType = null, $templateId = null, $messageCode = null)
68 {
69 if($templateType && $templateType !== 'BASE')
70 {
71 return array();
72 }
73 if($messageCode && $messageCode !== Message\iBase::CODE_TOLOKA)
74 {
75 return array();
76 }
77
78 return self::getTemplates($templateId, $messageCode);
79 }
80
81 private static function getListByType()
82 {
83 $list = [
84 [
85 'CODE' => 'video',
86 'SEGMENT_CODES' => [],
87 'NAME' => Loc::getMessage('SENDER_PRESET_TEMPLATE_TOLOKA_TITLE_VIDEO'),
88 'HINT' => Loc::getMessage('SENDER_PRESET_TEMPLATE_TOLOKA_HINT_VIDEO'),
89 'FIELDS' => [
90 'INSTRUCTION' => [
91 'CODE' => 'INSTRUCTION',
92 'VALUE' => Loc::getMessage('SENDER_PRESET_TEMPLATE_TOLOKA_VIDEO_INSTRUCTION')
93 ],
94 'DESCRIPTION' => [
95 'CODE' => 'DESCRIPTION',
96 'VALUE' => Loc::getMessage('SENDER_PRESET_TEMPLATE_TOLOKA_VIDEO_DESCRIPTION')
97 ],
98 'TASKS' => [
99 'CODE' => 'TASKS',
100 'VALUE' => Loc::getMessage('SENDER_PRESET_TEMPLATE_TOLOKA_VIDEO_TASKS')
101 ],
102 'INPUT_VALUE' => [
103 'CODE' => 'INPUT_VALUE',
104 'VALUE' => ['video' => InputOutputSpec::TYPES['URL']]
105 ],
106 'OUTPUT_VALUE' => [
107 'CODE' => 'OUTPUT_VALUE',
108 'VALUE' => ['result' => InputOutputSpec::TYPES['STRING']]
109 ],
110 'PRESET' => [
111 'CODE' => 'PRESET',
112 'VALUE' => self::getFileContent('video')
113 ]
114 ]
115 ],
116 [
117 'CODE' => 'leaflets',
118 'SEGMENT_CODES' => [],
119 'NAME' => Loc::getMessage('SENDER_PRESET_TEMPLATE_TOLOKA_TITLE_LEAFLETS'),
120 'HINT' => Loc::getMessage('SENDER_PRESET_TEMPLATE_TOLOKA_HINT_LEAFLETS'),
121 'FIELDS' => [
122 'INSTRUCTION' => [
123 'CODE' => 'INSTRUCTION',
124 'VALUE' => Loc::getMessage('SENDER_PRESET_TEMPLATE_TOLOKA_LEAFLETS_INSTRUCTION')
125 ],
126 'DESCRIPTION' => [
127 'CODE' => 'DESCRIPTION',
128 'VALUE' => Loc::getMessage('SENDER_PRESET_TEMPLATE_TOLOKA_LEAFLETS_DESCRIPTION')
129 ],
130 'TASKS' => [
131 'CODE' => 'TASKS',
132 'VALUE' => Loc::getMessage('SENDER_PRESET_TEMPLATE_TOLOKA_LEAFLETS_TASKS')
133 ],
134 'INPUT_VALUE' => [
135 'CODE' => 'INPUT_VALUE',
136 'VALUE' => ['url' => InputOutputSpec::TYPES['URL']]
137 ],
138 'OUTPUT_VALUE' => [
139 'CODE' => 'OUTPUT_VALUE',
140 'VALUE' => ['result' => InputOutputSpec::TYPES['STRING']]
141 ],
142 'PRESET' => [
143 'CODE' => 'PRESET',
144 'VALUE' => self::getFileContent('video')
145 ]
146 ] ],
147 [
148 'CODE' => 'mystery_shopper',
149 'SEGMENT_CODES' => [],
150 'NAME' => Loc::getMessage('SENDER_PRESET_TEMPLATE_TOLOKA_TITLE_MYSTERY'),
151 'HINT' => Loc::getMessage('SENDER_PRESET_TEMPLATE_TOLOKA_HINT_MYSTERY'),
152 'FIELDS' => [
153 'INSTRUCTION' => [
154 'CODE' => 'INSTRUCTION',
155 'VALUE' => Loc::getMessage('SENDER_PRESET_TEMPLATE_TOLOKA_MYSTERY_INSTRUCTION')
156 ],
157 'DESCRIPTION' => [
158 'CODE' => 'DESCRIPTION',
159 'VALUE' => Loc::getMessage('SENDER_PRESET_TEMPLATE_TOLOKA_MYSTERY_DESCRIPTION')
160 ],
161 'TASKS' => [
162 'CODE' => 'TASKS',
163 'VALUE' => Loc::getMessage('SENDER_PRESET_TEMPLATE_TOLOKA_MYSTERY_TASKS')
164 ],
165 'INPUT_VALUE' => [
166 'CODE' => 'INPUT_VALUE',
167 'VALUE' => ['url' => InputOutputSpec::TYPES['URL']]
168 ],
169 'OUTPUT_VALUE' => [
170 'CODE' => 'OUTPUT_VALUE',
171 'VALUE' => ['result' => InputOutputSpec::TYPES['STRING']]
172 ],
173 'PRESET' => [
174 'CODE' => 'PRESET',
175 'VALUE' => self::getFileContent('video')
176 ]
177 ] ],
178 ];
179 return $list;
180 }
181
182 private static function getTemplates($templateId = null, $messageCode = null)
183 {
184 $messageCodes = $messageCode ? array($messageCode) : [];
185
186 $result = [];
187 foreach (self::getListByType() as $item)
188 {
189 $originalCode = strtolower($item['CODE']);
190 $code = 'toloka_' . strtolower($item['CODE']);
191 if($templateId && $code !== $templateId)
192 {
193 continue;
194 }
195
196 $result[] = array(
197 'ID' => $code,
198 'TYPE' => Type::getCode(Type::BASE),
199 'CATEGORY' => Category::getCode(Category::CASES),
200 'MESSAGE_CODE' => $messageCodes,
201 'VERSION' => 2,
202 'HOT' => $item['HOT'] ?? '',
203 'ICON' => BX_ROOT . self::IMAGE_DIR . "$originalCode.png",
204 'NAME' => $item['NAME'] ?? '',
205 'DESC' => $item['DESC'] ?? '',
206 'HINT' => $item['HINT'] ?? '',
207 'FIELDS' => array_merge(
208 $item['FIELDS'],
209 [
210 'TITLE' => [
211 'CODE' => 'TITLE',
212 'VALUE' => $item['TITLE'] ?? '',
213 ],
214 'COMMENT' => [
215 'CODE' => 'COMMENT',
216 'VALUE' => $item['TEXT'] ?? '',
217 ],
218 'ALWAYS_ADD' => [
219 'CODE' => 'ALWAYS_ADD',
220 'VALUE' => 'Y',
221 ],
222 ]),
223 'SEGMENTS' => [],
224 'DISPATCH' => $item['DISPATCH'] ?? '',
225 );
226 }
227
228 return $result;
229 }
230}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static onPresetTemplateList($templateType=null, $templateId=null, $messageCode=null)
Definition toloka.php:67