X-Git-Url: http://git.maemo.org/git/?p=speedfreak;a=blobdiff_plain;f=Server%2Fapplication%2Fcontrollers%2Fapi.php;h=0b95e411b0650d08a5c8abf2d36f3c7a5fb8602e;hp=e40b263c3efbef072dec3d0decc07f382a371696;hb=604af45b2b4093b01dc7669a51d9fd67a4c43ad7;hpb=bd1316d1ef9a1cf5224d452824e5d5af19a02dd7 diff --git a/Server/application/controllers/api.php b/Server/application/controllers/api.php index e40b263..0b95e41 100644 --- a/Server/application/controllers/api.php +++ b/Server/application/controllers/api.php @@ -95,12 +95,55 @@ 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){ + $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->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