Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
usages.php
1<?php
3
4class Usages
5{
6 protected $list;
7
8 public function __construct()
9 {
10 $this->list = [];
11 }
12
13 public function add($ownerId, $sourceType, $value)
14 {
15 if (!isset($this->list[$sourceType]))
16 {
17 $this->list[$sourceType] = [];
18 }
19 $key = "{$ownerId}#{$value}";
20 $this->list[$sourceType][$key] = [$ownerId, $value];
21 return $this;
22 }
23
24 public function addOwnerSources($ownerId, array $sources)
25 {
26 foreach ($sources as $source)
27 {
28 $this->add($ownerId, $source[0], $source[1]);
29 }
30 return $this;
31 }
32
33 public function getBySourceType($sourceType)
34 {
35 return isset($this->list[$sourceType]) ? array_values($this->list[$sourceType]) : [];
36 }
37
38 public function getValuesBySourceType($sourceType): array
39 {
40 $result = $this->getBySourceType($sourceType);
41 $result = array_column($result, 1);
42 return array_unique($result);
43 }
44
45 public function getByOwner($ownerId)
46 {
47 $list = [];
48 foreach ($this->list as $sourceType => $items)
49 {
50 foreach ($items as list($id, $value))
51 {
52 if ($ownerId === $id)
53 {
54 $list[] = [$sourceType, $value];
55 }
56 }
57 }
58 return $list;
59 }
60
61 public function getAll()
62 {
63 return $this->list;
64 }
65}
add($ownerId, $sourceType, $value)
Definition usages.php:13