<?php
defined('SYSPATH') or die('No direct script access.');


class Model_User extends Kohana_Model {
	
	/**
	* add an comment to the database
	* @return int - comment id
	*/
	public function add($param) {
		
		$query_str = "INSERT INTO users (fb_user_id, first_name, last_name, avatar, profile_url) VALUES('";
		$query_str .= $param['fb_user_id'];
		$query_str .= "', ";
		$query_str .= $this->_db->escape($param['first_name']);
		$query_str .= " , ";
		$query_str .= $this->_db->escape($param['last_name']);
		$query_str .= " ,'";
		$query_str .= $param['avatar'];
		$query_str .= "' ,'";
		$query_str .= $param['profile_url'];
		$query_str .= "') ;";
			
		$result = $this->_db->query(Database::INSERT, $query_str, FALSE);
		
		return $result[0]; 
	} // end of add 
	 
	 
	/**
	* get comment(s) from the database
	* @return ARRAY
	*/
	public function get($param) { 
		$query_str = "SELECT * FROM users WHERE 1 ";
		
		if(!empty( $param['id'] )) {
			$query_str .= " AND id='" . $param['id'] . "' ";
		}
		
		if(!empty( $param['fb_user_id'] )) {
			$query_str .= " AND fb_user_id='" . $param['fb_user_id'] . "' ";
		}
		
		if(!empty( $param['order_by'] )) {
			$query_str .= " ORDER BY " . $param['order_by'];
		}
	
		if(!empty( $param['limit'] )) {
			$query_str .= " LIMIT " . $param['limit'];
		}

		return $this->_db->query(Database::SELECT, $query_str, FALSE)->as_array();
	} // end of get  
	
		
	/**
	* delete an comment's information
	* @return BOOLEAN
	*/
	public function delete($param) {
	
	} // end of delete	 
 } // end of comments 
