public function configUser($userId, Request $request)
 {
     $data = $this->userData($request);
     $editUser = Users::find($userId);
     \Log::info("inside configUser for {$userId}");
     $userRoles = UserRoles::where('user_id', $userId)->get();
     if ($editUser) {
         $data['user_id'] = $userId;
         $data['first_name'] = $editUser->first_name;
         $data['last_name'] = $editUser->last_name;
         $roles = Roles::orderBy('id')->get();
         $result = "<option value=''>select Roles</option>";
         foreach ($roles as $role) {
             $selected = '';
             foreach ($userRoles as $userRole) {
                 if ($role->id == $userRole->role_id) {
                     $selected = 'selected';
                 }
             }
             $result .= "<option value='{$role->id}' {$selected}>{$role->role_name}</option>";
         }
         $data['MemberRoles'] = $result;
         $data['SponsorId'] = $editUser->sponsor_id;
         $data['title'] = 'Admin';
         $data['description'] = 'Admin';
         return view('configUser', $data);
     } else {
         $data['selectNames'] = '';
         $data['title'] = 'Admin';
         $data['description'] = 'Admin';
         return view('configuration', $data);
     }
 }
Exemple #2
0
 public function run()
 {
     Eloquent::unguard();
     DB::statement('SET FOREIGN_KEY_CHECKS=0;');
     DB::table('users')->truncate();
     DB::table('roles')->truncate();
     DB::table('role_users')->truncate();
     DB::table('activations')->truncate();
     DB::table('throttle')->truncate();
     DB::table('persistences')->truncate();
     DB::table('reminders')->truncate();
     DB::statement('SET FOREIGN_KEY_CHECKS=1;');
     $adminrole = ['name' => 'Administrator', 'slug' => 'administrator', 'permissions' => ['admin' => true, 'user.*' => true, 'order.*' => true, 'category.*' => true, 'approval.*' => false, 'approval.*' => false]];
     $adminRole = Roles::firstOrNew($adminrole)->save();
     //Manager Role and user
     $role = ['name' => 'Manager', 'slug' => 'manager', 'permissions' => ['admin' => false, 'user.*' => true, 'order.*' => true, 'category.*' => true, 'approval.*' => true]];
     $managerRole = Roles::firstOrCreate($role);
     //      Sentinel::getRoleRepository()->createModel()->fill($role)->save();
     $role = ['name' => 'Member', 'slug' => 'member', 'permissions' => ['order.*' => true]];
     $memberRole = Roles::firstOrCreate($role);
     $admin = ['first_name' => 'admin', 'last_name' => 'admin', 'email' => '*****@*****.**', 'password' => 'password', 'permissions' => ['admin' => true, 'user.*' => true, 'order.*' => true, 'category.*' => true, 'approval.*' => false]];
     $adminUser = Sentinel::registerAndActivate($admin);
     $adminUser->roles()->attach($adminRole);
     $managerUsers = [['first_name' => 'Peter', 'last_name' => 'Du', 'email' => '*****@*****.**', 'password' => 'password', 'permissions' => ['admin' => false, 'user.*' => true, 'order.*' => true, 'category.*' => true, 'approval.*' => true]]];
     foreach ($managerUsers as $each) {
         $Manager = \Sentinel::registerAndActivate($each);
         $Manager->roles()->attach($managerRole->id);
     }
     //members
     $memberusers = [['first_name' => 'demo', 'last_name' => 'demo', 'email' => '*****@*****.**', 'password' => 'demo123', 'permissions' => ['order.*' => true]], ['first_name' => 'demo', 'last_name' => '2', 'email' => '*****@*****.**', 'password' => 'demo123', 'permissions' => ['order.*' => true]], ['first_name' => 'demo', 'last_name' => '3', 'email' => '*****@*****.**', 'password' => 'demo123', 'permissions' => ['order.*' => true]]];
     foreach ($memberusers as $user) {
         $member = Sentinel::registerAndActivate($user);
         $member->roles()->attach($memberRole->id);
     }
     $faker = Faker\Factory::create();
     foreach (range(1, 10) as $index) {
         $fakeruser = ['first_name' => $faker->firstName, 'last_name' => $faker->lastName, 'email' => $faker->safeEmail, 'password' => $faker->password(6), 'permissions' => ['order.*' => true]];
         $user = Sentinel::registerAndActivate($fakeruser);
         $user->roles()->attach($memberRole->id);
     }
 }
Exemple #3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getRoles()
 {
     return $this->hasMany(Roles::className(), ['id' => 'role_id'])->viaTable('user_role', ['user_id' => 'id']);
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getItemname0()
 {
     return $this->hasOne(Roles::className(), ['name' => 'itemname']);
 }
Exemple #5
0
 public function getRoles()
 {
     return $this->hasMany(Roles::className(), ['id' => 'roleId'])->viaTable('UsuariosRoles', ['usuarioId' => 'id']);
 }
Exemple #6
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getRoles()
 {
     return $this->hasOne(Roles::className(), ['id' => 'roleId']);
 }
 public function getformAction()
 {
     $rolesModel = new Roles();
     $this->view->roles = $rolesModel->select();
 }
Exemple #8
0
 public function actionImprimir()
 {
     // get your HTML raw content without any layouts or scrip
     $roles = Roles::find()->all();
     $content = $this->renderPartial('_imprimir', ['roles' => $roles]);
     $header = $this->renderPartial('_header', ['roles' => $roles]);
     $pdf = new Pdf(['format' => Pdf::FORMAT_A4, 'orientation' => Pdf::ORIENT_PORTRAIT, 'destination' => Pdf::DEST_BROWSER, 'content' => $content, 'cssFile' => '@vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.min.css', 'cssInline' => '.kv-heading-1{font-size:18px}', 'options' => ['title' => 'Krajee Report Title'], 'methods' => ['SetHeader' => $header, 'SetFooter' => ['{PAGENO}']]]);
     // return the pdf output as per the destination setting
     return $pdf->render();
 }
Exemple #9
0
 public function get_all_roles()
 {
     return Roles::all()->pluck('label', 'roles');
 }
 public function actionPermisos($id)
 {
     if (isset($_POST['permisos'])) {
         foreach ($_POST['permisos'] as $permiso) {
             if (isset($permiso['id'])) {
                 $modelttr = TipoTramitesRoles::find()->where('id = :id', ['id' => $permiso['id']])->one();
             } else {
                 $modelttr = new TipoTramitesRoles();
             }
             $modelttr->roleId = $permiso['rolid'];
             $modelttr->tipoTramiteId = $permiso['tipoTramiteId'];
             if (isset($permiso['leer'])) {
                 $modelttr->leer = 1;
             } else {
                 $modelttr->leer = 0;
             }
             if (isset($permiso['crear'])) {
                 $modelttr->crear = 1;
             } else {
                 $modelttr->crear = 0;
             }
             if (isset($permiso['actualizar'])) {
                 $modelttr->actualizar = 1;
             } else {
                 $modelttr->actualizar = 0;
             }
             if (isset($permiso['borrar'])) {
                 $modelttr->borrar = 1;
             } else {
                 $modelttr->borrar = 0;
             }
             $modelttr->save();
             if (isset($permiso['ppt'])) {
                 foreach ($permiso['ppt'] as $ppt) {
                     if (isset($ppt['leer']) or isset($ppt['crear']) or isset($ppt['actualizar']) or isset($ppt['borrar'])) {
                         if (isset($ppt['id'])) {
                             $modelppt = PermisosPasoTramite::find()->where('id = :id', ['id' => $ppt['id']])->one();
                         } else {
                             $modelppt = new PermisosPasoTramite();
                         }
                         $modelppt->pasoTramiteId = $ppt['ptid'];
                         $modelppt->tipoTramiteRoleId = $modelttr->id;
                         if (isset($ppt['leer'])) {
                             $modelppt->leer = 1;
                         } else {
                             $modelppt->leer = 0;
                         }
                         if (isset($ppt['crear'])) {
                             $modelppt->crear = 1;
                         } else {
                             $modelppt->crear = 0;
                         }
                         if (isset($ppt['actualizar'])) {
                             $modelppt->actualizar = 1;
                         } else {
                             $modelppt->actualizar = 0;
                         }
                         if (isset($ppt['borrar'])) {
                             $modelppt->borrar = 1;
                         } else {
                             $modelppt->borrar = 0;
                         }
                         $modelppt->save();
                     }
                 }
             }
         }
     }
     $tipoTramite = TiposTramite::find()->where('id = :id', ['id' => $id])->one();
     $roles = Roles::find()->all();
     $pasosTramite = PasosTramite::find()->all();
     return $this->render('permisos', ['tipoTramite' => $tipoTramite, 'roles' => $roles, 'pasosTramite' => $pasosTramite]);
 }
 /**
  * 多对多关系
  * 与function userRole() 对应
  * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  * A hasMany/hasOne B and B hasMany/hasOne A
  */
 public function roleUser()
 {
     $obj = new Roles();
     $rows = $obj->find(1)->user->toarray();
     print_r($rows);
     return view('index');
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy(Request $request)
 {
     Roles::destroy($request->rID);
     return "success";
 }
Exemple #13
0
echo $form->field($model, 'email')->textInput(['maxlength' => true]);
?>

    <?php 
echo $form->field($model, 'status')->hiddenInput(['value' => '10'])->label(false);
?>

    <?php 
echo $model->isNewRecord ? $form->field($model, 'created_at')->hiddenInput(['value' => time()])->label(false) : '';
?>

    <?php 
echo $form->field($model, 'updated_at')->hiddenInput(['value' => time()])->label(false);
?>

    <?php 
echo $form->field($model, 'role_id')->dropDownList(ArrayHelper::map(Roles::find()->all(), 'id', 'name'), array('prompt' => 'Wybierz rodzaj użytkownika'));
?>

    <div class="form-group">
        <?php 
echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
    </div>

    <?php 
ActiveForm::end();
?>

</div>
Exemple #14
0
 /**
  * Finds the Roles model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Roles the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Roles::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('Strona nie istnieje');
     }
 }
Exemple #15
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getItemnames()
 {
     return $this->hasMany(Roles::className(), ['name' => 'itemname'])->viaTable('users_roles', ['user_id' => 'id']);
 }