/** * 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 string $id the identifier of the model to be loaded */ public function loadModel($id) { $model = WaterRequestFormulas::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public function calculateWaterDemand($geom = null) { $zone = $this->zone_name; while ($zone != null) { $formula = WaterRequestFormulas::model()->find('zone=:zone', array(':zone' => $zone)); if ($formula) { break; } $zone = Zones::parentZone($zone); } //Yii::log('ctype_digit='.print_r(ctype_digit($geom_id),true).' geom_id='.$geom_id , CLogger::LEVEL_INFO, 'calculateWaterDemand'); // DEBUG if ($geom == null) { $comuni = Geometry::Get_City_State($this->wr_geometry_id); } else { $comuni = Geometry::Get_City_State_ByWKT($geom); } /* if(!ctype_digit($geom_id)){ $comuni = Geometry::Get_City_State_ByWKT($geom_id); }else{ $comuni = Geometry::Get_City_State($this->wr_geometry_id); }*/ if (count($comuni)) { $city_state = $comuni[0]['nome']; } else { Yii::log('non trovo il comune. geom_id=' . $geom, CLogger::LEVEL_INFO, 'calculateWaterDemand'); // DEBUG $city_state = 'Pisa'; } $water_supply = WaterSupply::model()->find('lower(city_state)=:city_state', array(':city_state' => strtolower($city_state))); if (!$water_supply) { Yii::log('Manca la WaterSupply. $city_state=' . $city_state, CLogger::LEVEL_INFO, 'calculateWaterDemand'); // DEBUG return -1; } $dg = $water_supply->daily_maximum_water_supply; $da = $water_supply->yearly_average_water_supply; $fformula = str_ireplace(array('ae', 'dg', 'da'), array($this->pe, $dg, $da), $formula->formula); //TODO: mettere nel config il valore delle stringe ae, dg e da $ret = Math::safe_eval($fformula); if (is_numeric($ret)) { return $ret; } return -1; }
/** * Returns the formula associated with the area */ public function getFormula() { $formula = null; $zone = $this->name; while ($zone != null) { $formula = WaterRequestFormulas::model()->find('zone=:zone', array(':zone' => $zone)); if ($formula) { break; } $zone = Zones::parentZone($zone); } return $formula; }