Example #1
0
 /**
  * Signs user up.
  *
  * @return Users|null the saved model or null if saving fails
  */
 public function register()
 {
     $user = null;
     $transaction = Yii::$app->db->beginTransaction();
     try {
         $group = new Groups();
         $group->name = $this->email;
         if ($group->save()) {
             $user = parent::register($group->id);
             for ($i = 0; $i < $this->beacon_count; $i++) {
                 $beacon = new Beacons();
                 $beacon->name = Yii::$app->security->generateRandomString(16);
                 $beacon->title = "Such title {$i}";
                 $beacon->description = "So description {$i}";
                 $beacon->minor = $group->id . $user->id . $i;
                 $beacon->major = $group->id . $user->id . $i;
                 $beacon->place = "Wow Place {$i}";
                 $beacon->uuid = UUID::v4();
                 $beacon->groupToBind = $group->id;
                 $beacon->save();
             }
         }
         $transaction->commit();
         return $user;
     } catch (Exception $e) {
         if ($transaction->isActive) {
             $transaction->rollBack();
         }
         return null;
     }
 }
Example #2
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 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;
 }
Example #4
0
 public function clientBeacons($client_user_id = null)
 {
     $query = Beacons::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     if ($client_user_id !== null) {
         $user = ClientUsers::findOne(['id' => $client_user_id]);
         $query->joinWith(['clientBeacons' => function (ActiveQuery $query) use($user) {
             $query->andFilterWhere(['client_id' => $user->id]);
         }]);
     }
     $query->andFilterWhere(['id' => $this->id, 'minor' => $this->minor, 'major' => $this->major]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'uuid', $this->uuid]);
     return $dataProvider;
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getId0()
 {
     return $this->hasOne(Beacons::className(), ['id' => 'id']);
 }
Example #6
0
 public function getBeaconsQuery($query = null)
 {
     if ($query == null) {
         $query = Beacons::find();
     }
     $user = $this;
     $query->joinWith(['groups' => function (ActiveQuery $query) use($user) {
         $query->joinWith(['users' => function (ActiveQuery $query) use($user) {
             $query->andFilterWhere(['users.id' => $user->id]);
         }]);
     }]);
     return $query;
 }
Example #7
0
 public function getBeacons()
 {
     return $this->hasMany(Beacons::className(), ['id' => 'beacon_id'])->via('beaconBindings');
 }
 public function actionGetSelectionById()
 {
     self::selectionById(Beacons::className());
 }