diff --git a/lib/api/search.php b/lib/api/search.php new file mode 100644 index 0000000..445743d --- /dev/null +++ b/lib/api/search.php @@ -0,0 +1,67 @@ + | + +--------------------------------------------------------------------------+ + | Author: Aleksander Machniak | + +--------------------------------------------------------------------------+ +*/ + +class kolab_api_search extends kolab_api +{ + protected $model = 'search'; + + public function run() + { + $this->initialize_handler(); + + $path = $this->input->path; + $method = $this->input->method; + $request_length = count($path); + + if ($request_length >= 1 && $method == 'POST') { + $this->api_search(); + } + + throw new kolab_api_exception(kolab_api_exception::NOT_FOUND); + } + + /** + * Search objects in specified folder + * + * This is the same as /folder//search, but here we + * operate on real folder names + */ + protected function api_search() + { + $search = $this->input->input('search'); + if (empty($search)) { + throw new kolab_api_exception(kolab_api_exception::INVALID_REQUEST, null, "Missing search criteria"); + } + + $folder = implode($this->backend->delimiter, $this->input->path); + $folder_uid = $this->backend->folder_name2uid($folder); + $type = $this->backend->folder_type($folder_uid); + $list = $this->backend->objects_list($folder_uid, $search); + $props = $this->input->get_list_arg('properties'); + $context = array('folder_uid' => $folder_uid); + + $this->output->send($list, $type . '-list', $context, $props); + } +}