-
-
Notifications
You must be signed in to change notification settings - Fork 153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Query does not works with array of search criterias #104
Comments
Loos like the where method just return the first instead to push it to the array. So, as a quick solution I did my own function to increment wheres: public function addWhere(object $query, array $search): object
{
foreach ($search as $k => $v) {
if (is_array($v)) {
$query = $this->addWhere($query, $v);
} else if (is_numeric($k)) {
$query->where($v);
} else {
$query->where([$k => $v]);
}
}
return $query;
}
// Usage
$query = $this->addWhere($folder->query(), [['subject' => 'foo'], ['UNSEEN']]); Maybe this logic can be imported to the where method itself in the future. ;) |
Hi @EthraZa , php-imap/src/Query/WhereQuery.php Lines 126 to 146 in 23c80eb
public function where($criteria, $value = null) {
if (is_array($criteria)) {
foreach ($criteria as $key => $value) {
if (is_numeric($key)) {
$this->where($value);
}
$this->where($key, $value);
}
} else {
$criteria = $this->validate_criteria($criteria);
$value = $this->parse_value($value);
if ($value === null || $value === '') {
$this->query->push([$criteria]);
} else {
$this->query->push([$criteria, $value]);
}
}
return $this;
} I believe this would work as well and would allow multiple search criteria as long as the provider accepts them: $query = $folder->query()->where([['subject' => 'foo'], ['UNSEEN']]); Best regards, Update 2021-11-04: |
Hi @EthraZa , Best regards, |
Array of multiple search criteria is not working, just the first one works.
Looking the docs at Custom search criteria, since it uses an array of arrays, I came to the conclusion that multiple search criterias shoud work but, it may be not true. Yet, it would be cool if it works.
The text was updated successfully, but these errors were encountered: