154 lines
3.6 KiB
PHP
154 lines
3.6 KiB
PHP
<?php
|
|
|
|
class VoiceplandestinationModel {
|
|
public $voiceplanzone_id;
|
|
public $destination;
|
|
public $prefix;
|
|
|
|
public $create_by;
|
|
public $edit_by;
|
|
public $create;
|
|
public $edit;
|
|
|
|
|
|
public static function create(Array $data) {
|
|
$model = new Voiceplandestination();
|
|
|
|
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("Voiceplandestination", "*", "1=1 ORDER BY destination,prefix");
|
|
if($db->num_rows($res)) {
|
|
while($data = $db->fetch_object($res)) {
|
|
$items[] = new Voiceplandestination($data);
|
|
}
|
|
}
|
|
return $items;
|
|
|
|
}
|
|
|
|
public static function getFirst($filter = null) {
|
|
$db = FronkDB::singleton();
|
|
|
|
$where = self::getSqlFilter($filter);
|
|
mfLoghandler::singleton()->debug($where);
|
|
$res = $db->select("Voiceplandestination", "*", "$where ORDER BY destination,prefix");
|
|
if($db->num_rows($res)) {
|
|
$data = $db->fetch_object($res);
|
|
$item = new Voiceplandestination($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 Voiceplandestination
|
|
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 Voiceplandestination
|
|
WHERE $where
|
|
ORDER BY destination,prefix";
|
|
|
|
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 Voiceplandestination($data);
|
|
}
|
|
}
|
|
return $items;
|
|
}
|
|
|
|
private static function getSqlFilter($filter) {
|
|
$db = FronkDB::singleton();
|
|
$where = "1=1 ";
|
|
|
|
if(!is_array($filter)) {
|
|
return $where;
|
|
}
|
|
|
|
if(array_key_exists("voiceplanzone_id", $filter)) {
|
|
$voiceplanzone_id = $filter['voiceplanzone_id'];
|
|
if(is_numeric($voiceplanzone_id)) {
|
|
$where .= " AND voiceplanzone_id = $voiceplanzone_id";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("name", $filter)) {
|
|
$name = $db->escape($filter['name']);
|
|
if($name) {
|
|
$where .= " AND name like '%$name%'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("destination", $filter)) {
|
|
$destination = $db->escape($filter['destination']);
|
|
if($destination) {
|
|
$where .= " AND destination like '%$destination%'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("prefix", $filter)) {
|
|
$prefix = $db->escape($filter['prefix']);
|
|
if($prefix) {
|
|
$where .= " AND prefix like '%$prefix%'";
|
|
}
|
|
}
|
|
|
|
//var_dump($filter, $where);exit;
|
|
return $where;
|
|
}
|
|
|
|
} |