1 <?php defined('SYSPATH') or die('No direct script access.');
3 * Categories model for creating and manipulating 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 Category_Model extends Model {
12 public function __construct(){
14 // load database library into $this->db
15 parent::__construct();
19 * Fetch all categories
21 * @return object|bool Returns object containing results if everything is ok and false otherwise
23 public function get_all(){
24 $results = $this->db->query("SELECT slug,description,unit FROM categories");
25 if ($results->count()>0)
32 * Check if category exists
34 * @param string $category Category name (slug)
35 * @return bool True if exists and False otherwise
37 public function category_exists($category){
38 $results = $this->db->query("SELECT id FROM categories where slug = ?", $category);
39 if ($results->count()>0)
48 * @param string $category Category name (slug)
49 * @return integer|bool Category id if successful or false
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;