public function actionGetRegionPolygons() { //Попытка грузить границы регионов из mif файла die; set_time_limit(0); $file = file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/regions2010_wgs.mif'); preg_match_all('/REGION 1\\s+(\\d+)\\s+([-\\d\\s\\.]*)\\s+PEN/ism', $file, $matches, PREG_SET_ORDER); echo count($matches) . '<br/>'; //print_r($matches); foreach ($matches as $i => $match) { echo $match[1] . '<br/>'; if ($match[1] && $match[2]) { $subj = RfSubjects::model()->find('region_num=' . $match[1]); if ($subj && $subj->gibdd) { //foreach ($subj->gibdd->areas as $item) $item->delete(); $areamodel = new GibddAreas(); $areamodel->gibdd_id = $subj->gibdd->id; $lines = explode("\n", $match[2]); if ($lines && $areamodel->save()) { foreach ($lines as $ii => $line) { $coord = explode(" ", $line); if (isset($coord[0]) && isset($coord[1]) && $coord[0] && $coord[1]) { $pointmodel = new GibddAreaPoints(); $pointmodel->lat = $coord[1]; $pointmodel->lng = $coord[0]; $pointmodel->area_id = $areamodel->id; $pointmodel->point_num = $ii; $pointmodel->save(); } } } } } } }
public function AfterSave() { parent::afterSave(); if ($this->scenario != 'fill') { $oldareas = GibddAreas::model()->findAll('gibdd_id=' . $this->id); foreach ($oldareas as $item) { $item->delete(); } if (isset($_POST['GibddAreaPoints'])) { //print_r($_POST['GibddAreaPoints']); die(); foreach ($_POST['GibddAreaPoints'] as $i => $area) { $areamodel = new GibddAreas(); $areamodel->gibdd_id = $this->id; if ($areamodel->save()) { foreach ($area as $ii => $point) { $pointmodel = new GibddAreaPoints(); $pointmodel->attributes = $point; $pointmodel->area_id = $areamodel->id; $pointmodel->point_num = $ii; $pointmodel->save(); } } } } } return true; }
public function BeforeDelete() { parent::beforeDelete(); GibddAreaPoints::model()->deleteAll('area_id=' . $this->id); return true; }
public function actionSaveAllPolygions() { if (isset($_POST['GibddAreaName'])) { foreach ($_POST['GibddAreaName'] as $i => $region) { $points = $_POST['GibddAreaPoints'][$i]; $subjId = RfSubjects::model()->SearchID($region); if ($subjId) { $subj = RfSubjects::model()->findByPk($subjId); echo '<font color="green">Обновлено: ' . $subj->name . '</font><br />'; if ($subj && $subj->gibdd) { foreach ($subj->gibdd->areas as $item) { $item->delete(); } $areamodel = new GibddAreas(); $areamodel->gibdd_id = $subj->gibdd->id; if ($points && $areamodel->save()) { foreach ($points as $ii => $point) { if ($point['lat'] && $point['lng']) { $pointmodel = new GibddAreaPoints(); $pointmodel->lat = $point['lat']; $pointmodel->lng = $point['lng']; $pointmodel->area_id = $areamodel->id; $pointmodel->point_num = $ii; $pointmodel->save(); } } } } } else { echo '<font color="red">Не найдено: ' . $region . '</font><br />'; } } } }