X-Git-Url: http://git.maemo.org/git/?p=speedfreak;a=blobdiff_plain;f=Server%2Fapplication%2Fcontrollers%2Fapi.php;h=fe8a5f7cb6107c19580d5e60d77f41a87f818739;hp=e40b263c3efbef072dec3d0decc07f382a371696;hb=1114c341c18ca536973fe5d0e2492a7413377024;hpb=bd1316d1ef9a1cf5224d452824e5d5af19a02dd7 diff --git a/Server/application/controllers/api.php b/Server/application/controllers/api.php index e40b263..fe8a5f7 100644 --- a/Server/application/controllers/api.php +++ b/Server/application/controllers/api.php @@ -95,12 +95,56 @@ class Api_Controller extends Controller{ */ public function categories(){ if ($this->is_authorized()){ - $xml = new View('api/categories'); + $view = new View('api/categories'); $cat = new Category_Model(); - $xml->categories=$cat->get_all(); - $xml->render(true); + $view->categories=$cat->get_all(); + $view->render(true); } else $this->not_authorized(); } + + /* + * Get results + * + */ + public function results($category, $limit, $show_unit=false){ + $results = New Result_Model(); + $cat = New Category_Model(); + if ($cat->category_exists($category) AND $this->is_authorized() AND isset($limit)){ + $view = new View('api/results'); + $view->results = $results->get_results($category, $limit); + $view->show_unit=$show_unit; + $view->render(true); + } + else + $this->not_authorized(); + } + + /* + * Submit results to selected category + * + * @param string $category Category to which results are submitted + */ + public function update($category){ + $cat = New Category_Model(); + if ($cat->category_exists($category) AND $this->is_authorized()){ + $xml = $this->get_xml(); + $result = New Result_Model(); + if ($result->insert($category,$_SERVER['PHP_AUTH_USER'], $xml['value'])){ + print "OK"; + die; + } + else { + header("HTTP/1.1 400 Bad Request"); + echo "Invalid request"; + die; + } + } + else { + header("HTTP/1.0 404 Not Found"); + die('Category not found or not authorized'); + } + + } } \ No newline at end of file