Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
Provider.php
1<?php
2
4
9
10final class Provider
11{
12 private const DEFAULT_LOAD_LIMIT = 25;
13
14 private int $offset = 0;
15 private Builder $builder;
16
17 public function __construct(private int $userId, private string $mode = Dictionary::FILTER_MODES['all'])
18 {
19 $this->builder = new Builder($this->userId);
20 }
21
22 public function setMode(string $mode): self
23 {
24 $this->mode = $mode;
25
26 return $this;
27 }
28
29 public function setOffset(int $offset): self
30 {
31 $this->offset = $offset;
32
33 return $this;
34 }
35
36 public function getSpaces(): Result
37 {
38 $result = new Result();
39 $limit = self::DEFAULT_LOAD_LIMIT;
40 $queryBuilder =
41 (new QueryBuilder($this->userId))
42 ->addModeFilter($this->mode)
43 ->addPaginationFilter($this->offset, $limit)
44 ;
45
46 $query = $queryBuilder->build();
47
48 $queryResult = $query->exec()->fetchAll();
49
50 $spaces = $this->builder->buildSpacesFromQueryResult($queryResult);
51 $result->setData([
52 'spaces' => $spaces,
53 'hasMoreSpacesToLoad' => count($spaces) === $limit,
54 ]);
55
56 return $result;
57 }
58
59 public function searchSpacesByName(string $searchString): Result
60 {
61 $result = new Result();
62 $limit = self::DEFAULT_LOAD_LIMIT;
63 $queryBuilder =
64 (new QueryBuilder($this->userId))
65 ->addModeFilter($this->mode)
66 ->addPaginationFilter($this->offset, $limit)
67 ->addNameSearchFilter($searchString)
68 ;
69
70 $query = $queryBuilder->build();
71
72 $queryResult = $query->exec()->fetchAll();
73
74 $spaces = $this->builder->buildSpacesFromQueryResult($queryResult);
75 $result->setData([
76 'spaces' => $spaces,
77 'hasMoreSpacesToLoad' => count($spaces) === $limit,
78 ]);
79
80 return $result;
81 }
82
83 public function getSpaceById(int $spaceId): ?Space
84 {
85 $query =
86 (new QueryBuilder($this->userId))
87 ->addModeFilter($this->mode)
88 ->addSpaceIdFilter($spaceId)
89 ->build()
90 ;
91
92 $queryResult = $query->exec()->fetchAll();
93
94 $spaces = $this->builder->buildSpacesFromQueryResult($queryResult);
95
96 return $spaces[0] ?? null;
97 }
98
100 public function getSpacesByIds(array $spaceIds): array
101 {
102 $query =
103 (new QueryBuilder($this->userId))
104 ->addModeFilter($this->mode)
105 ->addSpaceIdListFilter($spaceIds)
106 ->addPaginationFilter(0, count($spaceIds))
107 ->build()
108 ;
109
110 $queryResult = $query->exec()->fetchAll();
111
112 return $this->builder->buildSpacesFromQueryResult($queryResult);
113 }
114
115 public function getCommonSpace(): Space
116 {
117 return $this->builder->buildCommonSpace();
118 }
119}
searchSpacesByName(string $searchString)
Definition Provider.php:59
__construct(private int $userId, private string $mode=Dictionary::FILTER_MODES['all'])
Definition Provider.php:17