コード例 #1
0
ファイル: AccountController.php プロジェクト: AnduZhang/nws
 public function actionAlerts()
 {
     $alertsModel = new models\WeatherAlert();
     $searchModelPre = new models\WeatherAlertSearch();
     $searchModelPre->type = 0;
     $dataProviderPre = $searchModelPre->search(ArrayHelper::merge(Yii::$app->request->queryParams, ['type' => 0]));
     $searchModelPost = new models\WeatherAlertSearch();
     $searchModelPost->type = 1;
     $dataProviderPost = $searchModelPost->search(ArrayHelper::merge(Yii::$app->request->queryParams, ['type' => 1]));
     $unreadedPre = $alertsModel->getUnreadAlertsCount(0);
     $unreadedPost = $alertsModel->getUnreadAlertsCount(1);
     //
     //        if (Yii::$app->request->isPjax) {
     //            return $this->renderAjax('_pre_storm', [
     //                'searchModelPre' => $searchModelPre,
     //                'dataProviderPre' => $dataProviderPre,
     //                'searchModelPost' => $searchModelPost,
     //                'dataProviderPost' => $dataProviderPost,
     //            ]);
     //        }
     return $this->render('alerts', ['searchModelPre' => $searchModelPre, 'dataProviderPre' => $dataProviderPre, 'searchModelPost' => $searchModelPost, 'dataProviderPost' => $dataProviderPost, 'unreadedPre' => $unreadedPre, 'unreadedPost' => $unreadedPost]);
 }
コード例 #2
0
ファイル: AlertsController.php プロジェクト: AnduZhang/nws
 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]);
 }