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