9 private static $instances = [];
15 public static function getInstance(
int $tplId,
string $name): self
17 $cacheKey = $tplId .
'|' . $name;
19 if (!isset(self::$instances[$cacheKey]))
21 self::$instances[$cacheKey] =
new self($tplId, $name);
24 return self::$instances[$cacheKey];
27 private function __construct(
int $tplId,
string $name)
29 $this->tplId = $tplId;
33 private function __clone()
39 $row = $this->
getAll()[$key] ??
null;
41 return $row ? $row[
'value'] :
null;
44 public function setValue(
string $key, $value): self
46 $row = $this->
getAll()[$key] ??
null;
52 Entity\ActivityStorageTable::delete($row[
'id']);
53 unset($this->values[$key]);
57 $this->values[$key][
'value'] = $value;
58 Entity\ActivityStorageTable::update($row[
'id'], [
'KEY_VALUE' =>
Json::encode($value)]);
71 if ($this->values ===
null)
74 $listResult = Entity\ActivityStorageTable::getList([
76 '=WORKFLOW_TEMPLATE_ID' => $this->tplId,
77 '=ACTIVITY_NAME' => $this->name
81 foreach ($listResult as $item)
83 $this->values[$item[
'KEY_ID']] = [
93 protected function addValue(
string $key, $value)
95 $result = Entity\ActivityStorageTable::add([
96 'WORKFLOW_TEMPLATE_ID' => $this->tplId,
97 'ACTIVITY_NAME' => $this->name,
102 $id = $result->getId();
104 if (is_array($this->values))
106 $this->values[$key] = [
117 $listResult = Entity\ActivityStorageTable::getList([
119 '=WORKFLOW_TEMPLATE_ID' => $id,
124 foreach ($listResult as $item)
126 Entity\ActivityStorageTable::delete($item[
'ID']);
addValue(string $key, $value)
setValue(string $key, $value)
static getInstance(int $tplId, string $name)
static onAfterTemplateDelete(int $id)
static encode($data, $options=null)