106 lines
2.6 KiB
PHP
106 lines
2.6 KiB
PHP
<?php
|
|
|
|
class IvtCreditingProductModel {
|
|
|
|
|
|
public static function getAll() {
|
|
$items = [];
|
|
|
|
$db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME);
|
|
|
|
$res = $db->select("crediting_products", "*");
|
|
if($db->num_rows($res)) {
|
|
while($data = $db->fetch_object($res)) {
|
|
$items[] = new IvtCreditingProduct($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("crediting_products", "*", "$where LIMIT 1");
|
|
if($db->num_rows($res)) {
|
|
$data = $db->fetch_object($res);
|
|
$item = new IvtCreditingProduct($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 crediting_products WHERE $where";
|
|
|
|
$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 crediting_products WHERE $where";
|
|
|
|
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($count)) {
|
|
$sql .= " LIMIT ".$limit['count'];
|
|
}
|
|
}
|
|
|
|
$res = $db->query($sql);
|
|
if($db->num_rows($res)) {
|
|
while($data = $db->fetch_object($res)) {
|
|
$items[] = new IvtCreditingProduct($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, $where);exit;
|
|
return $where;
|
|
}
|
|
|
|
}
|