1 <?php defined('SYSPATH') OR die('No direct access allowed.');
3 * API controller for managing and viewing results and categories
5 * @author Artem Daniliants <artem@daniliants.com>
6 * @copyright (c) 2010 Speed Freak team
7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
10 class Results_Controller extends Controller{
13 * Get categories list and output it as XML
16 public function categories(){
17 if (apiler::is_authorized()){
18 $view = new View('api/categories');
19 $cat = new Category_Model();
20 $view->categories=$cat->get_all();
24 apiler::not_authorized();
31 public function list_results($category, $limit, $show_unit=false){
32 $results = New Result_Model();
33 $cat = New Category_Model();
34 if ($cat->category_exists($category) AND apiler::is_authorized() AND isset($limit)){
35 $view = new View('api/results');
36 $view->results = $results->get_results($category, $limit);
37 $view->show_unit=$show_unit;
41 apiler::not_authorized();
45 * Submit results to selected category
47 * @param string $category Category to which results are submitted
49 public function update($category){
50 $cat = New Category_Model();
51 if ($cat->category_exists($category) AND apiler::is_authorized()){
52 $xml = apiler::get_xml();
53 $result = New Result_Model();
54 if ($result->insert($category,$_SERVER['PHP_AUTH_USER'], $xml['value'])){
59 header("HTTP/1.1 400 Bad Request");
60 echo "Invalid request";
65 header("HTTP/1.0 404 Not Found");
66 die('Category not found or not authorized');