Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
Follow.php
1
<?php
2
3
namespace
Bitrix\Socialnetwork\Space\Toolbar\Switcher\Option
;
4
5
use
Bitrix\Main\Error
;
6
use
Bitrix\Main\Localization\Loc
;
7
use
Bitrix\Main\Result
;
8
use
Bitrix\Socialnetwork\Space\Toolbar\Switcher\AbstractSwitcher
;
9
use CSocNetSubscription;
10
11
class
Follow
extends
AbstractSwitcher
12
{
13
public
const
SOCIALNETWORK_GROUP
=
'SG'
;
14
15
public
function
enable
():
Result
16
{
17
$result =
new
Result
();
18
if
($this->
isEnabled
())
19
{
20
return
$result;
21
}
22
23
if
(!CSocNetSubscription::Set($this->userId, $this->
getCode
(), static::TYPE_ON))
24
{
25
$result->addError(
new
Error
(
'Cannot switch type'
));
26
}
27
28
$this->
invalidate
();
29
30
return
$result;
31
}
32
33
public
function
disable
():
Result
34
{
35
$result =
new
Result
();
36
if
(!$this->
isEnabled
())
37
{
38
return
$result;
39
}
40
41
if
(!CSocNetSubscription::Set($this->
getUserId
(), $this->
getCode
(), static::TYPE_OFF))
42
{
43
$result->addError(
new
Error
(
'Cannot switch type'
));
44
}
45
$this->
invalidate
();
46
47
return
$result;
48
}
49
50
public
function
getValue
(): string
51
{
52
if
($this->isInitialized)
53
{
54
return
$this->value
;
55
}
56
57
$result = \CSocNetSubscription::GetList(
58
[],
59
[
60
'USER_ID'
=> $this->
getUserId
(),
61
'CODE'
=> $this->
getCode
(),
62
]
63
);
64
65
if
($result ===
false
)
66
{
67
$this->value = static::TYPE_OFF;
68
return
$this->value
;
69
}
70
71
$result = $result->Fetch();
72
$this->value = empty($result) ? static::TYPE_OFF : static::TYPE_ON;
73
$this->isInitialized =
true
;
74
75
return
$this->value
;
76
}
77
78
public
function
getMessage
(): ?string
79
{
80
return
$this->
isEnabled
() ? static::getUnfollowedMessage() : static::getFollowedMessage();
81
}
82
83
public
function
getCode
(): string
84
{
85
return
$this->code .
$this->spaceId
;
86
}
87
88
public
static
function
getDefaultCode
(): string
89
{
90
return
static::SOCIALNETWORK_GROUP;
91
}
92
93
public
static
function
getFollowedMessage
(): ?string
94
{
95
Loc::loadMessages
(__FILE__);
96
return
Loc::getMessage
(
'SOCIALNETWORK_SPACES_SPACE_FOLLOW'
);
97
}
98
99
public
static
function
getUnfollowedMessage
(): ?string
100
{
101
Loc::loadMessages
(__FILE__);
102
return
Loc::getMessage
(
'SOCIALNETWORK_SPACES_SPACE_UNFOLLOW'
);
103
}
104
}
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\Data\Result
Definition
result.php:16
Bitrix\Socialnetwork\Space\Toolbar\Switcher\AbstractSwitcher
Definition
AbstractSwitcher.php:12
Bitrix\Socialnetwork\Space\Toolbar\Switcher\AbstractSwitcher\getUserId
getUserId()
Definition
AbstractSwitcher.php:58
Bitrix\Socialnetwork\Space\Toolbar\Switcher\AbstractSwitcher\$value
string $value
Definition
AbstractSwitcher.php:20
Bitrix\Socialnetwork\Space\Toolbar\Switcher\AbstractSwitcher\$spaceId
int $spaceId
Definition
AbstractSwitcher.php:18
Bitrix\Socialnetwork\Space\Toolbar\Switcher\AbstractSwitcher\isEnabled
isEnabled()
Definition
AbstractSwitcher.php:53
Bitrix\Socialnetwork\Space\Toolbar\Switcher\Option\Follow
Definition
Follow.php:12
Bitrix\Socialnetwork\Space\Toolbar\Switcher\Option\Follow\getMessage
getMessage()
Definition
Follow.php:78
Bitrix\Socialnetwork\Space\Toolbar\Switcher\Option\Follow\getUnfollowedMessage
static getUnfollowedMessage()
Definition
Follow.php:99
Bitrix\Socialnetwork\Space\Toolbar\Switcher\Option\Follow\getDefaultCode
static getDefaultCode()
Definition
Follow.php:88
Bitrix\Socialnetwork\Space\Toolbar\Switcher\Option\Follow\SOCIALNETWORK_GROUP
const SOCIALNETWORK_GROUP
Definition
Follow.php:13
Bitrix\Socialnetwork\Space\Toolbar\Switcher\Option\Follow\disable
disable()
Definition
Follow.php:33
Bitrix\Socialnetwork\Space\Toolbar\Switcher\Option\Follow\enable
enable()
Definition
Follow.php:15
Bitrix\Socialnetwork\Space\Toolbar\Switcher\Option\Follow\getFollowedMessage
static getFollowedMessage()
Definition
Follow.php:93
Bitrix\Socialnetwork\Space\Toolbar\Switcher\Option\Follow\getCode
getCode()
Definition
Follow.php:83
Bitrix\Socialnetwork\Space\Toolbar\Switcher\Option\Follow\getValue
getValue()
Definition
Follow.php:50
Bitrix\Socialnetwork\Space\Toolbar\Switcher\Option
Definition
Follow.php:3
Bitrix\Socialnetwork\Space\Toolbar\Switcher\invalidate
invalidate()
Definition
CacheTrait.php:32
modules
socialnetwork
lib
Space
Toolbar
Switcher
Option
Follow.php
Создано системой
1.10.0