Finished Addressattribute
This commit is contained in:
@@ -25,7 +25,7 @@
|
||||
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h4 class="header-title mb-4"><?=($address->id) ? "Person/Firma bearbeiten" : "Neue Person/Firma"?></h4>
|
||||
<h4 class="header-title mb-2"><?=($address->id) ? "Person/Firma bearbeiten" : "Neue Person/Firma"?></h4>
|
||||
|
||||
<form class="form-horizontal" method="post" action="<?=self::getUrl("Address", "save")?>">
|
||||
<div class="card">
|
||||
@@ -142,6 +142,18 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h4 class="header-title mb-2">Zusatzdaten</h4>
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-2 col-form-label" for="rtrcode">RTR Betreiber ID</label>
|
||||
<div class="col-lg-10">
|
||||
<input class="form-control" name="attributes[rtrcode]" id="rtrcode" value="<?=$address->attributes['rtrcode']->value?>">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<div class="form-group row">
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
class Address extends mfBaseModel {
|
||||
protected $forcestr = ['company','zip','phone','fax','mobile','note'];
|
||||
private $types;
|
||||
|
||||
private $attributes;
|
||||
|
||||
public function getFullName() {
|
||||
// Assumes "Firma1 Firma2" or "firstname lastname" as readable form
|
||||
@@ -44,6 +44,17 @@ class Address extends mfBaseModel {
|
||||
return $this->types;
|
||||
}
|
||||
|
||||
if($name == "attributes") {
|
||||
$attribs = AddressattributeModel::search(['address_id' => $this->id]);
|
||||
if(count($attribs)) {
|
||||
$this->attributes = [];
|
||||
foreach($attribs as $a) {
|
||||
$this->attributes[$a->name] = $a;
|
||||
}
|
||||
}
|
||||
return $this->attributes;
|
||||
}
|
||||
|
||||
$classname = ucfirst($name);
|
||||
$idfield = $name."_id";
|
||||
$this->$name = new $classname($this->$idfield);
|
||||
|
||||
@@ -42,7 +42,7 @@ class AddressController extends mfBaseController {
|
||||
protected function saveAction() {
|
||||
$r = $this->request;
|
||||
$id = $r->id;
|
||||
|
||||
//var_dump($r);
|
||||
if(is_numeric($id) && $id > 0) {
|
||||
$mode = "edit";
|
||||
$address = new Address($id);
|
||||
@@ -94,7 +94,7 @@ class AddressController extends mfBaseController {
|
||||
foreach($address->types as $existing_type) {
|
||||
//var_dump($existing_type);
|
||||
//var_dump($new_types);
|
||||
echo $existing_type->type;
|
||||
//echo $existing_type->type;
|
||||
if(!in_array($existing_type->type, $new_types)) {
|
||||
$existing_type->delete();
|
||||
} else {
|
||||
@@ -108,7 +108,19 @@ class AddressController extends mfBaseController {
|
||||
$type_object = AddresstypeModel::create(['address_id' => $address->id, 'type' => $type]);
|
||||
$type_object->save();
|
||||
$address->types[$type] = $type_object;
|
||||
}
|
||||
}
|
||||
|
||||
$attribs = $r->attributes;
|
||||
//var_dump($attribs);exit;
|
||||
if(is_array($attribs) && count($attribs)) {
|
||||
foreach($attribs as $atttrib => $value) {
|
||||
$aa = AddressattributeModel::getFirst(["address_id" => $new_id, "name" => $attrib]);
|
||||
if(!$aa) {
|
||||
$aa = AddressattributeModel::create(["address_id" => $new_id, "name" => $attrib]);
|
||||
}
|
||||
$aa->value = $value;
|
||||
$aa->save();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
5
application/Addressattribute/Addressattribute.php
Normal file
5
application/Addressattribute/Addressattribute.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
class Addressattribute extends mfBaseModel {
|
||||
|
||||
}
|
||||
124
application/Addressattribute/AddressattributeModel.php
Normal file
124
application/Addressattribute/AddressattributeModel.php
Normal file
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
|
||||
class AddressattributeModel {
|
||||
public $address_id = null;
|
||||
public $name = null;
|
||||
public $value = null;
|
||||
|
||||
public $create_by = null;
|
||||
public $edit_by = null;
|
||||
public $create = null;
|
||||
public $edit = null;
|
||||
|
||||
public static function create(Array $data) {
|
||||
$model = new Addressattribute();
|
||||
|
||||
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 getOne($idOrFilter) {
|
||||
if(!is_numeric($id) || !$id) {
|
||||
throw new Exception("Invalid number", 400);
|
||||
}
|
||||
$item = [];
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$res = $db->select("Addressattribute", "*", "id=$id LIMIT 1");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new Addressattribute($data);
|
||||
}
|
||||
return $item;
|
||||
}
|
||||
|
||||
public static function getAll($filter = false) {
|
||||
$items = [];
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$res = $db->select("Addressattribute", "*", "1=1 ORDER BY address_id ASC, name");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new Addressattribute($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
|
||||
public static function getFirst($filter) {
|
||||
$db = FronkDB::singleton();
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT Addressattribute.* FROM Addressattribute
|
||||
WHERE $where
|
||||
ORDER BY address_id ASC, name";
|
||||
//var_dump($sql);
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new Addressattribute($data);
|
||||
if($item->id) {
|
||||
return $item;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
|
||||
public static function search($filter) {
|
||||
$items = [];
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT Addressattribute.* FROM Addressattribute
|
||||
WHERE $where
|
||||
ORDER BY address_id ASC, name";
|
||||
//var_dump($sql);
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new Addressattribute($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
|
||||
private function getSqlFilter($filter) {
|
||||
$where = "1=1 ";
|
||||
|
||||
if(array_key_exists("address_id", $filter)) {
|
||||
$address_id = $filter['address_id'];
|
||||
if(!is_numeric($address_id) || !$address_id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$where .= " AND address_id=$address_id";
|
||||
}
|
||||
|
||||
if(array_key_exists("name", $filter)) {
|
||||
$name = FronkDB::singleton()->escape($filter['name']);
|
||||
if($name) {
|
||||
$where .= " AND `name`='$name'";
|
||||
}
|
||||
}
|
||||
|
||||
return $where;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user