/**
  * Home action
  */
 public function homeAction()
 {
     // Extract the current date from the request parameters if available
     $coderDojoDate = GeneralUtility::_GP('tx_twcoderdojo_date');
     if (is_array($coderDojoDate) && array_key_exists('date', $coderDojoDate) && intval($coderDojoDate['date'])) {
         $coderDojoDate = $this->dateRepository->findByIdentifier($coderDojoDate['date']);
         // Else: Get the next available date
     } else {
         $coderDojoDate = $this->dateRepository->findNext()->getFirst();
         $this->view->assign('nextLabel', true);
     }
     $this->view->assign('nextDate', $coderDojoDate);
 }
 /**
  * Download attendee CSV list
  *
  * @param int $date Selected date
  * @return void
  */
 public function downloadAction($date)
 {
     $recipients = [];
     /** @var Date $date */
     $date = $this->dateRepository->findByUid($date);
     $this->createRecipientList($recipients, self::$NINJA, $date->getSortedNinjas());
     $this->createRecipientList($recipients, self::$HELPER, $date->getSortedHelpers());
     $this->createRecipientList($recipients, self::$MENTOR, $date->getMentors());
     if (count($recipients)) {
         $tmpFileName = 'CoderDojo-' . $date->getDojoNumber() . '-' . date('Ymd') . '.csv';
         $tmpCsvFile = PATH_site . 'typo3temp/' . $tmpFileName;
         if (file_exists($tmpCsvFile)) {
             unlink($tmpCsvFile);
         }
         $tmpCsvResource = fopen($tmpCsvFile, 'w');
         fputcsv($tmpCsvResource, array_keys(current($recipients)));
         foreach ($recipients as $recipient) {
             $data = array_map(function ($field) {
                 if (is_array($field)) {
                     $result = implode(', ', array_slice($field, 0, count($field) - 1));
                     $result .= ' & ' . array_pop($field);
                     return $result;
                 }
                 return $field;
             }, $recipient);
             fputcsv($tmpCsvResource, $data);
         }
         fclose($tmpCsvResource);
         header('Location: /typo3temp/' . $tmpFileName);
     }
     exit;
 }
 /**
  * action list
  *
  * @return void
  */
 public function listAction()
 {
     $this->view->assign('nextDates', $this->dateRepository->findNext());
     $this->view->assign('pastDates', $this->dateRepository->findPast());
 }