changed default finish_date in Order to shippingdate if available
This commit is contained in:
@@ -1,8 +1,212 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
class VoicenumberModel {
|
||||
public $name;
|
||||
public $countrycode;
|
||||
public $areacode;
|
||||
public $first;
|
||||
public $last;
|
||||
public $number_prepend_zero;
|
||||
public $comment;
|
||||
|
||||
public $create_by;
|
||||
public $edit_by;
|
||||
public $create;
|
||||
public $edit;
|
||||
|
||||
|
||||
public static function create(Array $data) {
|
||||
$model = new Voicenumber();
|
||||
|
||||
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("Voicenumber", "*");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new Voicenumber($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
|
||||
}
|
||||
|
||||
public static function getFirst() {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("Voicenumber", "*", "$where ORDER BY voicenumberblock_id, number");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new Voicenumber($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 Voicenumber
|
||||
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 Voicenumber
|
||||
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 Voicenumber($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
|
||||
private 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("first", $filter)) {
|
||||
$add_zero = false;
|
||||
$first = $filter['first'];
|
||||
|
||||
mfLoghandler::singleton()->debug($first);
|
||||
|
||||
if(substr($first,0, 1) === "0") {
|
||||
$add_zero = true;
|
||||
$first = substr($first, 1);
|
||||
}
|
||||
|
||||
if(is_numeric($first)) {
|
||||
$where .= " AND first like '%$first%'";
|
||||
if($add_zero) {
|
||||
$where .= " AND number_prepend_zero = 1";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("last", $filter)) {
|
||||
$add_zero = false;
|
||||
$last = $filter['last'];
|
||||
|
||||
mfLoghandler::singleton()->debug($last);
|
||||
|
||||
if(substr($last,0, 1) === "0") {
|
||||
$add_zero = true;
|
||||
$last = substr($last, 1);
|
||||
}
|
||||
|
||||
if(is_numeric($last)) {
|
||||
$where .= " AND last like '%$last%'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("number", $filter)) {
|
||||
$add_zero = false;
|
||||
$number = $filter['number'];
|
||||
|
||||
mfLoghandler::singleton()->debug($number);
|
||||
|
||||
if(substr($number,0, 1) === "0") {
|
||||
$add_zero = true;
|
||||
$number = substr($number, 1);
|
||||
}
|
||||
if(is_numeric($number)) {
|
||||
$where .= " AND first <= $number AND last >= $number";
|
||||
|
||||
if($add_zero) {
|
||||
$where .= " AND number_prepend_zero = 1";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user