ILIAS  release_8 Revision v8.24
class.ilMailAutoCompleteRecipientResult.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
25{
26 public const MODE_STOP_ON_MAX_ENTRIES = 1;
27 public const MODE_FETCH_ALL = 2;
28 public const MAX_RESULT_ENTRIES = 1000;
29 protected bool $allow_smtp;
30 protected int $user_id;
32 protected array $handled_recipients = [];
34 protected int $max_entries;
36 public array $result = [
37 'items' => [],
38 'hasMoreResults' => false
39 ];
40
41 public function __construct(int $mode)
42 {
43 global $DIC;
44
45 $this->allow_smtp = $DIC->rbac()->system()->checkAccess('smtp_mail', MAIL_SETTINGS_ID);
46 $this->user_id = $DIC->user()->getId();
47 $this->max_entries = ilSearchSettings::getInstance()->getAutoCompleteLength();
48
49 $this->initMode($mode);
50 }
51
55 protected function initMode(int $mode): void
56 {
57 if (!in_array($mode, [self::MODE_FETCH_ALL, self::MODE_STOP_ON_MAX_ENTRIES], true)) {
58 throw new InvalidArgumentException("Wrong mode passed!");
59 }
60 $this->mode = $mode;
61 }
62
63 public function isResultAddable(): bool
64 {
65 if (
66 $this->mode === self::MODE_STOP_ON_MAX_ENTRIES &&
67 $this->max_entries >= 0 && count($this->result['items']) >= $this->max_entries
68 ) {
69 return false;
70 }
71
72 if (
73 $this->mode === self::MODE_FETCH_ALL &&
74 count($this->result['items']) >= self::MAX_RESULT_ENTRIES
75 ) {
76 return false;
77 }
78
79 return true;
80 }
81
82 public function addResult(string $login, string $firstname, string $lastname): void
83 {
84 if ($login !== '' && !isset($this->handled_recipients[$login])) {
85 $recipient = [];
86 $recipient['value'] = $login;
87
88 $label = $login;
89 if ($firstname && $lastname) {
90 $label .= " [" . $firstname . ", " . $lastname . "]";
91 }
92 $recipient['label'] = $label;
93
94 $this->result['items'][] = $recipient;
95 $this->handled_recipients[$login] = 1;
96 }
97 }
98
102 public function getItems(): array
103 {
104 return $this->result;
105 }
106
107 public function numItems(): int
108 {
109 return count($this->result['items']);
110 }
111}
addResult(string $login, string $firstname, string $lastname)
const MAIL_SETTINGS_ID
Definition: constants.php:36
global $DIC
Definition: feed.php:28