Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
RecentSearchManager.php
1<?php
3
7
9{
10 private const CONTEXT = 'SOCIALNETWORK_SPACE_LIST';
11 private const ENTITY_ID = 'socnet-space';
12 private const LOAD_LIMIT = 40;
13
14 public function __construct(private int $userId)
15 {}
16
17 public function addSpaceToRecentSearch(int $spaceId): void
18 {
20 'USER_ID' => $this->userId,
21 'CONTEXT' => self::CONTEXT,
22 'ENTITY_ID' => self::ENTITY_ID,
23 'ITEM_ID' => $spaceId,
24 ]);
25 }
26
28 {
29 $result = new SpaceSearchDataCollection();
30
31 $queryResult = EntityUsageTable::query()
32 ->setSelect(['ITEM_ID', 'LAST_USE_DATE'])
33 ->where('USER_ID', $this->userId)
34 ->where('CONTEXT', self::CONTEXT)
35 ->where('ENTITY_ID', self::ENTITY_ID)
36 ->addOrder('LAST_USE_DATE', 'DESC')
37 ->setLimit(self::LOAD_LIMIT)
38 ->setDistinct()
39 ->fetchAll()
40 ;
41
42 foreach ($queryResult as $value)
43 {
44 try
45 {
46 $result->add(new SpaceSearchData((int)$value['ITEM_ID'], new DateTime($value['LAST_USE_DATE'])));
47 }
48 catch (ObjectException $exception) {}
49 }
50
51 return $result;
52 }
53}