ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
MailFolderSearch.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\Mail\Folder;
22
29
36{
41 private ?array $filtered_ids = null;
42 private ?int $count = null;
43 private ?int $unread = null;
44
45 public function __construct(
46 private readonly MailFolderData $folder,
47 private readonly MailFilterData $filter,
48 private readonly bool $lucene_enabled,
49 ) {
50 $this->mailbox_query = (new MailBoxQuery(
51 $this->folder->getUserId()
52 ))
53 ->withFolderId($this->folder->getFolderId())
54 ->withSender($this->filter->getSender())
55 ->withRecipients($this->filter->getRecipients())
56 ->withSubject($this->filter->getSubject())
57 ->withBody($this->filter->getBody())
58 ->withPeriodStart($this->filter->getPeriodStart())
59 ->withPeriodEnd($this->filter->getPeriodEnd())
60 ->withIsUnread($this->filter->isUnread())
61 ->withIsSystem($this->filter->isSystem())
62 ->withHasAttachment($this->filter->hasAttachment());
63
64 if ($this->lucene_enabled && (
65 ($this->filter->getSender() ?? '') !== '' ||
66 ($this->filter->getRecipients() ?? '') !== '' ||
67 ($this->filter->getSubject() ?? '') !== '' ||
68 ($this->filter->getBody() ?? '') !== '' ||
69 ($this->filter->getAttachment() ?? '') !== ''
70 )) {
71 $query_parser = new ilMailLuceneQueryParser('');
72 $query_parser->setFields([
73 'title' => $this->filter->getSubject(),
74 'content' => $this->filter->getBody(),
75 'mattachment' => $this->filter->getAttachment(), // only possible with lucene
76 'msender' => $this->filter->getSender(),
77 ]);
78 $query_parser->parse();
79
80 // lucene search wil be done and cached by getFilteredIds
81 $this->lucene_result = new ilMailSearchResult();
82 $this->lucene_searcher = new ilMailLuceneSearcher($query_parser, $this->lucene_result);
83 }
84 }
85
89 public function getCount(): int
90 {
91 if ($this->count === null) {
92 $this->count = $this->mailbox_query->withFilteredIds($this->getFilteredIds())->count();
93 }
94
95 return $this->count;
96 }
97
101 public function getUnread(): int
102 {
103 if ($this->unread === null) {
104 $this->unread = $this->mailbox_query->withFilteredIds($this->getFilteredIds())->countUnread();
105 }
106
107 return $this->unread;
108 }
109
114 public function getMaiIds(): array
115 {
116 return $this->mailbox_query
117 ->withFilteredIds($this->getFilteredIds())
118 ->queryMailIds();
119 }
120
125 public function getRecords(): array
126 {
127 return $this->mailbox_query
128 ->withFilteredIds($this->getFilteredIds())
129 ->query(true);
130 }
131
136 public function getPagedRecords(
137 int $limit,
138 int $offset,
139 ?MailBoxOrderColumn $order_column,
140 ?string $order_direction
141 ): array {
142 return $this->mailbox_query
143 ->withFilteredIds($this->getFilteredIds())
144 ->withLimit($limit)
145 ->withOffset($offset)
146 ->withOrderColumn($order_column)
147 ->withOrderDirection($order_direction)
148 ->query(true);
149 }
150
156 private function getFilteredIds(): ?array
157 {
158 if ($this->filtered_ids === null &&
159 $this->lucene_result !== null &&
160 $this->lucene_searcher !== null) {
161 $this->lucene_searcher->search($this->folder->getUserId(), $this->folder->getFolderId());
162 $this->filtered_ids = $this->lucene_result->getIds();
163 }
164
165 return $this->filtered_ids;
166 }
167
172 public function forMailIds(array $ids): self
173 {
174 $clone = clone $this;
175 $clone->filtered_ids = $ids;
176 return $clone;
177 }
178}
Filter data for display of mail records Properties with null value will not be applied as a filter.
__construct(private readonly MailFolderData $folder, private readonly MailFilterData $filter, private readonly bool $lucene_enabled,)
getMaiIds()
Get the ids of all filtered mails.
forMailIds(array $ids)
Inject already filtered mail ids, e.g.
getFilteredIds()
Get the cached mail ids from a lucene search for selected filter criteria These will be used as addit...
getUnread()
Get a cached count of unread mails for the filter criteria.
getCount()
Get a cached count of mails for the filter criteria.
getRecords()
Get record objects of all filtered mails.
getPagedRecords(int $limit, int $offset, ?MailBoxOrderColumn $order_column, ?string $order_direction)
Get record objects of filtered and paged mails.
return true
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
filter(string $filter_id, $class_path, string $cmd, bool $activated=true, bool $expanded=true)