/**
  * Remind function
  *
  * @param string $surveyType Survey type
  * @return \App\Controller\Response|\Cake\Network\Response|null
  * @throws NotFoundException
  * @throws ForbiddenException
  */
 public function remind($surveyType)
 {
     $clientId = $this->getClientId();
     if (!$clientId) {
         return $this->chooseClientToImpersonate();
     }
     $communitiesTable = TableRegistry::get('Communities');
     $communityId = $communitiesTable->getClientCommunityId($clientId);
     if (!$communityId) {
         throw new NotFoundException('Your account is not currently assigned to a community');
     }
     $surveysTable = TableRegistry::get('Surveys');
     $surveyId = $surveysTable->getSurveyId($communityId, $surveyType);
     $survey = $surveysTable->get($surveyId);
     if (!$survey->active) {
         throw new ForbiddenException('Reminders cannot currently be sent out: Questionnaire is inactive');
     }
     if ($this->request->is('post')) {
         $Mailer = new Mailer();
         $sender = $this->Auth->user();
         if ($Mailer->sendReminders($surveyId, $sender)) {
             $this->Flash->success('Reminder email successfully sent');
             return $this->redirect(['prefix' => 'client', 'controller' => 'Communities', 'action' => 'index']);
         }
         $msg = 'There was an error sending reminder emails.';
         $adminEmail = Configure::read('admin_email');
         $msg .= ' Email <a href="mailto:' . $adminEmail . '">' . $adminEmail . '</a> for assistance.';
         $this->Flash->error($msg);
         // Redirect so that hitting refresh won't re-send POST request
         return $this->redirect(['prefix' => 'client', 'controller' => 'Surveys', 'action' => 'remind', $survey->type]);
     }
     $respondentsTable = TableRegistry::get('Respondents');
     $unresponsive = $respondentsTable->getUnresponsive($surveyId);
     $this->set(['community' => $communitiesTable->get($communityId), 'survey' => $survey, 'titleForLayout' => 'Send Reminders to Community ' . ucwords($survey->type) . 's', 'unresponsive' => $unresponsive, 'unresponsiveCount' => count($unresponsive)]);
 }
 /**
  * Method for /admin/surveys/remind
  *
  * @param int $surveyId Survey ID
  * @return \Cake\Network\Response|null
  */
 public function remind($surveyId)
 {
     $surveysTable = TableRegistry::get('Surveys');
     $survey = $surveysTable->get($surveyId);
     if (!$survey->active) {
         throw new ForbiddenException('Reminders cannot currently be sent out: Questionnaire is inactive');
     }
     $communitiesTable = TableRegistry::get('Communities');
     $community = $communitiesTable->get($survey->community_id);
     if ($this->request->is('post')) {
         $Mailer = new Mailer();
         $sender = $this->Auth->user();
         if ($Mailer->sendReminders($surveyId, $sender)) {
             $this->Flash->success('Reminder email successfully sent');
             return $this->redirect(['prefix' => 'admin', 'controller' => 'Surveys', 'action' => 'view', $community->id, $survey->type]);
         }
         $msg = 'There was an error sending reminder emails.';
         $adminEmail = Configure::read('admin_email');
         $msg .= ' Email <a href="mailto:' . $adminEmail . '">' . $adminEmail . '</a> for assistance.';
         $this->Flash->error($msg);
         // Redirect so that hitting refresh won't re-send POST request
         return $this->redirect(['prefix' => 'admin', 'controller' => 'Surveys', 'action' => 'remind', $survey->id]);
     }
     $respondentsTable = TableRegistry::get('Respondents');
     $unresponsive = $respondentsTable->getUnresponsive($surveyId);
     $this->set(['community' => $community, 'survey' => $survey, 'titleForLayout' => $community->name . ': Remind Community ' . ucwords($survey->type) . 's', 'unresponsive' => $unresponsive, 'unresponsiveCount' => count($unresponsive)]);
     $this->prepareAdminHeader();
     $this->render('..' . DS . '..' . DS . 'Client' . DS . 'Surveys' . DS . 'remind');
 }