Example #1
0
 public function beforeSave()
 {
     if (!$this->isNewRecord) {
         //retrieve old water_demand value
         $old = WaterRequestGeometryZones::model()->findByPk($this->id);
         if ($old) {
             $old_wd = (double) $old->water_demand;
             //check if water demand has been changed
             if ($old_wd != $this->water_demand) {
                 //update geometry water demand and water_request water demand
                 Yii::log('OLD WD: ' . $old_wd, CLogger::LEVEL_INFO, 'beforeSave');
                 // DEBUG
                 Yii::log('NEW WD: ' . $this->water_demand, CLogger::LEVEL_INFO, 'beforeSave');
                 // DEBUG
                 Yii::log('GEOM_WATER_DEMAND: ' . $this->geometry->geom_water_demand, CLogger::LEVEL_INFO, 'beforeSave');
                 // DEBUG
                 $this->geometry->geom_water_demand -= $old_wd;
                 $this->geometry->geom_water_demand += $this->water_demand;
                 Yii::log('UPDATED GEOM_WATER_DEMAND: ' . $this->geometry->geom_water_demand, CLogger::LEVEL_INFO, 'beforeSave');
                 // DEBUG
                 $this->geometry->save();
                 $this->geometry->wr->total_water_demand -= $old_wd;
                 $this->geometry->wr->total_water_demand += $this->water_demand;
                 $this->geometry->wr->save();
             }
         }
     }
     Yii::log('BEFORE', CLogger::LEVEL_INFO, 'beforeSave');
     // DEBUG
     return parent::beforeSave();
 }
Example #2
0
 protected function beforeDelete()
 {
     $geom = WaterRequestGeometries::model()->findAll('wr_id = :wr_id', array(':wr_id' => $this->id));
     if ($geom) {
         foreach ($geom as $g) {
             $geom_zone = WaterRequestGeometryZones::model()->findAll('wr_geometry_id = :wr_geometry_id', array(':wr_geometry_id' => $g->id));
             if ($geom_zone) {
                 foreach ($geom_zone as $z) {
                     WaterRequestGeometryZoneProperties::model()->deleteAll('geometry_zone = :geometry_zone', array(':geometry_zone' => $z->id));
                 }
                 WaterRequestGeometryZones::model()->deleteAll('wr_geometry_id = :wr_geometry_id', array(':wr_geometry_id' => $g->id));
             }
         }
         WaterRequestGeometries::model()->deleteAll('wr_id = :wr_id', array(':wr_id' => $this->id));
     }
     return parent::beforeDelete();
 }
Example #3
0
 protected function beforeDelete()
 {
     WaterRequestGeometryZones::model()->deleteAll('wr_geometry_id = :wr_geometry_id', array(':wr_geometry_id' => $this->id));
     return parent::beforeDelete();
 }
 /**
  * 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 = WaterRequestGeometryZones::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
 /**
  * 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);
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     $ref_zone = WaterRequestGeometryZones::model()->find('id=:id', array(':id' => $model->geometry_zone));
     if (!count($ref_zone)) {
         throw new CHttpException(404, 'The Property has a wrong geometry_zone.');
     }
     if (isset($_POST['WaterRequestGeometryZoneProperties'])) {
         $model->attributes = $_POST['WaterRequestGeometryZoneProperties'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('update', array('model' => $model, 'zone_type' => $ref_zone->zone));
 }