<commit_before><?php
/**
 * Created by PhpStorm.
 * User: mustafahanif
 * Date: 2/13/16
 * Time: 9:40 PM
 */
class Influencer extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->load->library('rssparser');
        $this->load->library('user');
        $this->load->model('Rss_model');
        $this->load->model('Domain_model');
        $this->load->model('Influencer_model');
        $this->load->model('Viral_model');
        $this->load->library('opengraph');
        $this->load->library('breadcrumbs');
        $this->load->helper('url');
        $this->load->helper('date');
                  
    }

    public function index(){
        if (!$this->user->is_logged_in()){
            redirect('/landing');
        }
        $data = array();
        $data = $this->user->add_user_data('influencer');
        if(!(is_null($this->input->post('search'))))
             $data['content'] =$this->search();
        $data['header']='Earnings Details';
        $data['active'] ='';
        $this->load->view('influencer/index',$data);
    }

    public function payment_history($start_date = null, $end_date = null){
        if (!$this->user->is_logged_in()){
            redirect('/landing');
        }
        $data = array();
        $data = $this->user->add_user_data('influencer');
        if(!(is_null($this->input->post('search'))))
            $data['content'] =$this->search();

        $data['content'] = $this->load_payment_history($start_date,$end_date);

        $data['header']=' ';
        $data['active'] ='';


        $this->load->view('influencer/payment_history',$data);
    }

    private function load_payment_history($start_date,$end_date){
        $userid = $this->session->userdata('user_id');
        $this->db->order_by('date', 'DESC');
        if ($start_date != null && $end_date != null){
            $data['start_date'] = $start_date;
            $data['end_date'] = $end_date;
            $this->db->where('date >=', $start_date);
            $this->db->where('date <=', $end_date);
        }
        $result = $this->db->get_where('revenue_history',array('influencer_id' => $userid));
        $data['rows'] = $result->result();
        return $this->load->view('influencer/template/payment_history', $data, TRUE);
    }

    public function rss_done(){<commit_msg>Updated influencer controller<commit_after><?php
/**
 * Created by PhpStorm.
 * User: mustafahanif
 * Date: 2/13/16
 * Time: 9:40 PM
 */
class Influencer extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->load->library('rssparser');
        $this->load->library('user');
        $this->load->model('Rss_model');
        $this->load->model('Domain_model');
        $this->load->model('Influencer_model');
        $this->load->model('Viral_model');
        $this->load->library('opengraph');
        $this->load->library('breadcrumbs');
        $this->load->helper('url');
        $this->load->helper('date');
                  
    }

    public function index(){
        if (!$this->user->is_logged_in()){
            redirect('/landing');
        }
        $data = array();
        $data = $this->user->add_user_data('influencer');
        if(!(is_null($this->input->post('search'))))
             $data['content'] =$this->search();
        $data['header']='Earnings Details';
        $data['active'] ='';
        $this->load->view('influencer/index',$data);
    }

    public function payment_history($start_date = null, $end_date = null){
        if (!$this->user->is_logged_in()){
            redirect('/landing');
        }
        $data = array();
        $data = $this->user->add_user_data('influencer');
        if(!(is_null($this->input->post('search'))))
            $data['content'] =$this->search();

        $data['content'] = $this->load_payment_history($start_date,$end_date);

        $data['header']=' ';
        $data['active'] ='';


        $this->load->view('influencer/payment_history',$data);
    }

    private function clean($value){
        $value = round($value,2);
        $value = ($value > 0) ? $value : '0';
        return $value;
    }

    private function getTotal($prop, $start_date, $end_date){
        if ($start_date != null && $end_date != null){
            $data['start_date'] = $start_date;
            $data['end_date'] = $end_date;
            $this->db->where('date >=', $start_date);
            $this->db->where('date <=', $end_date);
        }
        $this->db->select_sum($prop);
        $userid = $this->session->userdata('user_id');
        $value = $this->db->get_where('revenue_history',array('influencer_id' => $userid))->row_array()[$prop];
        return $this->clean($value);
    }
    private function load_payment_history($start_date,$end_date){
        $userid = $this->session->userdata('user_id');
        $this->db->order_by('date', 'DESC');
        if ($start_date != null && $end_date != null){
            $data['start_date'] = $start_date;
            $data['end_date'] = $end_date;
            $this->db->where('date >=', $start_date);
            $this->db->where('date <=', $end_date);
        }
        $result = $this->db->get_where('revenue_history',array('influencer_id' => $userid));
        $data['rows'] = $result->result();

        //Get total premium
        $total_premium = $this->getTotal('premium_visit', $start_date, $end_date);
        //Get total normal
        $total_normal = $this->getTotal('normal_visit', $start_date, $end_date);
        //Get total revenue
        $total_revenue = $this->getTotal('revenue_generated', $start_date, $end_date);
        //Payment left
        $payment_left = $this->db->get_where('influencer',array('id' => $userid))->row()->payment;

        $data['payment_left'] = $this->clean($payment_left);
        $data['total_premium'] = $total_premium;
        $data['total_normal'] = $total_normal;
        $data['total_revenue'] = $total_revenue;
        return $this->load->view('influencer/template/payment_history', $data, TRUE);
    }

    public function rss_done(){
{'fraction_non_alphanumeric': 0.20137637227592986, 'fraction_numerical': 0.003113223005079469, 'mean_word_length': 2.683765841882921, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 135, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '959982', 'n_tokens_mistral': 1946, 'n_tokens_neox': 1913, 'n_words': 271}