Skip to content

Instantly share code, notes, and snippets.

@kamaulynder
Created June 5, 2014 07:05
Show Gist options
  • Save kamaulynder/37895844b454142be4af to your computer and use it in GitHub Desktop.
Save kamaulynder/37895844b454142be4af to your computer and use it in GitHub Desktop.
<?php defined('SYSPATH') OR die('No direct access allowed.');
/**
* Ushahidi API Stats Controller
*
* @author Ushahidi Team <[email protected]>
* @package Ushahidi\Application\Controllers
* @copyright 2013 Ushahidi
* @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3)
*/
class Controller_Api_Stats extends Ushahidi_Api {
/**
* @var string oauth2 scope required for access
*/
protected $_scope_required = 'stats';
/**
* Load resource object
*
* @return void
*/
protected function _resource()
{
parent::_resource();
$this->_resource = 'stats';
}
/**
* Get a count of tags,posts,sets,users
*
* GET /api/stats
*
* @return void
*/
public function action_get_index_collection()
{
//Count of all tags
$tags_query = ORM::factory('Tag')
->offset($this->_record_offset)
->limit($this->_record_limit);
$tags = $tags_query->find_all();
$tags_count = $tags->count();
//Count of all posts
$posts_query = ORM::factory('Post')
->offset($this->_record_offset)
->limit($this->_record_limit);
$posts = $posts_query->find_all();
$posts_count = $posts->count();
//Count of all users
$users_query = ORM::factory('User')
->offset($this->_record_offset)
->limit($this->_record_limit);
$users = $users_query->find_all();
$users_count = $users->count();
// Respond with count
$this->_response_payload = array(
'tags_count' => $tags_count,
'posts_count' => $posts_count,
'users_count' => $users_count
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment