Exemplo n.º 1
0
 /**
  * Search by request criteria.
  *
  * @param array|null Filter params.
  * @return ActiveDataProvider Data provider.
  */
 public function search($params)
 {
     $query = AuthItem::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['name' => SORT_ASC]], 'pagination' => ['pageSize' => 50]]);
     $query->andFilterWhere(['type' => \yii\rbac\Item::TYPE_ROLE]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
Exemplo n.º 2
0
 public function actionSignup()
 {
     $model = new SignupForm();
     $authItems = AuthItem::find()->all();
     if ($model->load(Yii::$app->request->post())) {
         if ($user = $model->signup()) {
             if (Yii::$app->getUser()->login($user)) {
                 return $this->goHome();
             }
         }
     }
     return $this->render('signup', ['model' => $model, 'authItems' => $authItems]);
 }
Exemplo n.º 3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = AuthItem::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 5], 'sort' => ['attributes' => ['Name', 'Type']]]);
     $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(['type' => $this->type, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['ilike', 'name', $this->name])->andFilterWhere(['ilike', 'description', $this->description])->andFilterWhere(['ilike', 'rule_name', $this->rule_name])->andFilterWhere(['ilike', 'data', $this->data]);
     return $dataProvider;
 }
Exemplo n.º 4
0
 public function getRootRoles()
 {
     $raw = AuthItem::find()->where(['type' => 1])->asArray()->all();
     $allRoles = array();
     foreach ($raw as $row) {
         $allRoles[$row['name']] = $row['name'];
     }
     $sql = 'SELECT DISTINCT auth_item.name FROM 13027272d.auth_item, 13027272d.auth_item_child
             WHERE 13027272d.auth_item.name = 13027272d.auth_item_child.child
             AND type = 1';
     $raw = AuthItem::findBySql($sql)->asArray()->all();
     $chileRoles = array();
     foreach ($raw as $row) {
         $chileRoles[$row['name']] = $row['name'];
     }
     return array_diff($allRoles, $chileRoles);
 }
Exemplo n.º 5
0
  <div class=" box view-item col-xs-12 col-lg-12">
<div class="console-users-form">
    <?php 
$form = ActiveForm::begin();
?>

   <div class="col-xs-12 col-lg-12 no-padding">
    <p>&nbsp;</p>
    </div>
    <?php 
if (\Yii::$app->user->can('admin')) {
    ?>
   <div class="col-xs-12 col-lg-12 no-padding">
    <div class="col-sm-6">
    <?php 
    echo $form->field($model, 'user_level')->dropDownList(ArrayHelper::map(AuthItem::find()->where(['type' => 1])->all(), 'name', 'description'), ['id' => 'user_level', 'prompt' => 'Type of User'])->label('');
    ?>
    </div>
    <div class="col-sm-6" id="parent_insurance">
    <?php 
    echo $form->field($model, 'parent_insurance_company')->dropDownList(ArrayHelper::map(InsuranceCompanies::find()->all(), 'id', 'code'), ['id' => 'parent_ins', 'prompt' => 'Select Insurance Company'])->label('');
    ?>
    </div>
   </div>
<?php 
}
?>

   <div class="col-xs-12 col-lg-12 no-padding">
    <div class="col-sm-6">
    <?php 
 public function permissoesSortable()
 {
     $aux = [];
     //Array auxiliar para receber as permissões de cada tipo(agrupados)
     $roles_permission = [];
     // Array que irá guardar um conjunto de um tipo de permissão
     $roles = [];
     /* $authitem = AuthItem::find()
        ->where("name <> 'admin' ")->orderBy('type ASC')->all(); */
     $this->authitems = AuthItem::find()->where("name not like '%-%' and name <> 'admin' and name <> 'alterarprodutovenda'  \n            and name <> 'produtosvenda'   and name <> 'cadastrarprodutovenda'\n            and name <> 'avaliacaoproduto'\n            and name <> 'listadeinsumos'\n            and name <> 'listadeprodutosporinsumo'")->orderBy('type ASC')->all();
     foreach ($this->authitems as $ai) {
         $aux = AuthItem::find()->where("name <> 'admin' and name like '%" . $ai->name . "%' ")->orderBy('type ASC')->all();
         $r = ArrayHelper::map($aux, 'type', 'description');
         /* foreach ($aux as $p) {
                       ArrayHelper::map(
                       $roles_permission[$p->name] ,
                       'type', 'description');
                       $roles_permission[$p->name] = [
                       'content' => $p->description,
                       'options' => ['data' => ['name' => $p->name]],
         
                       } */
         array_push($roles, $r);
         $aux = [];
         $roles_permission = [];
     }
     /* $roles = ArrayHelper::map(
        AuthItem::find()
        ->where("name <> 'admin' and name <> 'alterarprodutovenda'   and name <> 'produtosvenda'   and name <> 'cadastrarprodutovenda'
        and name <> 'avaliacaoproduto'
        and name <> 'listadeinsumos'
        and name <> 'listadeprodutosporinsumo'")->orderBy('type ASC')->all(),
        'type', 'description'); */
     return $roles;
 }
Exemplo n.º 7
0
 /**
  * @return array|null
  * Gera a lista de Permissões com optgroups
  */
 public static function getListToDropDownList()
 {
     $options = [];
     $optGroups = AuthItem::find()->where("name not like '%-%' and name <> 'admin' and name <> 'alterarprodutovenda'  \n            and name <> 'produtosvenda'   and name <> 'cadastrarprodutovenda'\n            and name <> 'avaliacaoproduto'\n            and name <> 'listadeinsumos'\n            and name <> 'listadeprodutosporinsumo'\n            and name <>'definirvalorprodutovenda'")->distinct()->orderBy('type ASC')->all();
     foreach ($optGroups as $macroPermissao) {
         $permissao = [];
         $sqlWhere = "name <> 'admin' and name like 'index-" . $macroPermissao->name . "' or " . "name = '" . $macroPermissao->name . "" . "' or " . "name like 'view-" . $macroPermissao->name . "" . "' or " . "name like 'create-" . $macroPermissao->name . "" . "' or " . "name like 'delete-" . $macroPermissao->name . "" . "' or " . "name like 'index-" . $macroPermissao->name . "" . "' or " . "name like 'update-" . $macroPermissao->name . "'";
         $auxPermissoes = AuthItem::find()->where($sqlWhere)->orderBy('type ASC')->all();
         foreach ($auxPermissoes as $p) {
             $key = $p->name;
             $permissao[$key] = $p->description;
         }
         $options[strtoupper(Yii::t('app', $macroPermissao->name))] = $permissao;
     }
     return $options;
 }
Exemplo n.º 8
0
?>

    <div class="form-group">
        <label class="control-label col-md-3"><?php 
echo $model->getAttributeLabel('is_active');
?>
</label>
        <div class="col-md-9">
            <?php 
echo $form->field($model, 'is_active')->checkbox(['class' => 'make-switch', 'data-size' => 'normal'], false)->label(false);
?>
        </div>
    </div>

    <?php 
echo $form->field($model, 'user_role')->dropDownList(['' => 'Select user role ...'] + ArrayHelper::map(AuthItem::find()->where(['type' => Role::TYPE_ROLE])->all(), 'name', 'name'));
?>

    <?php 
echo $form->field($model, 'title')->textInput(['maxlength' => true]);
?>

    <?php 
echo $form->field($model, 'route')->textInput(['maxlength' => true]);
?>

    <?php 
echo $form->field($model, 'params')->textInput(['maxlength' => true]);
?>

    <?php 
Exemplo n.º 9
0
    <?php 
$form = ActiveForm::begin();
?>
    <div class="col-xs-12 col-lg-12 no-padding">
    <p>&nbsp;</p>
    </div>

<div class="col-xs-12 col-lg-12 no-padding">
    <div class="col-sm-6">
    <?php 
echo $form->field($model, 'parent')->dropDownList(ArrayHelper::map(AuthItem::find()->where(['type' => 1])->all(), 'name', 'name'), ['prompt' => 'Select Role'])->label('');
?>
  </div>
    <div class="col-sm-6">
    <?php 
echo $form->field($model, 'child')->dropDownList(ArrayHelper::map(AuthItem::find()->where(['type' => 2])->all(), 'name', 'name'), ['prompt' => 'Assign Permission'])->label('');
?>
  </div>
  
 <div class="form-group col-xs-12 col-sm-6 col-lg-4 no-padding">
    <div class="col-xs-6">
        <?php 
echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => 'btn btn-block btn-primary']);
?>
    </div>
    <div class="col-xs-6">
    <?php 
echo Html::resetButton('Reset', ['class' => 'btn btn-default btn-block']);
?>
    </div>
</div>
Exemplo n.º 10
0
 /**
  * Updates an existing User model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $modelUser = $this->findModel($id);
     $modelProfile = $this->findModelProfile($id);
     $roles = AuthItem::find()->all();
     $arrayRoles = ArrayHelper::map($roles, 'name', 'description');
     $regions = Region::find()->all();
     $arrayRegions = ArrayHelper::map($regions, 'id', 'name');
     if (!empty($modelUser->password_hash)) {
         $modelUser->password_hash = NULL;
     }
     $modelUser->worker_name = $modelProfile->worker_name;
     $modelUser->telephone = $modelProfile->telephone;
     $modelUser->head_position = $modelProfile->head_position;
     $modelUser->head_name = $modelProfile->head_name;
     $modelUser->region = $modelProfile->region_id;
     $modelUser->access = $modelUser->role->item_name;
     if ($modelUser->load(Yii::$app->request->post())) {
         if ($modelUser->validate()) {
             if ($modelUser->password_hash |= NULL) {
                 $modelUser->setPassword($modelUser->password_hash);
             } else {
                 $modelUser->password_hash = $modelUser->getOldAttribute('password_hash');
             }
             if ($modelUser->save(false)) {
                 $modelProfile->user_id = $modelUser->id;
                 $modelProfile->worker_name = $modelUser->worker_name;
                 $modelProfile->telephone = $modelUser->telephone;
                 $modelProfile->head_position = $modelUser->head_position;
                 $modelProfile->head_name = $modelUser->head_name;
                 $modelProfile->region_id = $modelUser->region;
                 if ($modelProfile->save(false)) {
                     $auth = Yii::$app->authManager;
                     $auth->revokeAll($modelUser->id);
                     $role = $auth->getRole($modelUser->access);
                     if ($auth->assign($role, $modelUser->id)) {
                         return $this->redirect(['view', 'id' => $modelUser->id]);
                     }
                 }
             }
         }
     }
     return $this->render('update', ['model' => $modelUser, 'arrayRoles' => $arrayRoles, 'arrayRegions' => $arrayRegions]);
 }