Esempio n. 1
0
 /**
  * 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;
 }
Esempio n. 2
0
 public function recordHoursStep3($req, $res)
 {
     $org = $this->getOrgForAdmin($req, $res);
     if (!is_object($org)) {
         return;
     }
     $place = $req->query('place');
     if ($place) {
         $place = new VolunteerPlace($place);
     }
     if (!$place || !$place->exists()) {
         return $res->redirect($org->manageUrl() . '/hours/add');
     }
     $input = $req->request();
     $totals = [];
     // recreate days and filter out empty entries
     $days = [];
     $remove = [];
     foreach ($input['days'] as $k => $day) {
         $date = \DateTime::createFromFormat('M j, Y', $day);
         if ($date) {
             $days[] = $this->dayArrayFromTs($date->getTimestamp());
         } else {
             $remove[] = $k;
         }
     }
     // reverse sort remove so that keys are in descending order for deletion
     sort($remove);
     array_reverse($remove);
     // remove empty day entries
     foreach ($remove as $k) {
         unset($input['days'][$k]);
     }
     foreach ($input['hours'] as $uid => $hours) {
         // remove empty hour entries
         foreach ($remove as $k) {
             unset($input['hours'][$uid][$k]);
             unset($hours[$k]);
         }
         // remove empty volunteer and hour entries
         $total = array_sum($hours);
         if ($total == 0) {
             unset($input['hours'][$uid]);
             unset($input['username'][$uid]);
         } else {
             $totals[$uid] = $total;
         }
     }
     // no entries?
     if (empty($input['hours'])) {
         return $this->recordHoursStep2($req, $res);
     }
     // validate tags
     $tags = $req->request('tags');
     foreach ((array) explode(' ', $tags) as $tag) {
         if (!Validate::is($tag, 'alpha_dash')) {
             $this->app['errors']->push(['error' => 'invalid_volunteer_hour_tags']);
             return $this->recordHoursStep2($req, $res);
         }
     }
     return new View('hours/add3', ['org' => $org, 'title' => 'Confirm Volunteer Hours', 'hoursPage' => true, 'input' => $input, 'days' => $days, 'json' => str_replace("'", '', json_encode($input)), 'totals' => $totals, 'place' => $place, 'tags' => $tags]);
 }
Esempio n. 3
0
 /**
  * Checks if this place is setup and approved to verify volunteer hours.
  *
  * @return bool
  */
 public function canApproveHours()
 {
     $email = $this->verify_email;
     return $this->verify_approved && Validate::is($email, 'email');
 }
Esempio n. 4
0
 public function reportHoursStep3($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()) {
         setcookie('redirect', $org->url() . '/hours/report', time() + 3600, '/');
         return $res->redirect('/login');
     }
     $place = $req->query('place');
     if ($place) {
         $place = new VolunteerPlace($place);
     }
     if (!$place || !$place->exists()) {
         return $res->redirect($org->manageUrl() . '/hours/add');
     }
     // validate tags
     $tags = $req->request('tags');
     foreach ((array) explode(' ', $tags) as $tag) {
         if (!Validate::is($tag, 'alpha_dash')) {
             $this->app['errors']->push(['error' => 'invalid_volunteer_hour_tags']);
             return $this->reportHoursStep2($req, $res);
         }
     }
     // validate day
     $date = \DateTime::createFromFormat('M j, Y', $req->request('timestamp'));
     if (!$date) {
         $this->app['errors']->push(['error' => 'validation_failed', 'params' => ['field_name' => 'Day']]);
         return $this->reportHoursStep2($req, $res);
     }
     $uid = $currentUser->id();
     $hour = new VolunteerHour();
     $success = $hour->create(['organization' => $org->id(), 'uid' => $uid, 'hours' => $req->request('hours'), 'timestamp' => $date->getTimestamp(), 'place' => $place->id(), 'approved' => false, 'tags' => $tags]);
     if ($success) {
         $res->redirect($org->url() . '/hours/thanks');
     } else {
         return $this->reportHoursStep2($req, $res);
     }
 }