/** * @param bool $insert * @param array $changedAttributes * @throws \WebSocket\BadOpcodeException */ public function afterSave($insert, $changedAttributes) { Yii::trace('try to send a call information to site ' . $this->paramint, 'app\\modules\\event\\PhoneEvent::afterSave'); //initialize the response object $res = []; $res['type'] = 'call'; $res['site'] = $this->paramint; $WSServer = \Yii::$app->params['websocketServerProtocol'] . \Yii::$app->params['clientCallWebsocketServerHost'] . ':' . \Yii::$app->params['clientCallWebsocketServerPort']; $client = new Client($WSServer); $timeinfo = Yii::$app->formatter->asDateTime($this->updated_at); $html = <<<EOF \t<div style="width:250px" class="event_notification"> \t\t<div class="{$this->action}"> \t\t\t<i class="fa fa-phone"></i> {$this->action} \t\t</div> \t\t<small>{$timeinfo}</small><br> \t\t<a href="#"> \t\t\tYou have an {$this->mod_table} call from {$this->paramtext}. \t\t</a> \t</div> EOF; $res['data'] = $html; try { $client->send(Json::encode($res)); } catch (ConnectionException $e) { echo "\n" . microtime(true) . " Client died: {$e}\n"; } return parent::afterSave($insert, $changedAttributes); }
public function searchLog($params) { $query = Event::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['created_at' => SORT_DESC]], 'pagination' => ['pageSize' => 5]]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'paramint' => $this->paramint, 'paramfloat' => $this->paramfloat, 'paramdate' => $this->paramdate, 'paramdatetwo' => $this->paramdatetwo, 'paramdatethree' => $this->paramdatethree, 'paramdateint' => $this->paramdateint, 'mod_id' => $this->mod_id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'deleted_at' => $this->deleted_at]); $query->andFilterWhere(['like', 'user', $this->user])->andFilterWhere(['like', 'action', $this->action])->andFilterWhere(['like', 'paramstring', $this->paramstring])->andFilterWhere(['like', 'paramtext', $this->paramtext])->andFilterWhere(['like', 'mod_table', $this->mod_table]); return $dataProvider; }
/** * function run * * @return mixed */ public function run() { $dataset = \app\modules\event\models\Event::find()->SELECT(['FROM_UNIXTIME(created_at, \'%H\' ) AS created_at', 'COUNT(created_at) AS mod_id'])->where('FROM_UNIXTIME(created_at, \'%Y%m%d\' ) = DATE_FORMAT(NOW(),\'%Y%m%d\')')->groupBy(['FROM_UNIXTIME(created_at, \'%H\' )'])->orderBy('created_at ASC')->limit(24)->all(); $labels = []; $values = []; foreach ($dataset as $data) { $labels[] = $data->created_at; $values[] = $data->mod_id; } return $this->render('@app/modules/templates/widgets/stats/views/_statistic', ['labels' => $labels, 'values' => $values]); }
/** * Finds the Event model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Event the loaded model * @throws HttpException if the model cannot be found */ protected function findModel($id) { if (($model = Event::findOne($id)) !== null) { return $model; } else { throw new HttpException(404, 'The requested page does not exist.'); } }