ILIAS  trunk Revision v12.0_alpha-16-g3e876e53c80
SentMailsBasedProvider..php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
27{
29 private array $users_stack = [];
30
35 public function current(): array
36 {
37 if (\is_array($this->data) && !empty($this->data)) {
38 return [
39 'login' => $this->data['login'],
40 'firstname' => '',
41 'lastname' => '',
42 ];
43 }
44
45 if ($this->users_stack !== []) {
46 return [
47 'login' => array_shift($this->users_stack),
48 'firstname' => '',
49 'lastname' => '',
50 ];
51 }
52
53 throw new \OutOfBoundsException('No more users available');
54 }
55
56 public function key(): string
57 {
58 if (\is_array($this->data) && !empty($this->data)) {
59 return $this->data['login'];
60 }
61
62 if ($this->users_stack !== []) {
63 return $this->users_stack[0]['login'];
64 }
65
66 return '';
67 }
68
69 public function valid(): bool
70 {
71 $this->data = $this->db->fetchAssoc($this->res);
72 if (\is_array($this->data) &&
73 !empty($this->data) &&
74 (
75 strpos((string) $this->data['login'], ',') ||
76 strpos((string) $this->data['login'], ';')
77 )) {
78 $parts = array_filter(
79 array_map(
80 'trim',
81 preg_split('/[ ]*[;,][ ]*/', trim((string) $this->data['login']))
82 )
83 );
84
85 foreach ($parts as $part) {
86 if (\ilStr::strPos(\ilStr::strToLower($part), \ilStr::strToLower($this->term), 0) !== false) {
87 $this->users_stack[] = $part;
88 }
89 }
90
91 if ($this->users_stack) {
92 $this->data = null;
93 }
94 }
95
96 return (\is_array($this->data) && !empty($this->data)) || $this->users_stack !== [];
97 }
98
99 public function rewind(): void
100 {
101 if ($this->res !== null) {
102 $this->db->free($this->res);
103 $this->res = null;
104 }
105
106 $query = '
107 SELECT DISTINCT
108 mail.rcp_to login
109 FROM mail
110 WHERE ' . $this->db->like('mail.rcp_to', 'text', $this->quoted_term) . "
111 AND mail.rcp_to IS NOT NULL AND mail.rcp_to != ''
112 AND sender_id = " . $this->db->quote($this->user_id, 'integer') . '
113 AND mail.sender_id = mail.user_id';
114
115 $this->res = $this->db->query($query);
116 }
117}
@phpstan-type AutoCompleteUserRecord array{login?: string, firstname?: string, lastname?...
@phpstan-import-type AutoCompleteUserRecord from RecipientSearchProvider
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