Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
Follow.php
1<?php
2
4
9use CSocNetSubscription;
10
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}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29