ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilMailAutoCompleteRecipientResult.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2014 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once 'Services/Search/classes/class.ilSearchSettings.php';
5
10{
12 const MODE_FETCH_ALL = 2;
13
14 const MAX_RESULT_ENTRIES = 1000;
15
16 protected $allow_smtp = null;
17 protected $user_id = null;
18 protected $handled_recipients = array();
20 protected $max_entries = null;
21 public $result = array();
22
26 public function __construct($mode)
27 {
28 global $DIC;
29
30 $this->allow_smtp = $DIC->rbac()->system()->checkAccess('smtp_mail', MAIL_SETTINGS_ID);
31 $this->user_id = $DIC->user()->getId();
32 $this->max_entries = ilSearchSettings::getInstance()->getAutoCompleteLength();
33
34 $this->result['items'] = array();
35 $this->result['hasMoreResults'] = false;
36
37 $this->initMode($mode);
38 }
39
44 protected function initMode($mode)
45 {
46 if (!in_array($mode, array(self::MODE_FETCH_ALL, self::MODE_STOP_ON_MAX_ENTRIES))) {
47 throw new InvalidArgumentException("Wrong mode passed!");
48 }
49 $this->mode = $mode;
50 }
51
55 public function isResultAddable()
56 {
57 if (
58 $this->mode == self::MODE_STOP_ON_MAX_ENTRIES &&
59 $this->max_entries >= 0 && count($this->result['items']) >= $this->max_entries
60 ) {
61 return false;
62 } elseif (
63 $this->mode == self::MODE_FETCH_ALL &&
64 count($this->result['items']) >= self::MAX_RESULT_ENTRIES
65 ) {
66 return false;
67 }
68 return true;
69 }
70
76 public function addResult($login, $firstname, $lastname)
77 {
78 if (!isset($this->handled_recipients[$login])) {
79 $recipient = array();
80 $recipient['value'] = $login;
81
82 $label = $login;
83 if ($firstname && $lastname) {
84 $label .= " [" . $firstname . ", " . $lastname . "]";
85 }
86 $recipient['label'] = $label;
87
88 $this->result['items'][] = $recipient;
89 $this->handled_recipients[$login] = 1;
90 }
91 }
92
96 public function getItems()
97 {
98 return $this->result;
99 }
100
104 public function numItems()
105 {
106 return (int) count($this->result['items']);
107 }
108}
An exception for terminatinating execution or to throw for unit testing.
global $DIC
Definition: saml.php:7