public function updateOperativeMargin() { if ($this->status == WaterRequests::CONFIRMED_STATUS && $this->phase == 2 || $this->status == WaterRequests::COMPLETED_STATUS && $this->phase == 3) { //loop into geoms foreach ($this->geometries as $geom) { $service_area = Geometry::Get_Service_Area_Detailed($geom->id); $city_state = Geometry::Get_City_State($geom->id); if ($service_area == null) { $operative_margin = OperativeMargin::model()->findAll('lower(area)=:area', array(':area' => strtolower($city_state))); $dummy_operative_margin = DummyOperativeMargin::model()->findAll('lower(area)=:area', array(':area' => strtolower($city_state))); if (count($operative_margin) == 0 || count($dummy_operative_margin) == 0) { Yii::log('Manca il margine operativo del comune. area=' . $city_state, CLogger::LEVEL_INFO, 'updateOperativeMargin'); // DEBUG return; } } else { $operative_margin = SAOperativeMargin::model()->findAll('lower(area)=:area', array(':area' => strtolower($service_area['area']))); $dummy_operative_margin = DummySAOperativeMargin::model()->findAll('lower(area)=:area', array(':area' => strtolower($service_area['area']))); if (count($operative_margin) == 0 || count($dummy_operative_margin) == 0) { Yii::log('Manca il margine operativo dell\'area di servizio. area=' . $service_area['area'], CLogger::LEVEL_INFO, 'updateOperativeMargin'); // DEBUG return; } } if ($this->phase == 2) { foreach ($dummy_operative_margin as $dop) { $dop->margin = $dop->margin - $geom->geom_water_demand; $dop->save(); } } else { foreach ($operative_margin as $op) { $op->margin = $op->margin - $geom->geom_water_demand; $op->save(); // it has a parent, release the water from the dummy tables if ($this->parent_wr) { $parent = $this->parent_wr; foreach ($parent->geometries as $g) { $sa = Geometry::Get_Service_Area_Detailed($g->id); $cs = Geometry::Get_City_State($g->id); if (strcmp($service_area, $sa) === 0 && strcmp($city_state, $cs) === 0) { foreach ($dummy_operative_margin as $dop) { $dop->margin = $dop->margin + $geom->geom_water_demand; $dop->save(); } } } } } } } } }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer the ID of the model to be loaded */ public function loadModel($id) { $model = SAOperativeMargin::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }