1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
controller.php
См. документацию.
1<?php
2
3namespace Bitrix\Vote\Attachment;
4
5use Bitrix\Main\AccessDeniedException;
6use Bitrix\Main\ArgumentException;
7use Bitrix\Main\ArgumentNullException;
8use Bitrix\Main\Localization\Loc;
9use Bitrix\Main\ObjectNotFoundException;
10use Bitrix\Main\ORM\Fields\ExpressionField;
11use Bitrix\Vote\EventTable;
12use Bitrix\Main;
13
14
15Loc::loadMessages(__FILE__);
16
18{
23
24 protected function listActions()
25 {
26 return array(
27 "vote" => array(
28 "need_auth" => false,
29 "method" => array("POST")
30 ),
31 "getBallot" => array(
32 "method" => array("POST", "GET")
33 ),
34 "stop" => array(
35 "method" => array("POST", "GET")
36 ),
37 "resume" => array(
38 "method" => array("POST", "GET")
39 ),
40 "getvoted" => array(
41 "method" => array("POST", "GET")
42 ),
43 "getmobilevoted" => array(
44 "method" => array("POST", "GET"),
45 "check_sessid" => false
46 ),
47 "exportXls" => array(
48 "method" => array("POST", "GET")
49 )
50 );
51 }
52
53 protected function init()
54 {
55 if ($this->request->getQuery("attachId"))
56 $this->attach = Manager::loadFromAttachId(intval($this->request->getQuery("attachId")));
57 else if ($this->request->getQuery("voteId"))
58 $this->attach = Manager::loadFromVoteId(array(
59 "MODULE_ID" => "vote",
60 "ENTITY_TYPE" => "VOTE",
61 "ENTITY_ID" => $this->request->getQuery("voteId")
62 ), $this->request->getQuery("voteId"));
63 else
64 throw new ArgumentNullException("attach ID");
65
66 AddEventHandler("vote", "onVoteReset", array(&$this, "clearCache"));
67 AddEventHandler("vote", "onAfterVoting", array(&$this, "clearCache"));
68 }
69
70
71 protected function processActionVote()
72 {
73 if ($this->checkRequiredGetParams(array("attachId")))
74 {
75 if (!$this->attach->canRead($this->getUser()->getId()))
76 throw new AccessDeniedException();
77
78 $request = $this->request->getPostList()->toArray();
79
80 //TODO decide what should we do with captcha in attaches
81 if ($this->attach->voteFor($request))
82 {
84 "action" => $this->getAction(),
85 "data" => array(
86 "attach" => array(
87 "ID" => $this->attach["ID"],
88 "VOTE_ID" => $this->attach["VOTE_ID"],
89 "COUNTER" => $this->attach["COUNTER"],
90 "QUESTIONS" => $this->attach["QUESTIONS"]
91 )
92 )
93 ));
94 }
95 elseif (($errors = $this->attach->getErrors()) && !empty($errors))
96 $this->errorCollection->add($errors);
97 else
98 throw new ArgumentException(GetMessage("V_ERROR_4501"));
99 }
100 }
101
102 protected function processActionGetBallot()
103 {
104 if (!$this->attach->canRead($this->getUser()->getId()))
105 {
106 throw new AccessDeniedException();
107 }
108
109 $attach = $this->attach;
110 $eventId = 0;
111 $userId = 0;
112 if ($this->getUser()->isAdmin() && $this->request->getQuery("eventId") > 0)
113 $eventId = $this->request->getQuery("eventId");
114 else
115 {
116 $userId = $this->getUser()->getId();
117 if ($attach->canRead($userId) && ($result = $attach->canRevote($userId)) && $result->isSuccess())
118 {
119 $event = reset($result->getData());
120 $eventId = $event["ID"];
121 }
122 }
123 $stat = array();
124 $extras = array();
125 if ($eventId > 0)
126 {
127 $userAnswersResult = $attach->getUserEventAnswers($eventId);
128 $stat = $userAnswersResult->stat;
129 $extras = $userAnswersResult->extras;
130 if ($userAnswersResult->userId)
131 {
132 $userId = $userAnswersResult->userId;
133 }
134 }
136 "action" => $this->getAction(),
137 "data" => array(
138 "attach" => array(
139 "ID" => $attach["ID"],
140 "VOTE_ID" => $attach["VOTE_ID"],
141 "FIELD_NAME" => $attach["FIELD_NAME"],
142 "QUESTIONS" => $attach["QUESTIONS"]
143 ),
144 "event" => array(
145 "id" => $eventId,
146 "userId" => $userId,
147 "ballot" => $stat,
148 "extras" => $extras
149 )
150 )
151 ));
152 }
153
154 protected function processActionStop()
155 {
156 $attach = $this->attach;
157 $userId = $this->getUser()->getId();
158 if (!$attach->canEdit($userId))
159 throw new AccessDeniedException();
160 $attach->stop();
162 "action" => $this->getAction(),
163 "data" => array(
164 "attach" => array(
165 "ID" => $this->attach["ID"],
166 "VOTE_ID" => $this->attach["VOTE_ID"],
167 "COUNTER" => $this->attach["COUNTER"],
168 "QUESTIONS" => $this->attach["QUESTIONS"]
169 )
170 )
171 ));
172 }
173
174 protected function processActionResume()
175 {
176 $attach = $this->attach;
177 $userId = $this->getUser()->getId();
178 if (!$attach->canEdit($userId))
179 throw new AccessDeniedException();
180 $attach->resume();
182 "action" => $this->getAction(),
183 "data" => array(
184 "attach" => array(
185 "ID" => $this->attach["ID"],
186 "VOTE_ID" => $this->attach["VOTE_ID"],
187 "COUNTER" => $this->attach["COUNTER"],
188 "QUESTIONS" => $this->attach["QUESTIONS"]
189 )
190 )
191 ));
192 }
193
200 protected static function getVoted(array $cacheParams, array $pageParams)
201 {
202 $iNumPage = intval($pageParams["iNumPage"]);
203 $nPageSize = intval($pageParams["nPageSize"]);
204 $showAll = $pageParams["bShowAll"] === true;
205
206 $cache = new \CPHPCache();
207 $result = array(
208 "statusPage" => "done",
209 "items" => array(),
210 "hiddenItems" => 0
211 );
212
213 $cacheTtl = defined("BX_COMP_MANAGED_CACHE") ? 3153600 : 3600*4;
214 $cacheId = "voted_".serialize(array($cacheParams["answerId"], $nPageSize, $iNumPage));
215 $cacheDir = "/vote/".$cacheParams["voteId"]."/voted/";
216
217 if (\Bitrix\Main\Config\Option::get("main", "component_cache_on", "Y") == "Y" && $cache->initCache($cacheTtl, $cacheId, $cacheDir))
218 {
219 $result = $cache->getVars();
220 }
221 else
222 {
223 if ($iNumPage <= 1)
224 {
225 $res = EventTable::getList(array(
226 "select" => array(
227 "CNT" => "CNT"
228 ),
229 "runtime" => array(
230 new ExpressionField("CNT", "COUNT(*)")
231 ),
232 "filter" => array(
233 "=VOTE_ID" => $cacheParams["voteId"],
234 "!=VISIBLE" => "Y",
235 "=VALID" => "Y",
236 "=QUESTION.ANSWER.ANSWER_ID" => $cacheParams["answerId"],
237 )
238 ))->fetch();
239 $result["hiddenItems"] = $res["CNT"];
240 }
241
242 $dbRes = \CVoteEvent::getUserAnswerStat(array(),
243 array(
244 "ANSWER_ID" => $cacheParams["answerId"],
245 "VALID" => "Y",
246 "VISIBLE" => "Y",
247 "bGetVoters" => "Y",
248 "bGetMemoStat" => "N"
249 ),
250 array(
251 "nPageSize" => $nPageSize,
252 "bShowAll" => $showAll,
253 "iNumPage" => $iNumPage
254 )
255 );
256 $userIds = array();
257 $result["statusPage"]= (($dbRes->NavPageNomer >= $dbRes->NavPageCount || $nPageSize > $dbRes->NavRecordCount) ? "done" : "continue");
258 while ($res = $dbRes->fetch())
259 $userIds[] = $res["AUTH_USER_ID"];
260
261 if (empty($userIds))
262 $result["statusPage"] = "done";
263 else
264 {
265 $departments = array();
266 if (IsModuleInstalled("extranet") &&
267 ($iblockId = \COption::GetOptionInt("intranet", "iblock_structure", 0)) &&
268 $iblockId > 0 &&
270 )
271 {
272 $dbRes = \CIBlockSection::GetList(
273 array("LEFT_MARGIN" => "DESC"),
274 array("IBLOCK_ID" => $iblockId),
275 false,
276 array("ID", "NAME")
277 );
278
279 while ($res = $dbRes->fetch())
280 $departments[$res["ID"]] = $res["NAME"];
281 }
282
283 $dbRes = \CUser::getList(
284 "ID",
285 "ASC",
286 array("ID" => implode("|", $userIds)),
287 array(
288 "FIELDS" => ["ID", "NAME", "LAST_NAME", "SECOND_NAME", "LOGIN", "PERSONAL_PHOTO", "WORK_POSITION"] +
289 (IsModuleInstalled("mail") ? array("EXTERNAL_AUTH_ID") : array()),
290 "SELECT" => (IsModuleInstalled("extranet") ? array("UF_DEPARTMENT") : array())
291 )
292 );
293 while ($res = $dbRes->fetch())
294 {
295 if (array_key_exists("PERSONAL_PHOTO", $res))
296 {
297 if (!empty($res["PERSONAL_PHOTO"]))
298 {
299 $f = \CFile::resizeImageGet(
300 $res["PERSONAL_PHOTO"],
301 array("width" => 64, "height" => 64),
303 false
304 );
305 $res["PHOTO_SRC"] = ($f["src"] ? $f["src"] : "");
306 $res["PHOTO"] = \CFile::showImage($f["src"], 21, 21, "border=0");
307 }
308 else
309 {
310 $res["PHOTO"] = $res["PHOTO_SRC"] = "";
311 }
312 }
313 $res["TYPE"] = "";
314 if (array_key_exists("EXTERNAL_AUTH_ID", $res) && $res["EXTERNAL_AUTH_ID"] == "email")
315 $res["TYPE"] = "mail";
316 elseif (array_key_exists("UF_DEPARTMENT", $res))
317 {
318 if (empty($res["UF_DEPARTMENT"]) || intval($res["UF_DEPARTMENT"][0]) <= 0)
319 $res["TYPE"] = "extranet";
320 else
321 {
322 $ds = array();
323 foreach ($res["UF_DEPARTMENT"] as $departmentId)
324 {
325 if (array_key_exists($departmentId, $departments))
326 $ds[] = $departments[$departmentId];
327 }
328 $res["TAGS"] = empty($res["WORK_POSITION"]) ? array() : array($res["WORK_POSITION"]);
329 $res["TAGS"] = implode(",", array_merge($res["TAGS"], $ds));
330 $res["WORK_DEPARTMENTS"] = $ds;
331 }
332 }
333 $result["items"][$res["ID"]] = $res;
334 }
335 }
336
337 if (!empty($result["items"]) || !empty($result["hiddenItems"]))
338 {
339 $cache->startDataCache($cacheTtl, $cacheId, $cacheDir);
340 \CVoteCacheManager::setTag($cacheDir, "V", $cacheParams["voteId"]);
341 $cache->endDataCache($result);
342 }
343 }
344 return $result;
345 }
346 protected function processActionGetVoted()
347 {
348 if (!$this->checkRequiredGetParams(array("answerId")))
349 return;
350 $answerId = intval($this->request->getQuery("answerId"));
351 if ($answerId <= 0)
352 throw new ArgumentNullException("Answer ID is required.");
353 $attach = $this->attach;
354 $userId = $this->getUser()->getId();
355 if (!$attach->canRead($userId))
356 throw new AccessDeniedException();
357
358 $belong = false;
359 foreach ($attach["QUESTIONS"] as $qID => $question)
360 {
361 if (array_key_exists($answerId, $question["ANSWERS"]))
362 {
363 $belong = true;
364 break;
365 }
366 }
367 if (!$belong)
368 throw new AccessDeniedException();
369
370 $nameTemplate = $this->request->getPost("nameTemplate") ?: \CSite::getNameFormat(null, $this->request->getPost("SITE_ID"));
371 $iNumPage = $this->request->getPost("iNumPage");
372 $nPageSize = 50;
373 $items = array();
374
375 $result = self::getVoted(
376 array(
377 "voteId" => $attach->getVoteId(),
378 "answerId" => $answerId),
379 array(
380 "iNumPage" => $iNumPage,
381 "nPageSize" => $nPageSize,
382 "bShowAll" => false)
383 );
384
385 if ($result["hiddenItems"] > 0)
386 {
387 $items[] = array(
388 "ID" => "HIDDEN",
389 "COUNT" => $result["hiddenItems"],
390 "FULL_NAME" => Loc::getMessage("VOTE_HIDDEN_VOTES_COUNT", ["#COUNT#" => $result["hiddenItems"]]),
391 );
392 }
393 foreach ($result["items"] as $k => $res)
394 {
395 $items[] = array(
396 "ID" => $res["ID"],
397 "TYPE" => $res["TYPE"],
398 "PHOTO" => $res["PHOTO"],
399 "PHOTO_SRC" => $res["PHOTO_SRC"],
400 "FULL_NAME" => \CUser::formatName($nameTemplate, $res),
401 );
402 }
403 $result["items"] = $items;
404 $result["pageSize"] = $nPageSize;
405 $result["iNumPage"] = $iNumPage;
407 "action" => $this->getAction(),
408 "data" => $result
409 ));
410 }
411
412 protected function processActionGetMobileVoted()
413 {
414 if (!$this->checkRequiredGetParams(array("answerId")))
415 return;
416 $answerId = intval($this->request->getQuery("answerId"));
417 if ($answerId <= 0)
418 throw new ArgumentNullException("Answer ID is required.");
419 $attach = $this->attach;
420 $userId = $this->getUser()->getId();
421 if (!$attach->canRead($userId))
422 throw new AccessDeniedException();
423
424 $belong = false;
425 foreach ($attach["QUESTIONS"] as $qID => $question)
426 {
427 if (array_key_exists($answerId, $question["ANSWERS"]))
428 {
429 $belong = true;
430 break;
431 }
432 }
433 if (!$belong)
434 throw new AccessDeniedException();
435
436 $nameTemplate = $this->request->getPost("nameTemplate") ?: \CSite::getNameFormat(null, $this->request->getPost("SITE_ID"));
437
438 $result = self::getVoted(
439 array(
440 "voteId" => $attach->getVoteId(),
441 "answerId" => $answerId),
442 array(
443 "iNumPage" => 1,
444 "nPageSize" => 50,
445 "bShowAll" => true)
446 );
447
448 $items = array();
449 foreach ($result["items"] as $k => $res)
450 {
451 $url = \CComponentEngine::MakePathFromTemplate(
452 "/mobile/users/?user_id=#user_id#",
453 array("UID" => $res["ID"], "user_id" => $res["ID"],
454 "USER_ID" => $res["ID"])
455 );
456 $items[] = array(
457 "ID" => $res["ID"],
458 "NAME" => \CUser::FormatName($nameTemplate, $res, true, false),
459 "IMAGE" => $res["PHOTO_SRC"],
460 "TAGS" => $res["TAGS"],
461 "WORK_POSITION" => $res["WORK_POSITION"],
462 "WORK_DEPARTMENTS" => $res["WORK_DEPARTMENTS"],
463 "URL" => $url,
464 'PAGE' => [
465 'bx24ModernStyle' => true,
466 'url' => $url,
467 'useTitle' => true,
468 ]
469 );
470 }
471 $result["items"] = $items;
473 "action" => $this->getAction(),
474 "data" => array(
475 "voted" => $items
476 ),
477 "names" => array(
478 "voted" => "Voted users"
479 )
480 ));
481 }
482
488 protected function processActionExportXls()
489 {
490 $attach = $this->attach;
491 $userId = $this->getUser()->getId();
492 if (!$attach->canRead($userId))
493 throw new AccessDeniedException();
494 $attach->exportExcel();
495 }
496
501 public function clearCache($voteId)
502 {
503 BXClearCache(true, "/vote/".$voteId."/voted/");
504 }
505}
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
static includeModule($moduleName)
Определения loader.php:67
clearCache($voteId)
Определения controller.php:501
static getVoted(array $cacheParams, array $pageParams)
Определения controller.php:200
static loadFromVoteId(array $attach, $id)
Определения manager.php:31
static loadFromAttachId($id)
Определения manager.php:20
sendJsonSuccessResponse(array $response=array())
Определения controller.php:230
checkRequiredGetParams(array $required)
Определения controller.php:517
$f
Определения component_props.php:52
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
$result
Определения get_property_values.php:14
$iblockId
Определения iblock_catalog_edit.php:30
$errors
Определения iblock_catalog_edit.php:74
const BX_RESIZE_IMAGE_EXACT
Определения constants.php:12
IsModuleInstalled($module_id)
Определения tools.php:5301
AddEventHandler($FROM_MODULE_ID, $MESSAGE_ID, $CALLBACK, $SORT=100, $FULL_PATH=false)
Определения tools.php:5165
GetMessage($name, $aReplace=null)
Определения tools.php:3397
BXClearCache($full=false, $initdir='')
Определения tools.php:5150
$event
Определения prolog_after.php:141
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$items
Определения template.php:224
$k
Определения template_pdf.php:567
$url
Определения iframe.php:7
$dbRes
Определения yandex_detail.php:168