Added Voicenumberblock
This commit is contained in:
@@ -80,7 +80,7 @@ class BuildingController extends mfBaseController {
|
||||
$building_search[$name] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$pagination['maxItems'] = BuildingModel::count($building_search);
|
||||
foreach(BuildingModel::search($building_search, $pagination) as $b) {
|
||||
if(!array_key_exists($b->id, $buildings)) {
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
class Voicenumberblock extends mfBaseModel {
|
||||
protected $forcestr = ['comment'];
|
||||
private $number_first;
|
||||
private $number_last;
|
||||
private $files;
|
||||
private $numbers;
|
||||
|
||||
private function getFullNumber($last = false) {
|
||||
if($last) {
|
||||
$number = $this->countrycode.$this->areacode.$this->last;
|
||||
} else {
|
||||
$number = $this->countrycode.$this->areacode.$this->first;
|
||||
}
|
||||
|
||||
return $number;
|
||||
|
||||
}
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
|
||||
if($name == "files") {
|
||||
$this->files = VoiceblocknumberFileModel::search(["voicenumberblock_id" => $this->id]);
|
||||
return $this->files;
|
||||
}
|
||||
|
||||
if($name == "numbers") {
|
||||
$this->numbers = VoicenumberModel::search(["voicenumberblock_id" => $this->id]);
|
||||
return $this->numbers;
|
||||
}
|
||||
|
||||
if($name == "number_first") {
|
||||
return $this->getFullNumber();
|
||||
}
|
||||
|
||||
if($name == "number_last") {
|
||||
return $this->getFullNumber(true);
|
||||
}
|
||||
|
||||
$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,122 @@
|
||||
<?php
|
||||
|
||||
class VoicenumberblockController 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 indexAction() {
|
||||
$this->layout()->setTemplate("Voicenumberblock/Index");
|
||||
|
||||
$filter = [];
|
||||
if(is_array($this->request->filter)) {
|
||||
$filter = $this->request->filter;
|
||||
}
|
||||
|
||||
$this->layout->set("filter", $filter);
|
||||
|
||||
if($filter) {
|
||||
$filter = $this->getPreparedFilter($filter);
|
||||
}
|
||||
|
||||
// pagination defaults
|
||||
$pagination = [];
|
||||
$pagination['start'] = 0;
|
||||
$pagination['count'] = 20;
|
||||
$pagination['maxItems'] = 0;
|
||||
|
||||
if(is_numeric($this->request->s)) {
|
||||
$pagination['start'] = intval($this->request->s);
|
||||
}
|
||||
|
||||
$pagination['maxItems'] = VoicenumberblockModel::count($filter);
|
||||
$blocks = VoicenumberblockModel::search($filter, $pagination);
|
||||
|
||||
|
||||
$this->layout()->set("blocks", $blocks);
|
||||
$this->layout()->set("pagination", $pagination);
|
||||
|
||||
}
|
||||
|
||||
private function getPreparedFilter($filter) {
|
||||
return $filter;
|
||||
}
|
||||
|
||||
protected function addAction() {
|
||||
$this->layout()->setTemplate("Voicenumberblock/Form");
|
||||
}
|
||||
|
||||
protected function editAction() {
|
||||
$id = $this->request->id;
|
||||
if(!is_numeric($id) || !$id) {
|
||||
$this->layout()->setFlash("Rufnummernblock nicht gefunden", "error");
|
||||
$this->redirect("Voicenumberblock");
|
||||
}
|
||||
|
||||
$block = new Voicenumberblock($id);
|
||||
if($block->id != $id) {
|
||||
$this->layout()->setFlash("Rufnummernblock nicht gefunden", "error");
|
||||
$this->redirect("Voicenumberblock");
|
||||
}
|
||||
|
||||
$this->layout()->set("block", $block);
|
||||
return $this->addAction();
|
||||
}
|
||||
|
||||
protected function saveAction() {
|
||||
$r = $this->request;
|
||||
$id = $r->id;
|
||||
//var_dump($r);exit;
|
||||
if(is_numeric($id) && $id > 0) {
|
||||
$mode = "edit";
|
||||
$block = new Voicenumberblock($id);
|
||||
if(!$block->id) {
|
||||
$this->layout()->setFlash("Rufnummernblock nicht gefunden", "error");
|
||||
$this->redirect("Voicenumberblock");
|
||||
}
|
||||
} else {
|
||||
$mode = "add";
|
||||
}
|
||||
|
||||
if(!$r->countrycode ||!$r->areacode || !$r->first || !$r->last) {
|
||||
$this->layout()->setFlash("Bitte alle benötigten Felder ausfüllen!", "error");
|
||||
$this->layout()->set("block", $r);
|
||||
return $this->add();
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data['countrycode'] = $r->countrycode;
|
||||
$data['areacode'] = $r->areacode;
|
||||
$data['first'] = $r->first;
|
||||
$data['last'] = $r->last;
|
||||
$data['comment'] = $r->comment;
|
||||
$data['edit_by'] = $this->me->id;
|
||||
|
||||
if($mode == "add") {
|
||||
$data['create_by'] = 1;
|
||||
$block = VoicenumberblockModel::create($data);
|
||||
} else {
|
||||
$block->update($data);
|
||||
}
|
||||
|
||||
$new_id = $block->save();
|
||||
if(!$new_id) {
|
||||
$this->layout()->setFlash("Fehler beim Speichern", "error");
|
||||
$this->layout()->set("block", $block);
|
||||
return $this->addAction();
|
||||
}
|
||||
|
||||
$this->layout()->setFlash("Rufnummernblock erfolgreich gespeichert.", "success");
|
||||
$this->redirect("Voicenumberblock");
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
<?php
|
||||
|
||||
class VoicenumberblockModel {
|
||||
public $countrycode;
|
||||
public $areacode;
|
||||
public $first;
|
||||
public $last;
|
||||
public $comment;
|
||||
|
||||
public $create_by;
|
||||
public $edit_by;
|
||||
public $create;
|
||||
public $edit;
|
||||
|
||||
|
||||
public static function create(Array $data) {
|
||||
$model = new Voicenumberblock();
|
||||
|
||||
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("Voicenumberblock", "*");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new Voicenumberblock($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
|
||||
}
|
||||
|
||||
public static function getFirst() {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("Voicenumberblock", "*", "$where ORDER BY countrycode, areacode, first, last");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new Voicenumberblock($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 Voicenumberblock
|
||||
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);
|
||||
//mfLoghandler::singleton()->log->debug($where);
|
||||
$res = $db->select("Voicenumberblock", "*", "$where ORDER BY countrycode, areacode, first, last");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new Voicenumberblock($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=$countrycode";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("areacode", $filter)) {
|
||||
$areacode = $filter['areacode'];
|
||||
if(is_numeric($areacode)) {
|
||||
$where .= " AND areacode=$areacode";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("first", $filter)) {
|
||||
$first = $filter['first'];
|
||||
if(is_numeric($first)) {
|
||||
$where .= " AND first=$first";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("last", $filter)) {
|
||||
$last = $filter['last'];
|
||||
if(is_numeric($last)) {
|
||||
$where .= " AND last=$last";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("number", $filter)) {
|
||||
$number = $filter['number'];
|
||||
if(is_numeric($number)) {
|
||||
$where .= " AND first <= $number AND last >= $number";
|
||||
}
|
||||
}
|
||||
|
||||
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