Merge branch 'package'
[speedfreak] / Server / application / models / category.php
1 <?php defined('SYSPATH') or die('No direct script access.');
2 /*
3  * Categories model for creating and manipulating categories
4  *
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
8  */
9
10 class Category_Model extends Model {
11
12     public function __construct(){
13
14         // load database library into $this->db
15         parent::__construct();
16     }
17
18     /*
19      * Fetch all categories
20      *
21      * @return object|bool Returns object containing results if everything is ok and false otherwise
22      */
23     public function get_all(){
24         $results = $this->db->query("SELECT slug,description,unit FROM categories");
25         if ($results->count()>0)
26             return $results;
27         else
28             return false;
29     }
30
31     /*
32      * Check if category exists
33      *
34      * @param string $category Category name (slug)
35      * @return bool True if exists and False otherwise
36      */
37     public function category_exists($category){
38         $results = $this->db->query("SELECT id FROM categories where slug = ?", $category);
39     if ($results->count()>0)
40             return true;
41         else
42             return false;
43     }
44
45     /*
46      * Get category id
47      *
48      * @param string $category Category name (slug)
49      * @return integer|bool Category id if successful or false
50      */
51     public function get_id($category){
52         $results = $this->db->query("SELECT id FROM categories where slug = ?", $category);
53     if ($results->count()>0)
54             return $results[0]->id;
55         else
56             return false;
57     }
58
59 }