| | |
| | | <?php |
| | | |
| | | /* |
| | | /** |
| | | +-----------------------------------------------------------------------+ |
| | | | This file is part of the Roundcube Webmail client | |
| | | | Copyright (C) 2005-2011, The Roundcube Dev Team | |
| | |
| | | */ |
| | | class rcube_result_multifolder |
| | | { |
| | | public $multi = true; |
| | | public $sets = array(); |
| | | public $multi = true; |
| | | public $sets = array(); |
| | | public $incomplete = false; |
| | | public $folder; |
| | | |
| | | protected $meta = array(); |
| | | protected $index = array(); |
| | | protected $meta = array(); |
| | | protected $index = array(); |
| | | protected $folders = array(); |
| | | protected $order = 'ASC'; |
| | | protected $sorting; |
| | | protected $order = 'ASC'; |
| | | |
| | | |
| | | /** |
| | |
| | | public function __construct($folders = array()) |
| | | { |
| | | $this->folders = $folders; |
| | | $this->meta = array('count' => 0); |
| | | $this->meta = array('count' => 0); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Initializes object with SORT command response |
| | |
| | | { |
| | | $this->sets[] = $result; |
| | | |
| | | if ($count = $result->count()) { |
| | | $this->meta['count'] += $count; |
| | | |
| | | // append UIDs to global index |
| | | $folder = $result->get_parameters('MAILBOX'); |
| | | $index = array_map(function($uid) use ($folder) { return $uid . '-' . $folder; }, $result->get()); |
| | | $this->index = array_merge($this->index, $index); |
| | | if ($result->count()) { |
| | | $this->append_result($result); |
| | | } |
| | | else if ($result->incomplete) { |
| | | $this->incomplete = true; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Append message UIDs from the given result to our index |
| | | */ |
| | | protected function append_result($result) |
| | | { |
| | | $this->meta['count'] += $result->count(); |
| | | |
| | | // append UIDs to global index |
| | | $folder = $result->get_parameters('MAILBOX'); |
| | | $index = array_map(function($uid) use ($folder) { return $uid . '-' . $folder; }, $result->get()); |
| | | |
| | | $this->index = array_merge($this->index, $index); |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | $this->sorting = $sort_field; |
| | | $this->order = $sort_order; |
| | | $this->order = $sort_order; |
| | | } |
| | | |
| | | /** |
| | |
| | | return false; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Checks if the result is empty |
| | | * |
| | |
| | | { |
| | | return empty($this->sets) || $this->meta['count'] == 0; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Returns number of elements in the result |
| | |
| | | return $this->meta['count']; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Returns number of elements in the result. |
| | | * Alias for count() for compatibility with rcube_result_thread |
| | |
| | | { |
| | | return $this->count(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Reverts order of elements in the result |
| | |
| | | if ($this->order != $set->get_parameters('ORDER')) { |
| | | $set->revert(); |
| | | } |
| | | |
| | | $folder = $set->get_parameters('MAILBOX'); |
| | | $index = array_map(function($uid) use ($folder) { return $uid . '-' . $folder; }, $set->get()); |
| | | $index = array_map(function($uid) use ($folder) { return $uid . '-' . $folder; }, $set->get()); |
| | | |
| | | $this->index = array_merge($this->index, $index); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Check if the given message ID exists in the object |
| | |
| | | if (!empty($this->folder)) { |
| | | $msgid .= '-' . $this->folder; |
| | | } |
| | | |
| | | return array_search($msgid, $this->index); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Filters data set. Removes elements listed in $ids list. |
| | |
| | | if ($set->get_parameters('MAILBOX') == $folder) { |
| | | $set->filter($ids); |
| | | } |
| | | |
| | | $this->meta['count'] += $set->count(); |
| | | } |
| | | } |
| | |
| | | return $this->index; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Return all messages in the result. |
| | | * |
| | |
| | | { |
| | | return ''; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Return result element at specified index |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Returns response parameters, e.g. ESEARCH's MIN/MAX/COUNT/ALL/MODSEQ |
| | | * or internal data e.g. MAILBOX, ORDER |
| | |
| | | public function get_parameters($param=null) |
| | | { |
| | | $params = array( |
| | | 'SORT' => $this->sorting, |
| | | 'ORDER' => $this->order, |
| | | 'SORT' => $this->sorting, |
| | | 'ORDER' => $this->order, |
| | | 'MAILBOX' => $this->folders, |
| | | ); |
| | | |
| | |
| | | $this->meta = array('count' => 0); |
| | | |
| | | foreach ($this->sets as $result) { |
| | | if ($count = $result->count()) { |
| | | $this->meta['count'] += $count; |
| | | |
| | | // append UIDs to global index |
| | | $folder = $result->get_parameters('MAILBOX'); |
| | | $index = array_map(function($uid) use ($folder) { return $uid . '-' . $folder; }, $result->get()); |
| | | $this->index = array_merge($this->index, $index); |
| | | if ($result->count()) { |
| | | $this->append_result($result); |
| | | } |
| | | else if ($result->incomplete) { |
| | | $this->incomplete = true; |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |