public function exportRoomReport(SS_HTTPRequest $request)
 {
     try {
         $query_string = $request->getVars();
         $event_type = isset($query_string['event_type']) ? Convert::raw2sql($query_string['event_type']) : 'all';
         $venues = isset($query_string['venues']) ? $query_string['venues'] : '';
         $summit_id = intval($request->param('SUMMIT_ID'));
         $summit = $this->summit_repository->getById($summit_id);
         if (is_null($summit)) {
             throw new NotFoundEntityException('Summit', sprintf(' id %s', $summit_id));
         }
         $filename = "room_report-" . date('Ymd') . ".xlsx";
         $objPHPExcel = new PHPExcel();
         $objPHPExcel->getProperties()->setCreator("OpenStack");
         $objPHPExcel->getProperties()->setTitle("Speaker Per Room Report");
         $objPHPExcel->setActiveSheetIndex(0);
         // sheet 1, key codes
         $categories = $summit->Categories()->toArray();
         $active_sheet = $objPHPExcel->getActiveSheet();
         $active_sheet->setTitle("Key Codes");
         $active_sheet->fromArray(array('Code', 'Category'), NULL, 'A1');
         foreach ($categories as $key => $category) {
             $row = $key + 2;
             $active_sheet->SetCellValue('A' . $row, $category->Code);
             $active_sheet->SetCellValue('B' . $row, $category->Title);
         }
         // day sheets
         $days = $summit->getDates();
         foreach ($days as $day) {
             $active_sheet = $objPHPExcel->createSheet();
             $active_sheet->setTitle(date('n-d', strtotime($day->Date)));
             $active_sheet->fromArray(array('Date', 'Time', 'Code', 'Event', 'Room', 'Venue', 'Capacity', 'Speakers', 'Headcount', 'Total', 'Speaker Names'), NULL, 'A1');
             $day_report = $this->assistance_repository->getRoomsBySummitAndDay($summit_id, $day->Date, $event_type, $venues);
             foreach ($day_report as $key2 => $val) {
                 $row = $key2 + 2;
                 $start_time = $summit->convertDateFromUTC2TimeZone($val['start_date'], 'g:ia');
                 $end_time = $summit->convertDateFromUTC2TimeZone($val['end_date'], 'g:ia');
                 $date = $summit->convertDateFromUTC2TimeZone($val['start_date'], 'm/d/Y');
                 $time = $start_time . ' - ' . $end_time;
                 unset($val['start_date']);
                 unset($val['end_date']);
                 unset($val['id']);
                 $val['date'] = $date;
                 $val['time'] = $time;
                 $active_sheet->fromArray($val, NULL, 'A' . $row);
             }
         }
         $objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
         header('Content-type: application/vnd.ms-excel');
         header('Content-Disposition: attachment; filename="' . $filename . '"');
         $objWriter->save('php://output');
         return;
     } catch (NotFoundEntityException $ex2) {
         SS_Log::log($ex2->getMessage(), SS_Log::WARN);
         return $this->notFound($ex2->getMessage());
     } catch (Exception $ex) {
         SS_Log::log($ex->getMessage(), SS_Log::ERR);
         return $this->serverError();
     }
 }
 public function getRoomReport(SS_HTTPRequest $request)
 {
     try {
         $summit_id = intval($request->param('SUMMIT_ID'));
         $summit = $this->summit_repository->getById($summit_id);
         $query_string = $request->getVars();
         $event_type = isset($query_string['event_type']) ? Convert::raw2sql($query_string['event_type']) : 'all';
         $venues = isset($query_string['venues']) ? $query_string['venues'] : '';
         if (is_null($summit)) {
             throw new NotFoundEntityException('Summit', sprintf(' id %s', $summit_id));
         }
         $days = $summit->getDates();
         $report_array = array();
         foreach ($days as $day) {
             $day_report = $this->assistance_repository->getRoomsBySummitAndDay($summit_id, $day->Date, $event_type, $venues);
             $report_array[$day->Label] = array();
             foreach ($day_report as $rooms) {
                 $report_array[$day->Label][] = array('id' => intVal($rooms['id']), 'date' => $summit->convertDateFromUTC2TimeZone($rooms['start_date'], 'm/d/Y'), 'start_time' => $summit->convertDateFromUTC2TimeZone($rooms['start_date'], 'g:ia'), 'end_time' => $summit->convertDateFromUTC2TimeZone($rooms['end_date'], 'g:ia'), 'code' => empty($rooms['code']) ? 'TBD' : $rooms['code'], 'title' => $rooms['event'], 'room' => $rooms['room'], 'venue' => $rooms['venue'], 'capacity' => $rooms['capacity'], 'speakers' => intVal($rooms['speakers']), 'headcount' => intVal($rooms['headcount']), 'total' => intVal($rooms['total']));
             }
         }
         $calendar_count = $this->assistance_repository->getAttendeesWithCalendar($summit_id);
         $return_array['calendar_count'] = $calendar_count->value();
         $return_array['report'] = $report_array;
         return $this->ok($return_array);
     } catch (NotFoundEntityException $ex2) {
         SS_Log::log($ex2->getMessage(), SS_Log::WARN);
         return $this->notFound($ex2->getMessage());
     } catch (Exception $ex) {
         SS_Log::log($ex->getMessage(), SS_Log::ERR);
         return $this->serverError();
     }
 }
 public function exportReport(SS_HTTPRequest $request)
 {
     try {
         $query_string = $request->getVars();
         $sort = isset($query_string['sort']) ? Convert::raw2sql($query_string['sort']) : 'name';
         $sort_dir = isset($query_string['sort_dir']) ? Convert::raw2sql($query_string['sort_dir']) : 'ASC';
         $event_type = isset($query_string['event_type']) ? Convert::raw2sql($query_string['event_type']) : 'all';
         $venues = isset($query_string['venues']) ? $query_string['venues'] : '';
         $tracks = isset($query_string['tracks']) ? html_entity_decode($query_string['tracks']) : 'all';
         $start_date = isset($query_string['start_date']) && $query_string['start_date'] ? date('Y-m-d', strtotime($query_string['start_date'])) : '';
         $end_date = isset($query_string['end_date']) && $query_string['end_date'] ? date('Y-m-d', strtotime($query_string['end_date'])) : '';
         $search_term = isset($query_string['search_term']) ? $query_string['search_term'] : '';
         $report = $request->param('REPORT');
         $summit_id = intval($request->param('SUMMIT_ID'));
         $summit = $this->summit_repository->getById($summit_id);
         if (is_null($summit)) {
             throw new NotFoundEntityException('Summit', sprintf(' id %s', $summit_id));
         }
         $ext = 'csv';
         switch ($report) {
             case 'speaker_report':
                 $filter = isset($query_string['filter']) ? $query_string['filter'] : 'all';
                 $report_data = $this->assistance_repository->getAssistanceBySummit($summit_id, null, null, $sort, $sort_dir, $filter);
                 $data = $report_data['Data'];
                 $results = array();
                 foreach ($data as $row) {
                     array_push($results, $row);
                 }
                 $filename = "speaker_report-" . date('Ymd') . "." . $ext;
                 $delimiter = $ext == 'xls' ? "\t" : ",";
                 return CSVExporter::getInstance()->export($filename, $results, $delimiter);
                 break;
             case 'room_report':
                 $filename = "room_report-" . date('Ymd') . ".xlsx";
                 $objPHPExcel = new PHPExcel();
                 $objPHPExcel->getProperties()->setCreator("OpenStack");
                 $objPHPExcel->getProperties()->setTitle("Speaker Per Room Report");
                 $objPHPExcel->setActiveSheetIndex(0);
                 // sheet 1, key codes
                 $categories = $summit->Categories()->toArray();
                 $active_sheet = $objPHPExcel->getActiveSheet();
                 $active_sheet->setTitle("Key Codes");
                 $active_sheet->fromArray(array('Code', 'Category'), NULL, 'A1');
                 foreach ($categories as $key => $category) {
                     $row = $key + 2;
                     $active_sheet->SetCellValue('A' . $row, $category->Code);
                     $active_sheet->SetCellValue('B' . $row, $category->Title);
                 }
                 // day sheets
                 $days = $summit->getDates();
                 foreach ($days as $day) {
                     $active_sheet = $objPHPExcel->createSheet();
                     $active_sheet->setTitle(date('n-d', strtotime($day->Date)));
                     $active_sheet->fromArray(array('Date', 'Time', 'Code', 'Event', 'Room', 'Venue', 'Capacity', 'Speakers', 'Headcount', 'Total', 'Speaker Names'), NULL, 'A1');
                     $day_report = $this->assistance_repository->getRoomsBySummitAndDay($summit_id, $day->Date, $event_type, $venues);
                     foreach ($day_report as $key2 => $val) {
                         $row = $key2 + 2;
                         $start_time = $summit->convertDateFromUTC2TimeZone($val['start_date'], 'g:ia');
                         $end_time = $summit->convertDateFromUTC2TimeZone($val['end_date'], 'g:ia');
                         $date = $summit->convertDateFromUTC2TimeZone($val['start_date'], 'm/d/Y');
                         $time = $start_time . ' - ' . $end_time;
                         unset($val['start_date']);
                         unset($val['end_date']);
                         unset($val['id']);
                         $val['date'] = $date;
                         $val['time'] = $time;
                         $active_sheet->fromArray($val, NULL, 'A' . $row);
                     }
                 }
                 $objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
                 header('Content-type: application/vnd.ms-excel');
                 header('Content-Disposition: attachment; filename="' . $filename . '"');
                 $objWriter->save('php://output');
                 return;
                 break;
             case 'presentation_report':
                 $search_term = isset($query_string['term']) ? Convert::raw2sql($query_string['term']) : '';
                 $filter = isset($query_string['filter']) ? $query_string['filter'] : 'all';
                 $report_data = $this->assistance_repository->getPresentationsAndSpeakersBySummit($summit_id, null, null, $sort, $sort_dir, $search_term, $filter);
                 $data = $report_data['Data'];
                 $results = array();
                 foreach ($data as $row) {
                     $row['start_date'] = $summit->convertDateFromUTC2TimeZone($row['start_date'], 'm/d/Y g:ia');
                     unset($row['presentation_id']);
                     unset($row['assistance_id']);
                     array_push($results, $row);
                 }
                 $filename = "presentations_report-" . date('Ymd') . "." . $ext;
                 $delimiter = $ext == 'xls' ? "\t" : ",";
                 return CSVExporter::getInstance()->export($filename, $results, $delimiter);
                 break;
             case 'video_report':
                 $filename = "video_report-" . date('Ymd') . ".xlsx";
                 $objPHPExcel = new PHPExcel();
                 $objPHPExcel->getProperties()->setCreator("OpenStack");
                 $objPHPExcel->getProperties()->setTitle("Video Output List");
                 // day sheets
                 $days = $summit->getDates();
                 foreach ($days as $day) {
                     $active_sheet = $objPHPExcel->createSheet();
                     $active_sheet->setTitle(date('n-d', strtotime($day->Date)));
                     $active_sheet->fromArray(array('Date', 'Time', 'Tags', 'Event', 'Description', 'Room', 'Venue', 'Display', 'YoutubeID'), NULL, 'A1');
                     $day_report = $this->assistance_repository->getPresentationMaterialBySummitAndDay($summit_id, $day->Date, $tracks, $venues, $start_date, $end_date, $search_term);
                     foreach ($day_report as $key2 => $val) {
                         $row = $key2 + 2;
                         $start_time = $summit->convertDateFromUTC2TimeZone($val['start_date'], 'g:ia');
                         $end_time = $summit->convertDateFromUTC2TimeZone($val['end_date'], 'g:ia');
                         $date = $summit->convertDateFromUTC2TimeZone($val['start_date'], 'm/d/Y');
                         $time = $start_time . ' - ' . $end_time;
                         unset($val['start_date']);
                         unset($val['end_date']);
                         unset($val['id']);
                         $val['date'] = $date;
                         $val['time'] = $time;
                         $val['tags'] .= ',' . $val['speakers'] . ',OpenStack Summit Austin';
                         unset($val['speakers']);
                         $active_sheet->fromArray($val, NULL, 'A' . $row);
                     }
                 }
                 $objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
                 header('Content-type: application/vnd.ms-excel');
                 header('Content-Disposition: attachment; filename="' . $filename . '"');
                 $objWriter->save('php://output');
                 return;
                 break;
             case 'rsvp_report':
                 $search_term = isset($query_string['term']) ? Convert::raw2sql($query_string['term']) : '';
                 $events = $this->event_repository->searchBySummitTermAndHasRSVP($summit, $search_term);
                 if (count($events)) {
                     if (count($events) == 1) {
                         $results = array();
                         $event = array_pop($events);
                         list($rsvps, $total) = $this->rsvp_repository->getByEventPaged($event->ID, null, null);
                         $rsvp_array_template = array();
                         foreach ($event->RSVPTemplate()->Questions()->sort('Order') as $question) {
                             if ($question->Label) {
                                 $rsvp_array_template[$question->Label] = '';
                             }
                         }
                         if (count($rsvps)) {
                             foreach ($rsvps as $rsvp) {
                                 $rsvp_array = $rsvp_array_template;
                                 foreach ($rsvp->Answers() as $answer) {
                                     $rsvp_array[$answer->Question()->Label] = $answer->getFormattedAnswer();
                                 }
                                 $results[] = $rsvp_array;
                             }
                         }
                         $filename = "rsvp_report-" . date('Ymd') . "." . $ext;
                         $delimiter = $ext == 'xls' ? "\t" : ",";
                         return CSVExporter::getInstance()->export($filename, $results, $delimiter);
                     }
                 }
                 return $this->notFound();
                 break;
         }
         return $this->notFound();
     } catch (NotFoundEntityException $ex2) {
         SS_Log::log($ex2->getMessage(), SS_Log::WARN);
         return $this->notFound($ex2->getMessage());
     } catch (Exception $ex) {
         SS_Log::log($ex->getMessage(), SS_Log::ERR);
         return $this->serverError();
     }
 }