WIP Voiceplan Zones

This commit is contained in:
Frank Schubert
2023-10-13 11:31:45 +02:00
parent 97432a24bb
commit 33c2c63100
17 changed files with 654 additions and 93 deletions
+1 -1
View File
@@ -73,7 +73,7 @@ class OpenAccessId extends mfBaseModel {
$unit_extdata = $extdata;
}
if(is_object($extdata) && isset($extdata->rimo) && isset($extdata->rimo->ftu->id)) {
if(is_object($extdata) && isset($extdata->rimo) && isset($extdata->rimo->ftu->id) && $extdata->rimo->ftu->id) {
//var_dump($extdata);exit;
$fetch_ftu = false;
}
+10 -1
View File
@@ -4,6 +4,7 @@ class Voiceplan extends mfBaseModel {
private $creator;
private $editor;
private $zones;
private $destinations;
public function importDestinationsFromCsv(File $file) {
@@ -68,10 +69,18 @@ class Voiceplan extends mfBaseModel {
if($this->$name == null) {
if($name == "destinations") {
$this->destinations = VoiceplandestinationModel::search(["voiceplan_id" => $this->id]);
$this->destinations = [];
foreach($this->getProperty("zones") as $zone) {
$this->destinations[] = $zone->destinations;
}
return $this->destinations;
}
if($name == "zones") {
$this->zones = VoiceplanzoneModel::search(["voiceplan_id" => $this->id]);
return $this->zones;
}
if($name == "creator") {
$user = mfValuecache::singleton()->get("Worker-id-".$this->create_by);
if($user) {
@@ -73,9 +73,9 @@ class VoiceplanController extends mfBaseController {
$pagination['start'] = intval($this->request->s);
}
$pagination['maxItems'] = VoiceplandestinationModel::count(['voiceplan_id' => $id]);
$destinations = VoiceplandestinationModel::search(['voiceplan_id' => $id], $pagination);
$this->layout()->set("destinations", $destinations);
$pagination['maxItems'] = VoiceplanzoneModel::count(['voiceplan_id' => $id]);
$zones = VoiceplanzoneModel::search(['voiceplan_id' => $id], $pagination);
$this->layout()->set("zones", $zones);
$this->layout()->set("pagination", $pagination);
@@ -3,4 +3,38 @@
class Voiceplandestination extends mfBaseModel {
protected $forcestr = ["name", "destination", "prefix"];
private $voiceplan;
public function getProperty($name) {
if($this->$name == null) {
if(!$this->id) {
return null;
}
if($name == "voiceplan") {
$zone = $this->getProperty("voiceplanzone");
if($zone->voiceplan_id) {
$voiceplan = new Voiceplan($zone->voiceplan_id);
if($voiceplan->id) {
$this->voiceplan = $voiceplan;
}
}
return $this->voiceplan;
}
$classname = ucfirst($name);
$idfield = $name."_id";
$this->$name = new $classname($this->$idfield);
if($this->$name->id) {
return $this->$name;
} else {
return null;
}
}
return $this->$name;
}
}
@@ -17,13 +17,14 @@ class VoiceplandestinationController extends mfBaseController {
protected function addAction() {
$this->layout()->setTemplate("Voiceplandestination/Form");
$voiceplans = VoiceplanModel::getAll();
$this->layout()->set("voiceplans", $voiceplans);
$zones = VoiceplanzoneModel::getAll();
$this->layout()->set("zones", $zones);
$voiceplan_id = $this->request->voiceplan_id;
if($voiceplan_id) {
$voiceplan = new Voiceplan($voiceplan_id);
$this->layout()->set("voiceplan", $voiceplan);
$zone_id = $this->request->voiceplanzone_id;
if(strtolower($this->action) == "add" && $zone_id) {
$zone = new Voiceplanzone($zone_id);
$this->layout()->set("zone", $zones);
$this->layout()->set("zone_id", $zone->id);
}
}
@@ -47,7 +48,7 @@ class VoiceplandestinationController extends mfBaseController {
protected function saveAction() {
$r = $this->request;
var_dump($r);
//var_dump($r);exit;
$id = $r->id;
if(is_numeric($id) && $id > 0) {
@@ -63,25 +64,11 @@ class VoiceplandestinationController extends mfBaseController {
}
$data = [];
$data['voiceplan_id'] = $r->voiceplan_id;
$data['voiceplanzone_id'] = $r->voiceplanzone_id;
$data['destination'] = $r->destination;
$data['prefix'] = intval($r->prefix);
$data['purchase_price'] = (str_replace(",",".",$r->purchase_price)) ? str_replace(",",".",$r->purchase_price) : 0;
$data['price'] = (str_replace(",",".",$r->price)) ? str_replace(",",".",$r->price) : 0;
if($r->increment) {
$increments = explode("/",$r->increment);
if(count($increments) != 2) {
$this->layout()->setFlash("Ungültige Taktung", "error");
$this->layout()->set("destination", VoiceplandestinationModel::create($data));
return $this->addAction();
}
$data["increment_first"] = $increments[0];
$data["increment"] = $increments[1];
}
if(!$data['destination'] || !$data['prefix'] || !$data['voiceplan_id']) {
if(!$data['destination'] || !$data['prefix'] || !$data['voiceplanzone_id']) {
$this->layout()->setFlash("Destination, Prefix und Tarifpaket sind erforderlich", "error");
$this->layout()->set("destination", VoiceplandestinationModel::create($data));
return $this->addAction();
@@ -100,6 +87,6 @@ class VoiceplandestinationController extends mfBaseController {
return $this->addAction();
}
$this->redirect("Voiceplan", "view", ["id" => $destination->voiceplan_id]);
$this->redirect("Voiceplanzone", "view", ["id" => $destination->voiceplanzone_id]);
}
}
@@ -1,14 +1,9 @@
<?php
class VoiceplandestinationModel {
public $voiceplan_id;
public $description;
public $voiceplanzone_id;
public $destination;
public $prefix;
public $purchase_price;
public $price;
public $increment_first;
public $increment;
public $create_by;
public $edit_by;
@@ -124,10 +119,10 @@ class VoiceplandestinationModel {
return $where;
}
if(array_key_exists("voiceplan_id", $filter)) {
$voiceplan_id = $filter['voiceplan_id'];
if(is_numeric($voiceplan_id)) {
$where .= " AND voiceplan_id = $voiceplan_id";
if(array_key_exists("voiceplanzone_id", $filter)) {
$voiceplanzone_id = $filter['voiceplanzone_id'];
if(is_numeric($voiceplanzone_id)) {
$where .= " AND voiceplanzone_id = $voiceplanzone_id";
}
}
@@ -0,0 +1,33 @@
<?php
class Voiceplanzone extends mfBaseModel {
private $destinations;
private $voiceplan;
public function getProperty($name) {
if($this->$name == null) {
if(!$this->id) {
return null;
}
if($name == "destinations") {
$this->destinations = VoiceplandestinationModel::search(["voiceplanzone_id" => $this->id]);
return $this->destinations;
}
$classname = ucfirst($name);
$idfield = $name."_id";
$this->$name = new $classname($this->$idfield);
if($this->$name->id) {
return $this->$name;
} else {
return null;
}
}
return $this->$name;
}
}
@@ -0,0 +1,140 @@
<?php
class VoiceplanzoneController extends mfBaseController {
protected function init() {
$this->needlogin=true;
$me = new User();
$me->loadMe();
$this->me = $me;
$this->layout()->set("me",$me);
if(!$me->isAdmin()) {
$this->redirect("Dashboard");
}
}
protected function addAction() {
$this->layout()->setTemplate("Voiceplanzone/Form");
if(strtolower($this->action) == "add" && $this->request->voiceplan_id) {
$this->layout()->set("voiceplan_id", $this->request->voiceplan_id);
$this->layout()->set("voiceplan", new Voiceplan($this->request->voiceplan_id));
}
}
protected function viewAction() {
$this->layout()->setTemplate("Voiceplanzone/View");
$id = $this->request->id;
if(!is_numeric($id) || $id < 1) {
$this->layout()->setFlash("Tarifzone nicht gefunden.", "error");
$this->redirect("Voiceplan");
}
$zone = new Voiceplanzone($id);
if(!$zone->id) {
$this->layout()->setFlash("Tarifzone nicht gefunden.", "error");
$this->redirect("Voiceplan");
}
$this->layout()->set("zone", $zone);
$pagination = [];
$pagination['start'] = 0;
$pagination['count'] = 20;
$pagination['maxItems'] = 0;
if(is_numeric($this->request->s)) {
$pagination['start'] = intval($this->request->s);
}
$pagination['maxItems'] = VoiceplandestinationModel::count(['voiceplanzone_id' => $id]);
$destinations = VoiceplandestinationModel::search(['voiceplanzone_id' => $id], $pagination);
$this->layout()->set("destinations", $destinations);
$this->layout()->set("pagination", $pagination);
}
protected function editAction() {
$id = $this->request->id;
if(!is_numeric($id) || $id < 1) {
$this->layout()->setFlash("Tarifzone nicht gefunden.", "error");
$this->redirect("Voiceplan");
}
$zone = new Voiceplanzone($id);
if(!$zone->id) {
$this->layout()->setFlash("Tarifzone nicht gefunden.", "error");
$this->redirect("Voiceplan");
}
$this->layout()->set("zone", $zone);
return $this->addAction();
}
protected function saveAction() {
$r = $this->request;
//var_dump($r);exit;
$id = $r->id;
if(is_numeric($id) && $id > 0) {
$mode = "edit";
$zone = new Voiceplanzone($id);
if(!$zone->id) {
$this->layout()->setFlash("Tarifzone nicht gefunden", "error");
$this->redirect("Voiceplan");
}
} else {
$id = false;
$mode = "add";
}
$data["voiceplan_id"] = $r->voiceplan_id;
$data["name"] = $r->name;
$data['purchase_price'] = (str_replace(",",".",$r->purchase_price)) ? str_replace(",",".",$r->purchase_price) : 0;
$data['price'] = (str_replace(",",".",$r->price)) ? str_replace(",",".",$r->price) : 0;
if($r->increment) {
$increments = explode("/",$r->increment);
if(count($increments) != 2) {
$this->layout()->setFlash("Ungültige Taktung", "error");
if($mode == "edit") {
$this->redirect("Voiceplanzone", "edit", ["id" => $id]);
} else {
$this->layout()->set("zone", VoiceplanzoneModel::create($data));
return $this->addAction();
}
}
$data["increment_first"] = $increments[0];
$data["increment"] = $increments[1];
}
if(!$data['name'] || !$data['voiceplan_id']) {
$this->layout()->setFlash("Name und Tarifpaket sind erforderlich", "error");
if($mode == "edit") {
$this->redirect("Voiceplanzone", "edit", ["id" => $id]);
} else {
$this->layout()->set("destination", VoiceplanzoneModel::create($data));
return $this->addAction();
}
}
if($mode == "edit") {
$zone->update($data);
} else {
$zone = VoiceplanzoneModel::create($data);
}
$id = $zone->save();
if(!$id) {
$this->layout()->setFlash("Fehler beim Speichern!", "error");
$this->layout()->set("zone", $zone);
return $this->addAction();
}
$this->redirect("Voiceplan", "view", ["id" => $zone->voiceplan_id]);
}
}
@@ -0,0 +1,134 @@
<?php
class VoiceplanzoneModel {
public $voiceplan_id;
public $name;
public $purchase_price;
public $price;
public $increment_first;
public $increment;
public $create_by;
public $edit_by;
public $create;
public $edit;
public static function create(Array $data) {
$model = new Voiceplanzone();
foreach($data as $field => $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() {
$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
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) {
$items = [];
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$sql = "SELECT * FROM Voiceplanzone
WHERE $where
ORDER BY voiceplan_id,name";
$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 name='$name'";
}
}
//var_dump($filter, $where);exit;
return $where;
}
}