From: Gunnar Wrobel Date: Mon, 22 Jun 2009 18:34:49 +0000 (+0200) Subject: Improve the search: X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=e466d37fd794ddc8af5306468c7e0456aeec6a69;p=horde.git Improve the search: - Allow a sizelimit parameter and indicate if the search result exceeded this limit - Disallow an empty search form - Use the find() method of the server class. --- diff --git a/koward/lib/Koward/Form/Search.php b/koward/lib/Koward/Form/Search.php index 70220f622..049cd8ab3 100644 --- a/koward/lib/Koward/Form/Search.php +++ b/koward/lib/Koward/Form/Search.php @@ -82,19 +82,31 @@ class Koward_Form_Search extends Horde_Form { if (isset($info['object'])) { $search_criteria = array(); foreach ($info['object'] as $key => $value) { - if (!empty($value)) { + if ($value != '' && $value !== null) { $search_criteria[] = array('field' => $key, 'op' => 'contains', 'test' => $value); } } + if (empty($search_criteria)) { + throw new Koward_Exception('Provide at least a single search parameter!'); + } $search_criteria = array('AND' => $search_criteria); $criteria = array('AND' => array($search_criteria, $this->koward->search['criteria'])); - $filter = $this->koward->getServer()->searchQuery($criteria); $params = array('scope' => 'sub', 'attributes' => array_merge(array('dn'), $attributes)); - return $this->koward->getServer()->search($filter, $params); + if (!empty($this->koward->conf['koward']['search']['sizelimit'])) { + $params['sizelimit'] = $this->koward->conf['koward']['search']['sizelimit']; + } + $server = &$this->koward->getServer(); + $result = $server->find($criteria, $params); + if (!empty($server->lastSearch) + && method_exists($server->lastSearch, 'sizeLimitExceeded') + && $server->lastSearch->sizeLimitExceeded()) { + $this->koward->notification->push(sprintf(_("More than the maximal allowed amount of %s elements were found. The list of results has been shortened."), $this->koward->conf['koward']['search']['sizelimit'], 'horde.message')); + } + return $result; } } }