Moved Building unit count to Building Model

This commit is contained in:
Frank Schubert
2024-01-05 17:45:50 +01:00
parent 7646345779
commit 3591da6729
3 changed files with 34 additions and 5 deletions

View File

@@ -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;