1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
CollabQueryBuilder.php
См. документацию.
1<?php
2
3declare(strict_types=1);
4
5namespace Bitrix\Socialnetwork\Collab\Provider;
6
7use Bitrix\Main\Entity\ReferenceField;
8use Bitrix\Main\ORM\Query\Join;
9use Bitrix\Main\ORM\Query\Query;
10use Bitrix\Socialnetwork\UserToGroupTable;
11use Bitrix\Socialnetwork\WorkgroupTable;
12
14{
16 protected Query $ormQuery;
17
18 public static function build(CollabQuery $collabQuery): Query
19 {
20 return (new static($collabQuery))
21 ->buildSelect()
22 ->buildWhere()
23 ->buildGroup()
24 ->buildOrder()
25 ->buildNavigation()
26 ->buildAccess()
27 ->getOrmQuery();
28 }
29
30 private function __construct(CollabQuery $collabQuery)
31 {
32 $this->collabQuery = $collabQuery;
33
34 $this->init();
35 }
36
37 protected function buildSelect(): static
38 {
39 $this->ormQuery->setDistinct($this->collabQuery->getDistinct());
40 $this->ormQuery->setSelect($this->collabQuery->getSelect());
41
42 return $this;
43 }
44
45 protected function buildWhere(): static
46 {
47 if ($this->collabQuery->getWhere() !== null)
48 {
49 $this->ormQuery->where($this->collabQuery->getWhere());
50 }
51
52 return $this;
53 }
54
55 protected function buildOrder(): static
56 {
57 $order = $this->collabQuery->getOrder();
58 if (!empty($order))
59 {
60 $this->ormQuery->setOrder($order);
61 }
62
63 return $this;
64 }
65
66 protected function buildGroup(): static
67 {
68 $group = $this->collabQuery->getGroup();
69 if (!empty($group))
70 {
71 $this->ormQuery->setGroup($group);
72 }
73
74 return $this;
75 }
76
77 protected function buildNavigation(): static
78 {
79 $limit = $this->collabQuery->getLimit();
80 if ($limit > 0)
81 {
82 $this->ormQuery->setLimit($limit);
83 }
84
85 $offset = $this->collabQuery->getOffset();
86 if ($offset > 0)
87 {
88 $this->ormQuery->setOffset($offset);
89 }
90
91
92 return $this;
93 }
94
95 protected function buildAccess(): static
96 {
97 if (!$this->collabQuery->getAccessCheck())
98 {
99 return $this;
100 }
101
102 $memberField = new ReferenceField(
103 'MEMBERS',
104 UserToGroupTable::getEntity(),
105 Join::on('this.ID', 'ref.GROUP_ID')
106 ->where('ref.USER_ID', $this->collabQuery->getUserId())
107 ->whereIn('ref.ROLE', UserToGroupTable::getRolesMember()),
108 );
109
110 $this->ormQuery->registerRuntimeField($memberField);
111
112 $conditions = Query::filter();
113
114 $openGroupsCondition = Query::filter()->where('VISIBLE', 'Y');
115
116 $memberCondition = Query::filter()->whereNotNull('MEMBERS.USER_ID');
117
118 $conditions
119 ->logic('or')
120 ->where($openGroupsCondition)
121 ->where($memberCondition);
122
123 $this->ormQuery->where($conditions);
124
125 return $this;
126 }
127
128 protected function getOrmQuery(): Query
129 {
130 return $this->ormQuery;
131 }
132
133 protected function init(): void
134 {
135 $this->ormQuery = WorkgroupTable::query();
136 }
137}
static build(CollabQuery $collabQuery)
Определения CollabQueryBuilder.php:18
Определения chain.php:3
$order
Определения payment.php:8