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;
 }