예제 #1
0
 public function getAreaNeighbors()
 {
     if (!$this->hole_area) {
         return array();
     }
     $condition = 'shape_id IN (' . implode(',', CHtml::listData($this->hole_area, 'id', 'id')) . ')';
     //print_r(CHtml::listData($this->hole_area,'id','id'));
     $left = UserAreaShapePoints::model()->find(array('condition' => $condition, 'order' => 'lat ASC'))->lat;
     $right = UserAreaShapePoints::model()->find(array('condition' => $condition, 'order' => 'lat DESC'))->lat;
     $top = UserAreaShapePoints::model()->find(array('condition' => $condition, 'order' => 'lng DESC'))->lng;
     $bottom = UserAreaShapePoints::model()->find(array('condition' => $condition, 'order' => 'lng ASC'))->lng;
     $criteria = new CDbCriteria();
     $criteria->with = 'hole_area';
     $criteria->condition = 'points.lat >= ' . ($left - 0.01);
     $criteria->addCondition('points.lat <= ' . ($right + 0.01), 'AND');
     $criteria->addCondition('points.lng <= ' . ($top + 0.01), 'AND');
     $criteria->addCondition('points.lat >= ' . ($bottom - 0.01), 'AND');
     $criteria->addCondition('t.id != ' . $this->id);
     $criteria->addCondition('t.params LIKE ("%showMyarea%") OR t.params IS NULL');
     $criteria->limit = 5;
     $criteria->together = true;
     return $this->findAll($criteria);
     //echo $point->lat.'=>'.$point->lng.'<br/>';
 }
예제 #2
0
 public function actionMyarea()
 {
     $cs = Yii::app()->getClientScript();
     $cs->registerCssFile('/css/add_form.css');
     $cs->registerScriptFile('http://api-maps.yandex.ru/1.1/index.xml?key=' . $this->mapkey);
     $model = $this->loadModel(Yii::app()->user->id);
     if (isset($_POST['UserAreaShapes']) || isset($_POST['UserGroupsUser'])) {
         $ids = array();
         if (isset($_POST['UserAreaShapes'])) {
             foreach ($_POST['UserAreaShapes'] as $i => $shape) {
                 if (isset($shape['id']) && $shape['id']) {
                     $ids[] = $shape['id'];
                 }
             }
         }
         if ($ids) {
             UserAreaShapes::model()->deleteAll('id NOT IN (' . implode(',', $ids) . ') AND ug_id=' . $model->id);
         } else {
             UserAreaShapes::model()->deleteAll('ug_id=' . $model->id);
         }
         if (isset($_POST['UserAreaShapes'])) {
             foreach ($_POST['UserAreaShapes'] as $i => $shape) {
                 $shapemodel = $shape['id'] ? UserAreaShapes::model()->findByPk((int) $shape['id']) : new UserAreaShapes();
                 if ($shapemodel) {
                     $shapemodel->ug_id = $model->id;
                     $shapemodel->ordering = $shape['ordering'];
                     if ($shapemodel->isNewRecord) {
                         $shapemodel->save();
                     }
                     $ii = 0;
                     foreach ($_POST['UserAreaShapePoints'][$i] as $point) {
                         if ($ii >= $shapemodel->countPoints) {
                             break;
                         }
                         $pointmodel = $point['id'] ? UserAreaShapePoints::model()->findByPk((int) $point['id']) : new UserAreaShapePoints();
                         $pointmodel->attributes = $point;
                         $pointmodel->shape_id = $shapemodel->id;
                         $pointmodel->save();
                         $ii++;
                     }
                     if (!$shapemodel->points) {
                         $shapemodel->delete();
                     }
                 }
             }
             $this->redirect(array('/holes/myarea'));
         }
     }
     $this->render('myarea', array('model' => $model));
 }