/application/modules/webapp/models/rating_model.php

https://bitbucket.org/bivekmindz/foxsky · PHP · 133 lines · 110 code · 19 blank · 4 comment · 0 complexity · d55d439fe516a9e37a004a52f1c34b27 MD5 · raw file

  1. <?php
  2. class Rating_Model extends CI_Model {
  3. public function __construct() {
  4. parent::__construct();
  5. }
  6. public function exist_id($id,$uid){
  7. $query=$this->db->query("SELECT ProId FROM tblproductmap where prodtmappid=".$id."");
  8. $data = $query->result();
  9. $pro_id = $data['0']->ProId;
  10. $query = $this->db->query("SELECT * FROM tblrating where ProId=$pro_id and UserId=$uid");
  11. $close= $this->db->close();
  12. return $query->num_rows();
  13. }
  14. public function check_user($email)
  15. {
  16. $query=$this->db->query("SELECT count(*) FROM tbl_manufacturermaster where compemailid=".$email);
  17. $data = $query->result();
  18. $close= $this->db->close();
  19. return $data;
  20. }
  21. public function insert_id($id,$uid){
  22. $query=$this->db->query("SELECT ProId FROM tblproductmap where prodtmappid=".$id."");
  23. $data = $query->result();
  24. $pro_id = $data['0']->ProId;
  25. $sql = "INSERT INTO tblrating (ProId,UserId) VALUES ('".$pro_id."','".$uid."')";
  26. $str = $this->db->query($sql);
  27. $close = $this->db->close();
  28. }
  29. public function exist_all($id,$uid){
  30. $query=$this->db->query("SELECT ProId FROM tblproductmap where prodtmappid=".$id."");
  31. $data = $query->result();
  32. $pro_id = $data['0']->ProId;
  33. $query = $this->db->query("SELECT TotalVotes,TotalValues,UsedIP FROM tblrating where ProId=$pro_id and UserId=$uid");
  34. $data = $query->result_array();
  35. $close = $this->db->close();
  36. return $data;
  37. }
  38. public function get_ip($id,$ip,$uid){
  39. $query=$this->db->query("SELECT ProId FROM tblproductmap where prodtmappid=".$id."");
  40. $data = $query->result();
  41. $pro_id = $data['0']->ProId;
  42. $query = $this->db->query("SELECT UsedIP FROM tblrating where UsedIP LIKE '%".$ip."%' AND ProId=$pro_id AND UserId=$uid");
  43. $rows = $query->num_rows();
  44. $close = $this->db->close();
  45. return $rows;
  46. }
  47. public function update_rating($added,$sum,$insertip,$id,$uid){
  48. $query=$this->db->query("SELECT ProId FROM tblproductmap where prodtmappid=".$id."");
  49. $data = $query->result();
  50. $pro_id = $data['0']->ProId;
  51. $data = array(
  52. 'TotalVotes' => $added,
  53. 'TotalValues' => $sum,
  54. 'UsedIp' => $insertip );
  55. $this->db->where(array('ProId'=>$pro_id,'UserId'=>$uid));
  56. $this->db->update('tblrating', $data);
  57. $close = $this->db->close();
  58. // return $data ;
  59. //$this->db->where($where);
  60. }
  61. public function lastinsrt_id($proid,$user_id,$headline,$review_des){
  62. $query = $this->db->query("SELECT ProId FROM tblproductmap where prodtmappid=$proid");
  63. $data = $query->result();
  64. $pro_id = $data['0']->ProId;
  65. $sql = "INSERT INTO tblreview (prod_id,user_id,headline,review_des,status) VALUES ('".$pro_id."','".$user_id."','".$headline."','".addslashes($review_des)."','I')";
  66. $str = $this->db->query($sql);
  67. $query = $this->db->query('SELECT LAST_INSERT_ID() FROM tblreview');
  68. $row = $query->row_array();
  69. $LastIdInserted = $row['LAST_INSERT_ID()'];
  70. $close= $this->db->close();
  71. return $LastIdInserted;
  72. }
  73. public function prodrate_info($id,$uid){
  74. $query=$this->db->query("SELECT ProId FROM tblproductmap where prodtmappid=".$id."");
  75. $data = $query->result();
  76. $pro_id = $data['0']->ProId;
  77. //echo "SELECT TotalVotes,TotalValues FROM tblrating where ProId=$id and UserId=$uid"; exit;
  78. $query = $this->db->query("SELECT TotalVotes,TotalValues FROM tblrating where ProId=$pro_id and UserId=$uid");
  79. $data = $query->result_array();
  80. $close= $this->db->close();
  81. return $data;
  82. }
  83. public function prod_info($proid){
  84. $query = $this->db->query("SELECT pr.ProName,fn_image(pm.prodtmappid) as image
  85. FROM tblproduct as pr, tblproductmap as pm where pm.prodtmappid=$proid and pr.ProId=pm.ProId");
  86. $data = $query->result();
  87. $close= $this->db->close();
  88. return $data;
  89. }
  90. public function reviewinfo($proid,$userid){
  91. $query = $this->db->query("SELECT headline,review_des FROM tblreview where prod_id=$proid and user_id=$userid");
  92. $data = $query->result_array();
  93. $close= $this->db->close();
  94. return $data;
  95. }
  96. public function review_list($userid){
  97. $query = $this->db->query("SELECT review_des,CreatedOn FROM tblreview where status='A' and user_id=$userid");
  98. $data = $query->result();
  99. $close= $this->db->close();
  100. return $data;
  101. }
  102. // search page query
  103. public function brandsearch($keyword){
  104. $query = $this->db->query('select pm.BrandID,b.BrandName
  105. from tblproduct p
  106. inner join tblproductmap pm on p.ProId=pm.ProId
  107. inner join tblbrand as b on pm.BrandID=b.BrandId
  108. where lower(p.ProName) like "%'.$keyword.'%" and fn_image(pm.prodtmappid)!="" and pm.BrandID!=0 group by pm.BrandID');
  109. $data = $query->result();
  110. $close= $this->db->close();
  111. return $data;
  112. }
  113. }
  114. ?>