public function actionBeaconData($beacons) { $return = []; if ($beacons = json_decode($beacons, true)) { foreach ($beacons as $beacon) { if (isset($beacon['uuid']) && isset($beacon['minor']) && isset($beacon['major'])) { $beacon = Beacons::find()->filterWhere(['uuid' => $beacon['uuid'], 'minor' => $beacon['minor'], 'major' => $beacon['major']])->one(); if ($beacon instanceof Beacons) { $beacon_statistic = new ClientBeacons(); $beacon_statistic->beacon_id = $beacon->id; if ($this->client_user instanceof ClientUsers) { $beacon_statistic->client_id = $this->client_user->id; } $beacon_statistic->save(); $beacon = $beacon->toArray(); $beacon['status'] = self::OK; } else { $beacon = ['status' => self::NOT_FOUND]; } $return[] = $beacon; } else { $return[] = ['status' => self::INVALID_REQUEST_DATA]; } } return $return; } else { throw new HttpException(400, 'Invalid data'); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params = []) { $query = ClientBeacons::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => self::ITEMS_PER_PAGE], 'sort' => ['attributes' => ['beaconTitle' => ['asc' => [Beacons::tableName() . '.title' => SORT_ASC], 'desc' => [Beacons::tableName() . '.title' => SORT_DESC]], 'created' => ['asc' => ['created' => SORT_ASC], 'desc' => ['created' => SORT_DESC]], 'updated' => ['asc' => ['updated' => SORT_ASC], 'desc' => ['updated' => SORT_DESC]]]]]); $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->joinWith('beacon', function (ActiveQuery $query) { $query->andFilterWhere('title', $this->beaconTitle); }); $query->andFilterWhere(['id' => $this->id, 'client_id' => $this->client_id, 'beacon_id' => $this->beacon_id]); return $dataProvider; }
/** * Provides json response for select2 plugin */ public function actionGetSelectionById() { self::selectionById(ClientBeacons::className(), 'name'); }
public function getClientBeacons() { return $this->hasMany(ClientBeacons::className(), ['beacon_id' => 'id']); }