<?php

if (!defined('BASEPATH'))
  exit('No direct script access allowed');

class Career_model extends MY_Model {

  public function get_career($limit = '10', $offset = '0', $param = array()) {
    $status = @$param['status'];
    $career_id = @$param['career_id'];
    $category_id = @$param['category_id'];
    $customers_id = @$param['customers_id'];
    $orderby = @$param['orderby'];
    $where = @$param['where'];
    $keyword = trim($this->input->get_post('keyword', TRUE));
    $keyword = $this->db->escape_str($keyword);

    if ($customers_id > 0) {
      $this->db->where("companyId ", "$customers_id");
    }
    if ($category_id != '') {
      $this->db->where("category_id ", "$category_id");
    }
    if ($career_id != '') {
      $this->db->where("career_id  ", "$career_id");
    }
    if ($status != '') {
      $this->db->where("status", "$status");
    }
    if ($where != '') {
      $this->db->where($where);
    }
    if ($keyword != '') {
      $this->db->where("(career_title LIKE '%" . $keyword . "%' OR description LIKE '%" . $keyword . "%' )");
    }
    if ($orderby != '') {
      $this->db->order_by($orderby);
    } else {
      $this->db->order_by('career_id ', 'desc');
    }

    //$this->db->limit($limit, $offset);
    $this->db->select('SQL_CALC_FOUND_ROWS*', FALSE);
    $this->db->from('wps_career');
    $this->db->where('status !=', '2');
    $q = $this->db->get();
    //echo_sql();
    $result = $q->result_array();
    $result = ($limit == '1') ? $result[0] : $result;
    return $result;
  }

  public function get_review_comment($limit = '10', $offset = '0', $param = array()) {

    $ref_media_id = @$param['ref_career_id'];
    $status = @$param['status'];
    $orderby = @$param['orderby'];
    $where = @$param['where'];
    $keyword = trim($this->input->get_post('keyword', TRUE));
    $keyword = $this->db->escape_str($keyword);
    $status = $this->input->get_post('status');
    if ($ref_media_id != '') {
      $this->db->where("career_id", "$ref_media_id");
    }
    if ($status != '') {
      $this->db->where("status", "$status");
    } else {
      $this->db->where('status !=', '2');
    }
    if ($where != '') {
      $this->db->where($where);
    }
    if ($keyword != '') {
      $this->db->where("(mem_name LIKE '%" . $keyword . "%' OR comment LIKE '%" . $keyword . "%' )");
    }
    if ($orderby != '') {
      $this->db->order_by($orderby);
    } else {
      $this->db->order_by('application_id ', 'desc');
    }
    // $this->db->group_by("rev.review_id"); 	
    if ($limit != FALSE) {
      $this->db->limit($limit, $offset);
    }
    $this->db->select('SQL_CALC_FOUND_ROWS *', FALSE);
    $this->db->from('wps_career_application');
    //$this->db->where('status !=','2');
    $q = $this->db->get();
    //echo_sql();
    $result = $q->result_array();
    $result = ($limit == '1') ? $result[0] : $result;
    return $result;
  }

}
