public static function setUpBeforeClass() { self::$org = new Organization(); self::$org->grantAllPermissions(); self::$org->create(['name' => 'Test Org', 'email' => '*****@*****.**', 'username' => 'test' . time()]); $uid = TestBootstrap::app('user')->id(); TestBootstrap::app('user')->enableSU(); $volunteer = new Volunteer(); $volunteer->create(['organization' => self::$org->id(), 'uid' => $uid, 'role' => Volunteer::ROLE_ADMIN]); TestBootstrap::app('user')->disableSU(); self::$ogUserId = $uid; }
public function getSections() { $section = ['title' => 'Volunteers', 'rows' => []]; $tagHeaders = $this->organization->hourTags(); $section['header'] = ['Volunteer', 'Metadata', 'Hours']; // $section['header'] = array_merge( $section['header'], $tagHeaders ); $totalHours = 0; $totalHoursByTag = []; foreach ($tagHeaders as $tag) { $totalHoursByTag[$tag] = 0; } $volunteers = Volunteer::findAll(['where' => ['active' => true, 'organization' => $this->organization->id()]]); foreach ($volunteers as $volunteer) { $metadata = $volunteer->metadata; if ($metadata) { $metadata = urldecode(http_build_query($metadata)); } $volunteerHours = $this->organization->totalHoursVolunteered($this->start, $this->end, $volunteer); $volunteerHoursBytag = $this->organization->totalHoursVolunteeredByTag($this->start, $this->end, $volunteer); $row = [$volunteer->name(), $metadata, $volunteerHours]; // process tags foreach ($tagHeaders as $tag) { $tagHours = 0; if (isset($volunteerHoursBytag[$tag])) { $tagHours = $volunteerHoursBytag[$tag]; } // $row[] = $tagHours; $totalHoursByTag[$tag] += $tagHours; } $section['rows'][] = $row; $totalHours += $volunteerHours; } $section['footer'] = ['', 'Total Hours', number_format($totalHours)]; // $section['footer'] = array_merge( $section['footer'], array_values( $totalHoursByTag ) ); return [$section]; }
/** * Adds a volunteer to the organization. If the volunteer is not a * member yet, then a temporary account will be created. This * will send an e-mail to the user. * * @param string $emailOrUsername * * @return Volunteer|false invited volunteer */ public function inviteVolunteer($emailOrUsername) { $user = false; $isEmail = true; if (Validate::is($emailOrUsername, 'email')) { $user = User::findOne(['where' => ['user_email' => $emailOrUsername]]); $isEmail = true; } else { $user = User::findOne(['where' => ['username' => $emailOrUsername]]); } // create temporary user if (!$user && $isEmail) { $user = User::createTemporary(['user_email' => $emailOrUsername, 'invited_by' => $this->id()]); } if (!$user) { return false; } $isTemporary = $user->isTemporary(); $volunteer = new Volunteer([$user->id(), $this->id()]); if ($volunteer->exists()) { return $volunteer; } $volunteer = new Volunteer(); $volunteer->grantAllPermissions(); $volunteer->create(['uid' => $user->id(), 'organization' => $this->id(), 'application_shared' => true, 'active' => true, 'role' => Volunteer::ROLE_VOLUNTEER]); $base = $this->app['base_url']; $orgName = $this->name; $ctaUrl = $isTemporary ? $base . 'signup?user_email=' . $user->user_email : $base . 'profile'; $user->sendEmail('volunteer-invite', ['subject' => "{$orgName} has invited you as a volunteer", 'orgname' => $orgName, 'cta_url' => $ctaUrl]); return $volunteer; }
/** * @depends testCreate */ public function testFind() { // try with the organization supplied $volunteers = Volunteer::find(['where' => ['organization' => self::$org->id()], 'sort' => 'id ASC'])['models']; $this->assertCount(2, $volunteers); // look for our 3 known customers $find = [self::$volunteer->id(), self::$volunteer2->id()]; foreach ($volunteers as $m) { if (($key = array_search($m->uid, $find)) !== false) { unset($find[$key]); } } $this->assertCount(0, $find); }
/** * @depends testCreate */ public function testEdit() { // reset last sent email time for volunteer $volunteer = new Volunteer([self::$hour2->uid, self::$hour2->organization]); $volunteer->grantAllPermissions(); $volunteer->set('last_email_sent_about_hours', 0); }
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 unjoinOrganization($req, $res) { $org = $this->getOrg($req, $res); if (!is_object($org)) { return $org; } $currentUser = $this->app['user']; // make sure the user is logged in if (!$currentUser->isLoggedIn()) { return $res->redirect('/login'); } $volunteer = new Volunteer([$currentUser->id(), $org->id()]); $volunteer->grantAllPermissions(); $volunteer->set(['role' => Volunteer::ROLE_NONE]); if ($req->query('redir') == 'profile') { return $res->redirect('/profile'); } }
public function testCreate() { self::$org = new Organization(); self::$org->grantAllPermissions(); $this->assertTrue(self::$org->create(['name' => 'Test Organization', 'email' => '*****@*****.**', 'username' => 'test' . time()])); self::$org2 = new Organization(); self::$org2->grantAllPermissions(); $this->assertTrue(self::$org2->create(['name' => 'Test Org', 'email' => '*****@*****.**', 'username' => 'test2' . time()])); /* Create some volunteers */ $user = TestBootstrap::app('user'); $uid = $user->id(); $user->enableSU(); $volunteer = new Volunteer(); $this->assertTrue($volunteer->create(['uid' => $uid, 'organization' => self::$org->id(), 'role' => Volunteer::ROLE_ADMIN])); $user->disableSU(); $volunteer = new Volunteer(); $this->assertTrue($volunteer->create(['uid' => -2, 'organization' => self::$org->id(), 'role' => Volunteer::ROLE_AWAITING_APPROVAL])); $volunteer = new Volunteer(); $this->assertTrue($volunteer->create(['uid' => -3, 'organization' => self::$org->id(), 'role' => Volunteer::ROLE_VOLUNTEER])); $volunteer = new Volunteer(); $this->assertTrue($volunteer->create(['organization' => self::$org->id(), 'uid' => -4, 'timestamp' => time(), 'approved' => true])); /* Create some hours */ for ($i = 0; $i < 5; ++$i) { $hour = new VolunteerHour(); $this->assertTrue($hour->create(['organization' => self::$org->id(), 'uid' => -3, 'hours' => 1, 'timestamp' => mktime(0, 0, 0, 5, 11, 2013), 'approved' => true])); } $hour = new VolunteerHour(); $this->assertTrue($hour->create(['organization' => self::$org->id(), 'uid' => -4, 'hours' => 10, 'timestamp' => mktime(0, 0, 0, 5, 12, 2013), 'approved' => true])); $hour = new VolunteerHour(); $this->assertTrue($hour->create(['organization' => self::$org->id(), 'uid' => $uid, 'timestamp' => mktime(10, 10, 10, 5, 10, 2013), 'hours' => 11, 'approved' => true])); // unapproved hours $hour = new VolunteerHour(); $this->assertTrue($hour->create(['organization' => self::$org->id(), 'uid' => $uid, 'timestamp' => mktime(0, 0, 0, 5, 11, 2013), 'hours' => 10, 'tags' => ['yo', 'hello', 'test'], 'approved' => false])); // approved hours $hour = new VolunteerHour(); $this->assertTrue($hour->create(['organization' => self::$org->id(), 'uid' => $uid, 'timestamp' => mktime(0, 0, 0, 5, 11, 2013), 'hours' => 5, 'approved' => true, 'tags' => ['test']])); $hour = new VolunteerHour(); $this->assertTrue($hour->create(['organization' => self::$org->id(), 'uid' => $uid, 'timestamp' => mktime(0, 0, 0, 5, 11, 2013), 'hours' => 10, 'approved' => true, 'tags' => ['test', 'test2']])); // official, outside hours $user->enableSU(); $hour = new VolunteerHour(); $this->assertTrue($hour->create(['organization' => self::$org2->id(), 'uid' => $uid, 'timestamp' => mktime(0, 0, 0, 5, 15, 2013), 'hours' => 12, 'approved' => true])); $user->disableSU(); self::$ogUserId = $uid; }