Пример #1
0
 /**
  * Sends an email to request joining of the project
  * @param string $projectId
  * @param string $inviterUserId
  * @param Website $website
  * @param string $toEmail
  * @param DeliveryInterface $delivery
  * @throws \Exception
  * @return string $userId
  */
 public static function sendJoinRequest($projectId, $userId, $website, DeliveryInterface $delivery = null)
 {
     $newUser = new UserModel($userId);
     $project = new ProjectModel();
     $project->read($projectId['id']);
     // Make sure the user exists on the site
     if (!$newUser->hasRoleOnSite($website)) {
         $newUser->siteRole[$website->domain] = $website->userDefaultSiteRole;
     }
     // Determine if user is already a member of the project
     if ($project->userIsMember($newUser->id->asString())) {
         return $newUser->id;
     }
     // Add the user to the project
     $project->createUserJoinRequest($userId, ProjectRoles::CONTRIBUTOR);
     $project->write();
     $admin = new UserModel($project->ownerRef->asString());
     if ($admin->email != '') {
         Communicate::sendJoinRequest($newUser, $admin, $project, $website, $delivery);
         Communicate::sendJoinRequestConfirmation($newUser, $project, $website, $delivery);
     }
     return $admin;
 }