Added filter to Voiceplan

This commit is contained in:
Frank Schubert
2023-12-05 22:09:00 +01:00
parent 8717db1a4d
commit dbc8d24810
5 changed files with 123 additions and 13 deletions

View File

@@ -77,9 +77,20 @@ class VoiceplanzoneModel {
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$sql = "SELECT COUNT(*) as cnt FROM Voiceplanzone
/*$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)) {
@@ -95,9 +106,12 @@ class VoiceplanzoneModel {
$where = self::getSqlFilter($filter);
$sql = "SELECT * FROM Voiceplanzone
$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
ORDER BY voiceplan_id,name";
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'])) {
@@ -107,6 +121,7 @@ class VoiceplanzoneModel {
}
}
mfLoghandler::singleton()->debug($sql);
$res = $db->query($sql);
if($db->num_rows($res)) {
@@ -132,17 +147,33 @@ class VoiceplanzoneModel {
if(array_key_exists("name", $filter)) {
$name = FronkDB::singleton()->escape($filter['name']);
if($name) {
$where .= " AND name='$name'";
$where .= " AND Voiceplanzone.name like '%$name%'";
}
}
if(array_key_exists("extref", $filter)) {
$extref = FronkDB::singleton()->escape($filter['extref']);
if($extref) {
$where .= " AND extref='$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;
}