ILIAS  release_8 Revision v8.24
class.ilMailAutoCompleteSentMailsRecipientsProvider.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
25{
27 private array $users_stack = [];
28
33 public function current(): array
34 {
35 if (is_array($this->data) && !empty($this->data)) {
36 return [
37 'login' => $this->data['login'],
38 'firstname' => '',
39 'lastname' => '',
40 ];
41 }
42
43 if ($this->users_stack !== []) {
44 return [
45 'login' => array_shift($this->users_stack),
46 'firstname' => '',
47 'lastname' => '',
48 ];
49 }
50
51 throw new OutOfBoundsException('No more users available');
52 }
53
54 public function key(): string
55 {
56 if (is_array($this->data) && !empty($this->data)) {
57 return $this->data['login'];
58 }
59
60 if ($this->users_stack !== []) {
61 return $this->users_stack[0]['login'];
62 }
63
64 return '';
65 }
66
67 public function valid(): bool
68 {
69 $this->data = $this->db->fetchAssoc($this->res);
70 if (is_array($this->data) &&
71 !empty($this->data) &&
72 (
73 strpos($this->data['login'], ',') ||
74 strpos($this->data['login'], ';')
75 )) {
76 $parts = array_filter(
77 array_map(
78 'trim',
79 preg_split("/[ ]*[;,][ ]*/", trim($this->data['login']))
80 )
81 );
82
83 foreach ($parts as $part) {
84 if (ilStr::strPos(ilStr::strToLower($part), ilStr::strToLower($this->term)) !== false) {
85 $this->users_stack[] = $part;
86 }
87 }
88
89 if ($this->users_stack) {
90 $this->data = null;
91 }
92 }
93
94 return (is_array($this->data) && !empty($this->data)) || $this->users_stack !== [];
95 }
96
97 public function rewind(): void
98 {
99 if ($this->res) {
100 $this->db->free($this->res);
101 $this->res = null;
102 }
103
104 $query = "
105 SELECT DISTINCT
106 mail.rcp_to login
107 FROM mail
108 WHERE " . $this->db->like('mail.rcp_to', 'text', $this->quoted_term) . "
109 AND mail.rcp_to IS NOT NULL AND mail.rcp_to != ''
110 AND sender_id = " . $this->db->quote($this->user_id, 'integer') . "
111 AND mail.sender_id = mail.user_id";
112
113 $this->res = $this->db->query($query);
114 }
115}
static strPos(string $a_haystack, string $a_needle, ?int $a_offset=null)
Definition: class.ilStr.php:42
static strToLower(string $a_string)
Definition: class.ilStr.php:72
if($clientAssertionType !='urn:ietf:params:oauth:client-assertion-type:jwt-bearer'|| $grantType !='client_credentials') $parts
Definition: ltitoken.php:64
$query