/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Groups::find(); $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; } $query->andFilterWhere(['id' => $this->id, 'office_id' => $this->office_id]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'status', $this->status]); return $dataProvider; }
/** * Displays a single Members model. * @param string $id * @return mixed */ public function actionView($id) { $dataProviderForGroupAss = new ActiveDataProvider(['query' => GroupAssignments::find()]); $dataProviderForGroup = new ActiveDataProvider(['query' => Groups::find()]); $dataProviderForProject = new ActiveDataProvider(['query' => Projects::find()]); try { $modelPic = new UploadForm(); if (Yii::$app->request->isPost) { $modelPic->file = UploadedFile::getInstance($modelPic, 'file'); if ($modelPic->validate() && $modelPic !== null) { $fileName = round(microtime(true) * 1000); $uploadPath = 'uploads/' . $fileName . '.' . $modelPic->file->extension; $modelPic->file->saveAs($uploadPath); //save avatar to user $model = $this->findModel($id); $model->avatar = $uploadPath; $model->save(); } } } catch (\Exception $e) { } return $this->render('view', ['model' => $this->findModel($id), 'modelPic' => $modelPic, 'dataProviderForGroupAss' => $dataProviderForGroupAss, 'dataProviderForGroup' => $dataProviderForGroup, 'dataProviderForProject' => $dataProviderForProject]); }
/* @var $searchModel app\models\UserSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = 'รายชื่อเจ้าหน้าที่ทั้งหมด'; $this->params['breadcrumbs'][] = $this->title; ?> <div class="user-index"> <div class="page-header"> <h4><?php echo Html::encode($this->title); ?> </h4> </div> <?php //echo $this->render('_search', ['model' => $searchModel]); $data = ArrayHelper::map(\app\models\Groups::find()->all(), 'name', 'name'); echo Html::dropDownList('groups', null, $data, ['prompt' => '- select group -', 'onchange' => ' $.pjax.reload({ url: "' . Url::to(['index2']) . '?UserSearch[group_id]="+$(this).val(), container: "#pjax-gridview", timeout: 1000, }); ', 'class' => 'form-control']); ?> <p> <?php Pjax::begin(['id' => 'pjax-gridview']); ?> <?php echo GridView::widget(['id' => 'user-grid', 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'containerOptions' => ['style' => 'overflow: auto'], 'pjax' => true, 'exportConfig' => true, 'floatHeader' => true, 'hover' => true, 'panel' => ['type' => GridView::TYPE_PRIMARY, 'heading' => '<h3 class="panel-title"><i class="glyphicon glyphicon-book"></i> ' . $this->title . '</h3>', 'before' => '<div style="padding-top: 7px;"><em>* The table at the right you can pull reports</em></div>'], 'toolbar' => [['content' => Html::a('<i class="glyphicon glyphicon-plus"></i>', ['user/create'], ['type' => 'button', 'title' => 'Add ' . $this->title, 'class' => 'btn btn-success']) . ' ' . Html::a('<i class="glyphicon glyphicon-repeat"></i>', ['user/index2'], ['data-pjax' => 0, 'class' => 'btn btn-default', 'title' => 'Reset Grid'])], '{export}'], 'export' => ['fontAwesome' => true], 'columns' => [['class' => 'kartik\\grid\\SerialColumn'], 'name', 'phone', 'city', ['class' => 'kartik\\grid\\BooleanColumn', 'attribute' => 'status', 'vAlign' => 'middle'], ['class' => 'yii\\grid\\ActionColumn', 'options' => ['style' => 'width:120px;'], 'template' => '<div class="btn-group btn-group-sm" role="group" aria-label="...">{view}{update}{delete}</div>', 'buttons' => ['view' => function ($url, $model, $key) {
public function listHotspots(Request $request) { try { $idGroup = $request->input('groups_id'); $dataGroup = Groups::find($idGroup); $exercise = new Hostpots(); if ($dataGroup->customer_id == Auth::customer()->user()->id) { $data = $exercise->listHotspots($dataGroup->customer_id, 'email_owner'); } else { $data = $exercise->listHotspots($dataGroup->customer_id, 'mac'); } $return = array('state' => 1, 'msg' => 'ok', 'data' => $data); } catch (Exception $exc) { $return = array('state' => 0, 'msg' => $exc->getMessage()); } return response()->json($return); }
public function register() { Users::redirectIf(true); $nickname = Helper::post('nickname'); $password = Helper::post('password'); $confirm = Helper::post('password_confirm'); $email = Helper::post('email'); if (empty($nickname) || empty($password) || empty($confirm) || empty($email)) { Session::setFlash('danger', '', Translate::get('error.forms.missing.content')); Router::redirect('user.signup'); } $errors = []; if (strlen($nickname) < 3 || strlen($nickname) > 40) { $errors['username'] = Translate::get('register.error.username'); } if (!preg_match('#[a-zA-Z0-9\\_\\.]+#', $nickname)) { $errors['username'] = Translate::get('register.error.username'); } if (strlen($password) < 6) { $errors['password'] = Translate::get('register.error.password'); } if ($password != $confirm) { $errors['password'] = Translate::get('register.error.password_confirm'); } if (!preg_match('/[a-zA-Z0-9\\_\\-\\.]{3,}@[a-zA-Z0-9\\-]{2,}\\.[a-z]{2,6}/', $email)) { $errors['email'] = Translate::get('register.error.email'); } if (!empty($errors)) { ob_start(); Translate::getContent('error_fields', ['errors' => $errors]); $content = ob_get_clean(); Session::setFlash('danger', '', $content); Router::redirect('user.signup'); } $users = Users::select()->addFields(['id'])->where('nickname', $nickname)->andWhere('mail', $email)->get(0, 1); if (!empty($users)) { Session::setFlash('danger', '', Translate::get('user.error.register')); Router::redirect('user.signup'); } $random = ''; while ($random == '') { $random = Config::randomString(14); if (Users::find('user_key', $random)) { $random = ''; } } $default_group = Groups::find('g_default', 1); $user = Users::create(); $user->id_group = $default_group->id; // TODO: Change for default group $user->nickname = $nickname; $user->password = password_hash($password, PASSWORD_BCRYPT); $user->user_key = $random; $user->mail = $email; $user->mail_check = sha1($user->user_key); $user->mail_check_at = BaseModel::now(); $user->register_at = BaseModel::now(); $user->connection_at = '0000-00-00 00:00:00'; $user->save(); Users::sendMailCheck($user); Session::setFlash('success', '', Translate::get('user.success.register')); Router::redirect('home.index'); }
/** * Lists all Groups models. * @return mixed */ public function actionIndex() { $dataProvider = new ActiveDataProvider(['query' => Groups::find()]); return $this->render('index', ['dataProvider' => $dataProvider]); }
/** * Help function to search database for the groups * that the current logged-in user joined * * @return ['myGroups'=>ActiveRecord, 'pagenation'=>Pagination] */ private function getJoinedGroups() { $NJ = 'NATURAL JOIN'; $queryJoinedGroup = Groups::find()->join($NJ, ['groupmembers'])->where(['m_user' => $this->getUser()->username])->select('*'); $pagination_joinedgroup = new Pagination(['defaultPageSize' => 2, 'totalCount' => $queryJoinedGroup->count(), 'pageParam' => 'joined-page']); $joinedGroups = $queryJoinedGroup->offset($pagination_joinedgroup->offset)->limit($pagination_joinedgroup->limit)->all(); return ['joinedGroups' => $joinedGroups, 'pagenation' => $pagination_joinedgroup]; }
public function actionCategories() { $return = []; $groups = Groups::find()->all(); foreach ($groups as $group) { $return[] = $group->toArray(['id', 'name']); } return $return; }
public function getGroupsProvider() { $dataProvider = new ActiveDataProvider(['query' => Groups::find()->joinWith(['users' => function ($query) { $query->andFilterWhere(['users.id' => $this->id]); }]), 'pagination' => ['pageSize' => 5]]); return $dataProvider; }
public function postValidateSchool(Request $request) { $registration_code = $request->input('registration_code'); $group_id = $request->input('group_id'); $input = ['group_id' => $group_id, 'registration_code' => $registration_code]; $validator = validator::make($request->all(), ['group_id' => 'required', 'registration_code' => 'required']); if ($validator->fails()) { return ApiResponseClass::errorResponse('You Have Some Input Errors. Please Try Again!!', $input, $validator->errors()); } else { $code = array(); $group = Groups::find($group_id); if ($group && $group->count() > 0) { if ($group_id == Groups::Teacher_Group_Id) { $code_for_teachers = $request->input('code_for_teachers'); $school = Schools::where('registration_code', $registration_code)->where('code_for_teachers', $code_for_teachers)->get()->first(); $code = array('code_for_teachers' => $code_for_teachers); } elseif ($group_id == Groups::Student_Group_Id) { $code_for_students = $request->input('code_for_students'); $school = Schools::where('registration_code', $registration_code)->where('code_for_students', $code_for_students)->get()->first(); $code = array('code_for_students' => $code_for_students); } elseif ($group_id == Groups::Administrator_Group_ID) { $code_for_admin = $request->input('code_for_admin'); $school = Schools::where('registration_code', $registration_code)->where('code_for_admin', $code_for_admin)->get()->first(); $code = array('code_for_admin' => $code_for_admin); } $input = array('registration_code' => $registration_code, 'group_id' => $group_id); $input = array_merge($input, $code); if ($school && $school->count() > 0) { $result = array('school' => $school); $users_registered_to_school = UsersRegisteredToSchool::where('user_id', Auth::user()->id)->where('school_id', $school->id)->get()->first(); if ($users_registered_to_school) { return ApiResponseClass::successResponse($result, $input); } $users_registered_to_school = new UsersRegisteredToSchool(); $users_registered_to_school->user_id = Auth::user()->id; $users_registered_to_school->school_id = $school->id; $users_registered_to_school->registration_date = date('Y-m-d H:i:s'); $users_registered_to_school->save(); if ($users_registered_to_school->save()) { return ApiResponseClass::successResponse($result, $input); } } else { return ApiResponseClass::errorResponse('School Codes are InValid. Please Try again with Correct Codes!!', $input); } } } return ApiResponseClass::errorResponse('Some Problem Occured. Please Try again With Correct Codes!!', $input); }
public function postGroups(FormGroupsRequest $request) { if (!empty($request)) { $data = $request->all(); $data['customer_id'] = $request->get('customer_id', 0); $data['flagactive'] = $request->get('flagactive', 1); if ($request->id) { $obj = Groups::find($request->id); $obj->update($data); } else { $obj = Groups::create($data); } return array('msg' => 'ok', 'state' => 1, 'data' => null); } return array('msg' => 'Error al guardar el modelo', 'state' => 0, 'data' => null); }
public function getEquipmentsFree(Request $request) { $groups_id = $request->input('groups_id'); if (isset($groups_id) && !empty($groups_id)) { $dataGroup = \App\Models\Groups::find($groups_id); if ($dataGroup->customer_id != 0) { $newHostPots = new Hostpots(); $data = $newHostPots->listHotspots($dataGroup->customer_id, 'name'); foreach ($data as $value => $e) { $dataInt[] = $value; } } } $HotsPotsGroups = DB::select("select DISTINCT H.id from hotspots as H " . "inner join hotspots_groups as HG ON H.id=HG.hotspots_id "); if (isset($dataInt) && count($dataInt) > 0) { if ($HotsPotsGroups) { foreach ($HotsPotsGroups as $value) { $idHotspots[] = $value->id; } $Hostpots = Hostpots::whereNotIn('id', $idHotspots)->whereIn('id', $dataInt)->orWhere('geocode', 0)->lists('mac', 'id'); } else { $Hostpots = Hostpots::whereIn('id', $dataInt)->whereIn('id', $dataInt)->orWhere('geocode', 0)->lists('mac', 'id'); } } else { if ($HotsPotsGroups) { foreach ($HotsPotsGroups as $value) { $idHotspots[] = $value->id; } $Hostpots = Hostpots::whereNotIn('id', $idHotspots)->whereGeocode(0)->lists('mac', 'id'); } else { $Hostpots = Hostpots::whereGeocode(0)->lists('mac', 'id'); } } return response()->json(array('state' => 1, 'msg' => 'ok', 'data' => $Hostpots)); }