/** * Sets up the fixture. * This method is called before a test is executed. * * @access protected */ protected function setUp() { parent::setUp(); $fe = new Tinebase_Frontend_Cli(); $opts = new Zend_Console_Getopt('abp:'); $path = dirname(dirname(dirname(dirname(dirname(__FILE__))))) . '/tine20/tine20/HumanResources/Export/definitions/hr_default_ods.xml'; $opts->setArguments(array($path)); ob_start(); $fe->updateImportExportDefinition($opts); $output = ob_get_clean(); $this->assertContains('hr_default_ods.xml successfully.', $output); $filter = new Tinebase_Model_ImportExportDefinitionFilter(array(array('field' => 'name', 'operator' => 'equals', 'value' => 'hr_default_ods'))); $backend = new Tinebase_Backend_Sql(array('modelName' => 'Tinebase_Model_ImportExportDefinition', 'tableName' => 'importexport_definition'), NULL); $this->_importDefinition = $backend->search($filter)->getFirstRecord(); $filter = new HumanResources_Model_EmployeeFilter(array()); $options = array('definitionId' => $this->_importDefinition->getId()); $this->_instance = Tinebase_Export::factory($filter, $options); }
/** * do ods export * * @return void * * @todo check custom fields */ protected function _exportTsOds($_definitionId = NULL) { // create $timesheet = $this->_getTimesheet(); $timesheetData = $this->_json->saveTimesheet($timesheet->toArray()); // export & check $options = $_definitionId === NULL ? array('format' => 'ods') : array('definitionId' => $_definitionId); $odsExportClass = Tinebase_Export::factory(new Timetracker_Model_TimesheetFilter($this->_getTimesheetFilter()), $options); $result = $odsExportClass->generate(); $this->assertTrue(file_exists($result)); $xmlBody = $odsExportClass->getDocument()->asXML(); $this->assertEquals(1, preg_match("/0.5/", $xmlBody), 'no duration'); $this->assertEquals(1, preg_match("/" . $timesheetData['description'] . "/", $xmlBody), 'no description'); $this->assertEquals(1, preg_match("/Description/", $xmlBody), 'no headline'); // cleanup / delete file unlink($result); }
/** * generic export function * * @param Tinebase_Model_Filter_FilterGroup $_filter * @param array $_options format/definition id * @param Tinebase_Controller_Record_Abstract $_controller * @return void * * @todo support single ids as filter? * @todo use stream here instead of temp file? */ protected function _export(Tinebase_Model_Filter_FilterGroup $_filter, $_options, Tinebase_Controller_Record_Abstract $_controller = NULL) { // extend execution time to 30 minutes $oldMaxExcecutionTime = Tinebase_Core::setExecutionLifeTime(1800); // get export object $export = Tinebase_Export::factory($_filter, $_options, $_controller); $format = $export->getFormat(); if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Exporting ' . $_filter->getModelName() . ' in format ' . $format); } if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) { Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . print_r($_options, TRUE)); } switch ($format) { case 'pdf': $ids = $_controller->search($_filter, NULL, FALSE, TRUE, 'export'); // loop records foreach ($ids as $id) { if (!empty($id)) { if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Creating pdf for ' . $_filter->getModelName() . ' id ' . $id); } $record = $_controller->get($id); $export->generate($record); } else { Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' ' . $_filter->getModelName() . ' id empty!'); } } // render pdf try { $pdfOutput = $export->render(); } catch (Zend_Pdf_Exception $e) { Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' error creating pdf: ' . $e->__toString()); exit; } break; case 'ods': $result = $export->generate(); break; default: if (in_array($format, array('csv', 'xls'))) { $result = $export->generate($_filter); } else { throw new Tinebase_Exception_UnexpectedValue('Format ' . $format . ' not supported.'); } } // write headers $contentType = $export->getDownloadContentType(); $filename = $export->getDownloadFilename($_filter->getApplicationName(), $format); header("Pragma: public"); header("Cache-Control: max-age=0"); header("Content-Disposition: " . ($format == 'pdf' ? 'inline' : 'attachment') . '; filename=' . $filename); header("Content-Description: {$format} File"); header("Content-type: {$contentType}"); // output export file switch ($format) { case 'pdf': echo $pdfOutput; break; case 'xls': // redirect output to client browser $export->write($result); break; default: readfile($result); unlink($result); } // reset max execution time to old value Tinebase_Core::setExecutionLifeTime($oldMaxExcecutionTime); }
/** * Sets up the fixture. * This method is called before a test is executed. * * @access protected */ protected function setUp() { $this->_instance = Tinebase_Export::factory(new Crm_Model_LeadFilter($this->_getLeadFilter()), 'ods'); parent::setUp(); }
/** * do ods export * * @return void * * @todo check custom fields */ protected function _exportTsOds($_definitionId = NULL) { // create $timesheet = $this->_getTimesheet(); $timesheetData = $this->_json->saveTimesheet($timesheet->toArray()); // export & check $options = $_definitionId === NULL ? array('format' => 'ods') : array('definitionId' => $_definitionId); $odsExportClass = Tinebase_Export::factory(new Timetracker_Model_TimesheetFilter($this->_getTimesheetFilter()), $options); $result = $odsExportClass->generate(); $this->assertTrue(file_exists($result)); $xmlBody = $odsExportClass->getDocument()->asXML(); $doc = $odsExportClass->getDocument()->getBody(); $i18n = Tinebase_Translation::getTranslation('Timetracker'); // the first line must not be empty foreach ($odsExportClass->getDocument()->getBody()->getTables() as $table) { $body = $table->getBody(); $namespaces = $body->getNamespaces(true); foreach ($body->xpath('//table:table') as $tbl) { $cells = $tbl->xpath('//table:table-cell'); foreach ($cells as $cell) { $xpath = $cell->xpath('//text:p'); $this->assertEquals($i18n->_('Date'), (string) $xpath[0]); $this->assertEquals($i18n->_('Description'), (string) $xpath[1]); } } } $this->assertEquals(1, preg_match("/0.5/", $xmlBody), 'no duration'); $this->assertEquals(1, preg_match("/" . $timesheetData['description'] . "/", $xmlBody), 'no description'); // test translation of headers $i18nValue = $i18n->_('Description'); $match = preg_match("/" . $i18nValue . "/", $xmlBody); $this->assertEquals(1, $match, 'no headline'); // cleanup / delete file unlink($result); }