Can now save Network Roles
This commit is contained in:
103
application/NetworkAddress/NetworkAddressController.php
Normal file
103
application/NetworkAddress/NetworkAddressController.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
class NetworkAddressController 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 saveAction() {
|
||||
$r = $this->request;
|
||||
|
||||
if(!is_array($r->roles)) {
|
||||
$this->redirect("Network");
|
||||
}
|
||||
if(!$r->network_id) {
|
||||
$this->redirect("Network");
|
||||
}
|
||||
$network_id = $r->network_id;
|
||||
|
||||
$network = new Network($network_id);
|
||||
if(!$network->id) {
|
||||
$this->layout()->setFlash("Netzgebiet nicht gefunden.", "error");
|
||||
$this->redirect("Network");
|
||||
}
|
||||
|
||||
foreach($r->roles as $address_id => $new_roles) {
|
||||
|
||||
$address = new Address($address_id);
|
||||
if(!$address->id) {
|
||||
$this->layout()->setFlash("Person/Firma nicht gefunden.", "error");
|
||||
$this->redirect("Network");
|
||||
}
|
||||
|
||||
foreach(TT_NETWORK_ROLES as $rolestring) {
|
||||
if(in_array($rolestring, $new_roles)) {
|
||||
// check if role exists
|
||||
if(NetworkAddressModel::search(['network_id' => $network, 'address_id' => $address_id, 'addresstype' => [$rolestring]])) {
|
||||
continue; // role exists
|
||||
} else {
|
||||
$na = NetworkAddressModel::create(['network_id' => $network_id, 'address_id' => $address_id, 'type' => $rolestring]);
|
||||
$na->save();
|
||||
}
|
||||
// role does not exist, create it
|
||||
} else {
|
||||
// not in new_roles, delete (if exists)
|
||||
$na = NetworkAddressModel::getFirst(['network_id' => $network, 'address_id' => $address_id, 'addresstype' => [$rolestring]]);
|
||||
if($na) {
|
||||
$na->delete();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
$this->redirect("Network");
|
||||
}
|
||||
|
||||
protected function createAction() {
|
||||
//var_dump($this->request);
|
||||
//var_dump($r->roles);exit;
|
||||
|
||||
$r = $this->request;
|
||||
//var_dump($r->roles);exit;
|
||||
if(!is_array($r->roles)) {
|
||||
$this->redirect("Network");
|
||||
}
|
||||
if(!$r->network_id) {
|
||||
$this->redirect("Network");
|
||||
}
|
||||
$network_id = $r->network_id;
|
||||
$network = new Network($network_id);
|
||||
if(!$network->id) {
|
||||
$this->log->info("Netzgebiet nicht gefunden (".$network_id.")");
|
||||
$this->layout()->setFlash("Netzgebiet nicht gefunden.", "error");
|
||||
$this->redirect("Network");
|
||||
}
|
||||
|
||||
if(!$r->address_id) {
|
||||
$this->redirect("Network");
|
||||
}
|
||||
$address_id = $r->address_id;
|
||||
$address = new Address($address_id);
|
||||
if(!$address->id) {
|
||||
$this->log->info("Person/Firma nicht gefunden (".$address_id.")");
|
||||
$this->layout()->setFlash("Person/Firma nicht gefunden.", "error");
|
||||
$this->redirect("Network");
|
||||
}
|
||||
|
||||
foreach($r->roles as $type) {
|
||||
$na = NetworkAddressModel::create(['network_id' => $network_id, 'address_id' => $address_id, 'type' => $type]);
|
||||
$na->save();
|
||||
}
|
||||
|
||||
$this->redirect("Network");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user