193 lines
4.5 KiB
PHP
193 lines
4.5 KiB
PHP
<?php
|
|
|
|
class VoicenumberblockModel {
|
|
public $name;
|
|
public $countrycode;
|
|
public $areacode;
|
|
public $prefix;
|
|
public $first;
|
|
public $last;
|
|
public $comment;
|
|
|
|
public $create_by;
|
|
public $edit_by;
|
|
public $create;
|
|
public $edit;
|
|
|
|
|
|
public static function create(Array $data) {
|
|
$model = new Voicenumberblock();
|
|
|
|
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($order = "countrycode,areacode,first,last") {
|
|
$items = [];
|
|
|
|
$db = FronkDB::singleton();
|
|
|
|
$order_by = "";
|
|
|
|
if($order) {
|
|
$order_by = $order;
|
|
}
|
|
|
|
$res = $db->select("Voicenumberblock", "*", "1=1 ORDER BY $order_by");
|
|
if($db->num_rows($res)) {
|
|
while($data = $db->fetch_object($res)) {
|
|
$items[] = new Voicenumberblock($data);
|
|
}
|
|
}
|
|
return $items;
|
|
|
|
}
|
|
|
|
public static function getFirst($filter = false) {
|
|
$db = FronkDB::singleton();
|
|
|
|
$where = self::getSqlFilter($filter);
|
|
$res = $db->select("Voicenumberblock", "*", "$where ORDER BY countrycode, areacode, first, last");
|
|
if($db->num_rows($res)) {
|
|
$data = $db->fetch_object($res);
|
|
$item = new Voicenumberblock($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 Voicenumberblock
|
|
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 Voicenumberblock
|
|
WHERE $where
|
|
ORDER BY countrycode, areacode, first, last";
|
|
|
|
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);
|
|
|
|
//mfLoghandler::singleton()->debug($sql);
|
|
|
|
if($db->num_rows($res)) {
|
|
while($data = $db->fetch_object($res)) {
|
|
$items[] = new Voicenumberblock($data);
|
|
}
|
|
}
|
|
return $items;
|
|
}
|
|
|
|
private static function getSqlFilter($filter) {
|
|
$db = FronkDB::singleton();
|
|
$where = "1=1 ";
|
|
|
|
if(!is_array($filter)) {
|
|
return $where;
|
|
}
|
|
|
|
//var_dump($filter);exit;
|
|
if(array_key_exists("countrycode", $filter)) {
|
|
$countrycode = $filter['countrycode'];
|
|
if(is_numeric($countrycode)) {
|
|
$where .= " AND countrycode like '%$countrycode%'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("areacode", $filter)) {
|
|
$areacode = $filter['areacode'];
|
|
if(is_numeric($areacode)) {
|
|
$where .= " AND areacode like '%$areacode%'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("prefix", $filter)) {
|
|
$prefix = $filter['prefix'];
|
|
if(is_numeric($prefix)) {
|
|
$where .= " AND prefix = '$prefix'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("first", $filter)) {
|
|
$first = $filter['first'];
|
|
if(is_numeric($first)) {
|
|
$where .= " AND first = '$first'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("last", $filter)) {
|
|
$last = $filter['last'];
|
|
if(is_numeric($last)) {
|
|
$where .= " AND last = '$last'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("number", $filter)) {
|
|
$number = $filter['number'];
|
|
|
|
if(is_numeric($number)) {
|
|
$where .= " AND first <= $number AND last >= $number";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("name", $filter)) {
|
|
$name = $db->escape($filter['name']);
|
|
if($name) {
|
|
$where .= " AND name like '%$name%'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("comment", $filter)) {
|
|
$comment = $db->escape($filter['comment']);
|
|
if($comment) {
|
|
$where .= " AND comment like '%$comment%'";
|
|
}
|
|
}
|
|
|
|
//var_dump($filter, $where);exit;
|
|
return $where;
|
|
}
|
|
|
|
} |