File: /home/barbeatleanalyti/public_html/beatleanalytics.com/application/models/BeatleModel.php-20-05-22
<?php
class BeatleModel extends CI_Model
{
//blog section start here
public function getallblogcount()
{
$data = $this->db->select("*")->from("beatle_blog")->get();
$result = $data->result();
return count($result);
}
public function getallbloglimit($limit,$start)
{
$data = $this->db->select("*")->from("beatle_blog")
->join("beatle_users","beatle_users.user_id = beatle_blog.created_by")
->limit($limit,$start)->get();
$result = $data->result();
return $result;
}
// END HERE
// get blog by category
public function getallblogcountcat($catname)
{
//$catname = substr($cat, 0, 5);
$getcatid = $this->db->select("id,tag_name,status")
->from("beatle_tag")
->like("tag_name",$catname,'after')
//->like("foo_column LIKE %$search%")
->get();
//echo $this->db->last_query();
$reget = $getcatid->result();
//echo '<pre>'; print_r($reget); die;
$catid = $reget[0]->id;
$selectblog = $this->db->select("*")
->from("beatle_blog")
->like("blog_tag",$catid)
->get();
$result = $selectblog->result();
return count($result);
}
public function getallblogcatlimit($limit,$start,$catname)
{
$getcatid = $this->db->select("id,tag_name,status")
->from("beatle_tag")
->like("tag_name",$catname,'before')
->get();
$reget = $getcatid->result();
$catid = $reget[0]->id;
$data = $this->db->select("*")->from("beatle_blog")
->join("beatle_users","beatle_users.user_id = beatle_blog.created_by")
->like("blog_tag",$catid)
->limit($limit,$start)->get();
$result = $data->result();
return $result;
}
// End Here
// 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);
}
//get Blog Comment Start here
public function getblogcomment($blogid)
{
$data = $this->db->select("*")
->from("beatle_comment")
->join("beatle_users","beatle_users.user_id = beatle_comment.user_comment_id")
->where("beatle_comment.blog_id",$blogid)
->order_by("beatle_comment.id","DESC")
->get();
//echo $this->db->last_query();die;
$result = $data->result();
return json_encode($result);
}
// End here
// Add Blog Comment Start From Here
public function addcomment($email,$username,$comment,$blog_id)
{
//echo '<pre>'; print_r($_POST); die;
$masg = array();
$date = date('Y-m-d H:i:s');
$checkuser = $this->BeatleModel->checkcommentuser($email);
// insert comment after verification start here
if (!empty($checkuser))
{
if ($checkuser[0]->user_verification_status != VERIFY_STATUS)
{
$masg = array('message'=>'Please verify your email to comment this post','status'=>'0');
}
else{
$userid = $checkuser[0]->user_id;
$insertcomment = array(
'blog_id' => $blog_id,
'user_comment_id' => $userid,
'blog_comment' => $comment,
'created_date' => $date,
);
$data = $this->db->insert("beatle_comment",$insertcomment);
if ($data)
{
$masg = array('message'=>'Thanks For Comment','status'=>'1');
//redirect(FRONTRND_URL.'blogDetails/'.$blog_id);
//$this->session->set_flashdata('success','Thanks For Comment',true);
}
}
}
// End here
// Send Mail For verification Start here
else
{
$veriCode = 'COMM'.rand(0,1000);
$status = '0';
$fromemail = ADMIN_EMAIL;
$toemail = $email;
$sendmail = $this->BeatleModel->sendMail($fromemail,$toemail,$veriCode,$blog_id,$email,$username);
// echo '<pre>';print_r($sendmail); die;
if ($sendmail == '1'){
$insertuser = array
(
'username' => $username,
'user_email' => $email,
'user_verification_code' => $veriCode,
'user_verification_status' => $status,
'created_date' => $date
);
$query = $this->db->insert("beatle_users",$insertuser);
$masg = array('message'=>'Verification link has been sent your mail. Please verify!','status'=>'1');
}
else{
// redirect(FRONTRND_URL.'blogDetails/'.$blog_id);
//$this->session->set_flashdata('error','Enable to send mail.Please try again',true);
$masg = array('message'=>'Enable to send mail.Please try again','status'=>'0');
}
}
return $masg;
// end here
}
//NEWS SECTION START HERE
public function getallnewscount()
{
$data = $this->db->select("*")->from("beatle_news")->get();
$result = $data->result();
return count($result);
}
public function getallnewslimit($limit,$start)
{
$data = $this->db->select("*")->from("beatle_news")
->join("beatle_users","beatle_users.user_id = beatle_news.created_by")
->where('beatle_news.status',STATUS_ACTIVE)->limit($limit,$start)->get();
$result = $data->result();
return $result;
}
// END HERE
// Check user for comment on blog
public function checkcommentuser($email)
{
$selectuser = $this->db->select("*")
->from("beatle_users")
->where("user_email",$email)
//->where("user_verification_status",VERIFY_STATUS)
->get();
$data = $selectuser->result();
return $data;
}
//Send Verification Code Start From Here
public function sendMail($fromemail,$toemail,$veriCode,$blogid,$email,$username)
{
$verifycode = FRONTRND_URL.'verifyUserComment/'.$veriCode.'/'.$toemail.'/'.$blogid;
//$mailmessage = $verifycode;
$data = (object) array('name'=>$username,'email'=>$email,"verifycaode"=>$verifycode);
/*$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.googlemail.com';
$config['smtp_port'] = '465';
$config['smtp_user'] = '2606ankit@gmail.com';
$config['smtp_pass'] = 'mahadev@86'; */
$config['charset'] = 'utf-8';
$config['newline'] = "\r\n";
$config['mailtype'] = 'html';
$config['priority'] = '1';
$this->email->initialize($config);
$mailmessage = $this->load->view('template/email',$data,TRUE);
// echo '<pre>'; print_r($mailmessage); die;
$this->email->from($fromemail, 'Verification Mail');
$this->email->to($toemail);
$this->email->subject('Beatle Group:Verification Mail');
$this->email->message($mailmessage);
//Send mail
if($this->email->send())
{
return TRUE;
//echo $this->email->print_debugger();
}
else {
return $this->email->print_debugger();
}
}
//Send Contact Mail
public function sendcontactmail($conname,$conphone,$conemail,$comment)
{
$toemail = ADMIN_EMAIL;
$data = (object) array('name'=>$conname,'email'=>$conemail,"phone"=>$conphone,'comment'=>$comment);
$config['charset'] = 'utf-8';
$config['newline'] = "\r\n";
$config['mailtype'] = 'html';
$config['priority'] = '1';
$this->email->initialize($config);
$mailmessage = $this->load->view('template/contactemail',$data,TRUE);
// echo '<pre>'; print_r($mailmessage); die;
$this->email->from($conemail, 'Contact Us');
$this->email->to($toemail);
$this->email->subject('Beatle Group:Contact Mail');
$this->email->message($mailmessage);
//Send mail
if($this->email->send())
{
return TRUE;
//echo $this->email->print_debugger();
}
else {
return $this->email->print_debugger();
}
}
// end here
// Check User if already
public function checkuser($email)
{
$result = $this->db->select("user_email")->from("beatle_users")
->where("user_email",$email)->get();
$data = $result->result();
return $data;
}
// Verify Email For Comment
public function verifyUserComment($getcode,$getemail)
{
$updatedata = array(
'user_verification_status' => VERIFY_STATUS,
);
$arr = array("user_email"=>$getemail,"user_verification_code"=>$getcode);
$update = $this->db->where($arr)->update("beatle_users",$updatedata);
if ($update){
return TRUE;
}
}
// News Like Dislike Start here
public function newsLikeDislike($news_id,$news_table,$newslike_type)
{
$gedata = $this->db->select("*")
->from("beatle_likedislike")
->where("news_id",$news_id)
->get();
$result = $gedata->result();
$date = date('Y-m-d H:i:s');
if(empty($result)){
if($newslike_type == 1){
$insertdata = array(
'news_id' => $news_id,
'news_like' => '1',
'created_date' => $date
);
}else{
$insertdata = array(
'news_id' => $news_id,
'news_dislike' => '1',
'created_date' => $date
);
}
$insert = $this->db->insert('beatle_likedislike',$insertdata);
if($insert){
return '1';
}
}
else{
$newslike = $result[0]->news_like +1 ;
$newsdislike = $result[0]->news_dislike +1;
if($newslike_type == 1){
$updatearry = array(
'news_id' => $news_id,
'news_like' => $newslike,
'updated_date' => $date
);
$returnval = $newslike;
}else{
$updatearry = array(
'news_id' => $news_id,
'news_dislike' => $newsdislike,
'updated_date' => $date
);
$returnval = $newsdislike;
}
$update = $this->db->where("news_id",$news_id)->update("beatle_likedislike",$updatearry);
if($update){
return $returnval;
}
}
}
// End here
// Get All News Like Dislike Start Here
public function getalllikedislike($newsid)
{
$data = $this->db->select("*")
->from("beatle_likedislike")
->where('news_id',$newsid)
->get();
$result = $data->result();
return $result;
}
// End Here
// Get All Blog Like Dislike Start here
public function getallbloglikedislike($blogid)
{
$data = $this->db->select("*")
->from("beatle_bloglikedislike")
->where('blog_id',$blogid)
->get();
$result = $data->result();
return $result;
}
public function blogLikeDislike($news_id,$news_table,$newslike_type)
{
$gedata = $this->db->select("*")
->from("beatle_bloglikedislike")
->where("blog_id",$news_id)
->get();
$result = $gedata->result();
$date = date('Y-m-d H:i:s');
if(empty($result)){
if($newslike_type == 1){
$insertdata = array(
'blog_id' => $news_id,
'blog_like' => '1',
'created_date' => $date
);
}else{
$insertdata = array(
'blog_id' => $news_id,
'blog_dislike' => '1',
'created_date' => $date
);
}
$insert = $this->db->insert('beatle_bloglikedislike',$insertdata);
if($insert){
return '1';
}
}
else{
$newslike = $result[0]->blog_like +1 ;
$newsdislike = $result[0]->blog_dislike +1;
if($newslike_type == 1){
$updatearry = array(
'blog_id' => $news_id,
'blog_like' => $newslike,
'updated_date' => $date
);
$returnval = $newslike;
}else{
$updatearry = array(
'blog_id' => $news_id,
'blog_dislike' => $newsdislike,
'updated_date' => $date
);
$returnval = $newsdislike;
}
$update = $this->db->where("blog_id",$news_id)->update("beatle_bloglikedislike",$updatearry);
if($update){
return $returnval;
}
}
}
//end
// get data from API start here
public function getallilsting()
{
$findarray = array(GYM,CLUB,HOTEL,RESTAURANT,SPA,MALL);
$data = $this->beatle_live->select("*")
->from("beatle_review")
//->join("beatle_organization","beatle_organization.OrgId = beatle_review.orgId")
//->join("beatle_industry","beatle_industry.IndId = beatle_review.indId")
->join("beatle_branch","beatle_branch.branchId = beatle_review.branchId ")
->where_in('restType',$findarray)
->get();
//echo $this->beatle_live->last_query(); die;
$result = $data->result();
return json_encode($result);
}
public function getlistbyid($listid)
{
//$findarray = array(GYM,CLUB,HOTEL,RESTAURANT,SPA,MALL);
$data = $this->beatle_live->select("*")
->from("beatle_review")
->join("beatle_organization","beatle_organization.OrgId = beatle_review.orgId")
->join("beatle_industry","beatle_industry.IndId = beatle_review.indId")
->join("beatle_branch","beatle_branch.branchId = beatle_review.branchId ")
->where('beatle_review.reviewId',$listid)
->get();
$result = $data->result();
return json_encode($result);
}
// end here
// get all review acc review ID
public function getallreview($revid)
{
$data = $this->beatle_live->select("AVG(avgRating) avgRating,count(avgRating) avgcount")->from("beatle_review_feedback")
->where("reviewId",$revid)
->get();
$result = $data->result();
return $result;
}
// get all photo by review id
public function getlistphoto($listid)
{
$data = $this->beatle_live->select("*")
->from("beatle_review_photo")
->where("reviewId",$listid)
->get();
$result = $data->result();
return $result;
}
// Get all feedback start from here
public function gettotalfeedback($listid)
{
$data = $this->beatle_live->select("*")->from("beatle_review_feedback")
->where("reviewId",$listid)
->get();
$result = $data->result();
return $result;
}
// get all according to the type
public function getlistacctype($listtype)
{
$findarray = array($listtype);
$data = $this->beatle_live->select("*")
->from("beatle_review")
//->join("beatle_organization","beatle_organization.OrgId = beatle_review.orgId")
//->join("beatle_industry","beatle_industry.IndId = beatle_review.indId")
->join("beatle_branch","beatle_branch.branchId = beatle_review.branchId ")
->where_in('restType',$findarray)
->get();
//echo $this->beatle_live->last_query(); die;
$result = $data->result();
return json_encode($result);
}
// Get all club
public function getallclub()
{
$data = $this->beatle_live->select("count(reviewId) totalcount")
->from("beatle_review")
->where('restType',CLUB)
->get();
$result = $data->result();
return $result;
}
// Get all Gym
public function getallgym()
{
$data = $this->beatle_live->select("count(reviewId) totalcount")
->from("beatle_review")
->where('restType',GYM)
->get();
//echo $this->beatle_live->last_query(); die;
$result = $data->result();
return $result;
}
// Get all Restaurant
public function getallrestaurant()
{
$data = $this->beatle_live->select("count(reviewId) totalcount")
->from("beatle_review")
->where('restType',RESTAURANT)
->get();
$result = $data->result();
return $result;
}
// Get all HOTEL
public function getallHotel()
{
$data = $this->beatle_live->select("count(reviewId) totalcount")
->from("beatle_review")
->where('restType',HOTEL)
->get();
$result = $data->result();
return $result;
}
}
?>