AddessLink WIP
This commit is contained in:
@@ -256,6 +256,71 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h4>Verknüpfte Adressen</h4>
|
||||
<div class="card">
|
||||
<div class="card-body" id="link-container">
|
||||
|
||||
<table class="table table-striped table-sm">
|
||||
<tr>
|
||||
<th>Typ</th>
|
||||
<th>Firma</th>
|
||||
<th>Vorname</th>
|
||||
<th>Nachname</th>
|
||||
<th>Telefon</th>
|
||||
<th>Mobil</th>
|
||||
<th>Email</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
<?php foreach(['techcontact'] as $type): ?>
|
||||
<?php if(array_key_exists($type, $address->links)): ?>
|
||||
<?php foreach($address->links[$type] as $addr): ?>
|
||||
<tr>
|
||||
<td class="font-weight-bold"><?=__($type)?></td>
|
||||
<td><?=$addr->address->company?></td>
|
||||
<td><?=$addr->address->firstname?></td>
|
||||
<td><?=$addr->address->lastname?></td>
|
||||
<td><?=$addr->address->phone?></td>
|
||||
<td><?=$addr->address->mobile?></td>
|
||||
<td><?=$addr->address->email?></td>
|
||||
<td>
|
||||
<a class="mr-2" href="<?=self::getUrl("Address", "edit", ["id" => $address->id])?>"><i class="far fa-edit" title="Bearbeiten"></i></a>
|
||||
<a href="<?=self::getUrl("Address", "deleteLink", ["id" => $address->id])?>" onclick="if(!confirm('Verknüpgung wirklich löschen?')) return false;" class="text-danger" title="Verknüpfung löschen"><i class="fas fa-xmark-large"></i></a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
|
||||
<?php $linknum = 1; ?>
|
||||
|
||||
<h5>Neue Verknüpfung</h5>
|
||||
<div class="form-group row" id="link-<?=$linknum?>">
|
||||
<div class="col-lg-2"></div>
|
||||
<div class="col-lg-6">
|
||||
<div class="input-group mb-3">
|
||||
<div class="input-group-prepend">
|
||||
<select class="form-control" name="links[<?=$linknum?>][type]">
|
||||
<option value="techcontact">Technischer Kontakt</option>
|
||||
</select>
|
||||
</div>
|
||||
<select class="form-control basicAutoComplete link-autocomplete" autocomplete="off" name="links[<?=$linknum?>][address_id]" id="links_<?=$linknum?>_address_id" data-linknum="<?=$linknum?>" data-url="<?=self::getUrl('Address','api')?>?do=findAddress&autocomplete=1&role=techcontact" placeholder="Name, Kundennummer, ID" data-noresults-text="Keine Suchergebnisse">
|
||||
<option></option>
|
||||
</select>
|
||||
|
||||
<div class="input-group-append">
|
||||
<button type="button" class="btn btn-danger" onclick="clearNewLink(<?=$linknum?>)"><i class="fas fa-xmark-large mr-1"></i> Entfernen</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<div class="form-group row">
|
||||
@@ -344,6 +409,106 @@
|
||||
return true;
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* link autocomplete
|
||||
*/
|
||||
|
||||
$('.link-autocomplete').autoComplete();
|
||||
$('.link-autocomplete').keydown(function() {
|
||||
if(event.keyCode == 13) {
|
||||
event.preventDefault();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* Links autocomplete
|
||||
*/
|
||||
$('.link-autocomplete').on("autocomplete.select", function(evt, item) {
|
||||
autocompleteSelect(evt,item);
|
||||
});
|
||||
|
||||
function autocompleteSelect(evt, item) {
|
||||
if(item && item.value === 0) {
|
||||
$('.link-autocomplete').autoComplete('set', null);
|
||||
return;
|
||||
}
|
||||
|
||||
var match = evt.currentTarget.id.match(/links_(\d+)_address_id/);
|
||||
var link_num = match[1];
|
||||
if(!link_num) {
|
||||
console.log("Couldn't find selected Address");
|
||||
}
|
||||
addLink(Number(link_num) + 1);
|
||||
}
|
||||
|
||||
function addLink(linknum) {
|
||||
if(!linknum) {
|
||||
console.log("no linknum");
|
||||
return false;
|
||||
}
|
||||
|
||||
if($("#links_" + linknum + "_address_id").length) {
|
||||
console.log("gibs scho");
|
||||
return false;
|
||||
}
|
||||
|
||||
var new_link = '<div class="form-group row" id="link-' + linknum + '"> \
|
||||
<label class="col-lg-2 col-form-label" for="links_' + linknum + '_address_id"></label> \
|
||||
<div class="col-lg-6"> \
|
||||
<div class="input-group mb-3"> \
|
||||
<div class="input-group-prepend"> \
|
||||
<select class="form-control" name="links[' + linknum + '][type]"> \
|
||||
<option value="techcontact">Technischer Kontakt</option> \
|
||||
</select> \
|
||||
</div> \
|
||||
<select class="form-control basicAutoComplete link-autocomplete" autocomplete="off" name="links[' + linknum + '][address_id]" id="links_' + linknum + '_address_id" data-linknum="' + linknum + '" data-url="<?=self::getUrl('Address','api')?>?do=findAddress&autocomplete=1" placeholder="Name, Kundennummer, ID" data-noresults-text="Keine Suchergebnisse"> \
|
||||
<option></option> \
|
||||
</select> \
|
||||
<div class="input-group-append"> \
|
||||
<button type="button" class="btn btn-danger" onclick="clearNewLink(' + linknum + ')"><i class="fas fa-xmark-large mr-1"></i> Entfernen</button> \
|
||||
</div> \
|
||||
</div> \
|
||||
</div> \
|
||||
</div>';
|
||||
|
||||
$('#link-container').append(new_link);
|
||||
//$('#links_' + linknum + '_address_id').autocomplete();
|
||||
$('#links_' + linknum + '_address_id').autoComplete();
|
||||
$('#links_' + linknum + '_address_id').keydown(function() {
|
||||
if(event.keyCode == 13) {
|
||||
event.preventDefault();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
$('#links_' + linknum + '_address_id').on("autocomplete.select", function(evt, item) {
|
||||
autocompleteSelect(evt,item);
|
||||
});
|
||||
}
|
||||
|
||||
function clearNewLink(linknum) {
|
||||
if(!$("#link-" + linknum).length) {
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
// only remove is not the only one
|
||||
if($('#link-container').find('div.row').length > 1) {
|
||||
$("#link-" + linknum).remove();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
<?php include(realpath(dirname(__FILE__)."/../../$mfLayoutPackage")."/footer.php"); ?>
|
||||
@@ -58,6 +58,7 @@
|
||||
<option value="customer" <?=(in_array("customer", $filter["addresstype"])) ? "selected='selected'" : ""?>><?=__("customer")?></option>
|
||||
<option value="supplier" <?=(in_array("supplier", $filter["addresstype"])) ? "selected='selected'" : ""?>><?=__("supplier")?></option>
|
||||
<option value="contact" <?=(in_array("contact", $filter["addresstype"])) ? "selected='selected'" : ""?>><?=__("contact")?></option>
|
||||
<option value="techcontact" <?=(in_array("techcontact", $filter["addresstype"])) ? "selected='selected'" : ""?>><?=__("techcontact")?></option>
|
||||
</select>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
@@ -4,6 +4,7 @@ class Address extends mfBaseModel {
|
||||
protected $forcestr = ['street','company','zip','phone','fax','mobile','note'];
|
||||
private $parent;
|
||||
private $childaddresses;
|
||||
private $links;
|
||||
private $types;
|
||||
private $attributes;
|
||||
private $permissions;
|
||||
@@ -128,6 +129,19 @@ class Address extends mfBaseModel {
|
||||
return $spin;
|
||||
}
|
||||
|
||||
public function deleteLinks() {
|
||||
$links = $this->getProperty("links");
|
||||
//var_dump($links);exit;
|
||||
if(is_array($links) && count($links)) {
|
||||
foreach($links as $type => $linktypes) {
|
||||
//var_dump($type, $linktypes);exit;
|
||||
foreach($linktypes as $link) {
|
||||
//var_dump($link);exit;
|
||||
$link->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
@@ -166,6 +180,30 @@ class Address extends mfBaseModel {
|
||||
$this->childaddresses = AddressModel::search(['parent' => $this->id]);
|
||||
return $this->childaddresses;
|
||||
}
|
||||
/*
|
||||
if($name == "links_to") {
|
||||
$links = AddressLinkModel::search(['address_id' => $this->id]);
|
||||
foreach($links as $link) {
|
||||
if(!array_key_exists($link->type, $this->links_to)) {
|
||||
$this->links_to[$link->type] = [];
|
||||
}
|
||||
$this->links_to[$link->type][] = $link->linked_to;
|
||||
}
|
||||
return $this->links_to;
|
||||
}*/
|
||||
|
||||
if($name == "links") {
|
||||
$links = AddressLinkModel::search(['origin_address_id' => $this->id]);
|
||||
//var_dump($links);exit;
|
||||
foreach($links as $link) {
|
||||
if(!array_key_exists($link->type, $this->links)) {
|
||||
$this->links[$link->type] = [];
|
||||
}
|
||||
$this->links[$link->type][] = $link;
|
||||
//var_dump($this->links);exit;
|
||||
}
|
||||
return $this->links;
|
||||
}
|
||||
|
||||
$classname = ucfirst($name);
|
||||
$idfield = $name."_id";
|
||||
|
||||
@@ -104,7 +104,7 @@ class AddressController extends mfBaseController {
|
||||
protected function saveAction() {
|
||||
$r = $this->request;
|
||||
$id = $r->id;
|
||||
//var_dump($r);exit;
|
||||
//var_dump($r->get());exit;
|
||||
if(is_numeric($id) && $id > 0) {
|
||||
$mode = "edit";
|
||||
$address = new Address($id);
|
||||
@@ -228,6 +228,24 @@ class AddressController extends mfBaseController {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$address->deleteLinks();
|
||||
//var_dump($r->links);exit;
|
||||
if(is_array($r->links) && count($r->links)) {
|
||||
//var_dump($r->links);exit;
|
||||
foreach($r->links as $linknum => $link) {
|
||||
if(!$link['type'] || !$link['address_id']) {
|
||||
continue;
|
||||
}
|
||||
$l = AddressLinkModel::create([
|
||||
'origin_address_id' => $new_id,
|
||||
'type' => $link['type'],
|
||||
'address_id' => $link['address_id']
|
||||
]);
|
||||
$l->save();
|
||||
}
|
||||
}
|
||||
|
||||
$this->layout()->setFlash("Adresse erfolgreich gespeichert.", "success");
|
||||
$this->redirect("Address", "Edit", ['id' => $new_id]);
|
||||
}
|
||||
@@ -287,6 +305,12 @@ class AddressController extends mfBaseController {
|
||||
$role = "billing";
|
||||
$po = 0;
|
||||
}
|
||||
if($this->request->role == "techcontact") {
|
||||
$role = "techcontact";
|
||||
$po = 0;
|
||||
}
|
||||
|
||||
$this->log->debug(print_r($this->request->get(),true));
|
||||
|
||||
$addresses = [];
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ class AddressModel {
|
||||
$res = $db->select("Address", "*", "$where ORDER BY company, lastname, firstname, zip, city LIMIT 1");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new Voicenumber($data);
|
||||
$item = new Address($data);
|
||||
if($item->id) {
|
||||
return $item;
|
||||
} else {
|
||||
|
||||
32
application/AddressLink/AddressLink.php
Normal file
32
application/AddressLink/AddressLink.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
class AddressLink extends mfBaseModel {
|
||||
private $address;
|
||||
private $origin;
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
|
||||
if(!$this->id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if($name == "origin") {
|
||||
$this->origin = new Address($this->origin_address_id);
|
||||
return $this->origin;
|
||||
}
|
||||
|
||||
$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;
|
||||
}
|
||||
}
|
||||
131
application/AddressLink/AddressLinkModel.php
Normal file
131
application/AddressLink/AddressLinkModel.php
Normal file
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
|
||||
class AddressLinkModel {
|
||||
public $address_id;
|
||||
public $origin_address_id;
|
||||
public $type;
|
||||
|
||||
public $create_by = null;
|
||||
public $edit_by = null;
|
||||
public $create = null;
|
||||
public $edit = null;
|
||||
|
||||
public static function create(Array $data) {
|
||||
$model = new AddressLink();
|
||||
|
||||
foreach($data as $field => $value) {
|
||||
if(property_exists(get_called_class(), $field)) {
|
||||
$model->$field = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
|
||||
if(!is_numeric($model->create_by) && !$model->create_by) {
|
||||
$model->create_by = $me->id;
|
||||
}
|
||||
if(!is_numeric($model->edit_by) && !$model->edit_by) {
|
||||
$model->edit_by = $me->id;
|
||||
}
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
public static function getFirst($filter = null) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("AddressLink", "*", "$where ORDER BY address_id,`create`,origin_address_idLIMIT 1");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new AddressLink($data);
|
||||
if($item->id) {
|
||||
return $item;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function getAll() {
|
||||
$items = [];
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$res = $db->select("AddressLink", "*", "1=1 ORDER BY address_id,`create`,origin_address_id");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new AddressLink($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
|
||||
}
|
||||
|
||||
public static function count($filter) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("AddressLink", "COUNT(*) as cnt", "$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, $limit = false) {
|
||||
$items = [];
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
|
||||
$sql = "SELECT * FROM AddressLink WHERE $where ORDER BY address_id,`create`,origin_address_id";
|
||||
|
||||
if(is_array($limit) && count($limit)) {
|
||||
if(is_numeric($limit['start']) && is_numeric($limit['count'])) {
|
||||
$sql .= " LIMIT ".$limit['start'].", ".$limit['count'];
|
||||
} elseif(is_numeric($count)) {
|
||||
$sql .= " LIMIT ".$limit['count'];
|
||||
}
|
||||
}
|
||||
|
||||
mfLoghandler::singleton()->debug($sql);
|
||||
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new AddressLink($data);
|
||||
}
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
private function getSqlFilter($filter) {
|
||||
$where = "1=1 ";
|
||||
|
||||
//var_dump($filter);exit;
|
||||
if(array_key_exists("address_id", $filter)) {
|
||||
$address_id = $filter["address_id"];
|
||||
if(is_numeric($address_id)) {
|
||||
$where .= " AND address_id=$address_id";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("origin_address_id", $filter)) {
|
||||
$origin_address_id = $filter["origin_address_id"];
|
||||
if(is_numeric($origin_address_id)) {
|
||||
$where .= " AND origin_address_id=$origin_address_id";
|
||||
}
|
||||
}
|
||||
|
||||
return $where;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user