public function actionApi($id) { $this->layout = "plain"; $model = Api::find()->select(['id' => 'id', 'name' => 'api.name', 'last_time_checked' => 'FROM_UNIXTIME(request_sent_at)', 'last_time_working' => 'FROM_UNIXTIME(api_status.last_time_worked_at)', 'status' => 'IF(COALESCE(api_status_code, http_status) = "200", "ok", "error")', 'latency' => 'latency'])->joinWith(['apiStatus'])->where(['id' => $id])->one(); if ($model == null) { throw new \yii\web\HttpException('Not found.'); } return $this->render('api', ['model' => $model]); }
public function actionStatus() { $modelList = Api::find()->select(['id' => 'id', 'name' => 'api.name', 'last_time_checked' => 'FROM_UNIXTIME(request_sent_at)', 'last_time_working' => 'FROM_UNIXTIME(api_status.last_time_worked_at)', 'status' => 'IF(COALESCE(api_status_code, http_status) = "200", "ok", "error")', 'latency' => 'latency'])->join('INNER JOIN', 'api_status', 'api_status.api_id = api.id')->asArray()->all(); $data = []; foreach ($modelList as $i => $model) { $data['api_' . $i] = $model; } \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; return $data; }
public function actionAllApi() { $modelList = Api::find()->all(); $apiRequest = new ApiRequest(); $token = $apiRequest->getToken(); //$apiRequest->breakIt = true; echo "Token: " . $token . PHP_EOL; foreach ($modelList as $model) { $apiRequest->checkApiStatus($model, $token); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Api::find()->joinWith(['apiStatus']); // add conditions that should always apply here $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } // grid filtering conditions $query->andFilterWhere(['id' => $this->id, 'updated_at' => $this->updated_at, 'created_at' => $this->created_at]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'endpoint', $this->endpoint])->andFilterWhere(['like', 'access', $this->access])->andFilterWhere(['like', 'params', $this->params])->andFilterWhere(['like', 'requirement', $this->requirement])->andFilterWhere(['like', 'category', $this->category]); return $dataProvider; }
/** * @return \yii\db\ActiveQuery */ public function getApi() { return $this->hasOne(Api::className(), ['id' => 'api_id']); }