public function testWriteRtfCode() { $section = $this->_rtf->addSection(); $section->writeRtfCode('This is a Unit Test text!'); $this->assertEquals(1, $section->countElements()); }
/** * tests render */ public function testRender() { $header = new PHPRtfLite_Container_Header($this->_rtf); $header->writeText('hello world and see my rtf header!'); $header->render(); $this->assertEquals('{\\header {hello world and see my rtf header!}' . "\r\n\\par}\r\n", $this->_rtf->getWriter()->getContent()); }
/** * Constructor * * @param PHPRtfLite $rtf * @param string $type */ public function __construct(PHPRtfLite $rtf, $type = self::TYPE_ALL) { $this->_rtf = $rtf; $this->_type = $type; if ($this->_type == self::TYPE_FIRST) { $rtf->setSpecialLayoutForFirstPage(true); } }
/** * tests render(). */ public function testRender() { $hyperlink = new PHPRtfLite_Element_Hyperlink($this->_rtf, 'My link text!'); $hyperlink->setHyperlink('http://www.phprtf.com/'); $hyperlink->render(); $expected = '{\\field {\\*\\fldinst {HYPERLINK "http://www.phprtf.com/"}}{\\fldrslt {My link text!}}}'; $this->assertEquals($expected, trim($this->_rtf->getWriter()->getContent())); }
/** * */ public function testRenderImageUnresized() { $source = dirname(__FILE__) . '/../../samples/sources/rtf_thumb.jpg'; if (!is_file($source)) { $this->markTestSkipped('Source image file could not be found!'); return; } $image = PHPRtfLite_Image::createFromFile($this->_rtf, $source); $image->render(); $expected = self::getRtfThumbHexCode(510, 510); $this->assertEquals($expected, $this->_rtf->getWriter()->getContent()); }
/** * renders rtf code for cell */ public function render() { $stream = $this->_rtf->getWriter(); $stream->write("\r\n"); // renders container elements parent::render(); $containerElements = $this->getElements(); $numOfContainerElements = count($containerElements); if ($this->_table->isNestedTable()) { // if last container element is not a nested table, close cell if ($numOfContainerElements == 0 || !$containerElements[$numOfContainerElements - 1] instanceof PHPRtfLite_Table_Nested) { $stream->write('{\\nestcell{\\nonesttables\\par}\\pard}' . "\r\n"); // if last cell of row, close row if ($this->getColumnIndex() == $this->_table->getColumnsCount()) { $stream->write('{\\*\\nesttableprops '); $row = $this->_table->getRow($this->_rowIndex); $this->_table->renderRowDefinition($row); $stream->write('\\nestrow}'); } } } else { if ($numOfContainerElements > 0 && $containerElements[$numOfContainerElements - 1] instanceof PHPRtfLite_Table_Nested) { $stream->write('\\intbl\\itap1\\~'); } // closing tag for cell definition $stream->write('\\cell'); } $stream->write("\r\n"); }
/** * Gets type as rtf code * * @return string rtf code * @throws PHPRtfLite_Exception, if type is not allowed, * because of the rtf document specific settings. */ protected function getTypeAsRtfCode() { switch ($this->_type) { case self::TYPE_ALL: if (!$this->_rtf->isOddEvenDifferent()) { return 'footer'; } throw new PHPRtfLite_Exception('Footer type ' . $this->_type . ' is not allowed, when using odd even different!'); case self::TYPE_LEFT: if ($this->_rtf->isOddEvenDifferent()) { return 'footerl'; } throw new PHPRtfLite_Exception('Footer type ' . $this->_type . ' is not allowed, when using not odd even different!'); case self::TYPE_RIGHT: if ($this->_rtf->isOddEvenDifferent()) { return 'footerr'; } throw new PHPRtfLite_Exception('Footer type ' . $this->_type . ' is not allowed, when using not odd even different!'); case self::TYPE_FIRST: if ($this->getFirstPageHasSpecialLayout()) { return 'footerf'; } throw new PHPRtfLite_Exception('Footer type ' . $this->_type . ' is not allowed, when using not special layout for first page!'); default: throw new PHPRtfLite_Exception('Footer type is not defined! You gave me: ', $this->_type); } }
/** * renders list */ public function render() { $stream = $this->_rtf->getWriter(); $number = 0; foreach ($this->_items as $item) { // item is a list if ($item instanceof PHPRtfLite_List_Numbering) { if ($this instanceof PHPRtfLite_List_Numbering) { $item->setPrefix($this->_prefix . $this->getNumber($number) . $this->_separator); $item->setSuffix($this->_suffix); } } else { $number++; $listCharFontIndex = $this->getListCharFontIndex(); $listCharacter = $this->getListCharacter($number); $listCharDefinition = '{\\*\\pn\\pnlvlblt' . '\\pnf' . $listCharFontIndex; if ($this->_font) { $listCharDefinition .= '\\pnfs' . $this->_font->getSize() * 2; if ($color = $this->_font->getColor()) { $listCharDefinition .= '\\pncf' . $this->_rtf->getColorTable()->getColorIndex($color); } } $listCharDefinition .= '\\pnindent0{\\pntxtb ' . $listCharacter . '}}'; $textIndent = $this->_listIndent + $this->_textIndent; $stream->write('\\nowidctlpar\\fi-' . $this->_listIndent . '\\li' . $textIndent . "\r\n"); $stream->write($listCharDefinition); } // renders item $item->render(); if (false == $item instanceof PHPRtfLite_List) { $stream->write('\\par\\pard' . "\r\n"); } } }
/** * Constructor * @param integer $size size of border * @param string $color color of border (example '#ff0000' or '#f00') * @param string $type represented by class constants PHPRtfLite_Border_Format::TYPE_*<br> * Possible values:<br> * TYPE_SINGLE => 'single'<br> * TYPE_DOT = 'dot'<br> * TYPE_DASH = 'dash'<br> * TYPE_DOTDASH = 'dotdash'<br> * @param float $space space between borders and the paragraph */ public function __construct($size = 0, $color = null, $type = null, $space = 0) { $this->_size = $size * PHPRtfLite::SPACE_IN_POINTS; $this->_type = $type; if ($color) { $this->_color = PHPRtfLite::convertHexColorToRtf($color); } $this->_space = round($space * PHPRtfLite::TWIPS_IN_CM); }
/** * tests setBorder on cell 1x1 * * @param PHPRtfLite_Table $table * @return PHPRtfLite_Table */ public function testSetBorderForCellWithRow1Column1() { $rtf = new PHPRtfLite(); $section = $rtf->addSection(); $table = $section->addTable(); // creating cells (2 rows x 2 columns) $table->addRowList(array(2, 2)); $table->addColumnsList(array(7, 7)); $border = new PHPRtfLite_Border($table->getRtf()); $border->setBorders(new PHPRtfLite_Border_Format(1, '#000')); $cell1x1 = $table->getCell(1, 1); $cell1x2 = $table->getCell(1, 2); $cell2x1 = $table->getCell(2, 1); $cell1x1->setBorder($border); $this->assertEquals('#000', $cell1x1->getBorder()->getBorderRight()->getColor()); $this->assertEquals('#000', $cell1x2->getBorder()->getBorderLeft()->getColor()); $this->assertEquals('#000', $cell2x1->getBorder()->getBorderTop()->getColor()); return $table; }
/** * renders rtf code for that container * * @return string rtf code */ public function render() { $stream = $this->_rtf->getWriter(); if ($this instanceof PHPRtfLite_Table_Cell && $this->countElements() == 0) { $stream->write('{'); $font = $this->getCellFont($this); if ($font) { $stream->write($font->getContent()); } if (!$this->isVerticalMerged() && !$this->isHorizontalMerged() || $this->isVerticalMergedFirstInRange()) { $stream->write('{\\~}'); } $stream->write('}\\intbl'); } $lastKey = $this->countElements() - 1; foreach ($this->_elements as $key => $element) { if ($this instanceof PHPRtfLite_Table_Cell && !$element instanceof PHPRtfLite_Table) { // table cell initialization $stream->write('\\intbl\\itap' . $this->getTable()->getNestDepth() . "\r\n"); $stream->write($this->getCellAlignment()); } if ($element instanceof PHPRtfLite_Element_Plain) { $element->render(); continue; } $parFormat = null; if (!$element instanceof PHPRtfLite_Table) { $parFormat = $element->getParFormat(); } if ($parFormat) { $stream->write($this->_pard); if ($this instanceof PHPRtfLite_Table_Cell && $lastKey != $key) { $stream->write('{'); } $stream->write($parFormat->getContent()); } $font = $this->getCellFont($element); if ($font) { $stream->write($font->getContent()); } $element->render(); if ($this->needToAddParagraphEnd($key)) { $stream->write('\\par '); } if ($font) { $stream->write($font->getClosingContent()); } if ($parFormat && $this instanceof PHPRtfLite_Table_Cell && $lastKey != $key) { $stream->write('}'); } } }
/** * renders form field */ public function render() { $stream = $this->_rtf->getWriter(); $stream->write(' '); if ($this->_font) { $stream->write('{' . $this->_font->getContent()); } $defaultValue = PHPRtfLite_Utf8::getUnicodeEntities($this->_defaultValue, $this->_rtf->getCharset()); $content = '{\\field' . '{\\*\\fldinst ' . $this->getType() . ' {\\*\\formfield' . $this->getRtfCode() . '}' . '}{\\fldrslt ' . $defaultValue . '}}'; $stream->write($content); if ($this->_font) { $stream->write($this->_font->getClosingContent() . '}'); } $stream->write(' '); }
function Generate_Content() { PHPRtfLite::registerAutoloader(); $largerFont = new PHPRtfLite_Font(16, 'Courier New'); $largerFont->setBold(); $smallerFont = new PHPRtfLite_Font(12, 'Times New Roman'); $tableFont = new PHPRtfLite_Font(10, 'Courier New'); //Izveido pašu dokumentu $rtf = new PHPRtfLite(); $parHead = new PHPRtfLite_ParFormat(); $parHead->setSpaceBefore(3); $parHead->setSpaceAfter(8); $parBody = new PHPRtfLite_ParFormat(); $parBody->setSpaceBefore(1); //Izveido pirmo sekciju $sect =& $rtf->addSection(); $sect->writeText("Atzīmju izraksts", $largerFont, $parHead); $sect->writeText("Skolnieks: " . $this->studentName, $smallerFont, $parHead); for ($i = 0; $i < count($this->grades); $i++) { $grade = $this->grades[$i]; $sect->writeText(sprintf("%s %s %s", $grade["date"], $grade["lesson"], $grade["grade"]), $tableFont, $parBody); } $this->fileContents = $rtf; }
public function onGenerate() { try { TTransaction::open('atividade'); $object = $this->form->getData(); $desenvolvimento = new RequisitoDesenvolvimento(1); $cliente_id = $desenvolvimento->ticket->solicitante_id; $responsavel_id = $desenvolvimento->ticket->responsavel_id; $pessoa = new Pessoa($cliente_id); $cliente = $pessoa->pessoa_nome; $pessoa = new Pessoa($responsavel_id); $responsavel = $pessoa->pessoa_nome; if (!class_exists('PHPRtfLite_Autoloader')) { PHPRtfLite::registerAutoloader(); } $tr = new TTableWriterRTF(array(500)); $tr->addStyle('title', 'Arial', '10', 'BI', '#000000', '#ffffff'); $tr->addStyle('datap', 'Arial', '10', '', '#000000', '#ffffff'); $string = new StringsUtil(); $data = $desenvolvimento->data_cadastro; $data = explode('-', $data); $desenvolvimento->ticket->data_prevista ? $data_prevista = $string->formatDateBR($desenvolvimento->ticket->data_prevista) : '___/___/___'; $cabecalho = 'DTR010 - Solicitação de Desenvolvimento Número: ' . $desenvolvimento->id . '/' . $data[0] . ' Data: ' . $string->formatDateBR($desenvolvimento->data_cadastro) . ' Prazo de entrega: ' . $data_prevista . ' Qtde de Horas: ' . strstr($desenvolvimento->ticket->orcamento_horas, ':', true) . ' Ticket: ' . $desenvolvimento->ticket_id . ' Benefício: ( )+Receita ( )-Despesa ( )+Eficiência ( )-NDA Título: ' . $desenvolvimento->titulo . ' Sistema: ' . $desenvolvimento->ticket->sistema->nome . ' Módulo: Rotina: ' . $desenvolvimento->rotina . ' Cliente: ' . $cliente . ' Solicitante/Dpto: ' . $responsavel; $tr->addRow(); $tr->addCell($cabecalho, 'left', 'title'); $tr->addRow(); $tr->addCell('<br /><b>Objetivo:</b> <br />' . $desenvolvimento->objetivo, 'left', 'datap'); $tr->addRow(); $tr->addCell('<br /><b>Entrada: </b><br />' . $desenvolvimento->entrada, 'left', 'datap'); $tr->addRow(); $tr->addCell('<br /><b>Processamento: </b><br />' . $desenvolvimento->processamento, 'left', 'datap'); $tr->addRow(); $tr->addCell('<br /><b>Saida: </b><br />' . $desenvolvimento->saida, 'left', 'datap'); $nome = 'DTR010 ' . $desenvolvimento->id . ' - ' . $data[0] . ' - ' . $desenvolvimento->titulo; $tr->save("app/output/{$nome}.rtf"); parent::openFile("app/output/{$nome}.rtf"); new TMessage('info', 'DTR gerado com sucesso!'); TTransaction::close(); } catch (Exception $e) { new TMessage('error', $e->getMessage); } }
public function __construct() { if (!class_exists('PHPRtfLite_Autoloader')) { PHPRtfLite::registerAutoloader(); } $this->rtf = new PHPRtfLite(); $this->rtf->setCharset("UTF-8"); $this->rtf->setPaperWidth(21); // A4 $this->rtf->setPaperHeight(29); //$this->rtf->setLandscape(); $this->rtf->setMargins(2, 2, 2, 2); $this->JUSTIFY = new PHPRtfLite_ParFormat(PHPRtfLite_ParFormat::TEXT_ALIGN_JUSTIFY); $this->LEFT = new PHPRtfLite_ParFormat(PHPRtfLite_ParFormat::TEXT_ALIGN_LEFT); $this->CENTER = new PHPRtfLite_ParFormat(PHPRtfLite_ParFormat::TEXT_ALIGN_CENTER); $this->RIGHT = new PHPRtfLite_ParFormat(PHPRtfLite_ParFormat::TEXT_ALIGN_RIGHT); $this->paragraphFormat = $this->JUSTIFY; $this->section = $this->rtf->addSection(); }
/** * writes image into rtf stream * * @param integer $startFrom */ protected function writeIntoRtfStream($startFrom = 0) { fseek($this->_stream, $startFrom); $rtfImageType = $this->getImageTypeAsRtf(); $rtfStream = $this->_rtf->getWriter(); $rtfStream->write('{\\*\\shppict {\\pict'); if ($this->_border) { $rtfStream->write($this->_border->getContent()); } $rtfStream->write($rtfImageType . '\\picscalex100\\picscaley100'); $rtfStream->write('\\picwgoal' . $this->getImageRtfWidth()); $rtfStream->write('\\pichgoal' . $this->getImageRtfHeight()); $rtfStream->write(' '); while (!feof($this->_stream)) { $stringBuffer = fread($this->_stream, 1024); $stringHex = bin2hex($stringBuffer); $rtfStream->write($stringHex); } $rtfStream->write('}}'); }
<?php $dir = dirname(__FILE__); require_once $dir . '/../lib/PHPRtfLite.php'; // register PHPRtfLite class loader PHPRtfLite::registerAutoloader(); // rtf document $rtf = new PHPRtfLite(); //paragraph formats $parFormat = new PHPRtfLite_ParFormat(); $parGreyLeft = new PHPRtfLite_ParFormat(); $parGreyLeft->setShading(10); $parGreyCenter = new PHPRtfLite_ParFormat(PHPRtfLite_ParFormat::TEXT_ALIGN_CENTER); $parGreyCenter->setShading(10); // header $header = $rtf->addHeader('first'); $header->addImage($dir . '/sources/rtf_thumb.jpg', $parFormat); $header->writeText('Image in header.', new PHPRtfLite_Font(), new PHPRtfLite_ParFormat()); $sect = $rtf->addSection(); $sect->writeText('Images with PHPRtfLite.', new PHPRtfLite_Font(14), new PHPRtfLite_ParFormat('center')); $sect->writeText('<br>Here is .jpg image. <tab>', new PHPRtfLite_Font(), new PHPRtfLite_ParFormat()); $sect->addImage($dir . '/sources/rtf_thumb.jpg', null); $sect->writeText('<br>Here is .png image. <tab>', new PHPRtfLite_Font(), new PHPRtfLite_ParFormat()); $sect->addImage($dir . '/sources/html.png', null); $sect->writeText('<br><br><b>Formating sizes of images:</b>', new PHPRtfLite_Font(), new PHPRtfLite_ParFormat()); $table = $sect->addTable(); $table->addRows(3, 4.5); $table->addRow(6); $table->addColumnsList(array(7.5, 6.5)); $table->writeToCell(1, 1, '<br> Original size.', new PHPRtfLite_Font(), new PHPRtfLite_ParFormat()); //getting cell object, writing text and adding image
<?php $dir = dirname(__FILE__); require_once $dir . '/../lib/PHPRtfLite.php'; // register PHPRtfLite class loader PHPRtfLite::registerAutoloader(); //Font formats $font1 = new PHPRtfLite_Font(11, 'Times new Roman', '#000055'); //Paragraph formats $parFC = new PHPRtfLite_ParFormat('center'); $parFL = new PHPRtfLite_ParFormat('left'); //Rtf document $rtf = new PHPRtfLite(); //section $sect = $rtf->addSection(); $sect->writeText('Chess tournamet information (write your data)' . "\n", new PHPRtfLite_Font(14, 'Arial'), new PHPRtfLite_ParFormat()); $chessPlayers = array('Mike Smith', 'Jim Morgan', 'Jochgan Berg', 'Bill Scott', 'Bill Martines', 'John Po', 'Aleck Harrison', 'Ann Scott', 'Johnatan Fredericson', 'Eva Carter'); /*$chessResults = (array( array(0 , 1 , 0.5, 1 , 0 , 1 , 0 , 0.5 , 1 , 1 ), array(0, 0, 0.5, 0.5, 0, 0, 0, 0, 0, 1), array(0.5, 1, 0, 1, 0.5, 1, 0.5, 0, 0, 1), array(0, 0.5, 0.5, 0, 0, 0.5, 0.5, 0, 0, 1), array(1, 0.5, 1, 0, 0, 0.5, 0.5, 0, 0, 1), ));*/ $count = count($chessPlayers); $countCols = $count + 2; $countRows = $count + 1; $colWidth = ($sect->getLayoutWidth() - 5) / $count;
/** * tests render */ public function testRender() { $footnote = new PHPRtfLite_Footnote($this->_rtf, 'hello rtf world!'); $footnote->render(); $this->assertEquals('\\chftn {\\footnote\\pard\\plain \\lin283\\fi-283 \\fs20 {\\up6\\chftn}' . "\r\n" . 'hello rtf world!} ', $this->_rtf->getWriter()->getContent()); }
<?php require_once 'src/PHPRtfLite.php'; PHPRtfLite::registerAutoloader(); require_once 'includes/cars_pdo.php'; if (isset($_POST['download'])) { try { $rtf = new PHPRtfLite(); // Установить свойства страницы $rtf->setMargins(2.54, 2.54, 2.54, 2.54); $rtf->setPaperFormat(PHPRtfLite::PAPER_LETTER); // Добавить футер $footer = $rtf->addFooter(); $fontFooter = new PHPRtfLite_Font(8, 'Arial', '#000000'); $alignFooter = new PHPRtfLite_ParFormat(PHPRtfLite_ParFormat::TEXT_ALIGN_CENTER); $footer->writeText('Used cars for sale - <pagenum>', $fontFooter, $alignFooter); // Определить шрифты $fontH1 = new PHPRtfLite_Font(16, 'Arial', '#4E9C93'); $fontH2 = new PHPRtfLite_Font(14, 'Arial', '#4E9C93'); $fontP = new PHPRtfLite_Font(12, 'Helvetica', '#000000'); // Вертикальное форматирование текста $formatH1 = new PHPRtfLite_ParFormat(); $formatH1->setSpaceAfter(8); $formatH2 = new PHPRtfLite_ParFormat(); $formatH2->setSpaceAfter(6); $formatP = new PHPRtfLite_ParFormat(); $formatP->setSpaceAfter(3); // Содержание страницы $section = $rtf->addSection(); $section->writeText('Used Cars for Sale', $fontH1, $formatH1); while ($row = getRow($result)) {
/** * renders footnote/endnote * * @return string */ public function getContent() { $content = '\\chftn ' . '{\\footnote' . ($this->isFootnote() ? '' : '\\ftnalt') . '\\pard\\plain \\lin283\\fi-283 '; if ($this->_parFormat) { $content .= $this->_parFormat->getContent($this->_rtf); } $content .= $this->_font->getContent($this->_rtf); $content .= '{\\up6\\chftn}' . "\r\n" . PHPRtfLite::quoteRtfCode($this->_text) . '} '; return $content; }
/** * renders footnote/endnote */ public function render() { $stream = $this->_rtf->getWriter(); $typeSetting = $this->_typeSettingType != self::TYPE_NORMAL ? '\\' . $this->_typeSettingType : ''; $stream->write('{' . $typeSetting . '\\chftn}' . '{' . $this->getTypeAsRtfCode() . '\\pard\\plain\\lin283\\fi-283 '); if ($this->_parFormat) { $stream->write($this->_parFormat->getContent()); } if ($this->_font) { $stream->write($this->_font->getContent()); } $stream->write('{\\up6\\chftn}' . "\r\n" . PHPRtfLite::quoteRtfCode($this->_text) . '} '); }
<?php require dirname(__FILE__) . '/../lib/PHPRtfLite.php'; // register PHPRtfLite class loader PHPRtfLite::registerAutoloader();
/** * gets opening token * * @return string */ protected function getOpeningToken() { $hyperlink = PHPRtfLite::quoteRtfCode($this->_hyperlink); return '{\\field {\\*\\fldinst {HYPERLINK "' . $hyperlink . '"}}{\\fldrslt {'; }
<?php $dir = dirname(__FILE__); require_once $dir . '/../lib/PHPRtfLite.php'; // register PHPRtfLite class loader PHPRtfLite::registerAutoloader(); $rtf = new PHPRtfLite(); $sect = $rtf->addSection(); $sect->writeText('Text before the list'); $enum = new PHPRtfLite_List_Enumeration($rtf); $enum->addItem('hello world'); $enum->addItem('foo'); $enum->addItem('bar'); $subEnum = new PHPRtfLite_List_Enumeration($rtf); $subEnum->addItem('hello world'); $subEnum->addItem('foo'); $subEnum->addItem('bar'); $enum->addList($subEnum); $sect->addEnumeration($enum); $subSubNumList = new PHPRtfLite_List_Numbering($rtf); $subSubNumList->addItem('hello world'); $subSubNumList->addItem('foo'); $subSubNumList->addItem('bar'); $subNumList = new PHPRtfLite_List_Numbering($rtf); $subNumList->addItem('hello world'); $subNumList->addItem('foo'); $subNumList->addItem('bar'); $subNumList->addList($subSubNumList); $font = new PHPRtfLite_Font('26', 'Tahoma', '#f00'); $numList = new PHPRtfLite_List_Numbering($rtf, null, $font); $numList->addItem('hello world');
/** * Gets rtf code for border * @param PHPRtfLite_Border_Format $borderFormat * @param PHPRtfLite $rtf * * @return string rtf code */ private function getBorderRtf(PHPRtfLite_Border_Format $borderFormat, PHPRtfLite $rtf) { $borderRtf = $borderFormat->getNotColoredPartOfContent(); $color = $borderFormat->getColor(); if ($color) { $rtf->addColor($color); $borderRtf .= '\\brdrcf' . $rtf->getColor($color); } return $borderRtf . ' '; }
/** * method onGenerate() * Executed whenever the user clicks at the generate button */ function onGenerate() { try { // open a transaction with database 'atividade' TTransaction::open('atividade'); // get the form data into an active record $formdata = $this->form->getData(); $validador = new TDuasDatasValidator(); $validador->validate('Datas', '', array($formdata->ano_atividade_inicial . '-' . str_pad($formdata->mes_atividade_inicial, 2, '0', STR_PAD_LEFT) . '-01', $formdata->ano_atividade_final . '-' . str_pad($formdata->mes_atividade_final, 2, '0', STR_PAD_LEFT) . '-01')); $meses = $this->colecaoMeses($formdata); $tickets = null; $arrayTickets = null; if ($formdata->cliente_id > 0) { $cliente = Pessoa::getPessoasEntidade($formdata->cliente_id); $retorno = Ticket::getTicketsCliente($cliente); $arrayTickets = $retorno; $tickets = implode(",", $retorno); } $criteria = new TCriteria(); $criteria->add(new TFilter("origem", "=", 1)); $criteria->add(new TFilter("codigo_cadastro_origem", "=", 100)); $criteria->add(new TFilter("ativo", "=", 1)); $criteria->add(new TFilter("usuario", "is not ")); $repo = new TRepository('Pessoa'); $pessoas = $repo->load($criteria); $criteria = new TCriteria(); $criteria->add(new TFilter('data_atividade', '<', $formdata->ano_atividade_inicial . '-' . str_pad($formdata->mes_atividade_inicial, 2, '0', STR_PAD_LEFT) . '-01'), TExpression::OR_OPERATOR); $criteria->add(new TFilter('data_atividade', '>', $formdata->ano_atividade_final . '-' . str_pad($formdata->mes_atividade_final, 2, '0', STR_PAD_LEFT) . '-' . cal_days_in_month(CAL_GREGORIAN, str_pad($formdata->mes_atividade_final, 2, '0', STR_PAD_LEFT), $formdata->ano_atividade_final)), TExpression::OR_OPERATOR); $repository = new TRepository('Atividade'); $count = $repository->count($criteria); $format = $formdata->output_type; if ($count > 0) { $widths = array(); switch ($format) { case 'html': $tr = new TTableWriterHTML($widths); $break = '<br />'; break; case 'pdf': $tr = new TTableWriterPDF($widths); $break = '<br />'; break; case 'rtf': if (!class_exists('PHPRtfLite_Autoloader')) { PHPRtfLite::registerAutoloader(); } $tr = new TTableWriterRTF($widths); $break = '<br />'; break; } // create the document styles $tr->addStyle('title', 'Arial', '10', 'B', '#ffffff', '#6B6B6B'); $tr->addStyle('datap', 'Arial', '10', '', '#000000', '#E5E5E5'); $tr->addStyle('datai', 'Arial', '10', '', '#000000', '#ffffff'); $tr->addStyle('header', 'Times', '16', 'B', '#4A5590', '#C0D3E9'); $tr->addStyle('footer', 'Times', '12', 'BI', '#4A5590', '#C0D3E9'); $colunas = count($meses) * 4 + 2; $arrayMeses = $this->string->array_meses(); // add a header row $tr->addRow(); $tr->addCell('RELATORIO XPTO', 'center', 'header', $colunas); // add a header row $tr->addRow(); $tr->addCell('Indicadores', 'center', 'header', $colunas); // add a header row $i = 0; $tr->addRow(); $tr->addCell('', 'center', 'header'); foreach ($meses as $mes) { $i++; $tr->addCell(substr(strtoupper($arrayMeses[intval(substr($mes, 3, 2))]), 0, 3), 'center', 'header'); $tr->addCell('%', 'center', 'header'); $tr->addCell(' ', 'center', 'datai'); } $tr->addCell('TOTAL', 'center', 'header'); $tr->addCell('%', 'center', 'header'); // add a carga horaria row $i = 0; $totalHorario = null; $arrayHorario = array(); $tr->addRow(); $tr->addCell(utf8_decode('Carga horária mensal:'), 'left', 'datap'); foreach ($meses as $mes) { $criteria = new TCriteria(); $criteria->add(new TFilter("mes", "=", substr($mes, 3, 2))); $criteria->add(new TFilter("ano", "=", substr($mes, 6, 4))); if ($formdata->colaborador_id > 0) { $criteria->add(new TFilter("colaborador_id", "=", $formdata->colaborador_id)); } $repo = new TRepository('CargaHoraria'); $cargaHoraria = $repo->load($criteria); $horario = null; foreach ($cargaHoraria as $carga) { $horario += $this->string->time_to_sec($carga->horario); } $totalHorario += $horario; $arrayHorario[$i] = $horario; $horario = $this->string->sec_to_time($horario); $tr->addCell($this->string->retira_segundos($horario), 'center', 'datap'); $tr->addCell('100%', 'center', 'datap'); $tr->addCell(' ', 'center', 'datai'); $i++; } $totalHorario = $this->string->sec_to_time($totalHorario); $tr->addCell($this->string->retira_segundos($totalHorario), 'center', 'datap'); $tr->addCell('100%', 'center', 'datap'); //add horas ponto total row $i = 0; $totalPontoTotal = null; $arrayPontoTotal = array(); $tr->addRow(); $tr->addCell(utf8_decode('Horas ponto total:'), 'left', 'datap'); foreach ($meses as $mes) { if ($formdata->colaborador_id > 0) { $totalPonto = $this->retornaPonto($formdata->colaborador_id, substr($mes, 3, 2), substr($mes, 6, 4)); $totalPontoTotal += $this->string->time_to_sec($totalPonto); $arrayPontoTotal[$i] = $this->string->time_to_sec($totalPonto); } else { foreach ($pessoas as $pessoa) { $totalPonto += $this->string->time_to_sec($this->retornaPonto($pessoa->pessoa_codigo, substr($mes, 3, 2), substr($mes, 6, 4))); } $totalPontoTotal += $totalPonto; $arrayPontoTotal[$i] = $totalPonto; $totalPonto = $this->string->sec_to_time($totalPonto); } $tr->addCell($this->string->retira_segundos($totalPonto), 'center', 'datap'); $tr->addCell(round($arrayPontoTotal[$i] * 100 / $arrayHorario[$i]) . '%', 'center', 'datap'); $tr->addCell(' ', 'center', 'datai'); $i++; } $totalPontoTotal = $this->string->sec_to_time($totalPontoTotal); $tr->addCell($this->string->retira_segundos($totalPontoTotal), 'center', 'datap'); $tr->addCell(round($this->string->time_to_sec($totalPontoTotal) * 100 / $this->string->time_to_sec($totalHorario)) . '%', 'center', 'datap'); //add horas ponto util row $i = 0; $totalPontoUtil = null; $arrayPontoUtil = array(); $tr->addRow(); $tr->addCell(utf8_decode('Horas ponto util:'), 'left', 'datap'); foreach ($meses as $mes) { $cri = new TCriteria(); if ($formdata->colaborador_id > 0) { $cri->add(new TFilter("colaborador_id", "=", $formdata->colaborador_id)); } $cri->add(new TFilter("ticket_id", "IN", array(328, 514))); $cri->add(new TFilter("extract('month' from data_atividade)", "=", substr($mes, 3, 2))); $cri->add(new TFilter("extract('year' from data_atividade)", "=", substr($mes, 6, 4))); $repo = new TRepository('Atividade'); $ausencias = $repo->count($cri); $tempo = 0; if ($ausencias) { $horas = $repo->load($cri); foreach ($horas as $h) { $tempo += $this->string->time_to_sec($h->hora_fim) - $this->string->time_to_sec($h->hora_inicio); } } $pontoUtil = $arrayPontoTotal[$i] - $tempo; $arrayPontoUtil[$i] = $pontoUtil; $totalPontoUtil += $pontoUtil; $pontoUtil = $this->string->sec_to_time($pontoUtil); $tr->addCell($this->string->retira_segundos($pontoUtil), 'center', 'datap'); $tr->addCell(round($arrayPontoUtil[$i] * 100 / $arrayHorario[$i]) . '%', 'center', 'datap'); $tr->addCell(' ', 'center', 'datai'); $i++; } $totalPontoUtil = $this->string->sec_to_time($totalPontoUtil); $tr->addCell($this->string->retira_segundos($totalPontoUtil), 'center', 'datap'); $tr->addCell(round($this->string->time_to_sec($totalPontoUtil) * 100 / $this->string->time_to_sec($totalHorario)) . '%', 'center', 'datap'); //add atividades indicador total $i = 0; $totalAtividadeTotal = null; $arrayAtividadeTotal = array(); $tr->addRow(); $tr->addCell(utf8_decode('Horas atividade (indicador total):'), 'left', 'datap'); foreach ($meses as $mes) { $total = Atividade::retornaTotalAtividadesColaborador($formdata->colaborador_id, substr($mes, 3, 2), substr($mes, 6, 4), $tickets); $arrayAtividadeTotal[$i] = $this->string->time_to_sec($total); $totalAtividadeTotal += $this->string->time_to_sec($total); $tr->addCell($this->string->retira_segundos($total), 'center', 'datap'); $tr->addCell(round($arrayAtividadeTotal[$i] * 100 / $arrayPontoTotal[$i]) . '%', 'center', 'datap'); $tr->addCell(' ', 'center', 'datai'); $i++; } $totalAtividadeTotal = $this->string->sec_to_time($totalAtividadeTotal); $tr->addCell($this->string->retira_segundos($totalAtividadeTotal), 'center', 'datap'); $tr->addCell(round($this->string->time_to_sec($totalAtividadeTotal) * 100 / $this->string->time_to_sec($totalPontoTotal)) . '%', 'center', 'datap'); //add atividades indicador util $i = 0; $tr->addRow(); $tr->addCell(utf8_decode('Horas atividade (indicador util):'), 'left', 'datap'); foreach ($meses as $mes) { $total = $this->string->sec_to_time($arrayAtividadeTotal[$i]); $tr->addCell($this->string->retira_segundos($total), 'center', 'datap'); $tr->addCell(round($arrayAtividadeTotal[$i] * 100 / $arrayPontoUtil[$i]) . '%', 'center', 'datap'); $tr->addCell(' ', 'center', 'datai'); $i++; } //$totalAtividadeTotal = $this->string->sec_to_time($totalAtividadeTotal); $tr->addCell($this->string->retira_segundos($totalAtividadeTotal), 'center', 'datap'); $tr->addCell(round($this->string->time_to_sec($totalAtividadeTotal) * 100 / $this->string->time_to_sec($totalPontoUtil)) . '%', 'center', 'datap'); // division row $tr->addRow(); $tr->addCell($break, 'center', 'datai', $colunas); // add a header row $tr->addRow(); $tr->addCell(utf8_decode('Ausências'), 'center', 'header', $colunas); // add a header row $i = 0; $tr->addRow(); $tr->addCell('', 'center', 'header'); foreach ($meses as $mes) { $i++; $tr->addCell(substr(strtoupper($arrayMeses[intval(substr($mes, 3, 2))]), 0, 3), 'center', 'header'); $tr->addCell('%', 'center', 'header'); $tr->addCell(' ', 'center', 'datai'); } $tr->addCell('TOTAL', 'center', 'header'); $tr->addCell('%', 'center', 'header'); // add atestado medico row $i = 0; $totalAtestados = null; $arrayAtestados = array(); $tr->addRow(); $tr->addCell(utf8_decode('Atestado médico:'), 'left', 'datap'); foreach ($meses as $mes) { $atestados = Atividade::retornaAtestados($formdata->colaborador_id, substr($mes, 3, 2), substr($mes, 6, 4)); $arrayAtestados[$i] = $this->string->time_to_sec($atestados); $totalAtestados += $this->string->time_to_sec($atestados); $tr->addCell($this->string->retira_segundos($atestados), 'center', 'datap'); $tr->addCell(round($arrayAtestados[$i] * 100 / $arrayPontoTotal[$i]) . '%', 'center', 'datap'); $tr->addCell(' ', 'center', 'datai'); $i++; } $totalAtestados = $this->string->sec_to_time($totalAtestados); $tr->addCell($this->string->retira_segundos($totalAtestados), 'center', 'datap'); $tr->addCell(round($this->string->time_to_sec($totalAtestados) * 100 / $this->string->time_to_sec($totalPontoTotal)) . '%', 'center', 'datap'); // add ausencias row $i = 0; $totalAusencias = null; $arrayAusencias = array(); $tr->addRow(); $tr->addCell(utf8_decode('Ausências:'), 'left', 'datap'); foreach ($meses as $mes) { $ausencias = Atividade::retornaAusencias($formdata->colaborador_id, substr($mes, 3, 2), substr($mes, 6, 4)); $arrayAusencias[$i] = $this->string->time_to_sec($ausencias); $totalAusencias += $this->string->time_to_sec($ausencias); $tr->addCell($this->string->retira_segundos($ausencias), 'center', 'datap'); $tr->addCell(round($arrayAusencias[$i] * 100 / $arrayPontoTotal[$i]) . '%', 'center', 'datap'); $tr->addCell(' ', 'center', 'datai'); $i++; } $totalAusencias = $this->string->sec_to_time($totalAusencias); $tr->addCell($this->string->retira_segundos($totalAusencias), 'center', 'datap'); $tr->addCell(round($this->string->time_to_sec($totalAusencias) * 100 / $this->string->time_to_sec($totalPontoTotal)) . '%', 'center', 'datap'); // division row $tr->addRow(); $tr->addCell($break, 'center', 'datai', $colunas); // add a header row $tr->addRow(); $tr->addCell(utf8_decode('Tipo Atividades'), 'center', 'header', $colunas); // add Tipo Atividades row $i = 0; $tr->addRow(); $tr->addCell('', 'center', 'header'); foreach ($meses as $mes) { $i++; $tr->addCell(substr(strtoupper($arrayMeses[intval(substr($mes, 3, 2))]), 0, 3), 'center', 'header'); $tr->addCell('%', 'center', 'header'); $tr->addCell(' ', 'center', 'datai'); } $tr->addCell('TOTAL', 'center', 'header'); $tr->addCell('%', 'center', 'header'); // verifica tipos de atividades do periodo $colour = FALSE; $tipoAtividades = array(); $objects = Atividade::retornaTiposAtividadesPeriodo($formdata->colaborador_id, $formdata->ano_atividade_inicial . '-' . str_pad($formdata->mes_atividade_inicial, 2, '0', STR_PAD_LEFT) . '-01', $formdata->ano_atividade_final . '-' . str_pad($formdata->mes_atividade_final, 2, '0', STR_PAD_LEFT) . '-' . cal_days_in_month(CAL_GREGORIAN, str_pad($formdata->mes_atividade_final, 2, '0', STR_PAD_LEFT), $formdata->ano_atividade_final), $tickets); $i = 1; foreach ($objects as $row) { $tipoAtividades[$i] = $row['tipo_atividade_id']; $i++; } foreach ($tipoAtividades as $ati) { // adiciona as linhas por tipo de atividade $style = $colour ? 'datap' : 'datai'; $i = 0; $totalAtividade = null; $arrayAtividade = array(); $tipoAtv = new TipoAtividade($ati); $tr->addRow(); $tr->addCell(utf8_decode($tipoAtv->nome . ':'), 'left', $style); foreach ($meses as $mes) { $cri = new TCriteria(); if ($formdata->colaborador_id > 0) { $cri->add(new TFilter("colaborador_id", "=", $formdata->colaborador_id)); } if ($tickets) { $cri->add(new TFilter("ticket_id", "IN", $arrayTickets)); } $cri->add(new TFilter("extract('month' from data_atividade)", "=", substr($mes, 3, 2))); $cri->add(new TFilter("extract('year' from data_atividade)", "=", substr($mes, 6, 4))); $cri->add(new TFilter("tipo_atividade_id", "=", $ati)); $repo = new TRepository('Atividade'); $count = $repo->count($cri); $tempo = 0; if ($count) { $horas = $repo->load($cri); foreach ($horas as $h) { $tempo += $this->string->time_to_sec($h->hora_fim) - $this->string->time_to_sec($h->hora_inicio); } } $arrayAtividade[$i] = $tempo; $totalAtividade += $tempo; $tempo = $this->string->sec_to_time($tempo); $tr->addCell($this->string->retira_segundos($tempo), 'center', $style); $tr->addCell(round($arrayAtividade[$i] * 100 / $arrayAtividadeTotal[$i]) . '%', 'center', $style); $tr->addCell(' ', 'center', 'datai'); $i++; $colour = !$colour; } $totalAtividade = $this->string->sec_to_time($totalAtividade); $tr->addCell($this->string->retira_segundos($totalAtividade), 'center', $style); $tr->addCell(round($this->string->time_to_sec($totalAtividade) * 100 / $this->string->time_to_sec($totalAtividadeTotal)) . '%', 'center', $style); } //row total $i = 0; $tr->addRow(); $tr->addCell(utf8_decode('<b>Total:</b>'), 'left', 'footer'); foreach ($meses as $mes) { $total = $this->string->sec_to_time($arrayAtividadeTotal[$i]); $tr->addCell($this->string->retira_segundos($total), 'center', 'footer'); $tr->addCell('100%', 'center', 'footer'); $tr->addCell(' ', 'center', 'datai'); $i++; } $tr->addCell($this->string->retira_segundos($totalAtividadeTotal), 'center', 'footer'); $tr->addCell('100%', 'center', 'footer'); // division row $tr->addRow(); $tr->addCell($break, 'center', 'datai', $colunas); // add Por Sistema row $tr->addRow(); $tr->addCell(utf8_decode('Por sistema'), 'center', 'header', $colunas); $i = 0; $tr->addRow(); $tr->addCell('', 'center', 'header'); foreach ($meses as $mes) { $i++; $tr->addCell(substr(strtoupper($arrayMeses[intval(substr($mes, 3, 2))]), 0, 3), 'center', 'header'); $tr->addCell('%', 'center', 'header'); $tr->addCell(' ', 'center', 'datai'); } $tr->addCell('TOTAL', 'center', 'header'); $tr->addCell('%', 'center', 'header'); // verifica tipos de atividades do periodo $colour = FALSE; $tipoSistemas = array(); $objects = Atividade::retornaSistemasPeriodo($formdata->colaborador_id, $formdata->ano_atividade_inicial . '-' . str_pad($formdata->mes_atividade_inicial, 2, '0', STR_PAD_LEFT) . '-01', $formdata->ano_atividade_final . '-' . str_pad($formdata->mes_atividade_final, 2, '0', STR_PAD_LEFT) . '-' . cal_days_in_month(CAL_GREGORIAN, str_pad($formdata->mes_atividade_final, 2, '0', STR_PAD_LEFT), $formdata->ano_atividade_final), $tickets); $i = 1; foreach ($objects as $row) { $tipoSistemas[$i] = $row['sistema_id']; $i++; } foreach ($tipoSistemas as $sis) { // adiciona as linhas por tipo de atividade $style = $colour ? 'datap' : 'datai'; $i = 0; $totalSistema = null; $arraySistema = array(); $sistema = new Sistema($sis); $tr->addRow(); $tr->addCell(utf8_decode($sistema->nome . ':'), 'left', $style); foreach ($meses as $mes) { $cri = new TCriteria(); if ($formdata->colaborador_id > 0) { $cri->add(new TFilter("colaborador_id", "=", $formdata->colaborador_id)); } if ($tickets) { $cri->add(new TFilter("ticket_id", "IN", $arrayTickets)); } $cri->add(new TFilter("extract('month' from data_atividade)", "=", substr($mes, 3, 2))); $cri->add(new TFilter("extract('year' from data_atividade)", "=", substr($mes, 6, 4))); $cri->add(new TFilter("sistema_id", "=", $sis)); $cri->add(new TFilter("ticket_id", "not in", array(328, 514))); $repo = new TRepository('Atividade'); $count = $repo->count($cri); $tempo = 0; if ($count) { $horas = $repo->load($cri); foreach ($horas as $h) { $tempo += $this->string->time_to_sec($h->hora_fim) - $this->string->time_to_sec($h->hora_inicio); } } $arraySistema[$i] = $tempo; $totalSistema += $tempo; $tempo = $this->string->sec_to_time($tempo); $tr->addCell($this->string->retira_segundos($tempo), 'center', $style); $tr->addCell(round($arraySistema[$i] * 100 / $arrayAtividadeTotal[$i]) . '%', 'center', $style); $tr->addCell(' ', 'center', 'datai'); $i++; $colour = !$colour; } $totalSistema = $this->string->sec_to_time($totalSistema); $tr->addCell($this->string->retira_segundos($totalSistema), 'center', $style); $tr->addCell(round($this->string->time_to_sec($totalSistema) * 100 / $this->string->time_to_sec($totalAtividadeTotal)) . '%', 'center', $style); } //row total $i = 0; $tr->addRow(); $tr->addCell(utf8_decode('<b>Total:</b>'), 'left', 'footer'); foreach ($meses as $mes) { $total = $this->string->sec_to_time($arrayAtividadeTotal[$i]); $tr->addCell($this->string->retira_segundos($total), 'center', 'footer'); $tr->addCell('100%', 'center', 'footer'); $tr->addCell(' ', 'center', 'datai'); $i++; } $tr->addCell($this->string->retira_segundos($totalAtividadeTotal), 'center', 'footer'); $tr->addCell('100%', 'center', 'footer'); // division row $tr->addRow(); $tr->addCell($break, 'center', 'datai', $colunas); // add Por Cliente row $tr->addRow(); $tr->addCell(utf8_decode('Por Cliente'), 'center', 'header', $colunas); $i = 0; $tr->addRow(); $tr->addCell('', 'center', 'header'); foreach ($meses as $mes) { $i++; $tr->addCell(substr(strtoupper($arrayMeses[intval(substr($mes, 3, 2))]), 0, 3), 'center', 'header'); $tr->addCell('%', 'center', 'header'); $tr->addCell(' ', 'center', 'datai'); } $tr->addCell('TOTAL', 'center', 'header'); $tr->addCell('%', 'center', 'header'); // monta array de clientes $tipoClientes = array(); $objects = Atividade::retornaClientesPeriodo($formdata->colaborador_id, $formdata->ano_atividade_inicial . '-' . str_pad($formdata->mes_atividade_inicial, 2, '0', STR_PAD_LEFT) . '-01', $formdata->ano_atividade_final . '-' . str_pad($formdata->mes_atividade_final, 2, '0', STR_PAD_LEFT) . '-' . cal_days_in_month(CAL_GREGORIAN, str_pad($formdata->mes_atividade_final, 2, '0', STR_PAD_LEFT), $formdata->ano_atividade_final), $tickets); foreach ($objects as $row) { $cliente = new Pessoa($row['solicitante_id']); if ($cliente->origem == 1) { $ind = $cliente->codigo_cadastro_origem; } else { $ind = 999; } $tipoClientes[$ind] += $this->string->time_to_sec($row['sum']); } arsort($tipoClientes); $colour = FALSE; foreach ($tipoClientes as $key => $value) { $style = $colour ? 'datap' : 'datai'; $i = 0; $totalClientes = null; $arrayClientes = array(); $labelCliente = ''; if ($key == '999') { $labelCliente = '999 - ECS'; } else { $entidade = new Entidade($key); $labelCliente = str_pad($key, 3, '0', STR_PAD_LEFT) . ' - ' . $entidade->entnomfan; } $tr->addRow(); $tr->addCell(utf8_decode($labelCliente), 'left', $style); foreach ($meses as $mes) { $cri = new TCriteria(); if ($formdata->colaborador_id > 0) { $cri->add(new TFilter("colaborador_id", "=", $formdata->colaborador_id)); } if (!$tickets) { $cliente = Pessoa::getPessoasEntidade($key); $retorno = Ticket::getTicketsCliente($cliente); $arrayTickets = $retorno; } $cri->add(new TFilter("ticket_id", "IN", $arrayTickets)); $cri->add(new TFilter("extract('month' from data_atividade)", "=", substr($mes, 3, 2))); $cri->add(new TFilter("extract('year' from data_atividade)", "=", substr($mes, 6, 4))); $cri->add(new TFilter("ticket_id", "not in", array(328, 514))); $repo = new TRepository('Atividade'); $count = $repo->count($cri); $tempo = 0; if ($count) { $horas = $repo->load($cri); foreach ($horas as $h) { $tempo += $this->string->time_to_sec($h->hora_fim) - $this->string->time_to_sec($h->hora_inicio); } } $arrayClientes[$i] = $tempo; $totalClientes += $tempo; $tempo = $this->string->sec_to_time($tempo); $tr->addCell($this->string->retira_segundos($tempo), 'center', $style); $tr->addCell(round($arrayClientes[$i] * 100 / $arrayAtividadeTotal[$i]) . '%', 'center', $style); $tr->addCell(' ', 'center', 'datai'); $i++; $colour = !$colour; } $totalClientes = $this->string->sec_to_time($totalClientes); $tr->addCell($this->string->retira_segundos($totalClientes), 'center', $style); $tr->addCell(round($this->string->time_to_sec($totalClientes) * 100 / $this->string->time_to_sec($totalAtividadeTotal)) . '%', 'center', $style); } //row total $i = 0; $tr->addRow(); $tr->addCell(utf8_decode('<b>Total:</b>'), 'left', 'footer'); foreach ($meses as $mes) { $total = $this->string->sec_to_time($arrayAtividadeTotal[$i]); $tr->addCell($this->string->retira_segundos($total), 'center', 'footer'); $tr->addCell('100%', 'center', 'footer'); $tr->addCell(' ', 'center', 'datai'); $i++; } $tr->addCell($this->string->retira_segundos($totalAtividadeTotal), 'center', 'footer'); $tr->addCell('100%', 'center', 'footer'); // stores the file if (!file_exists("app/output/Atividade.{$format}") or is_writable("app/output/Atividade.{$format}")) { $tr->save("app/output/Atividade.{$format}"); } else { throw new Exception(_t('Permission denied') . ': ' . "app/output/Atividade.{$format}"); } // open the report file parent::openFile("app/output/Atividade.{$format}"); // shows the success message new TMessage('info', 'Report generated. Please, enable popups in the browser (just in the web).'); } else { new TMessage('error', 'No records found'); } // fill the form with the active record data $this->form->setData($formdata); // close the transaction TTransaction::close(); } catch (Exception $e) { // shows the exception error message new TMessage('error', '<b>Error</b> ' . $e->getMessage()); // undo all pending operations TTransaction::rollback(); } }
/** * method onGenerate() * Executed whenever the user clicks at the generate button */ function onGenerate() { try { // open a transaction with database 'samples' TTransaction::open('samples'); // get the form data into an active record Customer $object = $this->form->getData(); $repository = new TRepository('Customer'); $criteria = new TCriteria(); if ($object->name) { $criteria->add(new TFilter('name', 'like', "%{$object->name}%")); } if ($object->city_id) { $criteria->add(new TFilter('city_id', '=', "{$object->city_id}")); } if ($object->category_id) { $criteria->add(new TFilter('category_id', '=', "{$object->category_id}")); } $customers = $repository->load($criteria); $format = $object->output_type; if ($customers) { $widths = array(40, 150, 80, 120, 80); switch ($format) { case 'html': $tr = new TTableWriterHTML($widths); break; case 'pdf': $tr = new TTableWriterPDF($widths); break; case 'rtf': if (!class_exists('PHPRtfLite_Autoloader')) { PHPRtfLite::registerAutoloader(); } $tr = new TTableWriterRTF($widths); break; } // create the document styles $tr->addStyle('title', 'Arial', '10', 'BI', '#ffffff', '#407B49'); $tr->addStyle('datap', 'Arial', '10', '', '#000000', '#869FBB'); $tr->addStyle('datai', 'Arial', '10', '', '#000000', '#ffffff'); $tr->addStyle('header', 'Times', '16', 'BI', '#ff0000', '#FFF1B2'); $tr->addStyle('footer', 'Times', '12', 'BI', '#2B2B2B', '#B5FFB4'); // add a header row $tr->addRow(); $tr->addCell('Customers', 'center', 'header', 5); // add titles row $tr->addRow(); $tr->addCell('Code', 'left', 'title'); $tr->addCell('Name', 'left', 'title'); $tr->addCell('Category', 'left', 'title'); $tr->addCell('Email', 'left', 'title'); $tr->addCell('Birthdate', 'left', 'title'); // controls the background filling $colour = FALSE; // data rows foreach ($customers as $customer) { $style = $colour ? 'datap' : 'datai'; $tr->addRow(); $tr->addCell($customer->id, 'left', $style); $tr->addCell($customer->name, 'left', $style); $tr->addCell($customer->category_name, 'left', $style); $tr->addCell($customer->email, 'left', $style); $tr->addCell($customer->birthdate, 'left', $style); $colour = !$colour; } // footer row $tr->addRow(); $tr->addCell(date('Y-m-d h:i:s'), 'center', 'footer', 5); // stores the file if (!file_exists("app/output/tabular.{$format}") or is_writable("app/output/tabular.{$format}")) { $tr->save("app/output/tabular.{$format}"); } else { throw new Exception(_t('Permission denied') . ': ' . "app/output/tabular.{$format}"); } parent::openFile("app/output/tabular.{$format}"); // shows the success message new TMessage('info', 'Report generated. Please, enable popups in the browser (just in the web).'); } else { new TMessage('error', 'No records found'); } // fill the form with the active record data $this->form->setData($object); // close the transaction TTransaction::close(); } catch (Exception $e) { // shows the exception error message new TMessage('error', '<b>Error</b> ' . $e->getMessage()); // undo all pending operations TTransaction::rollback(); } }
/** * @dataProvider provideQuoteRtfCode() */ public function testQuoteRtfCode($testString, $resultString) { $this->assertEquals($resultString, PHPRtfLite::quoteRtfCode($testString)); }
/** * Sets background color * * @param string $color background color */ public function setBackgroundColor($color) { $color = PHPRtfLite::convertHexColorToRtf($color); $this->_table->getRtf()->addColor($color); $this->_backgroundColor = $color; }