1 <?php defined('SYSPATH') or die('No direct script access.');
3 * Results model for creating and manipulating results
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 Result_Model extends Model {
12 public function __construct(){
14 // load database library into $this->db
15 parent::__construct();
21 * @param string $category From which category should we get results
22 * @param integer $limit How many results to return
23 * @return object|bool Returns object containing results if everything is ok and false otherwise
25 public function get_results($category, $limit=10){
26 $results = $this->db->query("SELECT u.username as username, c.unit as unit, r.value as value, r.result_date as result_date, c.slug as slug FROM users u, results r, categories c WHERE r.user_id=u.id AND c.slug = ? AND r.cat_id=c.id ORDER BY r.value ASC LIMIT ".(int)$limit, $category);
27 if ($results->count()>0)
36 * @param string $category Category name (slug)
37 * @return bool True if exists and False otherwise
39 public function insert($category, $username, $value){
40 $cat = New Category_Model();
41 $category = $cat->get_id($category);
42 $user = New User_Model();
43 $username = $user->get_id($username);
44 $results = $this->db->query("INSERT INTO results SET cat_id = ?, user_id = ?, value = ?, result_date = NOW()", $category, $username, $value);