/
model_class.php
93 lines (82 loc) · 3.26 KB
/
model_class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
require_once('databaseconn.php');
class model {
private $connhandle;
public function getcoupons($num = 60) {
//$query = "select coupon"
$query = "SELECT CouponID,WebsiteID,Description from coupon where";
$query = $query . " (date(coupon.expiry) > CURDATE() or (date(coupon.expiry) = CURDATE() and time(coupon.expiry) >= CURTIME()))";
if (is_numeric($num)) {
$query = $query . " limit " . $num;
} else {
$query = $query . " limit 60";
}
$connhandle = dbconnection :: getinstance() -> connhandle;
$result = $connhandle -> query($query);
echo $connhandle -> error;
return $result;
}
public function SearchCoupons($cpntype, $store, $category, $givecount = false) {
if ($cpntype == "deal") {
$deal = 1;
} else if ($cpntype == "coupon"){
$deal = 0;
} else {
$deal = -1;
}
if ($givecount) {
$query = "select count(couponcategoryinfo.couponid) from couponcategoryinfo ";
} else {
$query = "select couponcategoryinfo.categoryid, coupon.couponid, coupon.description, website.websiteid, website.websitetitle, coupon.expiry from couponcategoryinfo ";
}
$query = $query . "inner join coupon on couponcategoryinfo.couponid = coupon.couponid";
if (isset($category) && $category != null) {
//echo "category set";
$query = $query . " and couponcategoryinfo.categoryid in ";
$query = $query . " (select categoryid from couponcategories where name = '" . htmlspecialchars($category) . "')";
}
if ($deal != -1) {
$query = $query . " and coupon.isdeal = " . htmlspecialchars($deal);
}
$query = $query . " and (date(coupon.expiry) > CURDATE() or (date(coupon.expiry) = CURDATE() and time(coupon.expiry) >= CURTIME()))";
//$query = $query . " and coupon.isdeal = " . htmlspecialchars($deal);
//$query = $query . " group by couponcategoryinfo.couponid";
$query = $query . " inner join website on coupon.websiteid = website.websiteid";
if ($store != null) {
$query = $query . " and website.websitetitle = '" . htmlspecialchars($store) . "'";
}
$query = $query . " group by couponcategoryinfo.couponid";
if (!$givecount) {
$query = $query . " limit 60";
} else {
$query = $query . "";
}
//echo $query;
$connhandle = dbconnection :: getinstance() -> connhandle;
//echo $query;
$result = $connhandle -> query($query);
echo $connhandle -> error;
if ($givecount) {
//echo var_dump($result -> fetch_assoc()['count(couponcategoryinfo.couponid)']);
//return $result -> fetch_assoc()['count(couponcategoryinfo.couponid)'];
return mysqli_num_rows($result);
} else {
return $result;
}
}
public function getStoreHints ($q) {
$query = "select websiteid,websitetitle from website where websitetitle LIKE '" . htmlspecialchars($q) . "%'" . " limit 1";
$dbinstance = dbconnection :: getinstance();
$connhandle = $dbinstance -> connhandle;
$result = $connhandle -> query($query);
return $result;
}
public function getCategoryHints($q) {
$query = "select categoryid,name from couponcategories where name LIKE '" . htmlspecialchars($q) . "%'" . " limit 1";
$dbinstance = dbconnection :: getinstance();
$connhandle = $dbinstance -> connhandle;
$result = $connhandle -> query($query);
return $result;
}
}
?>