/**
  * Creates respondent records and sends invitation emails
  *
  * @param int $communityId Community ID
  * @param string $respondentType Respondent / survey type
  * @param int $surveyId Survey ID
  * @return void
  */
 public function sendInvitations($communityId, $respondentType, $surveyId)
 {
     $respondentsTable = TableRegistry::get('Respondents');
     $this->approvedRespondents = $respondentsTable->getApprovedList($surveyId);
     $this->unaddressedUnapprovedRespondents = $respondentsTable->getUnaddressedUnapprovedList($surveyId);
     $this->communityId = $communityId;
     $this->respondentType = $respondentType;
     $this->surveyId = $surveyId;
     $this->setInvitees();
     $this->cleanInvitees();
     $this->removeApproved();
     foreach ($this->invitees as $i => $invitee) {
         if ($this->isUnapproved($invitee['email'])) {
             $this->approveInvitee($invitee);
             continue;
         }
         $this->createRespondent($invitee);
     }
     $Mailer = new Mailer();
     $success = $Mailer->sendInvitations(['surveyId' => $this->surveyId, 'communityId' => $this->communityId, 'senderEmail' => $this->Auth->user('email'), 'senderName' => $this->Auth->user('name'), 'recipients' => $this->recipients]);
     if ($success) {
         $this->successEmails = array_merge($this->successEmails, $this->recipients);
     } else {
         $this->errorEmails = array_merge($this->errorEmails, $this->recipients);
     }
     $this->setInvitationFlashMessages();
     $this->request->data = [];
 }