public function submitVolunteerApplication($req, $res) { $currentUser = $this->app['user']; // make sure the user is logged in if (!$currentUser->isLoggedIn()) { setcookie('redirect', '/volunteers/application', time() + 3600, '/'); return $res->redirect('/login'); } if (!$req->request('accept')) { $req->setParams(['accept_error' => true]); return $this->volunteerApplication($req, $res); } $input = $req->request(); $input['uid'] = $currentUser->id(); $input['birth_date'] = mktime(0, 0, 0, $input['month'] + 1, $input['day'], $input['year']); $input['first_time_volunteer'] = !U::array_value($input, 'volunteered_before'); $application = $currentUser->volunteerApplication(); if (!$application->exists()) { $application = new VolunteerApplication(); if ($application->create($input)) { return $res->redirect('/volunteers/application/thanks'); } } else { if ($application->set($input)) { return $res->redirect('/volunteers/application/thanks'); } } return $this->volunteerApplication($req, $res); }
public function testPermissions() { $user = new User(100, true); $application = new VolunteerApplication(); $this->assertTrue($application->can('create', $user)); $this->assertFalse($application->can('edit', $user)); $application = new VolunteerApplication(100); $this->assertTrue($application->can('edit', $user)); }
/** * Notifies the organization via email * for approval of the volunteer. * * @return bool */ public function emailOrganizationForApproval() { $org = $this->relation('organization'); $user = $this->relation('uid'); $orgName = $org->name; $info = ['username' => $user->username, 'volunteer_email' => $user->user_email, 'subject' => "New volunteer requested to join {$orgName} on InspireVive", 'orgname' => $orgName, 'approval_link' => $this->approvalLink(), 'reject_link' => $this->rejectLink()]; $application = new VolunteerApplication($user->id()); if ($this->application_shared && $application->exists()) { $info = array_replace($info, $application->toArray()); $info['full_name'] = $application->fullName(); } return $org->sendEmail('volunteer-approval-request', $info); }