<?php
\n
\n
\nclass Users_model extends CI_Model {
\n
\n        public function create_account($data) {
\n\t       $this->db->insert('users',$data);
\n        }
\n
\n        public function check_nickname($nickname)  {
\n        \treturn $this->db->where('nickname',$nickname)->get('users')->num_rows() == 0;
\n        }
\n
\n        public function check_email($email) {
\n        \treturn $this->db->where('email',$email)->get('users')->num_rows() == 0;
\n        }
\n
\n        public function get_torrents($limit,$offset) {
\n            return $this->db->select('torrents.id , torrents.state, torrents.age , torrents.comments_count , torrents.publish_date , torrents.name , torrents.category_slug , torrents.size , torrents.seed , torrents.leech , torrents.completed , users.nickname AS nickname , categories.id AS category_id , categories.name AS category')
\n                    ->from('torrents')
\n                    ->join('users','torrents.uploader = users.id')
\n                    ->where('uploader',$this->session->id)
\n                    ->join('categories','torrents.category = categories.id')
\n                    ->order_by('id','desc')
\n                    ->limit($limit,$offset)
\n                    ->get()
\n                    ->result();
\n        }
\n
\n        public function get_spe_userdata($where_value, $user_data, $where = 'id') 
\n        {
\n            return $this->db->select($user_data)->where($where, $where_value)->get('users')->row();
\n        } 
\n
\n        public function get_user_comments($userId, $limit = 15, $offset = 0)
\n\t    {
\n\t        return $this->db->select('comments.*, torrents.name AS torrent_name, torrents.id AS torrent_id')
\n\t            ->from('comments')
\n\t            ->where('comments.publisher', $userId)
\n\t            ->order_by('comments.id', 'desc')
\n                ->join('torrents','torrents.id = comments.guid')
\n\t            ->limit($limit, $offset)
\n\t            ->get()->result();
\n\t    }
\n
\n        public function get_profile_torrents($user_id,$limit,$offset) {
\n            return $this->db->select('torrents.id , torrents.state , torrents.age , torrents.comments_count , torrents.publish_date , torrents.name , torrents.category_slug , torrents.size , torrents.completed, torrents.seed ,torrents.leech , users.nickname AS nickname , categories.id AS category_id , categories.name AS category')
\n                    ->from('torrents')
\n                    ->join('users','torrents.uploader = users.id')
\n                    ->where('torrents.state', 0)
\n                    ->where('uploader',$user_id)
\n                    ->join('categories','torrents.category = categories.id')
\n                    ->order_by('id','desc')
\n                    ->limit($limit,$offset)
\n                    ->get()
\n                    ->result();
\n        }
\n
\n        public function get_full_profile_torrents($user_id,$limit,$offset) {
\n            return $this->db->select('torrents.id , torrents.correction_request, torrents.state , torrents.age , torrents.comments_count , torrents.publish_date , torrents.name , torrents.category_slug , torrents.size , torrents.completed, torrents.seed ,torrents.leech , users.nickname AS nickname , categories.id AS category_id , categories.name AS category')
\n                    ->from('torrents')
\n                    ->join('users','torrents.uploader = users.id')
\n                    ->where('uploader',$user_id)
\n                    ->join('categories','torrents.category = categories.id')
\n                    ->order_by('id','desc')
\n                    ->limit($limit,$offset)
\n                    ->get()
\n                    ->result();
\n        }
\n
\n
\n        public function is_user_exists($id,$pass) {
\n                return $this->db->select('pass')->where('nickname',$id)->get('users')->row()->pass == md5($pass);
\n        }
\n
\n        public function get_userdata($value,$column='id') {
\n                return $this->db->where($column,$value)->get('users')->row();
\n        } 
\n
\n        public function add_comment($guid,$comment,$date) {
\n                $this->db->insert('comments',array('ip' => $_SERVER['REMOTE_ADDR'], 'guid' => $guid , 'publish_date' => $date , 'publisher' => $this->session->id , 'comment' => $comment));
\n                return $this->db->insert_id();
\n        }
\n        
\n        public function get_usertracker_data() {
\n\t\t\treturn $this->db->select('torrent_pass,end_freeleech,download_multiplier,downloaded,uploaded,can_leech,view_disabled_announce')->where('user_id',$this->session->id)->get('xbt_users')->row();
\n        }
\n
\n        public function update_favourites($user_id,$favourites) {
\n            $this->db->where('id',$user_id)->set('favourites',$favourites)->update('users');
\n        }
\n
\n
\n}
\n