コード例 #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);
 }
コード例 #2
0
 /**
  * Get a single resource by name.
  * @param  string $resource_name the resource name
  * @return Resource
  * @throws Resource_Exception_Notfound If the resource is not found
  */
 public static function get($resource_name)
 {
     if (!($resource = Arr::get(Resource::all(), $resource_name))) {
         throw new Kohana_Exception('Resource :resource is not defined!', array(':resource' => $resource_name));
     }
     return $resource;
 }
コード例 #3
0
ファイル: Index.php プロジェクト: openbuildings/jam-resource
 protected function _execute(array $options)
 {
     $resources_string = '';
     $resources = isset($options[1]) ? explode(',', $options[1]) : Resource::all();
     foreach ($resources as $resource) {
         if (is_numeric($resource)) {
             continue;
         }
         if (is_string($resource)) {
             $resource = Resource::get($resource);
         }
         if (!$resource->parent()) {
             $resources_string .= $this->_resource($resource);
         }
     }
     Minion_CLI::write($resources_string);
 }
コード例 #4
0
 public function addphotos()
 {
     $resources = Resource::all();
     $photos = Photo::owned(Auth::user()->ID)->get();
     if (Request::ajax()) {
         $resource = Resource::find(Input::get('resource_id'));
         $photo_id = Input::get('photo_id');
         //validating the user ownership in photos
         $photo_id = Photo::owned(Auth::user()->ID)->where("id", "=", $photo_id)->get()->first();
         $resource->photos()->attach($photo_id);
     }
     if (Auth::user()->role == 'admin' || Auth::user()->role == 'teacher') {
         $this->layout->content = View::make("resources.addphotos")->with(array('resources' => $resources, 'photos' => $photos));
     } else {
         return View::make("resources.addphotos-kids")->with(array('resources' => $resources, 'photos' => $photos));
     }
 }