Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
contentview.php
1<?php
2
4
9
10class ContentView extends Base
11{
12 public function configureActions(): array
13 {
14 $configureActions = parent::configureActions();
15 $configureActions['set'] = [
16 '+prefilters' => [
17 new ActionFilter\CloseSession(),
18 ]
19 ];
20
21 return $configureActions;
22 }
23
24 public function setAction(array $params = []): ?array
25 {
26 global $USER;
27
28 $xmlIdList = (
29 isset($params["viewXMLIdList"])
30 && is_array($params["viewXMLIdList"])
31 ? $params["viewXMLIdList"]
32 : []
33 );
34
35 $context = ($params['context'] ?? '');
36
37 if (!Loader::includeModule('socialnetwork'))
38 {
39 $this->addError(new Error('Cannot include Socialnetwork module', 'SONET_CONTROLLER_CONTENTVIEW_NO_SOCIALNETWORK_MODULE'));
40 return null;
41 }
42
43 $signer = new \Bitrix\Main\Engine\ActionFilter\Service\Token($USER->getId());
44
45 foreach ($xmlIdList as $key => $item)
46 {
47 if (empty($item['xmlId']))
48 {
49 unset($xmlIdList[$key]);
50 continue;
51 }
52
53 if (!empty($item['signedKey']))
54 {
55 try
56 {
57 if ($signer->unsign($item['signedKey'], $item['xmlId']) === $item['xmlId'])
58 {
59 $xmlIdList[$key]['checkAccess'] = false;
60 }
61 else
62 {
63 unset($xmlIdList[$key]);
64 }
65 }
66 catch(\Exception $e)
67 {
68 $xmlIdList[$key]['checkAccess'] = true;
69 }
70 }
71 else
72 {
73 $xmlIdList[$key]['checkAccess'] = true;
74 }
75 }
76
77 UserContentView::set([
78 'xmlIdList' => $xmlIdList,
79 'context' => $context,
80 'userId' => $this->getCurrentUser()->getId(),
81 ]);
82
83 return [
84 'SUCCESS' => 'Y'
85 ];
86 }
87
88 public function getListAction(array $params = []): ?array
89 {
90 $contentId = (
91 isset($params['contentId'])
92 && is_string($params['contentId'])
93 ? trim($params['contentId'])
94 : ''
95 );
96
97 $page = (
98 isset($params['page'])
99 && (int)$params['page'] > 0
100 ? (int)$params['page']
101 : 1
102 );
103
104 $pathToUserProfile = (
105 isset($params['pathToUserProfile'])
106 && is_string($params['pathToUserProfile'])
107 ? trim($params['pathToUserProfile'])
108 : ''
109 );
110
111 if ($contentId === '')
112 {
113 $this->addError(new Error('Empty Content ID', 'SONET_CONTROLLER_CONTENTVIEW_EMPTY_CONTENT_ID'));
114 return null;
115 }
116
117 if (!Loader::includeModule('socialnetwork'))
118 {
119 $this->addError(new Error('Cannot include Socialnetwork module', 'SONET_CONTROLLER_CONTENTVIEW_NO_SOCIALNETWORK_MODULE'));
120 return null;
121 }
122
123 $userList = UserContentView::getUserList([
124 'contentId' => $contentId,
125 'page' => $page,
126 'pathToUserProfile' => $pathToUserProfile
127 ]);
128
129 $result['items'] = $userList['items'];
130 $result['itemsCount'] = count($result['items']);
131 $result['hiddenCount'] = $userList['hiddenCount'];
132
133 return $result;
134 }
135}
136