/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Event::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, 'user_id' => $this->user_id, 'is_finished' => $this->is_finished, 'occur_at' => $this->occur_at, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'theme', $this->theme])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'urgent', $this->urgent]); return $dataProvider; }
/** * @param $event_id * @return bool */ public static function updateMap($event_id) { /** @var Event $event */ $event = Event::find()->with(['locationCurrents' => function ($query) { $query->orderBy('occur_at ASC'); }])->where('id=:event_id and is_finished=:is_finished', ['event_id' => $event_id, 'is_finished' => 0])->one(); if (!$event || !isset($event->locationCurrents[0])) { return false; } $content = ' <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <meta name="viewport" content="initial-scale=1.0, user-scalable=no"/> <title>' . $event->theme . '</title> <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=gZUugrfkf5TKwsGQmxEsliqL"></script> <script type="text/javascript" src="http://api.map.baidu.com/library/CurveLine/1.5/src/CurveLine.min.js"></script> <style type="text/css"> html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; font-family: Microsoft YaHei, monospace } </style> </head> <body> <div style="width:100%;height:100%;border:1px solid gray" id="container"></div> </body> </html>'; $content .= ' <script type="text/javascript"> // 百度地图API功能 var map = new BMap.Map("container"); map.centerAndZoom(new BMap.Point(' . $event->locationCurrents[0]->longitude . ',' . $event->locationCurrents[0]->latitude . '), 14); map.enableScrollWheelZoom(); var points = ['; $first = true; foreach ($event->locationCurrents as $current) { if ($first) { $first = false; } else { $content .= ','; } $content .= 'new BMap.Point(' . $current->longitude . ', ' . $current->latitude . ')'; } $content .= ' ]; var curve = new BMapLib.CurveLine(points, {strokeColor: "blue", strokeWeight: 3, strokeOpacity: 0.5}); //创建弧线对象 map.addOverlay(curve); //添加到地图中 curve.enableEditing(); //开启编辑功能 </script>'; $name = substr(hash('md5', $event_id), 0, 10); $createMap = file_put_contents("/alidata/www/default/maps/{$name}.html", $content); if (!$createMap) { return false; } return true; }
/** **显示针对该事件将要发送短信所需信息的表单,表单中已有信息,在确认发送短信前可以对某些信息进行调整,其中针对涉事儿童个人信息的修改,可以同时更新数据库中该涉事儿童的个人信息. * @param $id * @return string * @throws HttpException */ public function actionPreSendMessage($id) { /** @var Event $event */ $event = Event::find()->where('id=:id', [':id' => $id])->with(['locationCurrents' => function ($query) { $query->orderBy('occur_at DESC')->limit(1); }, 'profiles'])->one(); if (!$event) { throw new HttpException(404, 'The resource you requested does not exist'); } if ($event->is_finished) { throw new HttpException(405, 'The resource you requested has expired'); } $csrf = Yii::$app->request->csrfToken; return $this->render('send_message', ['event' => $event, 'current' => $event->locationCurrents[0], 'profile' => $event->profiles[0], 'csrf' => $csrf]); }