Beispiel #1
0
 /**
  * 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 = WaterSupply::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;
 }
 /**
  * Popup form to insert a new Geometry with Zone or add a Zone to an existing Geometry
  * @param string $wr_id
  * @param string $type
  * @param string $geom_or_id
  * @param string $zone_id
  * @throws CHttpException
  */
 public function actionPopup($wr_id, $type, $geom_or_id, $zone_id = null)
 {
     $wr_model = WaterRequests::model()->findByPk($wr_id);
     if ($wr_model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     if (!Yii::app()->user->checkAccess('updateWaterRequest', array('waterRequest' => $wr_model))) {
         echo Yii::t('waterrequest', 'You are not authorized to edit');
         Yii::app()->end();
     }
     //Yii::log('wr_id='.$wr_id.' type='.$type.' geom_or_id='.$geom_or_id.' $zone_id='.$zone_id, CLogger::LEVEL_INFO, 'popup');
     if ($type == 'update_geom') {
         $geom_id = $_POST['geom_id'];
         $geom_model = WaterRequestGeometries::model()->findByPk($geom_id);
         if (!$geom_model) {
             throw new CHttpException(404, 'The requested page does not exist.');
         }
         //Yii::app()->clientScript->scriptMap=array('jquery.yiiactiveform.js'=>false,'jquery.uniform.js'=>false,'jquery.js'=>false,);
         $this->renderPartial('/waterRequestGeometries/_popupeditgeom', array('model' => $geom_model), false, true);
         Yii::app()->end();
         return;
     }
     $geom_already_exist = false;
     if ($type == 'zone') {
         $geom_id = $geom_or_id;
         $geom_model = WaterRequestGeometries::model()->findByPk($geom_id);
         if ($geom_model) {
             $geom_already_exist = true;
         }
     }
     if (!$geom_already_exist) {
         // If geometry is outside working area, fail the popup.
         $city_state = Geometry::Get_City_State($geom_or_id);
         if ($city_state == null) {
             Yii::log('Comune non trovato. $g=' . $geom_or_id, CLogger::LEVEL_INFO, 'actionPopup');
             // DEBUG
             $this->renderPartial('_popup_fail');
             Yii::app()->end();
         }
         $water_supply = WaterSupply::model()->find('lower(city_state)=:city_state', array(':city_state' => strtolower($city_state)));
         if (!$water_supply) {
             Yii::log('Disegnato fuori. $city_state=' . $city_state, CLogger::LEVEL_INFO, 'actionPopup');
             // DEBUG
             $this->renderPartial('_popup_fail');
             Yii::app()->end();
         }
         $geom_model = new WaterRequestGeometries();
         $geom_model->wr_id = $wr_id;
     }
     $zone_model = null;
     if ($zone_id) {
         $zone_model = WaterRequestGeometryZones::model()->findByPk($zone_id);
     }
     if (!$zone_model) {
         $zone_model = new WaterRequestGeometryZones();
     }
     //Yii::app()->clientScript->scriptMap=array('jquery.yiiactiveform.js'=>false,'jquery.uniform.js'=>false,'jquery.js'=>false,);
     $this->renderPartial('_popupform', array('model' => $zone_model, 'geom_model' => $geom_model, 'geom_already_exist' => $geom_already_exist), false, true);
     Yii::app()->end();
 }