$value) { if(property_exists(get_called_class(), $field)) { $model ->$field = $value; } } $me = mfValuecache::singleton()->get("me"); if(!$me) { $me = new User(); $me->loadMe(); mfValuecache::singleton()->set("me", $me); } 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("Voiceplanzone", "*", "1=1 ORDER BY voiceplan_id,name"); if($db->num_rows($res)) { while($data = $db->fetch_object($res)) { $items[] = new Voiceplanzone($data); } } return $items; } public static function getFirst($filter = []) { $db = FronkDB::singleton(); $where = self::getSqlFilter($filter); $res = $db->select("Voiceplanzone", "*", "$where ORDER BY voiceplan_id,name"); if($db->num_rows($res)) { $data = $db->fetch_object($res); $item = new Voiceplanzone($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 Voiceplanzone LEFT JOIN Voiceplan ON (Voiceplanzone.voiceplan_id = Voiceplan.id) LEFT JOIN Voiceplandestination ON (Voiceplandestination.voiceplanzone_id = Voiceplanzone.id) WHERE $where "; */ $sql = "SELECT COUNT(*) as cnt FROM ( SELECT Voiceplanzone.* FROM Voiceplanzone LEFT JOIN Voiceplan ON (Voiceplanzone.voiceplan_id = Voiceplan.id) LEFT JOIN Voiceplandestination ON (Voiceplandestination.voiceplanzone_id = Voiceplanzone.id) WHERE $where GROUP BY Voiceplanzone.id ) c "; $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 = []) { $items = []; $db = FronkDB::singleton(); $where = self::getSqlFilter($filter); $sql = "SELECT Voiceplanzone.* FROM Voiceplanzone LEFT JOIN Voiceplan ON (Voiceplanzone.voiceplan_id = Voiceplan.id) LEFT JOIN Voiceplandestination ON (Voiceplandestination.voiceplanzone_id = Voiceplanzone.id) WHERE $where GROUP BY Voiceplanzone.id ORDER BY voiceplan_id,Voiceplanzone.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']; } } mfLoghandler::singleton()->debug($sql); $res = $db->query($sql); if($db->num_rows($res)) { while($data = $db->fetch_object($res)) { $items[] = new Voiceplanzone($data); } } return $items; } private static function getSqlFilter($filter) { $where = "1=1 "; if(array_key_exists("voiceplan_id", $filter)) { $voiceplan_id = $filter['voiceplan_id']; if(is_numeric($voiceplan_id)) { $where .= " AND voiceplan_id=$voiceplan_id"; } } //var_dump($filter);exit; if(array_key_exists("name", $filter)) { $name = FronkDB::singleton()->escape($filter['name']); if($name) { $where .= " AND Voiceplanzone.name like '%$name%'"; } } if(array_key_exists("extref", $filter)) { $extref = FronkDB::singleton()->escape($filter['extref']); if($extref) { $where .= " AND Voiceplanzone.extref='$extref'"; } } if(array_key_exists("prefix", $filter)) { $prefix = FronkDB::singleton()->escape($filter['prefix']); if($prefix) { $where .= " AND Voiceplandestination.prefix LIKE '$prefix'"; } } if(array_key_exists("price_difference", $filter)) { if($filter['price_difference'] == "same") { $where .= " AND IF(Voiceplan.price_multiplicator > 0, price = ROUND(Voiceplan.price_multiplicator * purchase_price, 4), 1=1)"; } elseif($filter['price_difference'] == "diff") { $where .= " AND IF(Voiceplan.price_multiplicator > 0, price <> ROUND(Voiceplan.price_multiplicator * purchase_price, 4), 1=1)"; } } //var_dump($filter, $where);exit; return $where; } }