Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
usersignature.php
1
<?php
2
3
namespace
Bitrix\Mail\Controller
;
4
5
use
Bitrix\Mail\Internals\UserSignatureTable
;
6
use
Bitrix\Main
;
7
use
Bitrix\Main\Engine\CurrentUser
;
8
use
Bitrix\Main\Error
;
9
use
Bitrix\Main\Localization\Loc
;
10
11
class
UserSignature
extends
Base
12
{
13
const
USER_SIGNATURES_LIMIT
= 100;
14
19
public
function
addAction
(array $fields)
20
{
21
$unsafeFields = (array) $this->
getRequest
()->getPostList()->getRaw(
'fields'
);
22
\CUtil::decodeUriComponent($unsafeFields);
23
24
if
(($limit = Main\
Config
\Option::get(
'mail'
,
'user_signatures_limit'
, static::USER_SIGNATURES_LIMIT)) > 0)
25
{
26
$count = UserSignatureTable::getCount(array(
27
'USER_ID'
=> CurrentUser::get()->getId(),
28
));
29
if
($count >= $limit)
30
{
31
Loc::loadMessages
(__FILE__);
32
$this->errorCollection[] =
new
Error
(
Loc::getMessage
(
'MAIL_USER_SIGNATURE_LIMIT'
));
33
return
false
;
34
}
35
}
36
37
$userSignature = new \Bitrix\Mail\Internals\Entity\UserSignature;
38
39
$userSignature->set(
'USER_ID'
, CurrentUser::get()->getId());
40
$userSignature->set(
'SENDER'
, $fields[
'sender'
]);
41
$userSignature->set(
'SIGNATURE'
, $this->
sanitize
($unsafeFields[
'signature'
]));
42
43
$result = $userSignature->save();
44
45
if
($result->isSuccess())
46
{
47
$userSignature = UserSignatureTable::getById($result->getId())->fetchObject();
48
return
$this->
getAction
($userSignature);
49
}
50
else
51
{
52
$this->errorCollection = $result->getErrors();
53
return
false
;
54
}
55
}
56
57
protected
function
checkAccess
(\
Bitrix
\
Mail
\Internals\
Entity
\
UserSignature
$userSignature): bool
58
{
59
if
($userSignature->getUserId() === (
int
) $this->getCurrentUser()->getId())
60
{
61
return
true
;
62
}
63
64
$this->
addError
(
new
Error
(
Loc::getMessage
(
'MAIL_USER_SIGNATURE_ACCESS_DENIED'
)));
65
return
false
;
66
}
67
71
public
function
deleteAction
(\
Bitrix
\
Mail
\Internals\
Entity
\
UserSignature
$userSignature): bool
72
{
73
if
(!$this->
checkAccess
($userSignature))
74
{
75
return
false
;
76
}
77
78
$userSignature->delete();
79
return
true
;
80
}
81
82
public
function
getAction
(\
Bitrix
\
Mail
\Internals\
Entity
\
UserSignature
$userSignature): bool|array
83
{
84
if
(!$this->
checkAccess
($userSignature))
85
{
86
return
false
;
87
}
88
89
return
[
90
'userSignature'
=> $this->
convertArrayKeysToCamel
($userSignature->collectValues(), 1),
91
];
92
}
93
99
public
function
updateAction
(\
Bitrix
\
Mail
\Internals\
Entity
\
UserSignature
$userSignature, array $fields): bool|array
100
{
101
if
(!$this->
checkAccess
($userSignature))
102
{
103
return
false
;
104
}
105
106
$unsafeFields = (array) $this->
getRequest
()->getPostList()->getRaw(
'fields'
);
107
\CUtil::decodeUriComponent($unsafeFields);
108
109
$userSignature->set(
'SENDER'
, $fields[
'sender'
]);
110
$userSignature->set(
'SIGNATURE'
, $this->
sanitize
($unsafeFields[
'signature'
]));
111
112
$result = $userSignature->save();
113
if
($result->isSuccess())
114
{
115
return
$this->
getAction
($userSignature);
116
}
117
else
118
{
119
$this->errorCollection = $result->getErrors();
120
return
false
;
121
}
122
}
123
}
Bitrix\Mail\Controller\Base
Definition
base.php:12
Bitrix\Mail\Controller\Base\convertArrayKeysToCamel
convertArrayKeysToCamel(array $array, $levels=0, $currentLevel=0)
Definition
base.php:46
Bitrix\Mail\Controller\Base\sanitize
sanitize($text)
Definition
base.php:26
Bitrix\Mail\Controller\UserSignature
Definition
usersignature.php:12
Bitrix\Mail\Controller\UserSignature\checkAccess
checkAccess(\Bitrix\Mail\Internals\Entity\UserSignature $userSignature)
Definition
usersignature.php:57
Bitrix\Mail\Controller\UserSignature\addAction
addAction(array $fields)
Definition
usersignature.php:19
Bitrix\Mail\Controller\UserSignature\deleteAction
deleteAction(\Bitrix\Mail\Internals\Entity\UserSignature $userSignature)
Definition
usersignature.php:71
Bitrix\Mail\Controller\UserSignature\getAction
getAction(\Bitrix\Mail\Internals\Entity\UserSignature $userSignature)
Definition
usersignature.php:82
Bitrix\Mail\Controller\UserSignature\updateAction
updateAction(\Bitrix\Mail\Internals\Entity\UserSignature $userSignature, array $fields)
Definition
usersignature.php:99
Bitrix\Mail\Controller\UserSignature\USER_SIGNATURES_LIMIT
const USER_SIGNATURES_LIMIT
Definition
usersignature.php:13
Bitrix\Mail\Internals\UserSignatureTable
Definition
usersignature.php:26
Bitrix\Main\Engine\Controller\addError
addError(Error $error)
Definition
controller.php:1051
Bitrix\Main\Engine\Controller\getRequest
getRequest()
Definition
controller.php:351
Bitrix\Main\Engine\CurrentUser
Definition
currentuser.php:8
Bitrix\Main\Error
Definition
error.php:14
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\Main\ORM\Entity
Definition
entity.php:26
Bitrix\Mail\Controller
Definition
addressbook.php:3
Bitrix\Main\Config
Definition
configuration.php:2
Bitrix\Main\Mail
Definition
address.php:8
Bitrix\Main
Bitrix
modules
mail
lib
controller
usersignature.php
Создано системой
1.10.0