Example #1
2
 public function exportDaytime()
 {
     $app = JFactory::getApplication();
     $modelCalendar = new EstivoleModelCalendar();
     $modelDaytime = new EstivoleModelDaytime();
     $modelServices = new EstivoleModelServices();
     $daytimeid = $app->input->get('daytime_id');
     $daytime = $modelDaytime->getDaytime($daytimeid);
     $calendar = $modelCalendar->getItem($daytime->calendar_id);
     $this->services = $modelServices->getServicesByDaytime($daytime->daytime_day);
     // Create new PHPExcel object
     $objPHPExcel = new PHPExcel();
     // Set document properties
     $objPHPExcel->getProperties()->setCreator("Estivale Open Air")->setLastModifiedBy("Estivole")->setTitle("Export Estivole")->setSubject("Export des tranches horaires Estivole");
     // Add some data
     $objPHPExcel->setActiveSheetIndex(0)->setCellValue("A1", "Plan de travail Estivale Open Air - Calendrier " . $calendar->name);
     // // Miscellaneous glyphs, UTF-8
     $objPHPExcel->setActiveSheetIndex(0)->setCellValue("A2", date('d-m-Y', strtotime($daytime->daytime_day)));
     // Rename worksheet
     $objPHPExcel->getActiveSheet()->setTitle("Export");
     // Set active sheet index to the first sheet, so Excel opens this as the first sheet
     $objPHPExcel->setActiveSheetIndex(0);
     $cellCounter = 4;
     // Add data
     for ($i = 0; $i < count($this->services); $i++) {
         $objPHPExcel->getActiveSheet()->setCellValue("A" . $cellCounter, $this->services[$i]->service_name);
         $this->daytimes = $modelDaytime->listItemsForExport($this->services[$i]->service_id);
         foreach ($this->daytimes as $daytime) {
             $userId = $daytime->user_id;
             $userProfileEstivole = EstivoleHelpersUser::getProfileEstivole($userId);
             $userProfile = JUserHelper::getProfile($userId);
             $user = JFactory::getUser($userId);
             $objPHPExcel->getActiveSheet()->setCellValue("A" . ($cellCounter + 1), $userProfileEstivole->profilestivole['lastname'] . ' ' . $userProfileEstivole->profilestivole['firstname'])->setCellValueExplicit("B" . ($cellCounter + 1), $userProfile->profile['phone'], PHPExcel_Cell_DataType::TYPE_STRING)->setCellValue("C" . ($cellCounter + 1), $user->email)->setCellValue("D" . ($cellCounter + 1), date('H:i', strtotime($daytime->daytime_hour_start)))->setCellValue("E" . ($cellCounter + 1), date('H:i', strtotime($daytime->daytime_hour_end)));
             $cellCounter++;
         }
         $cellCounter = $cellCounter + 2;
     }
     // Redirect output to a client’s web browser (Excel2007)
     header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
     header("Content-Disposition: attachment;filename=\"01simple.xlsx\"");
     header("Cache-Control: max-age=0");
     // If you"re serving to IE 9, then the following may be needed
     header("Cache-Control: max-age=1");
     // If you"re serving to IE over SSL, then the following may be needed
     header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
     // Date in the past
     header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
     // always modified
     header("Cache-Control: cache, must-revalidate");
     // HTTP/1.1
     header("Pragma: public");
     // HTTP/1.0
     $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, "Excel2007");
     $objWriter->save("php://output");
     exit;
 }
Example #2
0
 function display($tpl = null)
 {
     $app = JFactory::getApplication();
     $this->state = $this->get('State');
     $this->form = $this->get('Form');
     $model = new EstivoleModelDaytime();
     $modelService = new EstivoleModelService();
     $this->daytimes = $model->listItems();
     $this->daytime = $app->input->get('daytime', null);
     $modelCalendar = new EstivoleModelCalendar();
     $this->calendar = $modelCalendar->getItem($this->daytime->calendar_id);
     for ($i = 0; $i < count($this->daytimes); $i++) {
         $this->daytimes[$i]->filledQuota = count($model->getQuotasByDaytimeId($this->daytimes[$i]->daytime_id));
     }
     EstivoleHelpersEstivole::addSubmenu('daytime');
     $this->sidebar = JHtmlSidebar::render();
     $this->addToolbar();
     //display
     return parent::display($tpl);
 }