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;
|
||||
|
||||
Reference in New Issue
Block a user