Moved Building unit count to Building Model
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
class Building extends mfBaseModel {
|
||||
protected $forcestr = ['street','zip','phone','email','note'];
|
||||
|
||||
private $in_after_save;
|
||||
private $network;
|
||||
private $networksection;
|
||||
private $pop;
|
||||
@@ -29,7 +30,12 @@ class Building extends mfBaseModel {
|
||||
}
|
||||
|
||||
protected function afterSave() {
|
||||
if($this->in_after_save) return true;
|
||||
$this->in_after_save++;
|
||||
|
||||
$this->resetProperties();
|
||||
|
||||
$this->in_after_save--;
|
||||
}
|
||||
|
||||
public function resetProperties() {
|
||||
@@ -43,6 +49,18 @@ class Building extends mfBaseModel {
|
||||
$this->files = null;
|
||||
}
|
||||
|
||||
public function updateUnitCount() {
|
||||
if(!$this->id) return true;
|
||||
|
||||
$unit_count = TerminationModel::count(["building_id" => $this->id]);
|
||||
if($this->units != $unit_count) {
|
||||
$this->units = $unit_count;
|
||||
$this->save();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getNewObjectCode() {
|
||||
if(!$this->zip) {
|
||||
return false;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
class Termination extends mfBaseModel {
|
||||
protected $forcestr = ['phone','email','note'];
|
||||
|
||||
private $in_after_save = 0;
|
||||
private $building;
|
||||
private $status;
|
||||
private $lineworker;
|
||||
@@ -14,7 +15,16 @@ class Termination extends mfBaseModel {
|
||||
private $creator;
|
||||
private $editor;
|
||||
|
||||
|
||||
protected function afterSave() {
|
||||
if($this->in_after_save) return true;
|
||||
$this->in_after_save++;
|
||||
|
||||
if($this->building_id) {
|
||||
$this->getProperty("building")->updateUnitCount();
|
||||
}
|
||||
|
||||
$this->in_after_save--;
|
||||
}
|
||||
|
||||
public function getAddress($singelLine = false) {
|
||||
if(!$this->id) {
|
||||
|
||||
@@ -69,10 +69,10 @@ class TerminationController extends mfBaseController {
|
||||
}
|
||||
|
||||
// increment Building::units
|
||||
if(is_numeric($building->units)) {
|
||||
/*if(is_numeric($building->units)) {
|
||||
++$building->units;
|
||||
$building->save();
|
||||
}
|
||||
}*/
|
||||
|
||||
$this->layout()->setFlash("Anschluss gespeichert.", "success");
|
||||
$this->redirect("Building", "Index", [], "building=".$term->building_id);
|
||||
@@ -132,10 +132,11 @@ class TerminationController extends mfBaseController {
|
||||
|
||||
|
||||
$term->delete();
|
||||
if($building->units) {
|
||||
$building->updateUnitCount();
|
||||
/*if($building->units) {
|
||||
--$building->units;
|
||||
$building->save();
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
$this->layout()->setFlash("Anschluss gelöscht", "success");
|
||||
|
||||
Reference in New Issue
Block a user