Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
commonsendercomponent.php
1
<?php
8
namespace
Bitrix\Sender\Internals
;
9
10
use
Bitrix\Main\Access\Event\EventDictionary
;
11
use
Bitrix\Main\Access\Exception\AccessException
;
12
use
Bitrix\Main\Error
;
13
use
Bitrix\Main\ErrorCollection
;
14
use
Bitrix\Main\Loader
;
15
use
Bitrix\Main\LoaderException
;
16
use
Bitrix\Main\Localization\Loc
;
17
use
Bitrix\Sender\Access\AccessController
;
18
use
Bitrix\Sender\Access\Exception\UnknownActionException
;
19
use
Bitrix\Sender\Access\Exception\WrongPermissionException
;
20
use
Bitrix\Sender\Security
;
21
use CBitrixComponent;
22
23
Loc::loadMessages
(__FILE__);
24
29
abstract
class
CommonSenderComponent
extends
CBitrixComponent
30
{
32
protected
$errors
;
36
protected
$userId
;
37
41
protected
$accessController
;
42
43
protected
function
checkRequiredParams
()
44
{
45
try
46
{
47
if
(!Loader::includeModule(
'sender'
))
48
{
49
$this->errors->setError(
new
Error
(
Loc::getMessage
(
'SENDER_MODULE_NOT_INSTALLED'
)));
50
51
return
false
;
52
}
53
}
54
catch
(
LoaderException
$e)
55
{
56
return
false
;
57
}
58
59
return
true
;
60
}
61
67
protected
function
initParams
()
68
{
69
$this->arParams[
'PATH_TO_LIST'
] = $this->arParams[
'PATH_TO_LIST'
] ??
''
;
70
$this->arParams[
'PATH_TO_USER_PROFILE'
] = $this->arParams[
'PATH_TO_USER_PROFILE'
] ??
''
;
71
$this->arParams[
'NAME_TEMPLATE'
] = empty($this->arParams[
'NAME_TEMPLATE'
]) ?
72
\CSite::GetNameFormat(
false
) :
73
str_replace(array(
"#NOBR#"
,
"#/NOBR#"
), array(
""
,
""
), $this->arParams[
"NAME_TEMPLATE"
]);
74
75
$this->arParams[
'RENDER_FILTER_INTO_VIEW'
] = $this->arParams[
'RENDER_FILTER_INTO_VIEW'
] ??
''
;
76
$this->arParams[
'RENDER_FILTER_INTO_VIEW_SORT'
] = $this->arParams[
'RENDER_FILTER_INTO_VIEW_SORT'
] ?? 10;
77
78
if
(isset($this->arParams[
'GRID_ID'
]))
79
{
80
$this->arParams[
'FILTER_ID'
] = $this->arParams[
'FILTER_ID'
] ?? $this->arParams[
'GRID_ID'
] .
'_FILTER'
;
81
}
82
83
$this->arParams[
'SET_TITLE'
] = !isset($this->arParams[
'SET_TITLE'
]) || $this->arParams[
'SET_TITLE'
] ==
'Y'
;
84
85
$this->
canEdit
();
86
}
87
88
protected
function
canEdit
()
89
{
90
if
(is_null(static::getEditAction()))
91
{
92
return
;
93
}
94
95
try
96
{
97
$this->arParams[
'CAN_EDIT'
] = $this->arParams[
'CAN_EDIT'
]
98
??
99
$this->
getAccessController
()->check(static::getEditAction());
100
}
101
catch
(
UnknownActionException
$e)
102
{
103
$this->errors->setError(
new
Error
(
Loc::getMessage
(
'SENDER_WRONG_PERMISSION'
)));
104
exit;
105
}
106
}
107
108
protected
function
printErrors
()
109
{
110
foreach
($this->errors as $error)
111
{
112
$message = $error->getMessage() ??
''
;
113
ShowError($message);
114
}
115
}
116
117
protected
function
checkComponentExecution
()
118
{
119
if
(!$this->
checkRequiredParams
())
120
{
121
$this->
printErrors
();
122
return
false
;
123
}
124
125
if
(!static::prepareResult())
126
{
127
$this->
printErrors
();
128
return
false
;
129
}
130
131
return
true
;
132
}
133
134
protected
function
getAccessController
():
AccessController
135
{
136
if
(!$this->accessController)
137
{
138
$this->accessController =
new
AccessController
($this->userId);
139
}
140
return
$this->accessController
;
141
}
142
143
public
function
executeComponent
()
144
{
145
$this->errors =
new
ErrorCollection
();
146
$this->userId = Security\User::current()->getId();
147
Security\Access::registerEvent(EventDictionary::EVENT_ON_AFTER_CHECK);
148
149
try
150
{
151
$canAccess = $this->
getAccessController
()->check(static::getViewAction());
152
153
if
((!isset($this->arParams[
'CAN_VIEW'
]) || !$this->arParams[
'CAN_VIEW'
]) && !$canAccess)
154
{
155
throw
new
WrongPermissionException
();
156
}
157
}
158
catch
(
AccessException
$e)
159
{
160
$this->errors->setError(
new
Error
(
Loc::getMessage
(
'SENDER_WRONG_PERMISSION'
)));
161
$this->
printErrors
();
162
exit;
163
}
164
static::initParams();
165
166
if
(!$this->
checkRequiredParams
())
167
{
168
$this->
printErrors
();
169
exit;
170
}
171
}
172
178
protected
function
prepareResultAndTemplate
($template =
""
)
179
{
180
if
(!static::prepareResult())
181
{
182
$this->
printErrors
();
183
exit();
184
}
185
186
if
(!$this->errors->isEmpty())
187
{
188
$this->
printErrors
();
189
}
190
191
if
(!is_null($template))
192
{
193
$this->includeComponentTemplate($template);
194
return
;
195
}
196
}
197
198
abstract
protected
function
prepareResult
();
199
abstract
public
function
getEditAction
();
200
abstract
public
function
getViewAction
();
201
}
Bitrix\Main\Access\Event\EventDictionary
Definition
eventdictionary.php:13
Bitrix\Main\Access\Exception\AccessException
Definition
accessexception.php:14
Bitrix\Main\ErrorCollection
Definition
errorcollection.php:14
Bitrix\Main\Error
Definition
error.php:14
Bitrix\Main\LoaderException
Definition
loader.php:582
Bitrix\Main\Loader
Definition
loader.php:12
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\loadMessages
static loadMessages($file)
Definition
loc.php:64
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Definition
loc.php:29
Bitrix\Sender\Access\AccessController
Definition
accesscontroller.php:19
Bitrix\Sender\Access\Exception\UnknownActionException
Definition
unknownactionexception.php:14
Bitrix\Sender\Access\Exception\WrongPermissionException
Definition
wrongpermissionexception.php:14
Bitrix\Sender\Internals\CommonSenderComponent
Definition
commonsendercomponent.php:30
Bitrix\Sender\Internals\CommonSenderComponent\getViewAction
getViewAction()
Bitrix\Sender\Internals\CommonSenderComponent\checkRequiredParams
checkRequiredParams()
Definition
commonsendercomponent.php:43
Bitrix\Sender\Internals\CommonSenderComponent\$errors
$errors
Definition
commonsendercomponent.php:32
Bitrix\Sender\Internals\CommonSenderComponent\getAccessController
getAccessController()
Definition
commonsendercomponent.php:134
Bitrix\Sender\Internals\CommonSenderComponent\getEditAction
getEditAction()
Bitrix\Sender\Internals\CommonSenderComponent\$userId
$userId
Definition
commonsendercomponent.php:36
Bitrix\Sender\Internals\CommonSenderComponent\canEdit
canEdit()
Definition
commonsendercomponent.php:88
Bitrix\Sender\Internals\CommonSenderComponent\prepareResultAndTemplate
prepareResultAndTemplate($template="")
Definition
commonsendercomponent.php:178
Bitrix\Sender\Internals\CommonSenderComponent\$accessController
$accessController
Definition
commonsendercomponent.php:41
Bitrix\Sender\Internals\CommonSenderComponent\executeComponent
executeComponent()
Definition
commonsendercomponent.php:143
Bitrix\Sender\Internals\CommonSenderComponent\prepareResult
prepareResult()
Bitrix\Sender\Internals\CommonSenderComponent\initParams
initParams()
Definition
commonsendercomponent.php:67
Bitrix\Sender\Internals\CommonSenderComponent\printErrors
printErrors()
Definition
commonsendercomponent.php:108
Bitrix\Sender\Internals\CommonSenderComponent\checkComponentExecution
checkComponentExecution()
Definition
commonsendercomponent.php:117
Bitrix\Sender\Internals
Bitrix\Sender\Security
Definition
access.php:3
modules
sender
lib
internals
commonsendercomponent.php
Создано системой
1.10.0