Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
Builder.php
1<?php
2
4
15
16final class Builder
17{
18 private const SELECT = [
19 'ID',
20 'NAME',
21 'DATE_ACTIVITY',
22 'IMAGE_ID',
23 'AVATAR_TYPE',
24 'VISIBLE',
25 'OPENED',
26 'ROLE' => 'MEMBER.ROLE',
27// 'USER_ROLE_DATE_UPDATE' => 'MEMBER.DATE_UPDATE',
28 'ROLE_INIT_BY_TYPE' => 'MEMBER.INITIATED_BY_TYPE',
29// 'USER_ROLE_INIT_BY_USER_ID' => 'MEMBER.INITIATED_BY_USER_ID',
30 'PIN_ID' => 'PIN.ID'
31 ];
32
34 private array $filters = [];
35
36 public function __construct(private int $userId)
37 {
38 }
39
40 private function addFilter(FilterInterface $filter): self
41 {
42 $this->filters[] = $filter;
43
44 return $this;
45 }
46
47 public function build(): Query
48 {
49 $query = $this->getBaseQuery();
50 foreach ($this->filters as $filler)
51 {
52 $filler->apply($query);
53 }
54
55 return $query;
56 }
57
58 public function addModeFilter(string $mode): self
59 {
60 if ($mode === Dictionary::FILTER_MODES['all'])
61 {
62 $this->addFilter(new Filter\Mode\AllModeFilter($this->userId));
63 }
64 elseif ($mode === Dictionary::FILTER_MODES['my'])
65 {
66 $this->addFilter(new Filter\Mode\MyModeFilter($this->userId));
67 }
68 elseif ($mode === Dictionary::FILTER_MODES['other'])
69 {
70 $this->addFilter(new Filter\Mode\OtherModeFilter($this->userId));
71 }
72
73 return $this;
74 }
75
76 public function addPaginationFilter(int $offset, int $limit): self
77 {
78 return $this->addFilter(new Filter\Pagination\PaginationFilter($offset, $limit));
79 }
80
81 public function addSpaceIdFilter(int $spaceId): self
82 {
83 return $this->addFilter(new Filter\Id\IdFilter($spaceId));
84 }
85
86 public function addSpaceIdListFilter(array $spaceIds): self
87 {
88 return $this->addFilter(new Filter\Id\IdListFilter($spaceIds));
89 }
90
91 public function addNameSearchFilter(string $searchString): self
92 {
93 return $this->addFilter(new Filter\Search\NameSearchFilter($searchString));
94 }
95
96 private function getBaseQuery(): Query
97 {
98 $join =
99 Join::on('this.ID', 'ref.GROUP_ID')
100 ->where('ref.USER_ID', $this->userId)
101 ;
102
103 $query = WorkgroupTable::query();
104 $query
105 ->setSelect(self::SELECT)
106 ->addOrder('DATE_ACTIVITY', 'DESC')
107 ->registerRuntimeField(
108 (new Reference(
109 'PIN',
110 WorkgroupPinTable::class,
111 $join,
112 ))
113 ->configureJoinType(Join::TYPE_LEFT)
114 )
115 ->registerRuntimeField(
116 (new Reference(
117 'MEMBER',
118 UserToGroupTable::class,
119 $join,
120 ))
121 ->configureJoinType(Join::TYPE_LEFT)
122 )
123 ;
124
125 return $query;
126 }
127}
addPaginationFilter(int $offset, int $limit)
Definition Builder.php:76