Ejemplo n.º 1
0
 public function run()
 {
     DB::table('permissions')->delete();
     $roles = array();
     $roles[0] = Role::where('name', '=', 'admin')->first()->id;
     $roles[1] = Role::where('name', '=', 'moderator')->first()->id;
     $resources = Resource::all();
     $actions = array();
     $actions[0] = Action::where('name', '=', 'manage')->first()->id;
     /*
     $actions[0]  = Action::where('name','=','create')->first()->id;
     $actions[1]  = Action::where('name','=','read')->first()->id;
     $actions[2]  = Action::where('name','=','update')->first()->id;
     $actions[3]  = Action::where('name','=','delete')->first()->id
     */
     $data = array();
     foreach ($roles as $role) {
         foreach ($resources as $resource) {
             foreach ($actions as $action) {
                 $data[] = array('role_id' => $role, 'type' => $role == $roles[0] || $resource->name != 'role' && $resource->name != 'auth' ? 'allow' : 'deny', 'action_id' => $action, 'resource_id' => $resource->id);
             }
         }
     }
     DB::table('permissions')->insert($data);
 }
Ejemplo n.º 2
0
 /**
  * [checkData description]
  * @param  [type] $data [description]
  * @return [type]       [description]
  */
 public function checkAction($action)
 {
     $rs = Action::where('action_name', '=', $action)->count();
     if (isset($rs)) {
         return $rs >= 1 ? false : true;
     }
 }
Ejemplo n.º 3
0
 public function canUse($item1, $item2)
 {
     // is it useable
     $useable = Action::where("item_1", $item1)->firstOrFail();
     $useable = $useable->item_2;
     if ($useable == $item2) {
         return true;
     } else {
         return false;
     }
 }
Ejemplo n.º 4
0
 /**
  * hasPermissions
  *
  */
 public function hasPermission($action, $resource)
 {
     $action_id = Action::where('name', '=', $action)->first()->id;
     $resource_id = Resource::where('name', '=', $resource)->first()->id;
     foreach ($this->roles as $role) {
         foreach ($role->permissionsAllowed as $permission) {
             if ($permission->action_id == $action_id && $permission->resource_id == $resource_id) {
                 return true;
             }
         }
     }
     return false;
 }
 public function postUpdate($group_id)
 {
     Allow::permission($this->module['group'], 'groups');
     $json_request = array('status' => FALSE, 'responseText' => '', 'responseErrorText' => '', 'redirect' => FALSE);
     if (!Request::ajax()) {
         App::abort(404);
     }
     if (!($group = Group::find($group_id))) {
         $json_request['responseText'] = 'Запрашиваемая группа не найдена!';
         return Response::json($json_request, 400);
     }
     $validation = Validator::make(Input::all(), Group::$rules_update);
     if ($validation->passes()) {
         ## Update group
         $group->name = mb_strtolower(Input::get('name'));
         $group->desc = Input::get('desc');
         $group->dashboard = Input::get('dashboard');
         $group->start_url = Input::get('start_url');
         $group->save();
         $group->touch();
         ## Update actions
         Action::where('group_id', $group_id)->delete();
         if (is_array(Input::get('actions')) && count(Input::get('actions'))) {
             foreach (Input::get('actions') as $module_name => $actions) {
                 foreach ($actions as $a => $act) {
                     $action = new Action();
                     $action->group_id = $group_id;
                     $action->module = $module_name;
                     $action->action = $act;
                     $action->status = 1;
                     $action->save();
                 }
             }
         }
         $json_request['responseText'] = 'Группа обновлена';
         #$json_request['responseText'] = print_r($group_id, 1);
         #$json_request['responseText'] = print_r($group, 1);
         #$json_request['responseText'] = print_r(Input::get('actions'), 1);
         #$json_request['responseText'] = print_r($group->actions(), 1);
         #$json_request['redirect'] = link::auth('groups');
         $json_request['status'] = TRUE;
     } else {
         $json_request['responseText'] = 'Неверно заполнены поля';
         $json_request['responseErrorText'] = implode($validation->messages()->all(), '<br />');
     }
     return Response::json($json_request, 200);
 }
Ejemplo n.º 6
0
 public function getStatMonthByWeeks()
 {
     $in = Input::only('qlink');
     $out = array();
     $rules = array('qlink' => 'required | alpha_num');
     $vd = Validator::make($in, $rules);
     if ($vd->fails()) {
         return;
     }
     $cid = Church::where('qlink', $in['qlink'])->pluck('id');
     $church = Church::where('qlink', $in['qlink'])->first();
     if ($cid) {
         $actions = array_fill(1, 5, '');
         foreach (Action::where('cid', $cid)->groupMonthByWeeks() as $k => $v) {
             foreach ($v as $key => $value) {
                 $actions[$k]++;
             }
         }
         $users = array_fill(1, 5, '');
         foreach (UserChurch::where('cid', $cid)->groupMonthByWeeks() as $k => $v) {
             foreach ($v as $key => $value) {
                 $users[$k]++;
             }
         }
         $out['statistic_actions_month_by_weeks'] = array_values($actions);
         $out['statistic_users_month_by_weeks'] = array_values($users);
     }
     return Response::json($out);
 }
Ejemplo n.º 7
0
 /**
  * [delAction description]
  * @param  [type] $id [description]
  * @return [type]     [description]
  */
 public function delAction($id)
 {
     Action::where('id', '=', $id)->delete();
     return Redirect::to('action')->with('success', 'การกระทำรหัส = ' . $id . ' ลบทิ้งสำเร็จ');
 }