select("customer_product", "*", "1=1 ORDER BY $order"); if($db->num_rows($res)) { while($data = $db->fetch_object($res)) { $items[] = new IvtCustomerProduct($data); } } return $items; } public static function getFirst($filter = []) { $db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME); $where = self::getSqlFilter($filter); $res = $db->select("customer_product", "*", "$where ORDER BY id LIMIT 1"); if($db->num_rows($res)) { $data = $db->fetch_object($res); $item = new IvtCustomerProduct($data); if($item->id) { return $item; } else { return null; } } return null; } public static function count($filter) { $db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME); $where = self::getSqlFilter($filter); $sql = "SELECT COUNT(*) cnt FROM customer_product WHERE $where ORDER by id"; $res = $db->query($sql); if($db->num_rows($res)) { $data = $db->fetch_object($res); return $data->cnt; } return 0; } public static function search($filter, $limit = false) { $items = []; $db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME); $where = self::getSqlFilter($filter); $sql = "SELECT * FROM customer_product WHERE $where ORDER by id"; mfLoghandler::singleton()->debug($sql); if(is_array($limit) && count($limit)) { if(is_numeric($limit['start']) && is_numeric($limit['count'])) { $sql .= " LIMIT ".$limit['start'].", ".$limit['count']; } elseif(is_numeric($limit['count'])) { $sql .= " LIMIT ".$limit['count']; } } $res = $db->query($sql); if($db->num_rows($res)) { while($data = $db->fetch_object($res)) { $items[] = new IvtCustomerProduct($data); } } return $items; } private static function getSqlFilter($filter) { $where = "1=1 "; if(array_key_exists("cid", $filter)) { $cid = $filter['cid']; if(is_numeric($cid)) { $where .= " AND cid=$cid"; } } if(array_key_exists("pid", $filter)) { $pid = $filter['pid']; if(is_numeric($pid)) { $where .= " AND pid=$pid"; } } if(array_key_exists("sid", $filter)) { $sid = $filter['sid']; if(is_numeric($sid)) { $where .= " AND sid=$sid"; } } //var_dump($filter);exit; if(array_key_exists("lastdate", $filter)) { $lastdate = $filter['lastdate']; if($lastdate) { $where .= " AND lastdate = '$lastdate'"; } } if(array_key_exists("lastdate>", $filter)) { $lastdate = $filter['lastdate>']; if($lastdate) { $where .= " AND lastdate >= '$lastdate'"; } } if(array_key_exists("lastdate<", $filter)) { $lastdate = $filter['lastdate<']; if($lastdate) { $where .= " AND lastdate <= '$lastdate'"; } } if(array_key_exists("createdate>", $filter)) { $createdate = $filter['createdate>']; if($createdate) { $where .= " AND createdate >= '$createdate'"; } } if(array_key_exists("createdate<", $filter)) { $createdate = $filter['createdat<']; if($createdate) { $where .= " AND createdate <= '$createdate'"; } } //var_dump($filter, $where);exit; return $where; } }