public function resendVerificationRequests($req, $res) { if (!$req->isCli()) { return $res->setCode(404); } $hours = VolunteerHour::findAll(['where' => ['organization' => $req->params('org'), 'approved' => false]]); echo "Resending verification requests for organization\n"; $n = 0; foreach ($hours as $hour) { if ($hour->requestThirdPartyVerification()) { ++$n; } } echo "Sent {$n} verification request(s)\n"; }
public function numUnapprovedHours() { return VolunteerHour::totalRecords(['organization' => $this->id(), 'approved' => false]); }
protected function postSetHook() { if ($this->place_type == self::EXTERNAL && $this->justApproved) { // now that the place is approved // we can request verification of all // unapproved hours reported at this place $hours = VolunteerHour::findAll(['where' => ['organization' => $this->organization, 'place' => $this->id(), 'approved' => false]]); foreach ($hours as $hour) { $hour->requestThirdPartyVerification(); } $this->justApproved = false; } }
/** * @depends testCreate */ public function testRejectLink() { $hour = new VolunteerHour(); $hour->organization = self::$org->id(); $hour->approval_link = 'test'; $this->assertEquals(self::$org->url() . '/hours/reject/test', $hour->rejectLink()); }
private function getOrgForAdmin($req, $res) { $org = $this->getOrg($req, $res); if (is_object($org)) { if ($org->can('admin', $this->app['user'])) { // calculate the number of unapproved volunteers, places, and hours $unapprovedVolunteers = Volunteer::totalRecords(['organization' => $org->id(), 'role' => Volunteer::ROLE_AWAITING_APPROVAL]); $unapprovedHours = VolunteerHour::totalRecords(['organization' => $org->id(), 'approved' => false]); $unapprovedPlaces = VolunteerPlace::totalRecords(['organization' => $org->id(), 'place_type' => VolunteerPlace::EXTERNAL, 'verify_approved' => false]); $this->app['view_engine']->setGlobalParameters(['volunteersAwaitingApproval' => $unapprovedVolunteers, 'hoursAwaitingApproval' => $unapprovedHours, 'placesAwaitingApproval' => $unapprovedPlaces]); } else { $res->setCode(401); return false; } } return $org; }
public function myProfile($req, $res) { $currentUser = $this->app['user']; if (!$currentUser->isLoggedIn()) { return $res->redirect('/login'); } // organizations user is volunteer at $volunteersAt = Volunteer::find(['where' => ['organization IN ( SELECT id FROM Organizations )', 'role >= ' . Volunteer::ROLE_VOLUNTEER, 'uid' => $currentUser->id()]])['models']; // recent volunteer hours $recentVolunteerHours = VolunteerHour::find(['where' => ['uid' => $currentUser->id(), 'timestamp >= ' . strtotime('-1800 days')], 'sort' => 'timestamp DESC', 'limit' => 1000])['models']; return new View('myProfile', ['title' => 'My Profile', 'profileTab' => true, 'tabClass' => 'profile', 'recentVolunteerHours' => $recentVolunteerHours, 'volunteersAt' => $volunteersAt, 'completedApplication' => $currentUser->hasCompletedVolunteerApplication()]); }
public function rejectHours($req, $res) { $org = $this->getOrg($req, $res); if (!is_object($org)) { return $org; } $hour = VolunteerHour::findOne(['where' => ['organization' => $org->id(), 'approval_link' => $req->params('approval_link')]]); if (!$hour) { return new View('hoursNotFound', ['org' => $org, 'title' => 'Hours Not Found']); } $h = $hour->toArray(); $user = $hour->relation('uid'); $place = $hour->place()->toArray(); $hour->grantAllPermissions(); $success = $hour->delete(); return new View('hoursApprovedThanks', ['org' => $org, 'title' => $success ? 'Volunteer Hours Denied' : 'Could not reject volunteer hours', 'success' => $success, 'hour' => $h, 'user' => $user, 'place' => $place, 'approved' => false]); }
/** * @depends testCreate */ public function testOrgsWithUnapprovedHourNotifications() { $hour = new VolunteerHour(); $this->assertTrue($hour->create(['organization' => self::$org->id(), 'uid' => -2, 'hours' => 5, 'timestamp' => time(), 'approved' => false])); self::$org->load(); $this->assertEquals(2, self::$org->unapproved_hours_notify_count); $orgs = Organization::orgsWithUnapprovedHourNotifications(); $this->assertInstanceOf('infuse\\Model\\Iterator', $orgs); $orgs2 = []; foreach ($orgs as $org) { $orgs2[] = $org; } $this->assertCount(1, $orgs2); $this->assertEquals(self::$org->id(), $orgs2[0]->id()); }