Your IP : 18.118.136.90


Current Path : /var/www/axolotl/data/www/arhangelsk.axolotls.ru/a537b/
Upload File :
Current File : /var/www/axolotl/data/www/arhangelsk.axolotls.ru/a537b/attachment.tar

blogpostconnector.php000066400000006125147744601040011036 0ustar00<?
namespace Bitrix\Vote\Attachment;

use Bitrix\Main\Loader;
use Bitrix\Main\Localization\Loc;

Loc::loadMessages(__FILE__);

final class BlogPostConnector extends Connector
{
	private $canRead = null;
	private $canEdit = null;
	private static $permissions = array();
	private static $posts = array();

	private static function getPostData($entityId)
	{
		if (array_key_exists($entityId, self::$posts))
			return self::$posts[$entityId];
		$cacheTtl = 2592000;
		$cacheId = 'blog_post_socnet_general_' . $entityId . '_' . LANGUAGE_ID . '_voteconnector';
		$timezoneOffset = \CTimeZone::getOffset();
		if($timezoneOffset != 0)
		{
			$cacheId .= "_" . $timezoneOffset;
		}
		$cacheDir = '/blog/socnet_post/gen/' . intval($entityId / 100) . '/' . $entityId;

		$cache = new \CPHPCache;
		if ($cache->initCache($cacheTtl, $cacheId, $cacheDir))
		{
			$post = $cache->getVars();
		}
		else
		{
			$cache->startDataCache();
			$post = \CBlogPost::getList(array(), array("ID" => $entityId), false, false, array(
				"ID",
				"BLOG_ID",
				"BLOG_OWNER_ID",
				"PUBLISH_STATUS",
				"TITLE",
				"AUTHOR_ID",
				"ENABLE_COMMENTS",
				"NUM_COMMENTS",
				"VIEWS",
				"CODE",
				"MICRO",
				"DETAIL_TEXT",
				"DATE_PUBLISH",
				"CATEGORY_ID",
				"HAS_SOCNET_ALL",
				"HAS_TAGS",
				"HAS_IMAGES",
				"HAS_PROPS",
				"HAS_COMMENT_IMAGES"
			))->fetch();
			$cache->endDataCache($post);
		}
		self::$posts[$entityId] = $post;
		return $post;
	}

	private function getPermission($userId)
	{
		global $APPLICATION;

		if (!Loader::includeModule('socialnetwork'))
			return false;
		elseif (
			$APPLICATION->getGroupRight("blog") >= "W"
			|| \CSocNetUser::isCurrentUserModuleAdmin()
		)
		{
			self::$permissions[$this->entityId] = BLOG_PERMS_FULL;
		}
		else if (!array_key_exists($this->entityId, self::$permissions))
		{
			self::$permissions[$this->entityId] = BLOG_PERMS_DENY;
			$post = self::getPostData($this->entityId);
			if ($post && $post["ID"] > 0)
			{
				$p = \CBlogPost::getSocNetPostPerms($this->entityId, true, $userId, $post["AUTHOR_ID"]);
				if ($p > BLOG_PERMS_MODERATE || ($p >= BLOG_PERMS_WRITE && $post["AUTHOR_ID"] == $userId))
					$p = BLOG_PERMS_FULL;
				self::$permissions[$this->entityId] = $p;
			}

		}
		return self::$permissions[$this->entityId];
	}

	/**
	 * @param array $data
	 * @return array
	 */
	public function checkFields(&$data)
	{
		$post = self::getPostData($this->entityId);
		if ($post)
		{
			$data["TITLE"] = $post["TITLE"];
			$data["URL"] = str_replace(
				array("#user_id#", "#post_id#"),
				array($post["BLOG_OWNER_ID"], $post["ID"]),
				\COption::GetOptionString("socialnetwork", "userblogpost_page")
			);
		}
		return $data;
	}
	/**
	 * @param integer $userId User ID.
	 * @return bool
	 */
	public function canRead($userId)
	{
		if(is_null($this->canRead))
			$this->canRead = $this->getPermission($userId) >= BLOG_PERMS_READ;

		return $this->canRead;
	}

	/**
	 * @param integer $userId User ID.
	 * @return bool
	 */
	public function canEdit($userId)
	{
		if(is_null($this->canEdit))
			$this->canEdit = $this->getPermission($userId) > BLOG_PERMS_MODERATE;

		return $this->canEdit;
	}
}
defaultconnector.php000064400000002443147744601040010626 0ustar00<?
namespace Bitrix\Vote\Attachment;

use Bitrix\Main\Loader;
use Bitrix\Main\Localization\Loc;
use Bitrix\Vote\Channel;

Loc::loadMessages(__FILE__);

class DefaultConnector extends Connector implements Storable
{
	private $storage = null;
	private $canRead = array();
	private $canEdit = array();

	/**
	 * @param integer $userId UserID.
	 * @return bool
	 */
	public function canRead($userId)
	{
		if (!array_key_exists($userId, $this->canRead) && $this->isStorable())
			$this->canRead[$userId] = $this->getStorage()->canRead($userId);
		return (isset($this->canRead[$userId]) ? $this->canRead[$userId] : false);
	}

	/**
	 * @param integer $userId UserID.
	 * @return bool
	 */
	public function canEdit($userId)
	{
		if (!array_key_exists($userId, $this->canEdit) && $this->isStorable())
			$this->canEdit[$userId] = $this->getStorage()->canEditVote($userId);
		return (isset($this->canEdit[$userId]) ? $this->canEdit[$userId] : false);
	}

	/**
	 * @param Channel $channel Group of votes.
	 * @return $this
	 */
	public function setStorage(Channel $channel)
	{
		$this->storage = $channel;

		return $this;
	}

	/**
	 * @return Channel|null
	 */
	public function getStorage()
	{
		return $this->storage;
	}

	/**
	 * @return bool
	 */
	public function isStorable()
	{
		return ($this->storage !== null);
	}
}
storable.php000066400000000520147744601040007076 0ustar00<?php

namespace Bitrix\Vote\Attachment;

use Bitrix\Vote\Channel;

interface Storable
{
	/**
	 * @param Channel $channel Group of votes.
	 * @return $this
	 */
	public function setStorage(Channel $channel);
	/**
	 * @return Channel|null
	 */
	public function getStorage();
	/**
	 * @return boolean
	 */
	public function isStorable();
}manager.php000066400000004135147744601040006703 0ustar00<?php
namespace Bitrix\Vote\Attachment;

use Bitrix\Main\Localization\Loc;
use Bitrix\Main\ArgumentNullException;
use Bitrix\Main\ArgumentTypeException;
use Bitrix\Vote\Attach;
use Bitrix\Vote\Vote;

Loc::loadMessages(__FILE__);

final class Manager
{

	/**
	 * @param int $id Attachment ID.
	 * @return Attach
	 * @throws \Bitrix\Main\ArgumentException
	 */
	public static function loadFromAttachId($id)
	{
		return new Attach($id);
	}

	/**
	 * @param array $attach Data array from DB.
	 * @param $id Vote ID.
	 * @return array|Attach
	 * @throws \Bitrix\Main\ArgumentException
	 */
	public static function loadFromVoteId(array $attach, $id)
	{
		$attach = new Attach($attach);
		$attach->setVote($id);
		return $attach;
	}

	/**
	 * @param array $attach Data array from DB.
	 * @param array $voteParams Array(
	"TITLE" => "ABC...",
	"QUESTIONS" => array(
	1 => array(
	"ID" => 0,
	"QUESTION" => "Question text",
	"QUESTION_TYPE" => "text"||"html",
	"ANSWERS" => array(
	array(
	"ID" => 0,
	"MESSAGE" => "Answer text",
	"MESSAGE_TYPE" => "text"||"html",
	"FIELD_TYPE" => 0||1||2||3||4||
	)
	)
	);.
	 * @return Attach
	 */
	public static function loadEmptyAttach(array $attach, array $voteParams)
	{
		$attach = new Attach($attach);
		$attach->setStorage($voteParams["CHANNEL_ID"]);
		return $attach;
	}

	/**
	 * @param array $filter Array in terms ORM.
	 * @return Attach[]
	 * @throws ArgumentNullException
	 * @throws ArgumentTypeException
	 */
	public static function loadFromEntity(array $filter)
	{
		$filter = array_change_key_case($filter, CASE_UPPER);
		if (empty($filter))
			throw new ArgumentNullException("filter");

		$return = array();
		$res = Attach::getData($filter);
		if (is_array($res))
		{
			foreach ($res as $attach)
			{
				$res = new Attach($attach[0]);
				$res->setVote($attach[1]["ID"]);
				$return[$attach[0]["ID"]] = $res;
			}
		}
		return $return;
	}

	/**
	 * Deletes attach by Filter.
	 * @param array $filter Array in terms of ORM.
	 * @return void
	 */
	public static function detachByFilter(array $filter)
	{
		$votes = self::loadFromEntity($filter);
		foreach ($votes as $v)
			$v->delete();
	}
}

connector.php000066400000003762147744601040007270 0ustar00<?php

namespace Bitrix\Vote\Attachment;

use Bitrix\Main\Application;
use Bitrix\Main\ObjectNotFoundException;
use Bitrix\Main\Loader;
use Bitrix\Main\SystemException;

abstract class Connector
{
	protected $entityId;

	public function __construct($entityId)
	{
		$this->entityId = $entityId;
	}

	/**
	 * @param \Bitrix\Vote\Attach $attachedObject Attach.
	 * @return Connector
	 * @throws ObjectNotFoundException
	 * @throws SystemException
	 */
	final public static function buildFromAttachedObject(\Bitrix\Vote\Attach $attachedObject)
	{
		if(!Loader::includeModule($attachedObject->getModuleId()))
		{
			throw new SystemException("Module {$attachedObject->getModuleId()} is not included.");
		}
		$className = str_replace('\\\\', '\\', $attachedObject->getEntityType());
		/** @var \Bitrix\Vote\Attachment\Connector $connector */
		$connector = new $className($attachedObject->getEntityId());

		if(!$connector instanceof Connector)
		{
			throw new ObjectNotFoundException('Connector class should be instance of Connector.');
		}
		if($connector instanceof Storable)
		{
			$connector->setStorage($attachedObject->getStorage());
		}

		return $connector;
	}

	/**
	 * @return string
	 */
	public static function className()
	{
		return get_called_class();
	}

	/**
	 * @todo finis this method
	 * @return array
	 */
	public function getDataToShow()
	{
		return array();
	}

	/**
	 * @param integer $userId User ID.
	 * @return bool
	 */
	public function canRead($userId)
	{
		return false;
	}

	/**
	 * @param integer $userId User ID.
	 * @return bool
	 */
	public function canEdit($userId)
	{
		return false;
	}

	/**
	 * @param array $data Data array.
	 * @return array
	 */
	public function checkFields(&$data)
	{
		return $data;
	}

	/**
	 * @return Application|\Bitrix\Main\HttpApplication|\CAllMain|\CMain
	 */
	protected function getApplication()
	{
		global $APPLICATION;
		return $APPLICATION;
	}

	/**
	 * @return array|bool|\CAllUser|\CUser
	 */
	protected function getUser()
	{
		global $USER;
		return $USER;
	}
}controller.php000066400000035121147744601040007453 0ustar00<?php

namespace Bitrix\Vote\Attachment;

use Bitrix\Main\AccessDeniedException;
use Bitrix\Main\ArgumentException;
use Bitrix\Main\ArgumentNullException;
use Bitrix\Main\Localization\Loc;
use Bitrix\Main\ORM\Entity;
use Bitrix\Main\ORM\Fields\ExpressionField;
use Bitrix\Vote\EventTable;
use Bitrix\Vote\User;


Loc::loadMessages(__FILE__);

class Controller extends \Bitrix\Vote\Base\Controller
{
	/**
	 * @var $attach \Bitrix\Vote\Attach
	 */
	var $attach;

	protected function listActions()
	{
		return array(
			"vote" => array(
				"need_auth" => false,
				"method" => array("POST")
			),
			"getBallot" => array(
				"method" => array("POST", "GET")
			),
			"stop" => array(
				"method" => array("POST", "GET")
			),
			"resume" => array(
				"method" => array("POST", "GET")
			),
			"getvoted" => array(
				"method" => array("POST", "GET")
			),
			"getmobilevoted" => array(
				"method" => array("POST", "GET"),
				"check_sessid" => false
			),
			"exportXls" => array(
				"method" => array("POST", "GET")
			)
		);
	}

	protected function init()
	{
		if ($this->request->getQuery("attachId"))
			$this->attach = Manager::loadFromAttachId($this->request->getQuery("attachId"));
		else if ($this->request->getQuery("voteId"))
			$this->attach = Manager::loadFromVoteId(array(
				"MODULE_ID" => "vote",
				"ENTITY_TYPE" => "VOTE",
				"ENTITY_ID" => $this->request->getQuery("voteId")
			), $this->request->getQuery("voteId"));
		else
			throw new ArgumentNullException("attach ID");

		AddEventHandler("vote", "onVoteReset", array(&$this, "clearCache"));
		AddEventHandler("vote", "onAfterVoting", array(&$this, "clearCache"));
	}


	protected function processActionVote()
	{
		if ($this->checkRequiredGetParams(array("attachId")))
		{
			if (!$this->attach->canRead($this->getUser()->getId()))
				throw new AccessDeniedException();

			$request = $this->request->getPostList()->toArray();
			if ($this->isAjaxRequest())
				\CUtil::decodeURIComponent($request);

			//TODO decide what should we do with captcha in attaches
			if ($this->attach->voteFor($request))
			{
				if (\Bitrix\Main\Loader::includeModule("pull"))
				{
					$result = array();
					foreach ($this->attach["QUESTIONS"] as $question)
					{
						$result[$question["ID"]] = array(
							"ANSWERS" => array()
						);
						foreach ($question["ANSWERS"] as $answer)
						{
							$result[$question["ID"]]["ANSWERS"][$answer["ID"]] = array(
								"PERCENT" => $answer["PERCENT"],
								"USERS" => [],
								"COUNTER" => $answer["COUNTER"]
							);
						}
					}
					\CPullWatch::AddToStack("VOTE_".$this->attach["VOTE_ID"],
						Array(
							"module_id" => "vote",
							"command" => "voting",
							"params" => Array(
								"VOTE_ID" => $this->attach["VOTE_ID"],
								"AUTHOR_ID" => $this->getUser()->getId(),
								"COUNTER" => $this->attach["COUNTER"],
								"QUESTIONS" => $result
							)
						)
					);
				}

				$this->sendJsonSuccessResponse(array(
					"action" => $this->getAction(),
					"data" => array(
						"attach" => array(
							"ID" => $this->attach["ID"],
							"VOTE_ID" => $this->attach["VOTE_ID"],
							"COUNTER" => $this->attach["COUNTER"],
							"QUESTIONS" => $this->attach["QUESTIONS"]
						)
					)
				));
			}
			elseif (($errors = $this->attach->getErrors()) && !empty($errors))
				$this->errorCollection->add($errors);
			else
				throw new ArgumentException(GetMessage("V_ERROR_4501"));
		}
	}

	protected function processActionGetBallot()
	{
		$attach = $this->attach;
		$eventId = 0;
		$userId = 0;
		if ($this->getUser()->isAdmin() && $this->request->getQuery("eventId") > 0)
			$eventId = $this->request->getQuery("eventId");
		else
		{
			$userId = $this->getUser()->getId();
			if ($attach->canRead($userId) && ($result = $attach->canRevote($userId)) && $result->isSuccess())
			{
				$event = reset($result->getData());
				$eventId = $event["ID"];
			}
		}
		$stat = array();
		$extras = array();
		if ($eventId > 0)
		{
			$dbRes = EventTable::getList(array(
				"select" => array(
					"V_" => "*",
					"Q_" => "QUESTION.*",
					"A_" => "QUESTION.ANSWER.*",
					"U_" => "USER.USER.*",
				),
				"filter" => array(
					"ID" => $eventId,
					"VOTE_ID" => $attach["VOTE_ID"]
				)
			));
			$questions = $attach["QUESTIONS"];
			if ($dbRes && ($res = $dbRes->fetch()))
			{
				$userId = $res["U_ID"];
				$extras = array(
					"VISIBLE" => $res["V_VISIBLE"],
					"VALID" => $res["V_VALID"]
				);
				do
				{
					if (!array_key_exists($res["Q_QUESTION_ID"], $questions) ||
						!array_key_exists($res["A_ANSWER_ID"], $questions[$res["Q_QUESTION_ID"]]["ANSWERS"]))
						continue;
					if (!array_key_exists($res["Q_QUESTION_ID"], $stat))
						$stat[$res["Q_QUESTION_ID"]] = array();

					$stat[$res["Q_QUESTION_ID"]][$res["A_ANSWER_ID"]] = array(
						"EVENT_ID" => $res["A_ID"],
						"EVENT_QUESTION_ID" => $res["Q_ID"],
						"ANSWER_ID" => $res["ANSWER_ID"],
						"ID" => $res["A_ID"], // delete this
						"MESSAGE" => $res["A_MESSAGE"]
					);
				} while ($res = $dbRes->fetch());
			}
		}
		$this->sendJsonSuccessResponse(array(
			"action" => $this->getAction(),
			"data" => array(
				"attach" => array(
					"ID" => $attach["ID"],
					"VOTE_ID" => $attach["VOTE_ID"],
					"FIELD_NAME" => $attach["FIELD_NAME"],
					"QUESTIONS" => $attach["QUESTIONS"]
				),
				"event" => array(
					"id" => $eventId,
					"userId" => $userId,
					"ballot" => $stat,
					"extras" => $extras
				)
			)
		));
	}

	protected function processActionStop()
	{
		$attach = $this->attach;
		$userId = $this->getUser()->getId();
		if (!$attach->canEdit($userId))
			throw new AccessDeniedException();
		$attach->stop();
		$this->sendJsonSuccessResponse(array(
			"action" => $this->getAction(),
			"data" => array(
				"attach" => array(
					"ID" => $this->attach["ID"],
					"VOTE_ID" => $this->attach["VOTE_ID"],
					"COUNTER" => $this->attach["COUNTER"],
					"QUESTIONS" => $this->attach["QUESTIONS"]
				)
			)
		));
	}

	protected function processActionResume()
	{
		$attach = $this->attach;
		$userId = $this->getUser()->getId();
		if (!$attach->canEdit($userId))
			throw new AccessDeniedException();
		$attach->resume();
		$this->sendJsonSuccessResponse(array(
			"action" => $this->getAction(),
			"data" => array(
				"attach" => array(
					"ID" => $this->attach["ID"],
					"VOTE_ID" => $this->attach["VOTE_ID"],
					"COUNTER" => $this->attach["COUNTER"],
					"QUESTIONS" => $this->attach["QUESTIONS"]
				)
			)
		));
	}

	/**
	 * Returns array of users voted for this poll.
	 * @param array $cacheParams Array(voteId => , answerId => ).
	 * @param array $pageParams Array(iNumPage => , nPageSize => , bShowAll => ).
	 * @return array
	 */
	protected static function getVoted(array $cacheParams, array $pageParams)
	{
		$iNumPage = intval($pageParams["iNumPage"]);
		$nPageSize = intval($pageParams["nPageSize"]);
		$showAll = $pageParams["bShowAll"] === true;

		$cache = new \CPHPCache();
		$result = array(
			"statusPage" => "done",
			"items" => array(),
			"hiddenItems" => 0
		);

		$cacheTtl = defined("BX_COMP_MANAGED_CACHE") ? 3153600 : 3600*4;
		$cacheId = "voted_".serialize(array($cacheParams["answerId"], $nPageSize, $iNumPage));
		$cacheDir = "/vote/".$cacheParams["voteId"]."/voted/";

		if (\Bitrix\Main\Config\Option::get("main", "component_cache_on", "Y") == "Y" && $cache->initCache($cacheTtl, $cacheId, $cacheDir))
		{
			$result = $cache->getVars();
		}
		else
		{
			if ($iNumPage <= 1)
			{
				$res = EventTable::getList(array(
					"select" => array(
						"CNT" => "CNT"
					),
					"runtime" => array(
						new ExpressionField("CNT", "COUNT(*)")
					),
					"filter" => array(
						"VOTE_ID" => $cacheParams["voteId"],
						"!=VISIBLE" => "Y",
						"VALID" => "Y",
						"QUESTION.ANSWER.ANSWER_ID" => $cacheParams["answerId"],
					)
				))->fetch();
				$result["hiddenItems"] = $res["CNT"];
			}

			$dbRes = \CVoteEvent::getUserAnswerStat(array(),
				array(
					"ANSWER_ID" => $cacheParams["answerId"],
					"VALID" => "Y",
					"VISIBLE" => "Y",
					"bGetVoters" => "Y",
					"bGetMemoStat" => "N"
				),
				array(
					"nPageSize" => $nPageSize,
					"bShowAll" => $showAll,
					"iNumPage" => $iNumPage
				)
			);
			$userIds = array();
			$result["statusPage"]= (($dbRes->NavPageNomer >= $dbRes->NavPageCount || $nPageSize > $dbRes->NavRecordCount) ? "done" : "continue");
			while ($res = $dbRes->fetch())
				$userIds[] = $res["AUTH_USER_ID"];

			if (empty($userIds))
				$result["statusPage"] = "done";
			else
			{
				$departments = array();
				if (IsModuleInstalled("extranet") &&
					($iblockId = \COption::GetOptionInt("intranet", "iblock_structure", 0)) &&
					$iblockId > 0)
				{
					$dbRes = \CIBlockSection::GetList(
						array("LEFT_MARGIN" => "DESC"),
						array("IBLOCK_ID" => $iblockId),
						false,
						array("ID", "NAME")
					);

					while ($res = $dbRes->fetch())
						$departments[$res["ID"]] = $res["NAME"];
				}

				$dbRes = \CUser::getList(
					($by = "ID"),
					($order = "ASC"),
					array("ID" => implode("|", $userIds)),
					array(
						"FIELDS" => array("ID", "NAME", "LAST_NAME", "SECOND_NAME", "LOGIN", "PERSONAL_PHOTO") +
							(IsModuleInstalled("mail") ? array("EXTERNAL_AUTH_ID") : array()),
						"SELECT" => (IsModuleInstalled("extranet") ? array("UF_DEPARTMENT") : array())
					)
				);
				while ($res = $dbRes->fetch())
				{
					if (array_key_exists("PERSONAL_PHOTO", $res))
					{
						if (!empty($res["PERSONAL_PHOTO"]))
						{
							$f = \CFile::resizeImageGet(
								$res["PERSONAL_PHOTO"],
								array("width" => 64, "height" => 64),
								BX_RESIZE_IMAGE_EXACT,
								false
							);
							$res["PHOTO_SRC"] = ($f["src"] ? $f["src"] : "");
							$res["PHOTO"] = \CFile::showImage($f["src"], 21, 21, "border=0");
						}
						else
						{
							$res["PHOTO"] = $res["PHOTO_SRC"] = "";
						}
					}
					$res["TYPE"] = "";
					if (array_key_exists("EXTERNAL_AUTH_ID", $res) && $res["EXTERNAL_AUTH_ID"] == "email")
						$res["TYPE"] = "mail";
					elseif (array_key_exists("UF_DEPARTMENT", $res))
					{
						if (empty($res["UF_DEPARTMENT"]) || intval($res["UF_DEPARTMENT"][0]) <= 0)
							$res["TYPE"] = "extranet";
						else
						{
							$ds = array();
							foreach ($res["UF_DEPARTMENT"] as $departmentId)
							{
								if (array_key_exists($departmentId, $departments))
									$ds[] = $departments[$departmentId];
							}
							$res["TAGS"] = empty($res["WORK_POSITION"]) ? array() : array($res["WORK_POSITION"]);
							$res["TAGS"] = implode(",", array_merge($res["TAGS"], $ds));
							$res["WORK_DEPARTMENTS"] = $ds;
						}
					}
					$result["items"][$res["ID"]] = $res;
				}
			}

			if (!empty($result["items"]) || !empty($result["hiddenItems"]))
			{
				$cache->startDataCache($cacheTtl, $cacheId, $cacheDir);
				\CVoteCacheManager::setTag($cacheDir, "V", $cacheParams["voteId"]);
				$cache->endDataCache($result);
			}
		}
		return $result;
	}
	protected function processActionGetVoted()
	{
		if (!$this->checkRequiredGetParams(array("answerId")))
			return;
		$answerId = intval($this->request->getQuery("answerId"));
		if ($answerId <= 0)
			throw new ArgumentNullException("Answer ID is required.");
		$attach = $this->attach;
		$userId = $this->getUser()->getId();
		if (!$attach->canRead($userId))
			throw new AccessDeniedException();

		$belong = false;
		foreach ($attach["QUESTIONS"] as $qID => $question)
		{
			if (array_key_exists($answerId, $question["ANSWERS"]))
			{
				$belong = true;
				break;
			}
		}
		if (!$belong)
			throw new AccessDeniedException();

		$nameTemplate = $this->request->getPost("nameTemplate") ?: \CSite::getNameFormat(null, $this->request->getPost("SITE_ID"));
		$iNumPage = $this->request->getPost("iNumPage");
		$nPageSize = 50;
		$items = array();

		$result = self::getVoted(
			array(
				"voteId" => $attach->getVoteId(),
				"answerId" => $answerId),
			array(
				"iNumPage" => $iNumPage,
				"nPageSize" => $nPageSize,
				"bShowAll" => false)
			);

		if ($result["hiddenItems"] > 0)
		{
			$items[] = array(
				"ID" => "HIDDEN",
				"COUNT" => $result["hiddenItems"],
				"FULL_NAME" => Loc::getMessage("VOTE_HIDDEN_VOTES_COUNT", ["#COUNT#" => $result["hiddenItems"]]),
			);
		}
		foreach ($result["items"] as $k => $res)
		{
			$items[] = array(
				"ID" => $res["ID"],
				"TYPE" => $res["TYPE"],
				"PHOTO" => $res["PHOTO"],
				"PHOTO_SRC" => $res["PHOTO_SRC"],
				"FULL_NAME" => \CUser::formatName($nameTemplate, $res),
			);
		}
		$result["items"] = $items;
		$result["pageSize"] = $nPageSize;
		$result["iNumPage"] = $iNumPage;
		$this->sendJsonSuccessResponse(array(
			"action" => $this->getAction(),
			"data" => $result
		));
	}

	protected function processActionGetMobileVoted()
	{
		if (!$this->checkRequiredGetParams(array("answerId")))
			return;
		$answerId = intval($this->request->getQuery("answerId"));
		if ($answerId <= 0)
			throw new ArgumentNullException("Answer ID is required.");
		$attach = $this->attach;
		$userId = $this->getUser()->getId();
		if (!$attach->canRead($userId))
			throw new AccessDeniedException();

		$belong = false;
		foreach ($attach["QUESTIONS"] as $qID => $question)
		{
			if (array_key_exists($answerId, $question["ANSWERS"]))
			{
				$belong = true;
				break;
			}
		}
		if (!$belong)
			throw new AccessDeniedException();

		$nameTemplate = $this->request->getPost("nameTemplate") ?: \CSite::getNameFormat(null, $this->request->getPost("SITE_ID"));

		$result = self::getVoted(
			array(
				"voteId" => $attach->getVoteId(),
				"answerId" => $answerId),
			array(
				"iNumPage" => 1,
				"nPageSize" => 50,
				"bShowAll" => true)
		);

		$items = array();
		foreach ($result["items"] as $k => $res)
		{
			$items[] = array(
				"ID" => $res["ID"],
				"NAME" =>  \CUser::FormatName($nameTemplate, $res, true, false),
				"IMAGE" => $res["PHOTO_SRC"],
				"TAGS" => $res["TAGS"],
				"WORK_POSITION" => $res["WORK_POSITION"],
				"WORK_DEPARTMENTS" => $res["WORK_DEPARTMENTS"],
				"URL" => \CComponentEngine::MakePathFromTemplate(
					"/mobile/users/?user_id=#user_id#",
					array("UID" => $res["ID"], "user_id" => $res["ID"],
						"USER_ID" => $res["ID"])
				)
			);
		}
		$result["items"] = $items;
		$this->sendJsonSuccessResponse(array(
			"action" => $this->getAction(),
			"data" => array(
				"voted" => $items
			),
			"names" => array(
				"voted" =>  "Voted users"
			)
		));
	}

	/**
	 * Exports results in xls.
	 * @return void
	 * @throws AccessDeniedException
	 */
	protected function processActionExportXls()
	{
		$attach = $this->attach;
		$userId = $this->getUser()->getId();
		if (!$attach->canRead($userId))
			throw new AccessDeniedException();
		$attach->exportExcel();
	}

	/**
	 * @param integer $voteId Vote ID.
	 * @return void
	 */
	public function clearCache($voteId)
	{
		BXClearCache(true, "/vote/".$voteId."/voted/");
	}
}forummessageconnector.php000064400000001055147744601040011675 0ustar00<?php
namespace Bitrix\Vote\Attachment;

use Bitrix\Main\Loader;
use Bitrix\Main\Localization\Loc;

Loc::loadMessages(__FILE__);

final class ForumMessageConnector extends Connector
{
	protected static $messages = array();
	protected static $topics = array();

	private $canRead = null;


	/**
	 * @param integer $userId User ID.
	 * @return bool
	 */
	public function canRead($userId)
	{
		return $this->canRead;
	}

	/**
	 * @param integer $userId User ID.
	 * @return bool
	 */
	public function canEdit($userId)
	{
		return $this->canRead($userId);
	}
}