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