ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 {
32 global $ilUser, $rbacsystem;
33
34 $this->allow_smtp = $rbacsystem->checkAccess('smtp_mail', MAIL_SETTINGS_ID);
35 $this->user_id = $ilUser->getId();
36 $this->max_entries = ilSearchSettings::getInstance()->getAutoCompleteLength();
37
38 $this->result['items'] = array();
39 $this->result['hasMoreResults'] = false;
40
41 $this->initMode($mode);
42 }
43
48 protected function initMode($mode)
49 {
50 if(!in_array($mode, array(self::MODE_FETCH_ALL, self::MODE_STOP_ON_MAX_ENTRIES)))
51 {
52 throw new InvalidArgumentException("Wrong mode passed!");
53 }
54 $this->mode = $mode;
55 }
56
60 public function isResultAddable()
61 {
62 if(
63 $this->mode == self::MODE_STOP_ON_MAX_ENTRIES &&
64 $this->max_entries >= 0 && count($this->result['items']) >= $this->max_entries
65 )
66 {
67 return false;
68 }
69 else if(
70 $this->mode == self::MODE_FETCH_ALL &&
71 count($this->result['items']) >= self::MAX_RESULT_ENTRIES
72 )
73 {
74 return false;
75 }
76 return true;
77 }
78
84 public function addResult($login, $firstname, $lastname)
85 {
86 if(!isset($this->handled_recipients[$login]))
87 {
88 $recipient = array();
89 $recipient['value'] = $login;
90
91 $label = $login;
92 if($firstname && $lastname)
93 {
94 $label .= " [" . $firstname . ", " . $lastname . "]";
95 }
96 $recipient['label'] = $label;
97
98 $this->result['items'][] = $recipient;
99 $this->handled_recipients[$login] = 1;
100 }
101 }
102
106 public function getItems()
107 {
108 return $this->result;
109 }
110
114 public function numItems()
115 {
116 return (int)count($this->result['items']);
117 }
118}
global $ilUser
Definition: imgupload.php:15