Example #1
0
 /**
  * @param $id
  * @return mixed
  */
 public function edit($id, Request $request)
 {
     $view = View::make('includes.partials.medialist_grid');
     $user = $this->users->findOrThrowException($id, true);
     if ($request->ajax()) {
         $sections = $view->renderSections();
         return json_encode($sections['mediagrid']);
         //return Response::json(view('', compact('posts'))->render());
     } else {
         return view('backend.access.edit')->withUser($user)->withRoles($this->roles->getAllRoles('id', 'asc', true))->withUserPermissions($user->permissions->lists('id')->all())->withPermissions($this->permissions->getPermissionsNotAssociatedWithRole())->withOrganizations($this->organizations->getAllOrganizations('name', 'asc'));
     }
 }
 /**
  * 
  * @param integer $id
  * @param array $input
  * @param mixed $roles
  * @param mixed $locations
  * @return boolean
  * @throws GeneralException
  */
 public function update($participant, $input, $pcode, $org, $role_id)
 {
     $organization = $this->organization->findOrThrowException($org['org_id']);
     $role = $this->role->findOrThrowException($role_id['role']);
     $area = ['village', 'village_tract', 'township', 'district', 'state', 'country'];
     if (!filter_var($input['email'], FILTER_VALIDATE_EMAIL)) {
         // valid address
         unset($input['email']);
     }
     if (empty($input['nrc_id'])) {
         $input['nrc_id'] = null;
     }
     // get participant
     //$participant = $this->findOrThrowException($id);
     // attach participant to pcode
     if (!empty($pcode['pcode_id'])) {
         $location = PLocation::where('org_id', $org['org_id'])->where('pcode', $pcode['pcode_id'])->first();
         if (!empty($location)) {
             $participant->pcode()->attach($location);
         } else {
             return false;
         }
     }
     // dissociate old organization
     $participant->organization()->dissociate();
     // associate with updated organization
     $participant->organization()->associate($organization);
     // dissociate old role
     $participant->role()->dissociate();
     // associate with updated role
     $participant->role()->associate($role);
     if ($participant->update($input)) {
         return true;
     }
     throw new GeneralException('There was a problem updating this participant. Please try again.');
 }