Controller::getVoted

  1. Bitrix24 API (v. 23.675.0)
  2. vote
  3. Controller
  4. getVoted
  • Модуль: vote
  • Путь к файлу: ~/bitrix/modules/vote/lib/attachment/controller.php
  • Класс: BitrixVoteAttachmentController
  • Вызов: Controller::getVoted
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 (BitrixMainConfigOption::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(
				"ID",
				"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;
}

Добавить комментарий