Skip to content

Commit

Permalink
Return proper range values.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrubinsk committed Oct 7, 2013
1 parent e85b4af commit 22b1a19
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions framework/ActiveSync/lib/Horde/ActiveSync/Request/Search.php
Expand Up @@ -103,7 +103,6 @@ protected function _handle()
'[%s] Handling SEARCH command.',
$this->_device->id));

$search_range = '0';
$search_status = self::SEARCH_STATUS_SUCCESS;
$store_status = self::STORE_STATUS_SUCCESS;

Expand Down Expand Up @@ -254,6 +253,13 @@ protected function _handle()
// Get search results from backend
$search_result = $this->_driver->getSearchResults($search_name, $search_query);

// @TODO: Remove for H6. Total should be returned from the search call,
// if it's not, do the best we can an use the count of results from
// this page.
if (empty($search_result['total'])) {
$search_result['total'] = count($search_result['rows']);
}

/* Send output */
$this->_encoder->startWBXML();
$this->_encoder->startTag(self::SEARCH_SEARCH);
Expand All @@ -270,7 +276,6 @@ protected function _handle()
$this->_encoder->endTag();

if (is_array($search_result['rows']) && !empty($search_result['rows'])) {
$search_total = count($search_result['rows']);
foreach ($search_result['rows'] as $u) {
switch (strtolower($search_name)) {
case 'documentlibrary':
Expand Down Expand Up @@ -353,12 +358,22 @@ protected function _handle()
}
}

if (!empty($search_query['search_range'])) {
$range = explode('-', $search_query['search_range']);
// If total results are less than max range,
// we have all results and must modify the returned range.
if ($search_result['total'] < ($range[1] + 1)) {
$search_range = $range[0] . '-' . ($search_result['total'] - 1);
} else {
$search_range = $search_query['search_range'];
}
}
$this->_encoder->startTag(self::SEARCH_RANGE);
$this->_encoder->content($search_range);
$this->_encoder->endTag();

$this->_encoder->startTag(self::SEARCH_TOTAL);
$this->_encoder->content($search_total);
$this->_encoder->content($search_result['total']);
$this->_encoder->endTag();
}

Expand Down Expand Up @@ -448,4 +463,4 @@ protected function _handleError(array $data)
$this->_encoder->endTag();
}

}
}

0 comments on commit 22b1a19

Please sign in to comment.