1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
UrlPreview.php
См. документацию.
1<?php
2
4
15
16final class UrlPreview
17{
18 public static function checkUserReadAccess(array $params, int $userId): bool
19 {
20 $signedAttachId = (string)($params['signedAttachId'] ?? '');
21 if (!$signedAttachId || !$userId)
22 {
23 return false;
24 }
25
26 try
27 {
28 (new AttachedVoteResultUrlService())->getAttachByUrlId($signedAttachId);
29
30 return true;
31 }
33 {
34 return false;
35 }
36 }
37
39 {
40 $signedAttachId = (string)($params['signedAttachId'] ?? '');
41 if (!$signedAttachId || !Loader::includeModule('im'))
42 {
43 return false;
44 }
45
46 try
47 {
48 $attach = (new AttachedVoteResultUrlService())->getAttachByUrlId($signedAttachId);
49
50 $messageAttach = new \CIMMessageParamAttach();
51 $messageAttach->AddUser([
52 'NAME' => Loc::getMessage('VOTE_INTEGRATION_MAIN_URL_PREVIEW_TITLE'),
53 'LINK' => (new AttachedVoteResultUrlService())->getAbsoluteResultUrl($signedAttachId),
54 ]);
55 $messageAttach->AddDelimiter();
56 $messageAttach->AddGrid(self::getAttachGrid($attach));
57
58 return $messageAttach;
59 }
61 {
62 return false;
63 }
64 }
65
66 private static function getAttachGrid(Attach $attach): array
67 {
68 $rows = [];
69 $authorName = self::getAuthorFormattedName($attach);
70 if ($authorName)
71 {
72 $rows[] = self::getGridRow(
73 name: Loc::getMessage('VOTE_INTEGRATION_MAIN_URL_PREVIEW_OWNER'),
74 value: $authorName
75 );
76 }
77
78 $rows[] = self::getGridRow(
79 name: Loc::getMessage('VOTE_INTEGRATION_MAIN_URL_PREVIEW_QUESTION'),
80 value: self::getFirstQuestion($attach),
81 );
82
83 $rows[] = self::getGridRow(
84 name: Loc::getMessage('VOTE_INTEGRATION_MAIN_URL_PREVIEW_INFO'),
85 value: self::getInfo($attach),
86 );
87
88 return $rows;
89 }
90
91 private static function getGridRow(?string $name, ?string $value): array
92 {
93 return [
94 'NAME' => $name,
95 'VALUE' => $value,
96 'DISPLAY' => 'COLUMN',
97 'WIDTH' => 120,
98 ];
99 }
100
101 private static function getAuthorFormattedName(Attach $attach): ?string
102 {
103 $authorId = (int)($attach['AUTHOR_ID'] ?? 0);
104 if ($authorId <= 0)
105 {
106 return null;
107 }
108
109 $userFields = UserTable::query()
110 ->whereIn('ID', $authorId)
111 ->setSelect([
112 'ID',
113 'NAME',
114 'LAST_NAME',
115 'SECOND_NAME',
116 'LOGIN',
117 ])
118 ->setLimit(1)
119 ->exec()
120 ->fetch()
121 ;
122
123 if (empty($userFields))
124 {
125 return null;
126 }
127
128 return \CUser::FormatName(
129 \CSite::GetNameFormat(false),
130 $userFields,
131 true, false
132 );
133 }
134
135 private static function getFirstQuestion(Attach $attach): string
136 {
137 $firstKey = array_key_first($attach['QUESTIONS']);
138
139 return (string)($attach['QUESTIONS'][$firstKey]['QUESTION'] ?? '');
140 }
141
142 private static function getInfo(Attach $attach): ?string
143 {
144 $anonymity = $attach->isPublicVote()
145 ? Loc::getMessage('VOTE_INTEGRATION_MAIN_URL_PREVIEW_PUBLIC')
146 : Loc::getMessage('VOTE_INTEGRATION_MAIN_URL_PREVIEW_ANONYMOUS')
147 ;
148
149 if ($attach->isFinished())
150 {
151 return Loc::getMessage('VOTE_INTEGRATION_MAIN_URL_PREVIEW_FINISHED_MGSVER1', ['#ANONYMITY#' => $anonymity]);
152 }
153
154 $options = (int)($attach['OPTIONS'] ?? 0);
155 $allowRevote = $options & Option::ALLOW_REVOTE;
156
157 return $allowRevote
158 ? $anonymity
159 : Loc::getMessage('VOTE_INTEGRATION_MAIN_URL_PREVIEW_RESTRICT_REVOTE', ['#ANONYMITY#' => $anonymity])
160 ;
161 }
162}
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
Определения loader.php:13
static includeModule($moduleName)
Определения loader.php:67
Определения user.php:48
Определения attach.php:180
static getImAttach(array $params)
Определения UrlPreview.php:38
static checkUserReadAccess(array $params, int $userId)
Определения UrlPreview.php:18
$options
Определения commerceml2.php:49
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$name
Определения menu_edit.php:35
return false
Определения prolog_main_admin.php:185
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$rows
Определения options.php:264