Ejemplo n.º 1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     if (!Yii::app()->user->checkAccess('giveEvaluation')) {
         //throw new CHttpException(403,Yii::t('http_status', '403'));
         Yii::app()->user->setState('redirect', Yii::app()->request->requestUri);
         $this->redirect(array('/site/login'));
     }
     $model_quality = new WaterQualityOpinions();
     $model_fault = new WaterFaultOpinions();
     if (isset($_POST) && !empty($_POST)) {
         var_dump($_POST);
         if (empty($_POST['geom'])) {
             Yii::app()->user->setFlash('warning', 'ATTENTION: set a point on the map.');
         } else {
             if ($_POST['geom_type'] == 1) {
                 if (!empty($_POST['qualities_list'])) {
                     $model = new WaterQualityOpinions();
                     $model->quality = $_POST['qualities_list'];
                     //$model->geom = new CDbExpression(Geometry::Transform(Geometry::ST_GeomFromText($_POST['geom'])));
                     $model->geom = new CDbExpression(Geometry::Transform(Geometry::ST_GeomFromText($_POST['geom']), 4326));
                     $model->username = Yii::app()->user->id;
                     if ($model->save()) {
                         $this->redirect(array('view'));
                     } else {
                         Yii::app()->user->setFlash('error', 'An error occurred in data storage. Please try again.');
                     }
                 } else {
                     Yii::app()->user->setFlash('warning', 'ATTENTION: to point out the quality of the water service.');
                 }
             } else {
                 if (!empty($_POST['faults_list'])) {
                     $model = new WaterFaultOpinions();
                     $model->fault = $_POST['faults_list'];
                     //$model->geom = new CDbExpression(Geometry::Transform(Geometry::ST_GeomFromText($_POST['geom'])));
                     $model->geom = new CDbExpression(Geometry::Transform(Geometry::ST_GeomFromText($_POST['geom']), 4326));
                     $model->username = Yii::app()->user->id;
                     if ($model->save()) {
                         $this->redirect(array('view'));
                     } else {
                         Yii::app()->user->setFlash('error', 'An error occurred in data storage. Please try again.');
                     }
                 } else {
                     Yii::app()->user->setFlash('warning', 'ATTENTION: to point out the fault of the water network.');
                 }
             }
         }
     }
     $this->render('create');
 }
Ejemplo n.º 2
0
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id the ID of the model to be updated
  */
 public function actionUpdate($id)
 {
     $model = $this->loadModel($id);
     if ($this->deleteIfOrphan($model)) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     // TODO: si potrebbe fare una "getParentWr($model, $destroyOrphan=true)" per evitare la doppia findByPk
     $wr_model = WaterRequests::model()->findByPk($model->wr_id);
     if (!Yii::app()->user->checkAccess('updateWaterRequest', array('waterRequest' => $wr_model))) {
         throw new CHttpException(403, Yii::t('http_status', '403'));
     }
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['WaterRequestGeometries'])) {
         $model->attributes = $_POST['WaterRequestGeometries'];
         $model->geom = new CDbExpression(Geometry::Transform(Geometry::ST_GeomFromText($_POST['WaterRequestGeometries']['geom'])));
         $model->altitude = null;
         if ($model->save()) {
             echo 'ok';
         }
         //$this->redirect(array('view','id'=>$model->id));
     }
     //$this->render('update',array('model'=>$model,));
 }
Ejemplo n.º 3
0
 public static function save_geom($wkt, $wr_id, $proj = 3003)
 {
     $model = new WaterRequestGeometries();
     $model->wr_id = $wr_id;
     $model->name = 'uploaded';
     $model->geom = new CDbExpression(Geometry::Transform(Geometry::ST_GeomFromText($wkt, $proj), Yii::app()->params['geoserver']['water_request_geometries_srid']));
     return array('result' => $model->save(), 'newid' => $model->id);
 }
Ejemplo n.º 4
0
    /**
     * Calculate service area holding the geometry
     * @param string $wkt Geometria in WellKnownText format
     * @return array the result set (each array element represents a row of data). An empty array will be returned if the result contains no row. NULL is returned if ID is null.
     */
    public static function Get_Service_Area_ByWKT($wkt)
    {
        $wkt_geom = Geometry::Transform(Geometry::ST_GeomFromText($wkt), Yii::app()->params['geoserver']['service_areas_layer_srid']);
        //Yii::log(print_r($wkt_geom, true) , CLogger::LEVEL_INFO, 'Get_City_State_ByWKT');  // DEBUG
        //return;
        $connection = Yii::app()->db;
        $sql = '
		SELECT service_areas.gid, service_areas.area, service_areas.desc_area, service_areas.the_geom
		FROM service_areas
		WHERE st_intersects(
			service_areas.the_geom,
			ST_Centroid(' . $wkt_geom . ')
			);';
        $command = $connection->createCommand($sql);
        $dataReader = $command->query();
        $rows = $dataReader->readAll();
        /*
        if(count($rows)>1)
        	return Geometry::Get_Service_Area_ByWKT_all($wkt);  // Caso MOLTO particolare
        else
        */
        return $rows;
    }