Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
Pin.php
1
<?php
2
3
namespace
Bitrix\Socialnetwork\Space\Toolbar\Switcher\Option
;
4
5
use
Bitrix\Main\ArgumentException
;
6
use
Bitrix\Main\Localization\Loc
;
7
use
Bitrix\Main\ObjectPropertyException
;
8
use
Bitrix\Main\ORM\Query\Filter\ConditionTree
;
9
use
Bitrix\Main\ORM\Query\Query
;
10
use
Bitrix\Main\Result
;
11
use
Bitrix\Main\SystemException
;
12
use
Bitrix\Socialnetwork\Space\Toolbar\Switcher\AbstractSwitcher
;
13
use
Bitrix\Socialnetwork\WorkgroupPinTable
;
14
use
Bitrix\Socialnetwork\Internals
;
15
use Exception;
16
17
class
Pin
extends
AbstractSwitcher
18
{
19
public
const
PIN_CONTEXT
=
''
;
20
21
private
?
Internals\Pin\Pin
$pin =
null
;
22
23
public
function
enable
():
Result
24
{
25
$result =
new
Result
();
26
if
($this->
isEnabled
())
27
{
28
return
$result;
29
}
30
31
$result = (
new
Internals\Pin\Pin
())
32
->setGroupId($this->spaceId)
33
->setUserId($this->userId)
34
->setContext($this->code)
35
->save();
36
37
$this->
invalidate
();
38
39
return
$result;
40
}
41
42
public
function
disable
():
Result
43
{
44
$result =
new
Result
();
45
if
(!$this->
isEnabled
())
46
{
47
return
$result;
48
}
49
50
$result = $this->pin->delete();
51
$this->
invalidate
();
52
53
return
$result;
54
}
55
56
public
function
getValue
(): string
57
{
58
if
($this->isInitialized)
59
{
60
return
$this->value;
61
}
62
63
try
64
{
65
$this->setPin();
66
$this->value = is_null($this->pin) ? static::TYPE_OFF : static::TYPE_ON;
67
$this->isInitialized =
true
;
68
}
69
catch
(Exception)
70
{
71
$this->value = static::TYPE_OFF;
72
}
73
74
return
$this->value;
75
}
76
80
private
function
getContextFilter():
ConditionTree
81
{
82
$filter = Query::filter();
83
return
$this->code ===
''
84
? $filter->logic(
'or'
)->whereNull(
'CONTEXT'
)->where(
'CONTEXT'
,
''
)
85
: $filter->where(
'CONTEXT'
, $this->code);
86
}
87
88
public
function
getMessage
(): ?string
89
{
90
return
$this->
isEnabled
() ? static::getUnpinnedMessage() : static::getPinnedMessage();
91
}
92
98
private
function
setPin(): static
99
{
100
$query = WorkgroupPinTable::query()
101
->setSelect([
102
'ID'
,
103
'GROUP_ID'
,
104
'USER_ID'
,
105
])
106
->where(
'GROUP_ID'
, $this->spaceId)
107
->where(
'USER_ID'
, $this->userId)
108
->where($this->getContextFilter());
109
110
$this->pin = $query->exec()->fetchObject();
111
112
return
$this;
113
}
114
115
protected
function
canSwitch
(): bool
116
{
117
return
$this->
isSpaceExists
();
118
}
119
120
public
static
function
getDefaultCode
(): string
121
{
122
return
static::PIN_CONTEXT;
123
}
124
125
public
static
function
getPinnedMessage
(): ?string
126
{
127
Loc::loadMessages
(__FILE__);
128
return
Loc::getMessage
(
'SOCIALNETWORK_SPACES_SPACE_PIN'
);
129
}
130
131
public
static
function
getUnpinnedMessage
(): ?string
132
{
133
Loc::loadMessages
(__FILE__);
134
return
Loc::getMessage
(
'SOCIALNETWORK_SPACES_SPACE_UNPIN'
);
135
}
136
}
Bitrix\Main\ArgumentException
Definition
exception.php:34
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\Main\ORM\Query\Filter\ConditionTree
Definition
conditiontree.php:28
Bitrix\Main\ORM\Query\Query
Definition
query.php:118
Bitrix\Main\ObjectPropertyException
Definition
exception.php:181
Bitrix\Main\SystemException
Definition
exception.php:8
Bitrix\Socialnetwork\Internals\Pin\Pin
Definition
pin.php:8
Bitrix\Socialnetwork\Space\Toolbar\Switcher\AbstractSwitcher
Definition
AbstractSwitcher.php:12
Bitrix\Socialnetwork\Space\Toolbar\Switcher\AbstractSwitcher\isSpaceExists
isSpaceExists()
Definition
AbstractSwitcher.php:83
Bitrix\Socialnetwork\Space\Toolbar\Switcher\AbstractSwitcher\isEnabled
isEnabled()
Definition
AbstractSwitcher.php:53
Bitrix\Socialnetwork\Space\Toolbar\Switcher\Option\Pin
Definition
Pin.php:18
Bitrix\Socialnetwork\Space\Toolbar\Switcher\Option\Pin\getMessage
getMessage()
Definition
Pin.php:88
Bitrix\Socialnetwork\Space\Toolbar\Switcher\Option\Pin\canSwitch
canSwitch()
Definition
Pin.php:115
Bitrix\Socialnetwork\Space\Toolbar\Switcher\Option\Pin\getUnpinnedMessage
static getUnpinnedMessage()
Definition
Pin.php:131
Bitrix\Socialnetwork\Space\Toolbar\Switcher\Option\Pin\getDefaultCode
static getDefaultCode()
Definition
Pin.php:120
Bitrix\Socialnetwork\Space\Toolbar\Switcher\Option\Pin\disable
disable()
Definition
Pin.php:42
Bitrix\Socialnetwork\Space\Toolbar\Switcher\Option\Pin\enable
enable()
Definition
Pin.php:23
Bitrix\Socialnetwork\Space\Toolbar\Switcher\Option\Pin\PIN_CONTEXT
const PIN_CONTEXT
Definition
Pin.php:19
Bitrix\Socialnetwork\Space\Toolbar\Switcher\Option\Pin\getValue
getValue()
Definition
Pin.php:56
Bitrix\Socialnetwork\Space\Toolbar\Switcher\Option\Pin\getPinnedMessage
static getPinnedMessage()
Definition
Pin.php:125
Bitrix\Socialnetwork\WorkgroupPinTable
Definition
workgrouppin.php:31
Bitrix\Socialnetwork\Internals
Definition
counter.php:3
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
Pin.php
Создано системой
1.10.0