예제 #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = NRESProperty::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'latitude' => $this->latitude, 'longitude' => $this->longitude, 'status' => $this->status]);
     $query->andFilterWhere(['like', 'streetAddress', $this->streetAddress])->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'city', $this->city])->andFilterWhere(['like', 'state', $this->state])->andFilterWhere(['like', 'zipcode', $this->zipcode])->andFilterWhere(['=', 'client', $this->client]);
     if (isset($params['ids'])) {
         $query->andWhere('id IN (' . $params['ids'] . ')');
     }
     if (isset($params['orderBy'])) {
         $query->orderBy([$params['orderBy'] => SORT_ASC]);
     }
     return $dataProvider;
 }
예제 #2
0
 private function getAlertIdInformation($alertId)
 {
     try {
         if ($alertId) {
             $alertData = models\WeatherAlert::findOne($alertId);
             if (!$alertData) {
                 throw new Exception('Record with alertId=' . $alertId . ' not found in our database');
             }
             $WeatherAlertArea = models\WeatherAlertArea::find()->where(['WeatherAlert_id' => $alertData->id])->one();
             $areaForAlertData = models\AreaDefinition::findAll(['WeatherAlertArea_id' => $WeatherAlertArea->id]);
             $alertCircle = new \stdClass();
             $alertPolygonCoordinates = [];
             foreach ($areaForAlertData 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;
                 }
             }
             //                var_dump($alertPolygonCoordinates);die;
             $propertiesList = models\NRESProperty::find()->where(['status' => models\NRESProperty::STATUS_ACTIVE])->all();
             $pointChecker = new PointInPolygon();
             $this->_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;
                     }
                 }
                 if ($isPropertyAffectedByAlert) {
                     $this->_affectedProperties[] = $property;
                 }
             }
             if (!$this->_affectedProperties) {
                 throw new Exception("There are no properties affected by this Alert. Nothing to export");
             }
             return $alertData;
         } else {
             throw new Exception('Please choose Alert that you want to export');
         }
     } catch (\Exception $e) {
         echo json_encode(['error' => $e->getMessage()]);
     }
     Yii::$app->end();
 }
예제 #3
0
 public function actionExportrest()
 {
     $startTime = time();
     $this->_writeLogLine('Start Date/Time - ' . date('Y-m-d\\TH:i:s', $startTime));
     header('Content-type: application/json');
     try {
         $data = file_get_contents("php://input");
         $data = json_decode($data);
         if ($data && isset($data->alertId)) {
             $this->format = isset($data->format) && $data->format ? $data->format : $this->format;
             $this->tmpPath = isset($data->tmpPath) && $data->tmpPath ? $data->tmpPath : $this->tmpPath;
             if (!is_dir(Yii::$app->basePath . '/' . $this->tmpPath . '/')) {
                 throw new Exception('Temp directory path is invalid.');
             }
             $alertData = models\WeatherAlert::findOne($data->alertId);
             if (!$alertData) {
                 throw new Exception('Record with alertId=' . $data->alertId . ' not found in our database');
             }
             $areaForAlertData = models\AreaDefinition::findAll(['WeatherAlertArea_id' => $alertData->id]);
             $alertCircle = new \stdClass();
             $alertPolygonCoordinates = [];
             foreach ($areaForAlertData 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;
                 }
             }
             //                var_dump($alertPolygonCoordinates);die;
             $propertiesList = models\NRESProperty::find()->all();
             $pointChecker = new PointInPolygon();
             $this->_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;
                     }
                 }
                 if ($isPropertyAffectedByAlert) {
                     $this->_affectedProperties[] = $property;
                 }
             }
             if (!$this->_affectedProperties) {
                 throw new Exception("There are no properties affected by this Alert (" . $alertData->id . ")");
             }
             switch ($this->format) {
                 case 'csv':
                     $generatedFileURL = $this->generateCSV($alertData);
                     break;
                 case 'pdf':
                     $generatedFileURL = $this->generatePDF($alertData);
                     break;
                 default:
                     throw new Exception("Invalid format of output file is defined");
             }
             $this->_writeLogLine('Affected Properties - ' . count($this->_affectedProperties));
             $this->_writeLogLine('Generated File URL - ' . $generatedFileURL);
             $this->_writeLogLine('End Date/Time - ' . date('Y-m-d\\TH:i:s', time()));
             //Now we need to check if some properties are located inside this coordinates
             $responce = ['fileUrl' => $generatedFileURL, 'affectedProperties' => count($this->_affectedProperties)];
             header('Content-type: application/json');
             echo json_encode($responce);
             //                if ($this->_debug == 'true') {
             //
             //                    echo json_encode(array_merge(['start'=>date('Y-m-d\TH:i:s',$startTime),'end'=>date('Y-m-d\TH:i:s',$endTime)],(array)$atomGeneralInformation));
             //                } else {
             //                    echo json_encode(['result'=>'Job Done']);
             //                }
         } else {
             throw new Exception('Missing alertId parameter');
         }
     } catch (\Exception $e) {
         echo json_encode(['error' => $e->getMessage()]);
         $this->_writeLogLine($e->getMessage());
     }
     Yii::$app->end();
 }
예제 #4
0
파일: index.php 프로젝트: AnduZhang/nws
$this->title = 'Properties';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="actions">
    <div class="container">
        <?= Html::a(Yii::t('user', 'Add New Properties...'), ['/nresproperty/create'], ['data-method' => 'post','id'=>'addProperty','class'=>'btn btn-blue']) ?>
    </div>
</div>
<div class="container">
    <div class="filters">
        <?php $form = ActiveForm::begin([
            'action' => ['index'],
            'method' => 'get',
        ]); ?>
        <?php  echo $form->field($searchModel, 'client')->dropDownList(ArrayHelper::map(NRESProperty::find()->orderBy('client ASC')->all(), 'client', 'client')
            ,['class'=>'','onchange'=>'this.form.submit()','prompt'=>'Client: All'])->label(false) ?>

        <?php ActiveForm::end(); ?>
    </div>

    <div class="data-index">
        <?php Pjax::begin(['id' => 'properties']) ?>
        <?= GridView::widget([

            'dataProvider' => $dataProvider,

            'layout'=>"{items}\n{pager}",
            'tableOptions'=>['class'=>'table table-striped table-hover table-normal'],
            'pager' => [
                'firstPageLabel' => 'First',