Ejemplo n.º 1
0
 /**
  * @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);
 }
Ejemplo n.º 2
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;
 }
Ejemplo n.º 3
0
 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');
     }
 }