Skip to content

Commit

Permalink
Fixing get total count
Browse files Browse the repository at this point in the history
  • Loading branch information
willdoran committed May 15, 2017
1 parent 508512d commit 15b0b5d
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions application/classes/Ushahidi/Repository/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ public function getSearchFields()
'center_point', 'within_km',
'published_to',
'include_types', 'include_attributes', // Specify values to include
'include_unmapped',
'group_by', 'group_by_tags', 'group_by_attribute_key', // Group results
'timeline', 'timeline_interval', 'timeline_attribute', // Timeline params
'has_location' //contains a location or not
Expand Down Expand Up @@ -514,20 +515,28 @@ public function getSearchTotal()
->select([DB::expr('COUNT(DISTINCT posts.id)'), 'total']);

// Fetch the result and...
$result = $query->execute($this->db);

$results = $query->execute($this->db);
Kohana::$log->add(Log::ERROR, print_r($results,true));
// ... return the total.
return (int) $result->get('total', 0);
$total = 0;
foreach ($results->as_array() as $result) {
$total += (int) $result['total'];
}

return $total;
}

public function getUnmappedTotal($total_posts)
{

Kohana::$log->add(Log::ERROR, print_r($total_posts,true));
$mapped = 0;
$raw_sql = "select count(distinct post_id) as 'total' from (select post_geometry.post_id from post_geometry union select post_point.post_id from post_point) as sub;";
if ($total_posts > 0) {

$mapped = DB::query(Database::SELECT, $raw_sql)->execute();
}
Kohana::$log->add(Log::ERROR, print_r((int) $mapped->get('total', 0),true));

return $total_posts - (int) $mapped->get('total', 0);
}
Expand Down Expand Up @@ -704,11 +713,10 @@ public function getGroupedTotals(SearchData $search)
$results = $this->search_query->execute($this->db);
$results = $results->as_array();

if ($search->has_location) {
if ($search->include_unmapped) {
// Append unmapped totals to stats
$results['unmapped'] = $this->getUnmappedTotal($this->getSearchTotal());
}

// ... return them as an array
return $results;
}
Expand Down

0 comments on commit 15b0b5d

Please sign in to comment.