/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Action::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, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'name', $this->name]);
     $query->andFilterWhere(['like', 'data_structure', $this->data_structure]);
     return $dataProvider;
 }
Exemple #2
0
 public static function getAllowedAction($controllerId, $role_id)
 {
     //TODO: Using cache to speed process
     $output = [];
     foreach (Action::find()->where(["controller_id" => $controllerId])->all() as $action) {
         //bypass for super admin
         if ($role_id == 1) {
             $output[] = $action->action_id;
         } else {
             $roleAction = RoleAction::find()->where(["action_id" => $action->id, "role_id" => $role_id])->one();
             if ($roleAction) {
                 $output[] = $action->action_id;
             }
         }
     }
     return $output;
 }
 public function getActionsAll()
 {
     return ArrayHelper::map(Action::find()->all(), 'id', 'name');
 }
Exemple #4
0
function getAllChild($role_id, $parent_id = NULL, $level = 0)
{
    foreach (\app\models\Menu::find()->where(["parent_id" => $parent_id])->all() as $menu) {
        ?>
                    <div class="form-group" style="padding-left: <?php 
        echo $level * 20;
        ?>
px">
                        <label>
                            <input type="checkbox" name="menu[]" value="<?php 
        echo $menu->id;
        ?>
" class="minimal" <?php 
        echo isChecked($role_id, $menu->id) ? "checked" : "";
        ?>
>
                        </label>
                        <label style="padding-left: 10px"> <?php 
        echo $menu->name;
        ?>
</label>
                    </div>
                <?php 
        //Show All Actions
        $camelName = Inflector::id2camel($menu->controller);
        $fullControllerName = "app\\controllers\\" . $camelName . "Controller";
        if (class_exists($fullControllerName)) {
            $reflection = new ReflectionClass($fullControllerName);
            $methods = $reflection->getMethods();
            echo "<div class=\"form-group\" style=\"padding-left: " . ($level * 20 + 10) . "px;\">";
            echo "<label><input type=\"checkbox\" class=\"minimal select-all\" ></label><label style=\"padding: 0px 20px 0px 5px\"> Select All</label>";
            foreach ($methods as $method) {
                if (substr($method->name, 0, 6) == "action" && $method->name != "actions") {
                    $camelAction = substr($method->name, 6);
                    $id = Inflector::camel2id($camelAction);
                    $name = Inflector::camel2words($camelAction);
                    $action = \app\models\Action::find()->where(["action_id" => $id, "controller_id" => $menu->controller])->one();
                    if ($action == NULL) {
                        //If the action not in database, save it !
                        $action = new \app\models\Action();
                        $action->action_id = $id;
                        $action->controller_id = $menu->controller;
                        $action->name = $name;
                        $action->save();
                    }
                    showCheckbox("action[]", $action->id, $name, hasAccessToAction($role_id, $action->id));
                }
            }
            echo "</div>";
        }
        getAllChild($role_id, $menu->id, $level + 1);
    }
}
 public function getActionAll()
 {
     // get all the actions
     return Action::find()->asArray()->all();
 }