198 lines
5.4 KiB
PHP
198 lines
5.4 KiB
PHP
<?php
|
|
|
|
class CallcenterIdentity extends mfBaseModel {
|
|
protected $forcestr = [];
|
|
|
|
private $inumbers;
|
|
|
|
public function getProperty($name) {
|
|
if($this->$name == null) {
|
|
|
|
if($name == "inumbers") {
|
|
$inumbers = CallcenterIdentityIncomingnumber::search(["callcenteridentity_id" => $this->id]);
|
|
if($inumbers) {
|
|
$this->inumbers = $inumbers;
|
|
}
|
|
return $this->inumbers;
|
|
}
|
|
|
|
$classname = ucfirst($name);
|
|
$idfield = $name . "_id";
|
|
$this->$name = mfValuecache::singleton()->get("mfObjectmodel-$name-" . $this->$idfield);
|
|
if(!$this->$name) {
|
|
$this->$name = new $classname($this->$idfield);
|
|
}
|
|
|
|
if($this->$name->id) {
|
|
mfValuecache::singleton()->set("mfObjectmodel-$name-" . $this->$name->id, $this->$name);
|
|
return $this->$name;
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
return $this->$name;
|
|
|
|
}
|
|
|
|
/********************************
|
|
* Begin static Model functions
|
|
*/
|
|
|
|
public static function create(Array $data) {
|
|
$model = new CallcenterIdentity();
|
|
|
|
$table_fields = [
|
|
"name", "number", "display",
|
|
"create_by","edit_by","create","edit"
|
|
];
|
|
|
|
foreach($data as $field => $value) {
|
|
if(in_array($field, $table_fields)) {
|
|
$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("CallcenterIdentity", "*", "1 = 1 ORDER BY `order`");
|
|
if($db->num_rows($res)) {
|
|
while($data = $db->fetch_object($res)) {
|
|
$items[] = new CallcenterIdentity($data);
|
|
}
|
|
}
|
|
return $items;
|
|
|
|
}
|
|
|
|
public static function getFirst($filter) {
|
|
$db = FronkDB::singleton();
|
|
|
|
$where = self::getSqlFilter($filter);
|
|
$sql = "SELECT * FROM CallcenterIdentity
|
|
WHERE $where
|
|
ORDER BY `order` LIMIT 1";
|
|
//var_dump($sql);exit;
|
|
mfLoghandler::singleton()->debug($sql);
|
|
$res = $db->query($sql);
|
|
if($db->num_rows($res)) {
|
|
$data = $db->fetch_object($res);
|
|
$item = new CallcenterIdentity($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 CallcenterIdentity
|
|
WHERE $where";
|
|
|
|
//mfLoghandler::singleton()->debug($sql);
|
|
|
|
$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, $order = false) {
|
|
//var_dump($filter);exit;
|
|
$items = [];
|
|
|
|
if(!$order) {
|
|
$order = "`order` ASC";
|
|
}
|
|
|
|
$db = FronkDB::singleton();
|
|
|
|
$where = self::getSqlFilter($filter);
|
|
$sql = "SELECT * FROM CallcenterIdentity
|
|
WHERE $where
|
|
ORDER BY $order";
|
|
|
|
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'];
|
|
}
|
|
}
|
|
|
|
mfLoghandler::singleton()->debug($sql);
|
|
|
|
$res = $db->query($sql);
|
|
if($db->num_rows($res)) {
|
|
while($data = $db->fetch_object($res)) {
|
|
$items[$data->id] = new CallcenterIdentity($data);
|
|
}
|
|
}
|
|
|
|
return $items;
|
|
}
|
|
|
|
private static function getSqlFilter($filter) {
|
|
$where = "1=1 ";
|
|
|
|
if(array_key_exists("order", $filter)) {
|
|
$order = $filter['order'];
|
|
if(is_numeric($order)) {
|
|
$where .= " AND CallcenterIdentity.order=$order";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("number", $filter)) {
|
|
$number = FronkDB::singleton()->escape($filter['number']);
|
|
if($number) {
|
|
$where .= " AND CallcenterIdentity.number LIKE '$number'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("name", $filter)) {
|
|
$name = FronkDB::singleton()->escape($filter['name']);
|
|
if($name) {
|
|
$where .= " AND CallcenterIdentity.name LIKE '$name'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("display", $filter)) {
|
|
$display = FronkDB::singleton()->escape($filter['display']);
|
|
if($display) {
|
|
$where .= " AND CallcenterIdentity.display LIKE '$display'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("add-where", $filter)) {
|
|
$where .= " ".$filter['add-where'];
|
|
}
|
|
|
|
//var_dump($filter, $where);exit;
|
|
return $where;
|
|
}
|
|
|
|
} |