コード例 #1
0
 public function getRsvpReport(SS_HTTPRequest $request)
 {
     try {
         $query_string = $request->getVars();
         $page = isset($query_string['page']) ? Convert::raw2sql($query_string['page']) : '';
         $page_size = isset($query_string['items']) ? Convert::raw2sql($query_string['items']) : '';
         $search_term = isset($query_string['term']) ? Convert::raw2sql($query_string['term']) : '';
         $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));
         }
         $events = $this->event_repository->searchBySummitTermAndHasRSVP($summit, $search_term);
         $results = array('event_count' => 0, 'data' => array(), 'headers' => array());
         if (count($events)) {
             if (count($events) == 1) {
                 $results['event_count'] = 1;
                 $event = array_pop($events);
                 list($rsvps, $total) = $this->rsvp_repository->getByEventPaged($event->ID, $page, $page_size);
                 $rsvp_array_template = array();
                 foreach ($event->RSVPTemplate()->Questions()->sort('Order') as $question) {
                     if ($question->Label) {
                         $rsvp_array_template[$question->Label] = '';
                         $results['headers'][] = $question->Label;
                     }
                 }
                 if (count($rsvps)) {
                     foreach ($rsvps as $rsvp) {
                         $rsvp_array = array('attendee_id' => $rsvp->SubmittedBy()->ID, 'rsvp' => $rsvp_array_template);
                         foreach ($rsvp->Answers() as $answer) {
                             $rsvp_array['rsvp'][$answer->Question()->Label] = $answer->getFormattedAnswer();
                         }
                         $results['data'][] = $rsvp_array;
                     }
                 }
                 $results['event'] = array('event_id' => intval($event->ID), 'title' => $event->getTitle(), 'date' => $event->getDateNice());
                 $results['total'] = $total;
             } else {
                 $results['event_count'] = count($events);
                 foreach ($events as $event) {
                     $results['data'][] = array('event_id' => intval($event->ID), 'title' => $event->getTitle(), 'date' => $event->getDateNice());
                 }
             }
         }
         return $this->ok($results);
     } 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 $ex->getMessage();
     }
 }
コード例 #2
0
 public function exportRsvpReport(SS_HTTPRequest $request)
 {
     try {
         $query_string = $request->getVars();
         $search_term = isset($query_string['term']) ? Convert::raw2sql($query_string['term']) : '';
         $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';
         $events = $this->event_repository->searchBySummitTermAndHasRSVP($summit, $search_term);
         if (count($events)) {
             $objPHPExcel = new PHPExcel();
             $objPHPExcel->getProperties()->setCreator("OpenStack");
             $objPHPExcel->getProperties()->setTitle("RSVP per Event Report");
             foreach ($events as $event) {
                 $room_cap = $event->Location() && $event->Location()->is_a('SummitVenueRoom') ? $event->Location()->Capacity : 0;
                 list($regulars, $reg_count) = $this->rsvp_repository->getByEventAndType($event->ID, 'Regular');
                 list($waitlists, $wait_count) = $this->rsvp_repository->getByEventAndType($event->ID, 'WaitList');
                 list($rsvps, $total) = $this->rsvp_repository->getByEventPaged($event->ID, null, null);
                 $rsvp_array_template = array();
                 $headers = array();
                 $active_sheet = $objPHPExcel->createSheet();
                 $active_sheet->setTitle('Event ' . $event->Location());
                 foreach ($event->RSVPTemplate()->Questions()->sort('Order') as $question) {
                     if ($question->Label) {
                         $rsvp_array_template[$question->Label] = '';
                         $headers[] = $question->Label;
                     }
                 }
                 $headers[] = 'Seat Type';
                 $active_sheet->setCellValue('A1', $event->getTitleAndTime());
                 $active_sheet->mergeCells('A1:K1');
                 $active_sheet->setCellValue('A3', 'Room Total:');
                 $active_sheet->setCellValue('B3', $room_cap);
                 $active_sheet->setCellValue('A4', 'RSVP #:');
                 $active_sheet->setCellValue('B4', $reg_count);
                 $active_sheet->setCellValue('C4', 'WaitList #:');
                 $active_sheet->setCellValue('D4', $wait_count);
                 $active_sheet->fromArray($headers, NULL, 'A6');
                 $active_sheet->getStyle("A6:K6")->getFont()->setBold(true);
                 if (count($rsvps)) {
                     foreach ($rsvps as $key => $rsvp) {
                         $row = $key + 7;
                         $rsvp_array = $rsvp_array_template;
                         foreach ($rsvp->Answers() as $answer) {
                             $rsvp_array[$answer->Question()->Label] = $answer->getFormattedAnswer();
                         }
                         $rsvp_array['Seat Type'] = $rsvp->SeatType;
                         $active_sheet->fromArray($rsvp_array, NULL, 'A' . $row);
                     }
                 }
             }
             $filename = count($events) == 1 ? $event->getTitleForUrl() . "-" . date('Ymd') . ".xlsx" : "rsvp_report-" . date('Ymd') . ".xlsx";
             $objPHPExcel->removeSheetByIndex(0);
             $objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
             header('Content-type: application/vnd.ms-excel');
             header('Content-Disposition: attachment; filename="' . $filename . '"');
             $objWriter->save('php://output');
             return;
         }
         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 $ex->getMessage();
     }
 }
コード例 #3
0
 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();
     }
 }