/** * Creates a new Compare model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreatedraw() { $model = new Compare(); if (Yii::$app->request->post()) { ini_set("memory_limit", "-1"); /*** * Langkah - langkah mengambil data kesesuaian lahan * 1. INTERSECTS (TRUE | FALSE) * 2. INTERSECTION (Kesesuain To Geom from draw) * * S = geom from draw * B = Hasil intersects **/ $get_intersection = "SELECT b.*, ST_AsGeojson(ST_intersection(b.geom,ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326))) as geom from (select kesesuaian.*, st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),kesesuaian.geom)as touch from kesesuaian where st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),kesesuaian.geom) = true) as b;"; $value_intersections = Yii::$app->db->createCommand($get_intersection)->queryAll(); $area_of_interest = "SELECT ST_AsGeoJson(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326))"; $aoi = Yii::$app->db->createCommand($area_of_interest)->queryAll(); /*** * Get Average Geometry Climate **/ $climate_ag = ClimateAG::find()->OrderBy('id DESC')->one(); $landnp_ag = LandnpeatAG::find()->OrderBy('id DESC')->one(); $landp_ag = LandpeatAG::find()->OrderBy('id DESC')->one(); $accessibility_ag = AccessibilityAG::find()->OrderBy('id DESC')->one(); /*** * Get Average Geometry Factor **/ $factors_ag = FactorsAG::find()->OrderBy('id DESC')->one(); /* Deklarasi variable result geojson */ $result_geojson = '{"type": "FeatureCollection","features": ['; if (isset($climate_ag)) { if (isset($landnp_ag)) { if (isset($landp_ag)) { if (isset($accessibility_ag)) { if (isset($factors_ag)) { for ($i = 0; $i < count($value_intersections); $i++) { $kesesuaian_climate = $value_intersections[$i]['scorech'] * ($climate_ag->bobot_ch * $factors_ag->bobot_climate) + $value_intersections[$i]['scoresuhu'] * ($climate_ag->boobt_temp * $factors_ag->bobot_climate) + $value_intersections[$i]['scoredry'] * ($climate_ag->bobot_dm * $factors_ag->bobot_climate); $status_climate = 'N'; if ($kesesuaian_climate >= 0 and $kesesuaian_climate <= 1) { $status_climate = 'N'; } elseif ($kesesuaian_climate > 1 and $kesesuaian_climate <= 2) { $status_climate = 'S3'; } elseif ($kesesuaian_climate > 2 and $kesesuaian_climate <= 3) { $status_climate = 'S2'; } elseif ($kesesuaian_climate > 3 and $kesesuaian_climate <= 4) { $status_climate = 'S1'; } else { $status_climate = 'S(alah)'; } $result_geojson .= "{\"type\": \"Feature\",\"properties\": {\"kesesuaian_climate\":\"" . $kesesuaian_climate . "\", \"status_climate\":\"" . $status_climate . "\"},\"geometry\": "; $result_geojson .= $value_intersections[$i]['geom']; $result_geojson .= "},"; } $result_geojson .= ']}'; $result_data = substr($result_geojson, 0, -3) . ' ]}'; /* Convert WKT to Geom */ $query_geom_from_wkt = "SELECT ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326), ST_Area(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326))"; $result_geom_from_wkt = Yii::$app->db->createCommand($query_geom_from_wkt)->queryAll(); /* Climate Rainfall */ $get_rainfall = "SELECT b.scorech as scorech,ST_AsGeojson(st_union(st_intersection(b.geom,ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326))))as geom from (select u.*, st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom)as touch from kesesuaian as u where st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom) = true) as b group by b.scorech;"; $value_rainfall = Yii::$app->db->createCommand($get_rainfall)->queryAll(); $result_geojson_rain = '{"type": "FeatureCollection","features": ['; for ($i = 0; $i < count($value_rainfall); $i++) { $scorech = $value_rainfall[$i]['scorech']; $status_rainfall = ' '; if ($scorech <= 1) { $status_rainfall = '< 1250, > 4000'; } elseif ($scorech <= 2 and $scorech > 1) { $status_rainfall = '1250 - 1450, 3500 - 4000'; } elseif ($scorech <= 3 and $scorech > 2) { $status_rainfall = '1450 - 1700, 2500 - 3500'; } elseif ($scorech <= 4 and $scorech > 3) { $status_rainfall = '1700 - 2500'; } else { $status_rainfall = 'S(alah)'; } $result_geojson_rain .= "{\"type\": \"Feature\",\"properties\": {\"scorech\":\"" . $scorech . "\", \"status_rainfall\":\"" . $status_rainfall . "\"},\"geometry\": "; $result_geojson_rain .= $value_rainfall[$i]['geom']; $result_geojson_rain .= "},"; } $result_geojson_rain .= ']}'; $result_data_rain = substr($result_geojson_rain, 0, -3) . ' ]}'; /* Climate Temperature */ $get_temperature = "SELECT b.scoresuhu as scoresuhu, ST_AsGeojson(st_union(st_intersection(b.geom,ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326))))as geom from (select u.*, st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom)as touch from kesesuaian as u where st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom) = true) as b group by b.scoresuhu;"; $value_temperature = Yii::$app->db->createCommand($get_temperature)->queryAll(); $result_geojson_temp = '{"type": "FeatureCollection","features": ['; for ($i = 0; $i < count($value_temperature); $i++) { $scoresuhu = $value_temperature[$i]['scoresuhu']; $status_temperature = ' '; if ($scoresuhu <= 1) { $status_temperature = '< 20, > 35'; } elseif ($scoresuhu <= 2 and $scoresuhu > 1) { $status_temperature = '20 - 22, 32 - 35 '; } elseif ($scoresuhu <= 3 and $scoresuhu > 2) { $status_temperature = '22 - 25, 28 - 32'; } elseif ($scoresuhu <= 4 and $scoresuhu > 3) { $status_temperature = '25 - 28'; } else { $status_temperature = 'S(alah)'; } $result_geojson_temp .= "{\"type\": \"Feature\",\"properties\": {\"scoresuhu\":\"" . $scoresuhu . "\", \"status_temperature\":\"" . $status_temperature . "\"},\"geometry\": "; $result_geojson_temp .= $value_temperature[$i]['geom']; $result_geojson_temp .= "},"; } $result_geojson_temp .= ']}'; $result_data_temp = substr($result_geojson_temp, 0, -3) . ' ]}'; /* Climate Dry Month */ $get_drymonth = "SELECT b.scoredry as scoredry ,ST_AsGeojson(st_union(st_intersection(b.geom,ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326))))as geom from (select u.*, st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom)as touch from kesesuaian as u where st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom) = true) as b group by b.scoredry;"; $value_drymonth = Yii::$app->db->createCommand($get_drymonth)->queryAll(); $result_geojson_dm = '{"type": "FeatureCollection","features": ['; for ($i = 0; $i < count($value_drymonth); $i++) { $scoredry = $value_drymonth[$i]['scoredry']; $status_drymonth = '> 4'; if ($scoredry <= 1) { $status_drymonth = '> 4'; } elseif ($scoredry <= 2 and $scoredry > 1) { $status_drymonth = '3 – 4'; } elseif ($scoredry <= 3 and $scoredry > 2) { $status_drymonth = '3 – 2'; } elseif ($scoredry <= 4 and $scoredry > 3) { $status_drymonth = '< 2'; } else { $status_drymonth = 'S(alah)'; } $result_geojson_dm .= "{\"type\": \"Feature\",\"properties\": {\"scoredry\":\"" . $scoredry . "\", \"status_drymonth\":\"" . $status_drymonth . "\"},\"geometry\": "; $result_geojson_dm .= $value_drymonth[$i]['geom']; $result_geojson_dm .= "},"; } $result_geojson_dm .= ']}'; $result_data_dm = substr($result_geojson_dm, 0, -3) . ' ]}'; /* Land slope */ $get_slope = "SELECT b.score_lrg as score_lrg ,ST_AsGeojson(st_union(st_intersection(b.geom,ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326))))as geom from (select u.*, st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom)as touch from kesesuaian as u where st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom) = true) as b group by b.score_lrg order by b.score_lrg asc;"; $value_slope = Yii::$app->db->createCommand($get_slope)->queryAll(); $result_geojson_slp = '{"type": "FeatureCollection","features": ['; for ($i = 0; $i < count($value_slope); $i++) { $score_lrg = $value_slope[$i]['score_lrg']; $status_slope = '>30'; if ($score_lrg <= 1) { $status_slope = '>30'; } elseif ($score_lrg <= 2 and $score_lrg > 1) { $status_slope = '16 - 30'; } elseif ($score_lrg <= 3 and $score_lrg > 2) { $status_slope = '8 - 16'; } elseif ($score_lrg <= 4 and $score_lrg > 3) { $status_slope = '<8'; } else { $status_slope = 'S(alah)'; } $result_geojson_slp .= "{\"type\": \"Feature\",\"properties\": {\"score_lrg\":\"" . $score_lrg . "\", \"status_slope\":\"" . $status_slope . "\"},\"geometry\": "; $result_geojson_slp .= $value_slope[$i]['geom']; $result_geojson_slp .= "},"; } $result_geojson_slp .= ']}'; $result_data_slp = substr($result_geojson_slp, 0, -3) . ' ]}'; /* Land Non Peat Texture */ $get_texture = "SELECT b.score_text as score_text ,ST_AsGeojson(st_union(st_intersection(b.geom,ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326))))as geom from (select u.*, st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom)as touch from kesesuaian as u where st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom) = true) as b group by b.score_text;"; $value_texture = Yii::$app->db->createCommand($get_texture)->queryAll(); $result_geojson_txt = '{"type": "FeatureCollection","features": ['; for ($i = 0; $i < count($value_texture); $i++) { $score_text = $value_texture[$i]['score_text']; $status_texture = 'Peat Area'; if ($score_text <= 1) { $status_texture = 'Coarse'; } elseif ($score_text <= 2 and $score_text > 1) { $status_texture = 'Slightly Coarse'; } elseif ($score_text <= 3 and $score_text > 2) { $status_texture = '–'; } elseif ($score_text <= 4 and $score_text > 3) { $status_texture = 'Fine, Slightly fine, Medium'; } else { $status_texture = 'S(alah)'; } $result_geojson_txt .= "{\"type\": \"Feature\",\"properties\": {\"score_text\":\"" . $score_text . "\", \"status_texture\":\"" . $status_texture . "\"},\"geometry\": "; $result_geojson_txt .= $value_texture[$i]['geom']; $result_geojson_txt .= "},"; } $result_geojson_txt .= ']}'; $result_data_txt = substr($result_geojson_txt, 0, -3) . ' ]}'; /* Land Non Peat Elevation */ $get_elevation = "SELECT b.score_elev as score_elev ,ST_AsGeojson(st_union(st_intersection(b.geom,ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326))))as geom from (select u.*, st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom)as touch from kesesuaian as u where st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom) = true) as b group by b.score_elev;"; $value_elevation = Yii::$app->db->createCommand($get_elevation)->queryAll(); $result_geojson_elev = '{"type": "FeatureCollection","features": ['; for ($i = 0; $i < count($value_elevation); $i++) { $score_elev = $value_elevation[$i]['score_elev']; $status_elevation = 'Peat Area'; if ($score_elev <= 1) { $status_elevation = '> 400'; } elseif ($score_elev <= 2 and $score_elev > 1) { $status_elevation = '300 - 400'; } elseif ($score_elev <= 3 and $score_elev > 2) { $status_elevation = '200 - 300'; } elseif ($score_elev <= 4 and $score_elev > 3) { $status_elevation = '0 - 200'; } else { $status_elevation = 'S(alah)'; } $result_geojson_elev .= "{\"type\": \"Feature\",\"properties\": {\"score_elev\":\"" . $score_elev . "\", \"status_elevation\":\"" . $status_elevation . "\"},\"geometry\": "; $result_geojson_elev .= $value_elevation[$i]['geom']; $result_geojson_elev .= "},"; // print_r($status_elevation); } // die; $result_geojson_elev .= ']}'; $result_data_elev = substr($result_geojson_elev, 0, -3) . ' ]}'; /* Land Peat Thickness */ $get_thickness = "SELECT b.scoredept as scoredept ,ST_AsGeojson(st_union(st_intersection(b.geom,ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326))))as geom from (select u.*, st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom)as touch from kesesuaian as u where st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom) = true) as b group by b.scoredept;"; $value_thickness = Yii::$app->db->createCommand($get_thickness)->queryAll(); $result_geojson_thick = '{"type": "FeatureCollection","features": ['; for ($i = 0; $i < count($value_thickness); $i++) { $scoredept = $value_thickness[$i]['scoredept']; $status_thickness = 'Non Peat Area'; if ($scoredept <= 1 and $scoredept > 0) { $status_thickness = '< 140'; } elseif ($scoredept <= 2 and $scoredept > 1) { $status_thickness = '140 – 200'; } elseif ($scoredept <= 3 and $scoredept > 2) { $status_thickness = '200 – 400'; } elseif ($scoredept <= 4 and $scoredept > 3) { $status_thickness = '> 400'; } else { $status_thickness = 'S(alah)'; } $result_geojson_thick .= "{\"type\": \"Feature\",\"properties\": {\"scoredept\":\"" . $scoredept . "\", \"status_thickness\":\"" . $status_thickness . "\"},\"geometry\": "; $result_geojson_thick .= $value_thickness[$i]['geom']; $result_geojson_thick .= "},"; } $result_geojson_thick .= ']}'; $result_data_thick = substr($result_geojson_thick, 0, -3) . ' ]}'; /* Land Peat Ripe */ $get_ripening = "SELECT b.scoreripe as scoreripe ,ST_AsGeojson(st_union(st_intersection(b.geom,ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326))))as geom from (select u.*, st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom)as touch from kesesuaian as u where st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom) = true) as b group by b.scoreripe;"; $value_ripening = Yii::$app->db->createCommand($get_ripening)->queryAll(); $result_geojson_ripe = '{"type": "FeatureCollection","features": ['; for ($i = 0; $i < count($value_ripening); $i++) { $scoreripe = $value_ripening[$i]['scoreripe']; $status_ripening = 'Non Peat Area'; if ($scoreripe <= 1 and $scoreripe > 0) { $status_ripening = 'Sapric*'; } elseif ($scoreripe <= 2 and $scoreripe > 1) { $status_ripening = 'Sapric, Hemic*'; } elseif ($scoreripe <= 3 and $scoreripe > 2) { $status_ripening = 'Hemic, Fibric*'; } elseif ($scoreripe <= 4 and $scoreripe > 3) { $status_ripening = 'Fibric'; } else { $status_ripening = 'S(alah)'; } $result_geojson_ripe .= "{\"type\": \"Feature\",\"properties\": {\"scoreripe\":\"" . $scoreripe . "\", \"status_ripening\":\"" . $status_ripening . "\"},\"geometry\": "; $result_geojson_ripe .= $value_ripening[$i]['geom']; $result_geojson_ripe .= "},"; } $result_geojson_ripe .= ']}'; $result_data_ripe = substr($result_geojson_ripe, 0, -3) . ' ]}'; /* Accessibility Distance From Road */ $get_road = "SELECT b.score_road as score_road ,ST_AsGeojson(st_union(st_intersection(b.geom,ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326))))as geom from (select u.*, st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom)as touch from kesesuaian as u where st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom) = true) as b group by b.score_road;"; $value_road = Yii::$app->db->createCommand($get_road)->queryAll(); $result_geojson_rod = '{"type": "FeatureCollection","features": ['; for ($i = 0; $i < count($value_road); $i++) { $score_road = $value_road[$i]['score_road']; $status_road = '-'; if ($score_road <= 1 and $score_road > 0) { $status_road = '-'; } elseif ($score_road <= 2 and $score_road > 1) { $status_road = '> 10 Km'; } elseif ($score_road <= 3 and $score_road > 2) { $status_road = '5 - 10 Km'; } elseif ($score_road <= 4 and $score_road > 3) { $status_road = '0 - 5 Km'; } else { $status_road = 'S(alah)'; } $result_geojson_rod .= "{\"type\": \"Feature\",\"properties\": {\"score_road\":\"" . $score_road . "\", \"status_road\":\"" . $status_road . "\"},\"geometry\": "; $result_geojson_rod .= $value_road[$i]['geom']; $result_geojson_rod .= "},"; } $result_geojson_rod .= ']}'; $result_data_rod = substr($result_geojson_rod, 0, -3) . ' ]}'; /* Accessibility Distance From Mills */ $get_mills = "SELECT b.score_mill as score_mill ,ST_AsGeojson(st_union(st_intersection(b.geom,ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326))))as geom from (select u.*, st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom)as touch from kesesuaian as u where st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom) = true) as b group by b.score_mill;"; $value_mills = Yii::$app->db->createCommand($get_mills)->queryAll(); $result_geojson_mls = '{"type": "FeatureCollection","features": ['; for ($i = 0; $i < count($value_mills); $i++) { $score_mill = $value_mills[$i]['score_mill']; $status_mills = '-'; if ($score_mill <= 1 and $score_mill > 0) { $status_mills = '-'; } elseif ($score_mill <= 2 and $score_mill > 1) { $status_mills = '> 10 Km'; } elseif ($score_mill <= 3 and $score_mill > 2) { $status_mills = '5 - 10 Km'; } elseif ($score_mill <= 4 and $score_mill > 3) { $status_mills = '0 - 5 Km'; } else { $status_mills = 'S(alah)'; } $result_geojson_mls .= "{\"type\": \"Feature\",\"properties\": {\"score_mill\":\"" . $score_mill . "\", \"status_mills\":\"" . $status_mills . "\"},\"geometry\": "; $result_geojson_mls .= $value_mills[$i]['geom']; $result_geojson_mls .= "},"; } $result_geojson_mls .= ']}'; $result_data_mls = substr($result_geojson_mls, 0, -3) . ' ]}'; /* Accessibility Distance From town */ $get_town = "SELECT b.score_town as score_town ,ST_AsGeojson(st_union(st_intersection(b.geom,ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326))))as geom from (select u.*, st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom)as touch from kesesuaian as u where st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom) = true) as b group by b.score_town;"; $value_town = Yii::$app->db->createCommand($get_town)->queryAll(); $result_geojson_twn = '{"type": "FeatureCollection","features": ['; for ($i = 0; $i < count($value_town); $i++) { $score_town = $value_town[$i]['score_town']; $status_town = '-'; if ($score_town <= 1 and $score_town > 0) { $status_town = '-'; } elseif ($score_town <= 2 and $score_town > 1) { $status_town = '> 10 Km'; } elseif ($score_town <= 3 and $score_town > 2) { $status_town = '5 - 10 Km'; } elseif ($score_town <= 4 and $score_town > 3) { $status_town = '0 - 5 Km'; } else { $status_town = 'S(alah)'; } $result_geojson_twn .= "{\"type\": \"Feature\",\"properties\": {\"score_town\":\"" . $score_town . "\", \"status_town\":\"" . $status_town . "\"},\"geometry\": "; $result_geojson_twn .= $value_town[$i]['geom']; $result_geojson_twn .= "},"; } $result_geojson_twn .= ']}'; $result_data_twn = substr($result_geojson_twn, 0, -3) . ' ]}'; } else { return $this->redirect(['nodata', 'id' => $model->id]); } } else { return $this->redirect(['nodata', 'id' => $model->id]); } } else { return $this->redirect(['nodata', 'id' => $model->id]); } } else { return $this->redirect(['nodata', 'id' => $model->id]); } } else { return $this->redirect(['nodata', 'id' => $model->id]); } /* Convert m2 to Ha (Ha = m2 ÷ 10,000)*/ $data_st_area = $result_geom_from_wkt[0]['st_area']; /* Intervensi POST with result */ $_POST['Compare']['data'] = $result_data; $_POST['Compare']['geom'] = $result_geom_from_wkt[0]['st_geomfromtext']; $_POST['Compare']['st_area'] = $data_st_area; $_POST['Compare']['data_rain'] = $result_data_rain; $_POST['Compare']['data_temp'] = $result_data_temp; $_POST['Compare']['data_dm'] = $result_data_dm; $_POST['Compare']['data_slope'] = $result_data_slp; $_POST['Compare']['data_text'] = $result_data_txt; $_POST['Compare']['data_elev'] = $result_data_elev; $_POST['Compare']['data_thick'] = $result_data_thick; $_POST['Compare']['data_ripe'] = $result_data_ripe; $_POST['Compare']['data_road'] = $result_data_rod; $_POST['Compare']['data_mills'] = $result_data_mls; $_POST['Compare']['data_town'] = $result_data_twn; if (!Yii::$app->user->isGuest) { $_POST['Compare']['id_user'] = Yii::$app->user->identity->id; } if ($model->load($_POST) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { echo "error"; } } else { $get_geojson_kecamatan = "SELECT *, ST_AsGeoJson(geom), ST_X(ST_Centroid(geom)), ST_Y(ST_Centroid(geom)) FROM admin"; $data_admin = Yii::$app->db->createCommand($get_geojson_kecamatan)->queryAll(); $get_bbox = "SELECT ST_AsGeoJson(Box2D(ST_Union(geom))) FROM admin"; $bbox_geojsons = Yii::$app->db->createCommand($get_bbox)->queryColumn(); $bbox_geojson = $bbox_geojsons[0]; return $this->render('createdraw', ['model' => $model, 'data_admin' => $data_admin, 'bbox_geojson' => $bbox_geojson]); } }
/** * Creates a new Landpeat model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Landpeat(); if (Yii::$app->request->post()) { $slope_thick = $_POST['Landpeat']['slope_thick']; $thick_slope = 1 / $slope_thick; $slope_slope = 1; $thick_ripe = $_POST['Landpeat']['thick_ripe']; $ripe_thick = 1 / $thick_ripe; $thick_thick = 1; $slope_ripe = $_POST['Landpeat']['slope_ripe']; $ripe_slope = 1 / $slope_ripe; $ripe_ripe = 1; $sum_column_slope = $slope_slope + $thick_slope + $ripe_slope; $sum_column_thick = $slope_thick + $thick_thick + $ripe_thick; $sum_column_ripe = $slope_ripe + $thick_ripe + $ripe_ripe; /* ---- */ $divided_sum_sum = $sum_column_slope / $sum_column_slope; $divided_slope_slope_sum = $slope_slope / $sum_column_slope; $divided_slope_thick_sum = $thick_slope / $sum_column_slope; $divided_slope_ripe_sum = $ripe_slope / $sum_column_slope; $divided_thick_slope_sum = $slope_thick / $sum_column_thick; $divided_thick_thick_sum = $thick_thick / $sum_column_thick; $divided_thick_ripe_sum = $ripe_thick / $sum_column_thick; $divided_ripe_slope_sum = $slope_ripe / $sum_column_ripe; $divided_ripe_thick_sum = $thick_ripe / $sum_column_ripe; $divided_ripe_ripe_sum = $ripe_ripe / $sum_column_ripe; /* ---- */ $sum_slope = $divided_slope_slope_sum + $divided_thick_slope_sum + $divided_ripe_slope_sum; $sum_thick = $divided_slope_thick_sum + $divided_thick_thick_sum + $divided_ripe_thick_sum; $sum_ripe = $divided_slope_ripe_sum + $divided_thick_ripe_sum + $divided_ripe_ripe_sum; $sum_divided = $divided_sum_sum + $divided_sum_sum + $divided_sum_sum; /* ---- */ $bobot_slope = $sum_slope / $sum_divided; $bobot_thick = $sum_thick / $sum_divided; $bobot_ripe = $sum_ripe / $sum_divided; /* ---- */ /* ---- */ $multiple_slope_slope_bobot = $slope_slope * $bobot_slope; $multiple_slope_thick_bobot = $thick_slope * $bobot_slope; $multiple_slope_ripe_bobot = $ripe_slope * $bobot_slope; $multiple_thick_slope_bobot = $slope_thick * $bobot_thick; $multiple_thick_thick_bobot = $thick_thick * $bobot_thick; $multiple_thick_ripe_bobot = $ripe_thick * $bobot_thick; $multiple_ripe_slope_bobot = $slope_ripe * $bobot_ripe; $multiple_ripe_thick_bobot = $thick_ripe * $bobot_ripe; $multiple_ripe_ripe_bobot = $ripe_ripe * $bobot_ripe; /* ---- */ /* ---- */ $sum_bobot_slope = $multiple_slope_slope_bobot + $multiple_thick_slope_bobot + $multiple_ripe_slope_bobot; $sum_bobot_thick = $multiple_slope_thick_bobot + $multiple_thick_thick_bobot + $multiple_ripe_thick_bobot; $sum_bobot_ripe = $multiple_slope_ripe_bobot + $multiple_thick_ripe_bobot + $multiple_ripe_ripe_bobot; /* ---- */ $divided_bobot_slope = $sum_bobot_slope / $bobot_slope; $divided_bobot_thick = $sum_bobot_thick / $bobot_thick; $divided_bobot_ripe = $sum_bobot_ripe / $bobot_ripe; /* ---- */ $lamda_max = ($divided_bobot_slope + $divided_bobot_thick + $divided_bobot_ripe) / $sum_divided; $jumlah_factor = $sum_divided; $consistensi_index = ($lamda_max - $jumlah_factor) / ($jumlah_factor - 1); $rasio_index = 0.58; $consistensi_rasio = $consistensi_index / $rasio_index; /* ---- */ if ($consistensi_rasio < 0.1) { $validation = TRUE; } else { $validation = FALSE; } if (Yii::$app->user->getId()) { $_POST['Landpeat']['slope_thick'] = $slope_thick; $_POST['Landpeat']['slope_ripe'] = $slope_ripe; $_POST['Landpeat']['thick_ripe'] = $thick_ripe; $_POST['Landpeat']['bobot_slope'] = $bobot_slope; $_POST['Landpeat']['bobot_thick'] = $bobot_thick; $_POST['Landpeat']['bobot_ripe'] = $bobot_ripe; $_POST['Landpeat']['cr'] = $consistensi_rasio; $_POST['Landpeat']['validation'] = $validation; $_POST['Landpeat']['id_user'] = Yii::$app->user->getId(); if ($model->load($_POST) && $model->save()) { $data_landpeats = Landpeat::find()->where(['validation' => TRUE])->AsArray()->All(); $slope_thick_ag_base = []; $slope_ripe_ag_base = []; $thick_ripe_ag_base = []; $bobot_slope_ag_base = []; $bobot_thick_ag_base = []; $bobot_ripe_ag_base = []; $consistensi_rasio_ag_base = []; for ($i = 0; $i < count($data_landpeats); $i++) { $slope_thick_ag_base[$i] = $data_landpeats[$i]['slope_thick']; $slope_ripe_ag_base[$i] = $data_landpeats[$i]['slope_ripe']; $thick_ripe_ag_base[$i] = $data_landpeats[$i]['thick_ripe']; // $bobot_slope_ag_base[$i] = $data_landpeats[$i]['bobot_slope']; // $bobot_thick_ag_base[$i] = $data_landpeats[$i]['bobot_thick']; // $bobot_ripe_ag_base[$i] = $data_landpeats[$i]['bobot_ripe']; // $consistensi_rasio_ag_base[$i] = $data_landpeats[$i]['cr']; } $slope_thick_ag = pow(array_product($slope_thick_ag_base), 1 / count($data_landpeats)); $thick_slope_ag = 1 / $slope_thick_ag; $slope_slope_ag = 1; $slope_ripe_ag = pow(array_product($slope_ripe_ag_base), 1 / count($data_landpeats)); $ripe_slope_ag = 1 / $slope_ripe_ag; $ripe_ripe_ag = 1; $thick_ripe_ag = pow(array_product($thick_ripe_ag_base), 1 / count($data_landpeats)); $ripe_thick_ag = 1 / $thick_ripe_ag; $thick_thick_ag = 1; // $bobot_slope_ag = sqrt (array_product($bobot_slope_ag_base)); // $bobot_thick_ag = sqrt (array_product($bobot_thick_ag_base)); // $bobot_ripe_ag = sqrt (array_product($bobot_ripe_ag_base)); // $consistensi_rasio_ag = sqrt (array_product($consistensi_rasio_ag_base)); $sum_column_slope_ag = $slope_slope_ag + $thick_slope_ag + $ripe_slope_ag; $sum_column_thick_ag = $slope_thick_ag + $thick_thick_ag + $ripe_thick_ag; $sum_column_ripe_ag = $slope_ripe_ag + $thick_ripe_ag + $ripe_ripe_ag; /* ---- */ $divided_sum_sum_ag = $sum_column_slope_ag / $sum_column_slope_ag; $divided_slope_slope_ag_sum = $slope_slope_ag / $sum_column_slope_ag; $divided_slope_thick_ag_sum = $thick_slope_ag / $sum_column_slope_ag; $divided_slope_ripe_ag_sum = $ripe_slope_ag / $sum_column_slope_ag; $divided_thick_slope_ag_sum = $slope_thick_ag / $sum_column_thick_ag; $divided_thick_thick_ag_sum = $thick_thick_ag / $sum_column_thick_ag; $divided_thick_ripe_ag_sum = $ripe_thick_ag / $sum_column_thick_ag; $divided_ripe_slope_ag_sum = $slope_ripe_ag / $sum_column_ripe_ag; $divided_ripe_thick_ag_sum = $thick_ripe_ag / $sum_column_ripe_ag; $divided_ripe_ripe_ag_sum = $ripe_ripe_ag / $sum_column_ripe_ag; /* ---- */ $sum_slope_ag = $divided_slope_slope_ag_sum + $divided_thick_slope_ag_sum + $divided_ripe_slope_ag_sum; $sum_thick_ag = $divided_slope_thick_ag_sum + $divided_thick_thick_ag_sum + $divided_ripe_thick_ag_sum; $sum_ripe_ag = $divided_slope_ripe_ag_sum + $divided_thick_ripe_ag_sum + $divided_ripe_ripe_ag_sum; $sum_divided_ag = $divided_sum_sum_ag + $divided_sum_sum_ag + $divided_sum_sum_ag; /* ---- */ $bobot_slope_ag = $sum_slope_ag / $sum_divided_ag; $bobot_thick_ag = $sum_thick_ag / $sum_divided_ag; $bobot_ripe_ag = $sum_ripe_ag / $sum_divided_ag; /* ---- */ /* ---- */ $multiple_slope_slope_ag_bobot = $slope_slope_ag * $bobot_slope_ag; $multiple_slope_thick_ag_bobot = $thick_slope_ag * $bobot_slope_ag; $multiple_slope_ripe_ag_bobot = $ripe_slope_ag * $bobot_slope_ag; $multiple_thick_slope_ag_bobot = $slope_thick_ag * $bobot_thick_ag; $multiple_thick_thick_ag_bobot = $thick_thick_ag * $bobot_thick_ag; $multiple_thick_ripe_ag_bobot = $ripe_thick_ag * $bobot_thick_ag; $multiple_ripe_slope_ag_bobot = $slope_ripe_ag * $bobot_ripe_ag; $multiple_ripe_thick_ag_bobot = $thick_ripe_ag * $bobot_ripe_ag; $multiple_ripe_ripe_ag_bobot = $ripe_ripe_ag * $bobot_ripe_ag; /* ---- */ /* ---- */ $sum_bobot_slope_ag = $multiple_slope_slope_ag_bobot + $multiple_thick_slope_ag_bobot + $multiple_ripe_slope_ag_bobot; $sum_bobot_thick_ag = $multiple_slope_thick_ag_bobot + $multiple_thick_thick_ag_bobot + $multiple_ripe_thick_ag_bobot; $sum_bobot_ripe_ag = $multiple_slope_ripe_ag_bobot + $multiple_thick_ripe_ag_bobot + $multiple_ripe_ripe_ag_bobot; /* ---- */ $divided_bobot_slope_ag = $sum_bobot_slope_ag / $bobot_slope_ag; $divided_bobot_thick_ag = $sum_bobot_thick_ag / $bobot_thick_ag; $divided_bobot_ripe_ag = $sum_bobot_ripe_ag / $bobot_ripe_ag; /* ---- */ $lamda_max_ag = ($divided_bobot_slope_ag + $divided_bobot_thick_ag + $divided_bobot_ripe_ag) / $sum_divided_ag; $jumlah_factor_ag = $sum_divided_ag; $consistensi_index_ag = ($lamda_max_ag - $jumlah_factor_ag) / ($jumlah_factor_ag - 1); $rasio_index_ag = 0.58; $consistensi_rasio_ag = $consistensi_index_ag / $rasio_index_ag; /* ---- */ $model_ag = new LandpeatAG(); $_POSTAG['LandpeatAG']['slope_thick'] = $slope_thick_ag; $_POSTAG['LandpeatAG']['slope_ripe'] = $slope_ripe_ag; $_POSTAG['LandpeatAG']['thick_ripe'] = $thick_ripe_ag; $_POSTAG['LandpeatAG']['bobot_slope'] = $bobot_slope_ag; $_POSTAG['LandpeatAG']['bobot_thick'] = $bobot_thick_ag; $_POSTAG['LandpeatAG']['bobot_ripe'] = $bobot_ripe_ag; $_POSTAG['LandpeatAG']['cr'] = $consistensi_rasio_ag; if ($model_ag->load($_POSTAG) && $model_ag->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } } else { return $this->render('create', ['model' => $model]); } } else { return $this->render('create', ['model' => $model]); } } else { return $this->render('create', ['model' => $model]); } }