Files
thetool/application/PreordercampaignOperatorIsp/PreordercampaignOperatorIspModel.php
2024-04-18 14:00:25 +02:00

160 lines
4.3 KiB
PHP

<?php
class PreordercampaignOperatorIspModel {
public $campaignoperator_id;
public $isp_id;
public $type;
public $create_by;
public $edit_by;
public $create;
public $edit;
public static function create(Array $data) {
$model = new PreordercampaignOperatorIsp();
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("PreordercampaignOperatorIsp", "*", "1=1 ORDER BY id");
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {
$items[] = new PreordercampaignOperatorIsp($data);
}
}
return $items;
}
public static function getFirst($filter = null) {
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
mfLoghandler::singleton()->debug($where);
$res = $db->select("PreordercampaignOperatorIsp", "*", "$where ORDER BY id");
if($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new PreordercampaignOperatorIsp($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("PreordercampaignOperatorIsp", "*", "$where ORDER BY id");
if($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new PreordercampaignOperatorIsp($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 PreordercampaignOperatorIsp
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 PreordercampaignOperatorIsp
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 PreordercampaignOperatorIsp($data);
}
}
return $items;
}
private static function getSqlFilter($filter) {
$db = FronkDB::singleton();
$where = "1=1 ";
if(!is_array($filter)) {
return $where;
}
if(array_key_exists("isp_id", $filter)) {
$isp_id = $filter['isp_id'];
if(is_numeric($isp_id)) {
$where .= " AND isp_id = $isp_id";
}
}
if(array_key_exists("campaignoperator_id", $filter)) {
$campaignoperator_id = $filter['campaignoperator_id'];
if(is_numeric($campaignoperator_id)) {
$where .= " AND campaignoperator_id = $campaignoperator_id";
}
}
//var_dump($filter, $where);exit;
return $where;
}
}