Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
SmartTracking.php
1<?php
2
4
8use CSocNetLogFollow;
9
11{
12 public const COMMON_LIVEFEED = '**';
13
14 public function enable(): Result
15 {
16 $result = new Result();
17 if ($this->isEnabled())
18 {
19 return $result;
20 }
21
22 if (!CSocNetLogFollow::Set($this->userId, $this->code, static::TYPE_OFF))
23 {
24 $result->addError(new Error('Cannot switch type'));
25 }
26
27 $this->invalidate();
28
29 return $result;
30 }
31
32 public function disable(): Result
33 {
34 $result = new Result();
35 if (!$this->isEnabled())
36 {
37 return $result;
38 }
39
40 if (!CSocNetLogFollow::Set($this->userId, $this->code, static::TYPE_ON))
41 {
42 $result->addError(new Error('Cannot switch type'));
43 }
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 $this->value = CSocNetLogFollow::GetDefaultValue($this->userId);
58 $this->isInitialized = true;
59
60 return $this->value;
61 }
62
63 public function isEnabled(): bool
64 {
65 return $this->getValue() === static::TYPE_OFF;
66 }
67
68 public static function getDefaultCode(): string
69 {
70 return static::COMMON_LIVEFEED;
71 }
72
73 protected function canSwitch(): bool
74 {
75 return true;
76 }
77}