Added Preorder network Operators/ISPs & snopp api
This commit is contained in:
@@ -0,0 +1,169 @@
|
||||
<?php
|
||||
|
||||
class PreordercampaignOperatorModel {
|
||||
public $preordercampaign_id;
|
||||
public $operator_id;
|
||||
public $type;
|
||||
|
||||
public $create_by;
|
||||
public $edit_by;
|
||||
public $create;
|
||||
public $edit;
|
||||
|
||||
|
||||
public static function create(Array $data) {
|
||||
$model = new PreordercampaignOperator();
|
||||
|
||||
foreach($data as $field => $value) {
|
||||
if(property_exists(get_called_class(), $field)) {
|
||||
$model->$field = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
|
||||
if($model->create_by === null) {
|
||||
$model->create_by = $me->id;
|
||||
}
|
||||
if($model->edit_by === null) {
|
||||
$model->edit_by = $me->id;
|
||||
}
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
public static function getAll() {
|
||||
$items = [];
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$res = $db->select("PreordercampaignOperator", "*", "1=1 ORDER BY id");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new PreordercampaignOperator($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
|
||||
}
|
||||
|
||||
public static function getFirst($filter = null) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
mfLoghandler::singleton()->debug($where);
|
||||
$res = $db->select("PreordercampaignOperator", "*", "$where ORDER BY id");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new PreordercampaignOperator($data);
|
||||
if($item->id) {
|
||||
return $item;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function getFirstOaid($oaid) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
if(!$oaid) return null;
|
||||
|
||||
$where = self::getSqlFilter(["oaid" => $oaid]);
|
||||
//mfLoghandler::singleton()->debug($where);
|
||||
$res = $db->select("PreordercampaignOperator", "*", "$where ORDER BY id");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new PreordercampaignOperator($data);
|
||||
if($item->id) {
|
||||
return $item;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function count($filter) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT COUNT(*) as cnt FROM PreordercampaignOperator
|
||||
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();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT * FROM PreordercampaignOperator
|
||||
WHERE $where
|
||||
ORDER BY id";
|
||||
|
||||
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);
|
||||
|
||||
//mfLoghandler::singleton()->debug($sql);
|
||||
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new PreordercampaignOperator($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
|
||||
private static function getSqlFilter($filter) {
|
||||
$db = FronkDB::singleton();
|
||||
$where = "1=1 ";
|
||||
|
||||
if(!is_array($filter)) {
|
||||
return $where;
|
||||
}
|
||||
|
||||
if(array_key_exists("preordercampaign_id", $filter)) {
|
||||
$preordercampaign_id = $filter['preordercampaign_id'];
|
||||
if(is_numeric($preordercampaign_id)) {
|
||||
$where .= " AND preordercampaign_id = $preordercampaign_id";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("operator_id", $filter)) {
|
||||
$operator_id = $filter['operator_id'];
|
||||
if(is_numeric($operator_id)) {
|
||||
$where .= " AND operator_id = $operator_id";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("type", $filter)) {
|
||||
$type = $db->escape($filter['type']);
|
||||
if($type) {
|
||||
$where .= " AND type LIKE '$type'";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//var_dump($filter, $where);exit;
|
||||
return $where;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user