/**
  *
  * @param UserProfileModel $user
  * @param ProjectSettingsModel $project
  * @param string $subject
  * @param string $smsTemplate
  * @param string $emailTemplate
  * @param string $htmlEmailTemplate
  * @param DeliveryInterface $delivery
  */
 public static function communicateToUser($user, $project, $subject, $smsTemplate, $emailTemplate, $htmlEmailTemplate = '', DeliveryInterface $delivery = null)
 {
     // Prepare the email message if required
     if ($user->communicate_via == UserModel::COMMUNICATE_VIA_EMAIL || $user->communicate_via == UserModel::COMMUNICATE_VIA_BOTH) {
         CodeGuard::checkNotFalseAndThrow($project->emailSettings->fromAddress, 'email from address');
         CodeGuard::checkNotFalseAndThrow($user->email, 'email to address');
         $from = array($project->emailSettings->fromAddress => $project->emailSettings->fromName);
         $to = array($user->email => $user->name);
         $vars = array('user' => $user, 'project' => $project);
         $template = CommunicateHelper::templateFromString($emailTemplate);
         $content = $template->render($vars);
         $htmlContent = '';
         if ($htmlEmailTemplate) {
             $template = CommunicateHelper::templateFromString($emailTemplate);
             $htmlContent = $template->render($vars);
         }
         CommunicateHelper::deliverEmail($from, $to, $subject, $content, $htmlContent, $delivery);
     }
     // Prepare the sms message if required
     if ($project->smsSettings->hasValidCredentials()) {
         if ($user->communicate_via == UserModel::COMMUNICATE_VIA_SMS || $user->communicate_via == UserModel::COMMUNICATE_VIA_BOTH) {
             $databaseName = $project->databaseName();
             $sms = new SmsModel($databaseName);
             $sms->providerInfo = $project->smsSettings->accountId . '|' . $project->smsSettings->authToken;
             $sms->to = $user->mobile_phone;
             $sms->from = $project->smsSettings->fromNumber;
             $vars = array('user' => $user, 'project' => $project);
             $template = CommunicateHelper::templateFromString($smsTemplate);
             $sms->message = $template->render($vars);
             CommunicateHelper::deliverSMS($sms, $delivery);
         }
     }
 }
Esempio n. 2
0
 /**
  * Returns the array of rights for this $role in the given $realm
  * @param string $role
  * @return array
  */
 protected static function _getRightsArray($rightsArray, $role)
 {
     CodeGuard::checkNotFalseAndThrow($role, 'role');
     if (!array_key_exists($role, $rightsArray)) {
         throw new \Exception("Role '{$role}' does not exist.");
     }
     return $rightsArray[$role];
 }
 /**
  * Update the user project role in the project
  * @param string $projectId
  * @param string $userId
  * @param string $projectRole
  * @throws \Exception
  * @return string $userId
  */
 public static function updateUserRole($projectId, $userId, $projectRole = ProjectRoles::CONTRIBUTOR)
 {
     CodeGuard::checkNotFalseAndThrow($projectId, '$projectId');
     CodeGuard::checkNotFalseAndThrow($userId, 'userId');
     //CodeGuard::assertInArrayOrThrow($role, array(ProjectRoles::CONTRIBUTOR, ProjectRoles::MANAGER));
     // Add the user to the project
     $user = new UserModel($userId);
     $project = ProjectModel::getById($projectId);
     if ($project->userIsMember($userId) && $projectRole == $project->users[$userId]->role) {
         return $userId;
     }
     if ($userId == $project->ownerRef->asString()) {
         throw new \Exception("Cannot update role for project owner");
     }
     ProjectCommands::usersDto($projectId);
     if (!$project->userIsMember($userId)) {
         ActivityCommands::addUserToProject($project, $userId);
     }
     $project->addUser($userId, $projectRole);
     $user->addProject($projectId);
     $project->write();
     $user->write();
     return $userId;
 }
 /**
  * Update the user project role in the project
  * @param string $projectId
  * @param string $userId
  * @param string $projectRole
  * @return string - userId
  */
 public static function updateUserRole($projectId, $userId, $projectRole = ProjectRoles::CONTRIBUTOR)
 {
     CodeGuard::checkNotFalseAndThrow($projectId, '$projectId');
     CodeGuard::checkNotFalseAndThrow($userId, 'userId');
     //CodeGuard::assertInArrayOrThrow($role, array(ProjectRoles::CONTRIBUTOR, ProjectRoles::MANAGER));
     // Add the user to the project
     $user = new UserModel($userId);
     $project = ProjectModel::getById($projectId);
     if ($userId == $project->ownerRef->asString()) {
         throw new \Exception("Cannot update role for project owner");
     }
     // TODO: Only trigger activity if this is the first time they have been added to project
     $usersDto = ProjectCommands::usersDto($projectId);
     if (!$project->users->offsetExists($userId)) {
         ActivityCommands::addUserToProject($project, $userId);
     }
     $project->addUser($userId, $projectRole);
     $user->addProject($projectId);
     $project->write();
     $user->write();
     return $userId;
 }
 /**
  * Updates an answer's tags.
  * @param string $projectId
  * @param string $questionId
  * @param string $answerId
  * @param array $tagsArray
  * @return array Returns an encoded QuestionDTO fragment for the Answer
  */
 public static function updateAnswerTags($projectId, $questionId, $answerId, $tagsArray)
 {
     CodeGuard::checkNotFalseAndThrow($answerId, 'answerId');
     $project = new ProjectModel($projectId);
     ProjectCommands::checkIfArchivedAndThrow($project);
     $question = new QuestionModel($project, $questionId);
     $answer = $question->readAnswer($answerId);
     $answer->tags = new ArrayOf();
     foreach ($tagsArray as $tag) {
         $answer->tags[] = $tag;
     }
     $question->writeAnswer($answer);
     return self::encodeAnswer($answer);
 }