73 if ($this->checkRequiredGetParams(array(
"attachId")))
75 if (!$this->attach->canRead($this->getUser()->getId()))
78 $request = $this->request->getPostList()->toArray();
79 if ($this->isAjaxRequest())
80 \CUtil::decodeURIComponent(
$request);
83 if ($this->attach->voteFor(
$request))
88 foreach ($this->attach[
"QUESTIONS"] as $question)
90 $result[$question[
"ID"]] = array(
93 foreach ($question[
"ANSWERS"] as $answer)
95 $result[$question[
"ID"]][
"ANSWERS"][$answer[
"ID"]] = array(
96 "PERCENT" => $answer[
"PERCENT"],
98 "COUNTER" => $answer[
"COUNTER"]
102 \CPullWatch::AddToStack(
"VOTE_".$this->attach[
"VOTE_ID"],
104 "module_id" =>
"vote",
105 "command" =>
"voting",
107 "VOTE_ID" => $this->attach[
"VOTE_ID"],
108 "AUTHOR_ID" => $this->getUser()->getId(),
109 "COUNTER" => $this->attach[
"COUNTER"],
110 "QUESTIONS" => $result
116 $this->sendJsonSuccessResponse(array(
117 "action" => $this->getAction(),
120 "ID" => $this->attach[
"ID"],
121 "VOTE_ID" => $this->attach[
"VOTE_ID"],
122 "COUNTER" => $this->attach[
"COUNTER"],
123 "QUESTIONS" => $this->attach[
"QUESTIONS"]
128 elseif (($errors = $this->attach->getErrors()) && !empty($errors))
129 $this->errorCollection->add($errors);
140 if ($this->getUser()->isAdmin() && $this->request->getQuery(
"eventId") > 0)
141 $eventId = $this->request->getQuery(
"eventId");
144 $userId = $this->getUser()->getId();
145 if (
$attach->canRead($userId) && ($result =
$attach->canRevote($userId)) && $result->isSuccess())
147 $event = reset($result->getData());
148 $eventId = $event[
"ID"];
155 $dbRes = EventTable::getList(array(
158 "Q_" =>
"QUESTION.*",
159 "A_" =>
"QUESTION.ANSWER.*",
160 "U_ID" =>
"USER.USER.ID",
161 "U_NAME" =>
"USER.USER.NAME",
162 "U_LAST_NAME" =>
"USER.USER.LAST_NAME",
163 "U_SECOND_NAME" =>
"USER.USER.SECOND_NAME",
164 "U_LOGIN" =>
"USER.USER.LOGIN",
165 "U_PERSONAL_PHOTO" =>
"USER.USER.PERSONAL_PHOTO",
169 "VOTE_ID" =>
$attach[
"VOTE_ID"]
172 $questions =
$attach[
"QUESTIONS"];
173 if ($dbRes && ($res = $dbRes->fetch()))
175 $userId = $res[
"U_ID"];
177 "VISIBLE" => $res[
"V_VISIBLE"],
178 "VALID" => $res[
"V_VALID"]
182 if (!array_key_exists($res[
"Q_QUESTION_ID"], $questions) ||
183 !array_key_exists($res[
"A_ANSWER_ID"], $questions[$res[
"Q_QUESTION_ID"]][
"ANSWERS"]))
185 if (!array_key_exists($res[
"Q_QUESTION_ID"], $stat))
186 $stat[$res[
"Q_QUESTION_ID"]] = array();
188 $stat[$res[
"Q_QUESTION_ID"]][$res[
"A_ANSWER_ID"]] = array(
189 "EVENT_ID" => $res[
"A_ID"],
190 "EVENT_QUESTION_ID" => $res[
"Q_ID"],
191 "ANSWER_ID" => $res[
"ANSWER_ID"],
192 "ID" => $res[
"A_ID"],
193 "MESSAGE" => $res[
"A_MESSAGE"]
195 }
while ($res = $dbRes->fetch());
198 $this->sendJsonSuccessResponse(array(
199 "action" => $this->getAction(),
203 "VOTE_ID" =>
$attach[
"VOTE_ID"],
204 "FIELD_NAME" =>
$attach[
"FIELD_NAME"],
205 "QUESTIONS" =>
$attach[
"QUESTIONS"]
263 protected static function getVoted(array $cacheParams, array $pageParams)
265 $iNumPage = intval($pageParams[
"iNumPage"]);
266 $nPageSize = intval($pageParams[
"nPageSize"]);
267 $showAll = $pageParams[
"bShowAll"] ===
true;
269 $cache = new \CPHPCache();
271 "statusPage" =>
"done",
276 $cacheTtl = defined(
"BX_COMP_MANAGED_CACHE") ? 3153600 : 3600*4;
277 $cacheId =
"voted_".serialize(array($cacheParams[
"answerId"], $nPageSize, $iNumPage));
278 $cacheDir =
"/vote/".$cacheParams[
"voteId"].
"/voted/";
280 if (\
Bitrix\Main\
Config\Option::get(
"main",
"component_cache_on",
"Y") ==
"Y" && $cache->initCache($cacheTtl, $cacheId, $cacheDir))
282 $result = $cache->getVars();
288 $res = EventTable::getList(array(
296 "VOTE_ID" => $cacheParams[
"voteId"],
299 "QUESTION.ANSWER.ANSWER_ID" => $cacheParams[
"answerId"],
302 $result[
"hiddenItems"] = $res[
"CNT"];
305 $dbRes = \CVoteEvent::getUserAnswerStat(array(),
307 "ANSWER_ID" => $cacheParams[
"answerId"],
311 "bGetMemoStat" =>
"N"
314 "nPageSize" => $nPageSize,
315 "bShowAll" => $showAll,
316 "iNumPage" => $iNumPage
320 $result[
"statusPage"]= (($dbRes->NavPageNomer >= $dbRes->NavPageCount || $nPageSize > $dbRes->NavRecordCount) ?
"done" :
"continue");
321 while ($res = $dbRes->fetch())
322 $userIds[] = $res[
"AUTH_USER_ID"];
325 $result[
"statusPage"] =
"done";
328 $departments = array();
329 if (IsModuleInstalled(
"extranet") &&
330 ($iblockId = \COption::GetOptionInt(
"intranet",
"iblock_structure", 0)) &&
333 $dbRes = \CIBlockSection::GetList(
334 array(
"LEFT_MARGIN" =>
"DESC"),
335 array(
"IBLOCK_ID" => $iblockId),
340 while ($res = $dbRes->fetch())
341 $departments[$res[
"ID"]] = $res[
"NAME"];
344 $dbRes = \CUser::getList(
347 array(
"ID" => implode(
"|", $userIds)),
349 "FIELDS" => array(
"ID",
"NAME",
"LAST_NAME",
"SECOND_NAME",
"LOGIN",
"PERSONAL_PHOTO") +
350 (IsModuleInstalled(
"mail") ? array(
"EXTERNAL_AUTH_ID") : array()),
351 "SELECT" => (IsModuleInstalled(
"extranet") ? array(
"UF_DEPARTMENT") : array())
354 while ($res = $dbRes->fetch())
356 if (array_key_exists(
"PERSONAL_PHOTO", $res))
358 if (!empty($res[
"PERSONAL_PHOTO"]))
360 $f = \CFile::resizeImageGet(
361 $res[
"PERSONAL_PHOTO"],
362 array(
"width" => 64,
"height" => 64),
363 BX_RESIZE_IMAGE_EXACT,
366 $res[
"PHOTO_SRC"] = ($f[
"src"] ? $f[
"src"] :
"");
367 $res[
"PHOTO"] = \CFile::showImage($f[
"src"], 21, 21,
"border=0");
371 $res[
"PHOTO"] = $res[
"PHOTO_SRC"] =
"";
375 if (array_key_exists(
"EXTERNAL_AUTH_ID", $res) && $res[
"EXTERNAL_AUTH_ID"] ==
"email")
376 $res[
"TYPE"] =
"mail";
377 elseif (array_key_exists(
"UF_DEPARTMENT", $res))
379 if (empty($res[
"UF_DEPARTMENT"]) || intval($res[
"UF_DEPARTMENT"][0]) <= 0)
380 $res[
"TYPE"] =
"extranet";
384 foreach ($res[
"UF_DEPARTMENT"] as $departmentId)
386 if (array_key_exists($departmentId, $departments))
387 $ds[] = $departments[$departmentId];
389 $res[
"TAGS"] = empty($res[
"WORK_POSITION"]) ? array() : array($res[
"WORK_POSITION"]);
390 $res[
"TAGS"] = implode(
",", array_merge($res[
"TAGS"], $ds));
391 $res[
"WORK_DEPARTMENTS"] = $ds;
394 $result[
"items"][$res[
"ID"]] = $res;
398 if (!empty($result[
"items"]) || !empty($result[
"hiddenItems"]))
400 $cache->startDataCache($cacheTtl, $cacheId, $cacheDir);
401 \CVoteCacheManager::setTag($cacheDir,
"V", $cacheParams[
"voteId"]);
402 $cache->endDataCache($result);
409 if (!$this->checkRequiredGetParams(array(
"answerId")))
411 $answerId = intval($this->request->getQuery(
"answerId"));
415 $userId = $this->getUser()->getId();
416 if (!
$attach->canRead($userId))
420 foreach (
$attach[
"QUESTIONS"] as $qID => $question)
422 if (array_key_exists($answerId, $question[
"ANSWERS"]))
431 $nameTemplate = $this->request->getPost(
"nameTemplate") ?: \CSite::getNameFormat(
null, $this->request->getPost(
"SITE_ID"));
432 $iNumPage = $this->request->getPost(
"iNumPage");
438 "voteId" =>
$attach->getVoteId(),
439 "answerId" => $answerId),
441 "iNumPage" => $iNumPage,
442 "nPageSize" => $nPageSize,
446 if ($result[
"hiddenItems"] > 0)
450 "COUNT" => $result[
"hiddenItems"],
451 "FULL_NAME" =>
Loc::getMessage(
"VOTE_HIDDEN_VOTES_COUNT", [
"#COUNT#" => $result[
"hiddenItems"]]),
454 foreach ($result[
"items"] as $k => $res)
458 "TYPE" => $res[
"TYPE"],
459 "PHOTO" => $res[
"PHOTO"],
460 "PHOTO_SRC" => $res[
"PHOTO_SRC"],
461 "FULL_NAME" => \CUser::formatName($nameTemplate, $res),
464 $result[
"items"] = $items;
465 $result[
"pageSize"] = $nPageSize;
466 $result[
"iNumPage"] = $iNumPage;
467 $this->sendJsonSuccessResponse(array(
468 "action" => $this->getAction(),
475 if (!$this->checkRequiredGetParams(array(
"answerId")))
477 $answerId = intval($this->request->getQuery(
"answerId"));
481 $userId = $this->getUser()->getId();
482 if (!
$attach->canRead($userId))
486 foreach (
$attach[
"QUESTIONS"] as $qID => $question)
488 if (array_key_exists($answerId, $question[
"ANSWERS"]))
497 $nameTemplate = $this->request->getPost(
"nameTemplate") ?: \CSite::getNameFormat(
null, $this->request->getPost(
"SITE_ID"));
501 "voteId" =>
$attach->getVoteId(),
502 "answerId" => $answerId),
510 foreach ($result[
"items"] as $k => $res)
512 $url = \CComponentEngine::MakePathFromTemplate(
513 "/mobile/users/?user_id=#user_id#",
514 array(
"UID" => $res[
"ID"],
"user_id" => $res[
"ID"],
515 "USER_ID" => $res[
"ID"])
519 "NAME" => \CUser::FormatName($nameTemplate, $res,
true,
false),
520 "IMAGE" => $res[
"PHOTO_SRC"],
521 "TAGS" => $res[
"TAGS"],
522 "WORK_POSITION" => $res[
"WORK_POSITION"],
523 "WORK_DEPARTMENTS" => $res[
"WORK_DEPARTMENTS"],
526 'bx24ModernStyle' =>
true,
532 $result[
"items"] = $items;
533 $this->sendJsonSuccessResponse(array(
534 "action" => $this->getAction(),
539 "voted" =>
"Voted users"