Esempio n. 1
0
 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 a new ClientBeacons model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new ClientBeacons();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('client-beacon-form', ['model' => $model]);
     }
 }