* @license PHP License * @package WB * @subpackage content */ /** * Load classes */ WBClass::load('WBITS' , 'WBITS_TicketList_Exporter' ); /** * Wombat Incident Ticket System Ticket List Exporter: Spreadsheet * * @version 1.1.0 * @package WB * @subpackage content */ class WBITS_TicketList_Exporter_Spreadsheet extends WBITS_TicketList_Exporter { /** * @var WBFile */ private $tmpFile; /** * @var WBFile_Spreadsheet */ private $sheet; /** * @var WBDictionary_URL */ private $dictURL; /** * @var WBDatasource_Table */ private $table; /** * 2nd Constructor */ protected function init() { $this->tmpFile = WBClass::create('WBFile'); //$this->tmpFile->tempdir('tic-'); $this->tmpFile->mkdir('var/tmp/tic'); $this->dictURL = WBClass::create('WBDictionary_URL'); $this->table = WBClass::create('WBDatasource_Table'); } public function realpath() { return $this->tmpFile->realpath() . '/tickets.xls'; } /** * Event Handler to Start Export * */ protected function onExportStart() { $cols = $this->getColumnConfig(); $this->sheet = WBClass::create('WBFile_Spreadsheet'); $this->sheet->setSpreadsheetType('xls'); $this->sheet->touch($this->tmpFile->dirname() . '/tickets.xls'); $this->sheet->open('w'); $this->sheet->getProperties() ->setCreator('Wombat') ->setTitle('Ticketliste'); //->setSubject($data['title']) //->setDescription('List of active newsletter subscribers'); //->setKeywords('office PhpSpreadsheet php') //->setCategory('Test result file'); $this->sheet->setActiveSheetIndex(0) ->setTitle('Tickets'); $this->sheet->getActiveSheet()->getStyle('A1:AZ1000') ->getAlignment()->setVertical(\PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_TOP); $map = array_flip(array_keys($cols)); $this->sheet->setMap($map); $head = array(); foreach ($cols as $k => $v) { $head[$k] = $v['name']; } $this->sheet->write($head); $colNames = $this->sheet->getColumnNames(); // timestamp columns foreach (array('created', 'changed', 'statuschanged', 'deadline') as $dc) { if (!isset($map[$dc])) { continue; } $c = $colNames[$map[$dc]]; $this->sheet->getActiveSheet() ->getStyle($c . '2:' . $c . '1000') ->getNumberFormat() ->setFormatCode( \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_YYYYMMDD2 ); } } /** * Event Handler for Each List Item * * @param array list item data */ protected function exportListItem($item) { foreach ($item as $k => &$v) { if (0 < $v && preg_match('/urlid$/', $k)) { $this->dictURL->load($v); $v = $this->dictURL->getWord(); continue; } $v = trim($v); switch ($k) { case 'uid': case 'assigneduid': case 'owneruid': case 'customeruid': $v = $this->uid2Name($v); break; case 'created': case 'changed': case 'statuschanged': case 'deadline': $ts = strtotime($v); $v = \PhpOffice\PhpSpreadsheet\Shared\Date::PHPToExcel($ts); break; } $v = $this->filterColumn($k, $v); } $this->sheet->write($item); } /** * Event Handler at End of Export * */ protected function onExportEnd() { $this->sheet->setActiveSheetIndex(0); $this->sheet->close(); } }