/** * Creates data provider instance with search query applied * * @param null $user_id * @param null $group_id * @throws \yii\web\NotFoundHttpException * @return ActiveDataProvider */ public function search($user_id = null, $group_id = null) { $query = Beacons::find(); if (!Yii::$app->user->can(RbacController::admin)) { $user = Users::getLogged(true); $user->getBeaconsQuery($query); } if ($user_id !== null) { $user = Users::findOne(['id' => $user_id]); $user->getBeaconsQuery($query); } if ($group_id !== null) { $group = Groups::findOne(['id' => $group_id]); $query = $group->getBeacons(); } $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; } $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; }
/** * Finds the Groups model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Groups the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Groups::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function saveGroup() { if (!empty($this->groupToBind)) { BeaconBindings::deleteAll(['beacon_id' => $this->id]); $group = Groups::findOne(['id' => $this->groupToBind]); if ($group instanceof Groups) { $beacon_binding = new BeaconBindings(); $beacon_binding->beacon_id = $this->id; $beacon_binding->group_id = $group->id; $beacon_binding->save(); } } }
/** * action without php in views * Update, Delete from gorups or groupmember * * @return ['myGroups'=>ActiveRecord, 'pagenation'=>Pagination] */ public function actionUserAction() { $request = Yii::$app->request; $groupinfo = $request->post(); if ($groupinfo == null) { return $this->render('error', ['name' => 'error', 'message' => 'Request is not operated...']); } $thisuser = $this->getUser()->username; $action = $groupinfo['action']; $groupname = str_replace('`', ' ', $groupinfo['groupname']); switch ($action) { case 'delete': $group = Groups::deleteAll(["l_user" => $thisuser, "groupname" => $groupname]); return $this->goHome(); case 'leave': $l_user = $groupinfo['l_user']; $group = Groups::findOne([["l_user" => $l_user, "groupname" => $groupname]]); if (count($group) != 0 && $group->status != 'c') { $grp_mem = Groupmembers::deleteAll(["l_user" => $groupinfo['l_user'], "groupname" => $groupname, "m_user" => $thisuser]); return $this->goHome(); } return $this->render('error', ['name' => 'error', 'message' => "Unable to leave {$groupname} created by {$l_user}. Checking the status of this group"]); case 'close': $group = Groups::findOne(["l_user" => $thisuser, "groupname" => $groupname]); $group->status = 'c'; $group->update(); return $this->goHome(); case 'join': //check existence of the group $l_user = $groupinfo['l_user']; $group = Groups::findOne([["l_user" => $l_user, "groupname" => $groupname]]); if (count($group) != 0) { $grp_mem = new Groupmembers(); $grp_mem->l_user = $l_user; $grp_mem->groupname = $groupname; $grp_mem->m_user = $thisuser; if ($grp_mem->save()) { return $this->goHome(); } return $this->render('error', ['name' => 'error', 'message' => "Unable to join {$groupname} created by {$l_user}"]); } return $this->render('error', ['name' => 'error', 'message' => "Unable to join {$groupname} created by {$l_user}"]); //return $this->goHome(); //return $this->goHome(); default: return $this->render('error', ['name' => 'error', 'message' => "No Action"]); } }