1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
ActivityStorage.php
См. документацию.
1<?php
2
4
6
8{
9 private static $instances = [];
10
11 private $tplId;
12 private $name;
13 private $values;
14
15 public static function getInstance(int $tplId, string $name): self
16 {
17 $cacheKey = $tplId . '|' . $name;
18
19 if (!isset(self::$instances[$cacheKey]))
20 {
21 self::$instances[$cacheKey] = new self($tplId, $name);
22 }
23
24 return self::$instances[$cacheKey];
25 }
26
27 private function __construct(int $tplId, string $name)
28 {
29 $this->tplId = $tplId;
30 $this->name = $name;
31 }
32
33 private function __clone()
34 {
35 }
36
37 public function getValue(string $key)
38 {
39 $row = $this->getAll()[$key] ?? null;
40
41 return $row ? $row['value'] : null;
42 }
43
44 public function setValue(string $key, $value): self
45 {
46 $row = $this->getAll()[$key] ?? null;
47
48 if ($row)
49 {
50 if ($value === null)
51 {
53 unset($this->values[$key]);
54 }
55 else
56 {
57 $this->values[$key]['value'] = $value;
58 Entity\ActivityStorageTable::update($row['id'], ['KEY_VALUE' => Json::encode($value)]);
59 }
60 }
61 else
62 {
63 $this->addValue($key, $value);
64 }
65
66 return $this;
67 }
68
69 protected function getAll()
70 {
71 if ($this->values === null)
72 {
73 $this->values = [];
75 'filter' => [
76 '=WORKFLOW_TEMPLATE_ID' => $this->tplId,
77 '=ACTIVITY_NAME' => $this->name
78 ]
79 ]);
80
81 foreach ($listResult as $item)
82 {
83 $this->values[$item['KEY_ID']] = [
84 'id' => $item['ID'],
85 'value' => Json::decode($item['KEY_VALUE'])
86 ];
87 }
88 }
89
90 return $this->values;
91 }
92
93 protected function addValue(string $key, $value)
94 {
96 'WORKFLOW_TEMPLATE_ID' => $this->tplId,
97 'ACTIVITY_NAME' => $this->name,
98 'KEY_ID' => $key,
99 'KEY_VALUE' => Json::encode($value)
100 ]);
101
102 $id = $result->getId();
103
104 if (is_array($this->values))
105 {
106 $this->values[$key] = [
107 'id' => $id,
108 'value' => $value
109 ];
110 }
111
112 return $id;
113 }
114
115 public static function onAfterTemplateDelete(int $id)
116 {
118 'filter' => [
119 '=WORKFLOW_TEMPLATE_ID' => $id,
120 ],
121 'select' => ['ID']
122 ]);
123
124 foreach ($listResult as $item)
125 {
127 }
128 }
129}
addValue(string $key, $value)
Определения ActivityStorage.php:93
setValue(string $key, $value)
Определения ActivityStorage.php:44
static getInstance(int $tplId, string $name)
Определения ActivityStorage.php:15
static onAfterTemplateDelete(int $id)
Определения ActivityStorage.php:115
static getList(array $parameters=array())
Определения datamanager.php:431
static delete($primary)
Определения datamanager.php:1644
static add(array $data)
Определения datamanager.php:877
static update($primary, array $data)
Определения datamanager.php:1256
Определения json.php:9
$result
Определения get_property_values.php:14
$name
Определения menu_edit.php:35
if(empty($signedUserToken)) $key
Определения quickway.php:257