File: /home/barbeatleanalyti/public_html/beatleanalytics.com/application/models/AdminModel.php
<?php
class AdminModel extends CI_Model
{
// Admin login start here
public function loginadminuser($username,$userpass)
{
$data = $this->db->select("*")
->from("beatle_users")
->where("username",$username)
->where("user_password",md5($userpass))
->get();
$result = $data->result();
//echo $this->db->last_query();
$sessData = array
(
'fname' => $result[0]->first_name,
'lname' => $result[0]->last_name,
'userid' => $result[0]->user_id,
'username' => $result[0]->username,
);
$sessiondata = $this->session->set_userdata($sessData);
return $sessiondata;
//return $result;
}
// Get all news from here
public function getallNews()
{
$data = $this->db->select("*")->from("beatle_news")->order_by("id", "DESC")->get();
$result = $data->result();
return json_encode($result);
}
// Get all news from here Check By Status and current date
public function getallNewsdatestatus()
{
$date = date('Y-m-d');
$data = $this->db->select("*")
->from("beatle_news")
->where("status",STATUS_ACTIVE)
->where("DATE_FORMAT(news_start_time,'%Y-%m-%d') <= ",$date)
->get();
$result = $data->result();
//echo $this->db->last_query(); die;
return json_encode($result);
}
// Get news Acc. to the newsid
public function getNewsAccId($newsid)
{
$data = $this->db->select("*")
->from("beatle_news")
->where('id',$newsid)
->get();
$result = $data->result();
return json_encode($result);
}
// news Hold Status
public function newsholdstatus()
{
$data = $this->db->select("*")->from("beatle_news")->where('status',STATUS_HOLD)->get();
$result = $data->result();
return json_encode($result);
}
// news PENDING Status
public function newspendingstatus()
{
$data = $this->db->select("*")->from("beatle_news")->where('status',STATUS_PENDING)->get();
$result = $data->result();
return json_encode($result);
}
// news Active Status
public function newsactivestatus()
{
$data = $this->db->select("*")->from("beatle_news")->where('status',STATUS_ACTIVE)->get();
$result = $data->result();
return json_encode($result);
}
// Get all blog from here
public function getallblog()
{
$data = $this->db->select("*")->from("beatle_blog")->where("status",STATUS_ACTIVE)->get();
$result = $data->result();
return json_encode($result);
}
// Get all news from here Check By Status and current date
public function getallBlogdatestatus()
{
$date = date('Y-m-d');
$data = $this->db->select("*")
->from("beatle_blog")
->where("status",STATUS_ACTIVE)
->where("DATE_FORMAT(blog_start_date,'%Y-%m-%d') <= ",$date)
->get();
$result = $data->result();
//echo $this->db->last_query(); die;
return json_encode($result);
}
// Blog Hold Status
public function blogholdstatus()
{
$data = $this->db->select("*")->from("beatle_blog")->where('status',STATUS_HOLD)->get();
$result = $data->result();
return json_encode($result);
}
// Blog PENDING Status
public function blogpendingstatus()
{
$data = $this->db->select("*")->from("beatle_blog")->where('status',STATUS_PENDING)->get();
$result = $data->result();
return json_encode($result);
}
// Blog Active Status
public function blogactivestatus()
{
$data = $this->db->select("*")->from("beatle_blog")->where('status',STATUS_ACTIVE)->get();
$result = $data->result();
return json_encode($result);
}
// Get news Acc. to the newsid
public function getBlogAccId($newsid)
{
$data = $this->db->select("*")
->from("beatle_blog")
->join("beatle_users","beatle_users.user_id = beatle_blog.created_by")
->where('beatle_blog.id',$newsid)
->get();
$result = $data->result();
return json_encode($result);
}
// Change status (delete,hold,pending,active) fomr blog and news table
public function changestatus($status,$pagetype,$mainid)
{
$tablename = 'beatle_'.$pagetype;
$date = date('Y-m-d H:i:s');
$updatearr = array(
'status' => $status,
'updated_date' => $date
);
$updatequery = $this->db->where("id",$mainid)->update($tablename,$updatearr);
if($updatequery){
return true;
}else{
return false;
}
}
// Get admin details for profile update
public function getadmindetail($userid)
{
$data = $this->db->select("*")
->from("beatle_users")
->where("user_id",$userid)
->get();
$result = $data->result();
return $result;
}
// get all tag
public function getalltag()
{
$data = $this->db->select("*")
->from("beatle_tag")
->where("status !=",STATUS_DELETE)
->get();
$result = $data->result();
return $result;
}
public function getalltagactive()
{
$data = $this->db->select("*")
->from("beatle_tag")
->where("status",STATUS_ACTIVE)
->get();
$result = $data->result();
return $result;
}
//end here
// get tag by id
public function gettagAccid($tagid)
{
$data = $this->db->select("*")
->from("beatle_tag")
->where("id ",$tagid)
->get();
$result = $data->result();
return $result;
}
public function gettagAccidwherein($preblog)
{
$data = $this->db->select("id,tag_name")
->from("beatle_tag")
->where_in("id ",$preblog)
->get();
$result = $data->result();
return $result;
}
// end here
public function delete_news($id){
$this -> db -> where('id', $id);
$this -> db -> delete('beatle_news');
}
public function delete_blog($id){
$this -> db -> where('id', $id);
$this -> db -> delete('beatle_blog');
}
public function delete_tag($id){
$this -> db -> where('id', $id);
$this -> db -> delete('beatle_tag');
}
}
?>