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