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
+36 -3
View File
@@ -64,6 +64,17 @@ class VoiceplanController extends mfBaseController {
$this->layout()->set("plan", $plan);
$filter = [];
if(is_array($this->request->filter)) {
$filter = $this->request->filter;
}
$this->layout->set("filter", $filter);
if($filter) {
$filter = $this->getPreparedViewFilter($filter);
}
$pagination = [];
$pagination['start'] = 0;
$pagination['count'] = 20;
@@ -73,14 +84,36 @@ class VoiceplanController extends mfBaseController {
$pagination['start'] = intval($this->request->s);
}
$pagination['maxItems'] = VoiceplanzoneModel::count(['voiceplan_id' => $id]);
$zones = VoiceplanzoneModel::search(['voiceplan_id' => $id], $pagination);
$zone_search = $filter;
$zone_search['voiceplan_id'] = $id;
$pagination['maxItems'] = VoiceplanzoneModel::count($zone_search);
$zones = VoiceplanzoneModel::search($zone_search, $pagination);
$this->layout()->set("zones", $zones);
$this->layout()->set("pagination", $pagination);
}
private function getPreparedViewFilter($filter) {
$new_filter = [];
if(array_key_exists("prefix", $filter) && $filter['prefix']) {
$prefix = $filter['prefix'];
if(substr($prefix, 0, 1) == "+") {
$prefix = substr($prefix, 1)."%";
}
$new_filter['prefix'] = $prefix;
unset($filter['prefix']);
}
foreach($filter as $name => $value) {
$new_filter[$name] = $value;
}
return $new_filter;
}
protected function addAction() {
$this->layout()->setTemplate("Voiceplan/Form");
@@ -124,7 +157,7 @@ class VoiceplanController extends mfBaseController {
$data = [];
$data['name'] = $r->name;
$data['description'] = $r->description;
$data['price_multiplicator'] = ($r->price_multiplicator) ? $r->price_multiplicator : 1;
$data['price_multiplicator'] = ($r->price_multiplicator) ? $r->price_multiplicator : null;
if($r->increment) {
@@ -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;
}