20 $signedAttachId = (string)(
$params[
'signedAttachId'] ??
'');
21 if (!$signedAttachId || !
$userId)
40 $signedAttachId = (string)(
$params[
'signedAttachId'] ??
'');
50 $messageAttach = new \CIMMessageParamAttach();
51 $messageAttach->AddUser([
52 'NAME' => Loc::getMessage(
'VOTE_INTEGRATION_MAIN_URL_PREVIEW_TITLE'),
55 $messageAttach->AddDelimiter();
56 $messageAttach->AddGrid(self::getAttachGrid($attach));
58 return $messageAttach;
66 private static function getAttachGrid(
Attach $attach):
array
69 $authorName = self::getAuthorFormattedName($attach);
72 $rows[] = self::getGridRow(
73 name: Loc::getMessage(
'VOTE_INTEGRATION_MAIN_URL_PREVIEW_OWNER'),
78 $rows[] = self::getGridRow(
79 name: Loc::getMessage(
'VOTE_INTEGRATION_MAIN_URL_PREVIEW_QUESTION'),
80 value: self::getFirstQuestion($attach),
83 $rows[] = self::getGridRow(
84 name: Loc::getMessage(
'VOTE_INTEGRATION_MAIN_URL_PREVIEW_INFO'),
85 value: self::getInfo($attach),
91 private static function getGridRow(?
string $name, ?
string $value):
array
96 'DISPLAY' =>
'COLUMN',
101 private static function getAuthorFormattedName(Attach $attach): ?string
103 $authorId = (int)($attach[
'AUTHOR_ID'] ?? 0);
109 $userFields = UserTable::query()
110 ->whereIn(
'ID', $authorId)
123 if (empty($userFields))
128 return \CUser::FormatName(
129 \CSite::GetNameFormat(
false),
135 private static function getFirstQuestion(Attach $attach): string
137 $firstKey = array_key_first($attach[
'QUESTIONS']);
139 return (
string)($attach[
'QUESTIONS'][$firstKey][
'QUESTION'] ??
'');
142 private static function getInfo(Attach $attach): ?string
144 $anonymity = $attach->isPublicVote()
145 ? Loc::getMessage(
'VOTE_INTEGRATION_MAIN_URL_PREVIEW_PUBLIC')
146 : Loc::getMessage(
'VOTE_INTEGRATION_MAIN_URL_PREVIEW_ANONYMOUS')
149 if ($attach->isFinished())
151 return Loc::getMessage(
'VOTE_INTEGRATION_MAIN_URL_PREVIEW_FINISHED_MGSVER1', [
'#ANONYMITY#' => $anonymity]);
154 $options = (
int)($attach[
'OPTIONS'] ?? 0);
155 $allowRevote =
$options & Option::ALLOW_REVOTE;
159 : Loc::getMessage(
'VOTE_INTEGRATION_MAIN_URL_PREVIEW_RESTRICT_REVOTE', [
'#ANONYMITY#' => $anonymity])
static includeModule($moduleName)
static getImAttach(array $params)
static checkUserReadAccess(array $params, int $userId)