public function actionAffectedpropertieslist($id = null, $makeRead = false) { if (!Yii::$app->request->isAjax && Yii::$app->request->isGet) { $this->redirect(['account/alerts']); } $returnArray = []; $affectedProperties = null; $weatherAlert = models\WeatherAlertSearch::findOne($id); if ($weatherAlert) { $returnArray['alert'] = $weatherAlert->attributes; $WeatherAlertArea = models\WeatherAlertArea::find()->where(['WeatherAlert_id' => $id])->one(); $allCoordinates = models\AreaDefinition::findAll(['WeatherAlertArea_id' => $WeatherAlertArea->id]); foreach ($allCoordinates as $coordinateScope) { $returnArray['coordinates'][] = $coordinateScope->attributes; } $propertiesList = models\NRESProperty::find()->where(['status' => models\NRESProperty::STATUS_ACTIVE])->all(); $pointChecker = new PointInPolygon(); $alertCircle = new \stdClass(); $alertPolygonCoordinates = []; foreach ($allCoordinates as $coordinates) { if ($coordinates->radius) { $alertCircle->radius = $coordinates->radius; //Radius can be only one record $alertCircle->centerLat = $coordinates->latitude; //Radius can be only one record $alertCircle->centerLon = $coordinates->longitude; //Radius can be only one record } else { $alertPolygonCoordinates[] = $coordinates->latitude . ' ' . $coordinates->longitude; } } $affectedProperties = []; foreach ($propertiesList as $property) { $isPropertyAffectedByAlert = false; if (isset($alertCircle->radius)) { //Checking circle coordinates if ($pointChecker->pointInsideCircle($alertCircle->centerLat, $alertCircle->centerLon, $alertCircle->radius, $property->latitude, $property->longitude)) { $isPropertyAffectedByAlert = true; } } if (!empty($alertPolygonCoordinates)) { if ($pointChecker->pointInPolygon($property->latitude . ' ' . $property->longitude, $alertPolygonCoordinates) !== "outside") { $isPropertyAffectedByAlert = true; } } // var_dump($isPropertyAffectedByAlert); if ($isPropertyAffectedByAlert) { $affectedProperties[] = $property->id; } } if ($makeRead == 'true') { $this->_markAlertReaded($weatherAlert->id); } } $IdsList = $affectedProperties ? implode(',', $affectedProperties) : 0; // $provider = new ActiveDataProvider([ // 'query' => models\NRESProperty::find()->where(['status'=>models\NRESProperty::STATUS_ACTIVE])->andWhere('id IN (' . $IdsList . ')'), // ]); $searchModel = new models\NRESPropertySearch(); $searchModel->status = models\NRESProperty::STATUS_ACTIVE; $dataProvider = $searchModel->search(array_merge(Yii::$app->request->queryParams, ['ids' => $IdsList])); $clients = $searchModel->search(array_merge(Yii::$app->request->queryParams, ['ids' => $IdsList, 'orderBy' => 'client']))->getModels(); // var_dump($clients); return $this->renderAjax('//account/_affected', ['dataProvider' => $dataProvider, 'searchModel' => $searchModel, 'clients' => $clients]); }
/** * Lists all NRESProperty models. * @return mixed */ public function actionIndex() { $searchModel = new NRESPropertySearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]); }