示例#1
0
文件: Pdf.php 项目: robjacoby/xlr8u
 public function calculateCellSize()
 {
     $titles = parent::_buildTitles();
     $sqlexp = parent::_buildSqlExp();
     $grid = parent::_buildGrid();
     $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA);
     $i = 0;
     foreach ($titles as $titulos) {
         if (@$titulos['field'] != $this->getInfo('hRow,field') && $this->getInfo('hRow,title') != '' || $this->getInfo('hRow,title') == '') {
             $larg[$i] = $this->widthForStringUsingFontSize($titulos['value'], $font, 8);
             $i++;
         }
     }
     $i = 0;
     if (is_array($sqlexp)) {
         foreach ($sqlexp as $sql) {
             if ($sql['field'] != $this->getInfo('hRow,field') && $this->getInfo('hRow,title') != '' || $this->getInfo('hRow,title') == '') {
                 if ($larg[$i] < strlen($sql['value'])) {
                     $larg[$i] = strlen($sql['value']);
                 }
                 $i++;
             }
         }
     }
     if ($this->getInfo('hRow,title') != '') {
         $bar = $grid;
         $hbar = trim($this->getInfo('hRow,field'));
         $p = 0;
         foreach ($grid[0] as $value) {
             if ($value['field'] == $hbar) {
                 $hRowIndex = $p;
             }
             $p++;
         }
         $aa = 0;
     }
     foreach ($grid as $row) {
         $i = 0;
         $a = 1;
         foreach ($row as $value) {
             $value['value'] = strip_tags($value['value']);
             if (isset($value['field']) && $value['field'] != $this->getInfo('hRow,field') && $this->getInfo('hRow,title') != '' || $this->getInfo('hRow,title') == '') {
                 if ($larg[$i] < strlen($value['value'])) {
                     $larg[$i] = strlen($value['value']);
                 }
                 $i++;
             }
             $a++;
         }
         $i++;
     }
     return $larg;
 }
示例#2
0
文件: Excel.php 项目: robjacoby/xlr8u
    /**
     * Deploys
     *
     * @return void
     * @see library/Bvb/Bvb_Grid::deploy()
     */
    public function deploy()
    {
        $this->setRecordsPerPage(0);
        parent::deploy();
        if (!isset($this->options['title'])) {
            $this->options['title'] = 'ZFDatagrid';
        }
        $titles = parent::_buildTitles();
        $wsData = parent::_buildGrid();
        $sql = parent::_buildSqlExp();
        if (is_array($wsData) && count($wsData) > 65569) {
            throw new Bvb_Grid_Exception('Maximum number of records allowed is 65569');
        }
        $xml = '<?xml version="1.0"?><?mso-application progid="Excel.Sheet"?>
<Workbook xmlns:x="urn:schemas-microsoft-com:office:excel"
  xmlns="urn:schemas-microsoft-com:office:spreadsheet"
  xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">';
        $xml .= '<Worksheet ss:Name="' . $this->options['title'] . '" ss:Description="' . $this->options['title'] . '"><ss:Table>';
        $xml .= '<ss:Row>';
        foreach ($titles as $value) {
            $type = !is_numeric($value['value']) ? 'String' : 'Number';
            $xml .= '<ss:Cell><Data ss:Type="' . $type . '">' . $value['value'] . '</Data></ss:Cell>';
        }
        $xml .= '</ss:Row>';
        if (is_array($wsData)) {
            foreach ($wsData as $row) {
                $xml .= '<ss:Row>';
                $a = 1;
                foreach ($row as $value) {
                    $value['value'] = strip_tags($value['value']);
                    $type = !is_numeric($value['value']) ? 'String' : 'Number';
                    $xml .= '<ss:Cell><Data ss:Type="' . $type . '">' . $value['value'] . '</Data></ss:Cell>';
                    $a++;
                }
                $xml .= '</ss:Row>';
            }
        }
        if (is_array($sql)) {
            $xml .= '<ss:Row>';
            foreach ($sql as $value) {
                $type = !is_numeric($value['value']) ? 'String' : 'Number';
                $xml .= '<ss:Cell><Data ss:Type="' . $type . '">' . $value['value'] . '</Data></ss:Cell>';
            }
            $xml .= '</ss:Row>';
        }
        $xml .= '</ss:Table></Worksheet>';
        $xml .= '</Workbook>';
        if (!isset($this->_deploy['save'])) {
            $this->_deploy['save'] = false;
        }
        if (!isset($this->_deploy['download'])) {
            $this->_deploy['download'] = false;
        }
        if ($this->_deploy['save'] != 1 && $this->_deploy['download'] != 1) {
            throw new Exception('Nothing to do. Please specify download&&|save options');
        }
        if (empty($this->_deploy['name'])) {
            $this->_deploy['name'] = date('H_m_d_H_i_s');
        }
        if (substr($this->_deploy['name'], -4) == '.xls') {
            $this->_deploy['name'] = substr($this->_deploy['name'], 0, -4);
        }
        $this->_deploy['dir'] = rtrim($this->_deploy['dir'], '/') . '/';
        if (!is_dir($this->_deploy['dir']) && $this->_deploy['save'] == 1) {
            throw new Bvb_Grid_Exception($this->_deploy['dir'] . ' is not a dir');
        }
        if (!is_writable($this->_deploy['dir']) && $this->_deploy['save'] == 1) {
            throw new Bvb_Grid_Exception($this->_deploy['dir'] . ' is not writable');
        }
        if ($this->_deploy['save'] == 1) {
            file_put_contents($this->_deploy['dir'] . $this->_deploy['name'] . ".xls", $xml);
        }
        if ($this->_deploy['download'] == 1) {
            header('Content-type: application/excel');
            header('Content-Disposition: attachment; filename="' . $this->_deploy['name'] . '.xls"');
            echo $xml;
        }
        die;
    }
示例#3
0
 /**
  * Combines all parts from the output
  * To deploy or to render()
  *
  * @param bool $deploy IF this is the deploy and not a render part
  *
  * @return void
  */
 private function _buildGridRender($deploy = true)
 {
     $bHeader = $this->_buildExtraRows('beforeHeader') . $this->_buildHeader() . $this->_buildExtraRows('afterHeader');
     $bTitles = $this->_buildExtraRows('beforeTitles') . $this->_buildMassActions() . $this->_buildTitlesTable(parent::_buildTitles(), true) . $this->_buildExtraRows('afterTitles');
     $bFilters = $this->_buildExtraRows('beforeFilters') . $this->_buildFiltersTable(parent::_buildFilters()) . $this->_buildExtraRows('afterFilters');
     $bGrid = $this->_buildGridTable(parent::_buildGrid());
     if (!$this->getInfo("hRow,title")) {
         $bSqlExp = $this->_buildExtraRows('beforeSqlExpTable') . $this->_buildSqlexpTable(parent::_buildSqlExp()) . $this->_buildExtraRows('afterSqlExpTable');
     } else {
         $bSqlExp = '';
     }
     $bPagination = $this->_buildExtraRows('beforePagination') . $this->_buildPagination() . $this->_buildExtraRows('afterPagination');
     if ($deploy == true) {
         $this->_renderDeploy['header'] = $bHeader;
         $this->_renderDeploy['titles'] = $bTitles;
         $this->_renderDeploy['filters'] = $bFilters;
         $this->_renderDeploy['grid'] = $bGrid;
         $this->_renderDeploy['sqlExp'] = $bSqlExp;
         $this->_renderDeploy['pagination'] = $bPagination;
     }
     $this->_render['header'] = $bHeader;
     $this->_render['titles'] = $bTitles;
     $this->_render['filters'] = $bFilters;
     $this->_render['grid'] = $bGrid;
     $this->_render['sqlExp'] = $bSqlExp;
     $this->_render['pagination'] = $bPagination;
 }
示例#4
0
 public function deploy()
 {
     $this->checkExportRights();
     $this->setRecordsPerPage(0);
     parent::deploy();
     if (!$this->_temp['print'] instanceof Bvb_Grid_Template_Print) {
         $this->setTemplate('print', 'print');
     }
     $titles = parent::_buildTitles();
     $wsData = parent::_buildGrid();
     $sql = parent::_buildSqlExp();
     if (!isset($this->_deploy['title'])) {
         $this->_deploy['title'] = '';
     }
     $print = $this->_temp['print']->globalStart();
     $print .= $this->_temp['print']->header();
     //[PT] Títulos
     $print .= $this->_temp['print']->titlesStart();
     foreach ($titles as $value) {
         if (isset($value['field']) && $value['field'] != $this->getInfo('hRow,field') && $this->getInfo('hRow,title') != '' || $this->getInfo('hRow,title') == '') {
             $print .= str_replace("{{value}}", $value['value'], $this->_temp['print']->titlesLoop());
         }
     }
     $print .= $this->_temp['print']->titlesEnd();
     if (is_array($wsData)) {
         if ($this->getInfo('hRow,title') != '') {
             $bar = $wsData;
             $hbar = trim($this->getInfo('hRow,field'));
             $p = 0;
             foreach ($wsData[0] as $value) {
                 if ($value['field'] == $hbar) {
                     $hRowIndex = $p;
                 }
                 $p++;
             }
             $aa = 0;
         }
         $i = 1;
         $aa = 0;
         foreach ($wsData as $row) {
             //horizontal row
             if ($this->getInfo('hRow,title') != '') {
                 if (!isset($bar[$aa - 1][$hRowIndex])) {
                     $bar[$aa - 1][$hRowIndex]['value'] = '';
                 }
                 if ($bar[$aa][$hRowIndex]['value'] != $bar[$aa - 1][$hRowIndex]['value']) {
                     $print .= str_replace("{{value}}", $bar[$aa][$hRowIndex]['value'], $this->_temp['print']->hRow());
                 }
             }
             $i++;
             $print .= $this->_temp['print']->loopStart();
             $a = 1;
             foreach ($row as $value) {
                 $value['value'] = strip_tags($value['value']);
                 if (isset($value['field']) && $value['field'] != $this->getInfo('hRow,field') && $this->getInfo('hRow,title') != '' || $this->getInfo('hRow,title') == '') {
                     $print .= str_replace("{{value}}", $value['value'], $this->_temp['print']->loopLoop());
                 }
             }
             $print .= $this->_temp['print']->loopEnd();
             $aa++;
             $i++;
         }
     }
     // SQL EXPRESSIONS
     if (is_array($sql)) {
         $print .= $this->_temp['print']->sqlExpStart();
         foreach ($sql as $value) {
             $print .= str_replace("{{value}}", $value['value'], $this->_temp['print']->sqlExpLoop());
         }
         $print .= $this->_temp['print']->sqlExpEnd();
     }
     $print .= $this->_temp['print']->globalEnd();
     if (!isset($this->_deploy['save'])) {
         $this->_deploy['save'] = false;
     }
     if (!isset($this->_deploy['download'])) {
         $this->_deploy['download'] = false;
     }
     if ($this->_deploy['save'] != 1 && $this->_deploy['download'] != 1) {
         header("Content-type: text/html");
     }
     if ($this->_deploy['save'] != 1 && $this->_deploy['download'] != 1) {
         echo $print;
         die;
     }
     if (empty($this->_deploy['name'])) {
         $this->_deploy['name'] = date('H_m_d_H_i_s');
     }
     if (substr($this->_deploy['name'], -5) == '.html') {
         $this->_deploy['name'] = substr($this->_deploy['name'], 0, -5);
     }
     $this->_deploy['dir'] = rtrim($this->_deploy['dir'], '/') . '/';
     if (!is_dir($this->_deploy['dir'])) {
         throw new Bvb_Grid_Exception($this->_deploy['dir'] . ' is not a dir');
     }
     if (!is_writable($this->_deploy['dir'])) {
         throw new Bvb_Grid_Exception($this->_deploy['dir'] . ' is not writable');
     }
     file_put_contents($this->_deploy['dir'] . $this->_deploy['name'] . ".html", $print);
     if ($this->_deploy['download'] == 1) {
         header('Content-Disposition: attachment; filename="' . $this->_deploy['name'] . '.html"');
         readfile($this->_deploy['dir'] . $this->_deploy['name'] . '.html');
     }
     if ($this->_deploy['save'] != 1) {
         unlink($this->_deploy['dir'] . $this->_deploy['name'] . '.html');
     }
     die;
 }
示例#5
0
 public function deploy()
 {
     $this->checkExportRights();
     $this->setRecordsPerPage(0);
     parent::deploy();
     if (!$this->_temp['wordx'] instanceof Bvb_Grid_Template_Wordx) {
         $this->setTemplate('wordx', 'wordx');
     }
     $this->templateInfo = $this->_temp['wordx']->options;
     if (!isset($this->_deploy['title'])) {
         $this->_deploy['title'] = '';
     }
     if (!isset($this->_deploy['subtitle'])) {
         $this->_deploy['subtitle'] = '';
     }
     if (!isset($this->_deploy['logo'])) {
         $this->_deploy['logo'] = '';
     }
     if (!isset($this->_deploy['footer'])) {
         $this->_deploy['footer'] = '';
     }
     if (!isset($this->_deploy['save'])) {
         $this->_deploy['save'] = false;
     }
     if (!isset($this->_deploy['download'])) {
         $this->_deploy['download'] = false;
     }
     if ($this->_deploy['save'] != 1 && $this->_deploy['download'] != 1) {
         throw new Exception('Nothing to do. Please specify download&&|save options');
     }
     $this->_deploy['dir'] = rtrim($this->_deploy['dir'], '/') . '/';
     $this->inicialDir = $this->_deploy['dir'];
     if (empty($this->_deploy['name'])) {
         $this->_deploy['name'] = date('H_m_d_H_i_s');
     }
     if (substr($this->_deploy['name'], -5) == '.docx') {
         $this->_deploy['name'] = substr($this->_deploy['name'], 0, -5);
     }
     if (!is_dir($this->_deploy['dir'])) {
         throw new Bvb_Grid_Exception($this->_deploy['dir'] . ' is not a dir');
     }
     if (!is_writable($this->_deploy['dir'])) {
         throw new Bvb_Grid_Exception($this->_deploy['dir'] . ' is not writable');
     }
     $this->templateDir = explode('/', $this->_deploy['dir']);
     array_pop($this->templateDir);
     $this->templateDir = ucfirst(end($this->templateDir));
     $this->_deploy['dir'] = rtrim($this->_deploy['dir'], '/') . '/' . ucfirst($this->_deploy['name']) . '/';
     if (!defined('APPLICATION_PATH')) {
         $pathTemplate = substr($this->templateInfo['dir'], 0, -4) . '/';
     } else {
         $pathTemplate = APPLICATION_PATH . '/../' . rtrim($this->getLibraryDir(), '/') . '/' . substr($this->templateInfo['dir'], 0, -4) . '/';
     }
     Bvb_Grid_Deploy_Helper_File::deldir($this->_deploy['dir']);
     Bvb_Grid_Deploy_Helper_File::copyDir($pathTemplate, $this->_deploy['dir']);
     $xml = $this->_temp['wordx']->globalStart();
     $titles = parent::_buildTitles();
     $wsData = parent::_buildGrid();
     $sql = parent::_buildSqlExp();
     # HEADER
     if (file_exists($this->_deploy['logo'])) {
         $data = explode("/", $this->_deploy['logo']);
         copy($this->_deploy['logo'], $this->_deploy['dir'] . 'word/media/' . end($data));
         $logo = $this->_temp['wordx']->logo();
         file_put_contents($this->dir . "word/_rels/header1.xml.rels", $logo);
         $header = str_replace(array('{{title}}', '{{subtitle}}'), array($this->_deploy['title'], $this->_deploy['subtitle']), $this->_temp['wordx']->header());
     } else {
         $header = str_replace(array('{{title}}', '{{subtitle}}'), array($this->_deploy['title'], $this->_deploy['subtitle']), $this->_temp['wordx']->header());
     }
     file_put_contents($this->_deploy['dir'] . "word/header1.xml", $header);
     #BEGIN FOOTER
     $footer = str_replace("{{value}}", $this->_deploy['footer'], $this->_temp['wordx']->footer());
     file_put_contents($this->_deploy['dir'] . "word/footer2.xml", $footer);
     #START DOCUMENT.XML
     $xml = $this->_temp['wordx']->globalStart();
     $xml .= $this->_temp['wordx']->titlesStart();
     foreach ($titles as $value) {
         if (isset($value['field']) && $value['field'] != $this->getInfo('hRow,field') && $this->getInfo('hRow,title') != '' || $this->getInfo('hRow,title') == '') {
             $xml .= str_replace("{{value}}", utf8_encode($value['value']), $this->_temp['wordx']->titlesLoop());
         }
     }
     $xml .= $this->_temp['wordx']->titlesEnd();
     if (is_array($wsData)) {
         if ($this->getInfo('hRow,title') != '') {
             $bar = $wsData;
             $hbar = trim($this->getInfo('hRow,title'));
             $p = 0;
             foreach ($wsData[0] as $value) {
                 if (isset($value['field']) && $value['field'] == $hbar) {
                     $hRowIndex = $p;
                 }
                 $p++;
             }
             $aa = 0;
         }
         $i = 1;
         $aa = 0;
         foreach ($wsData as $row) {
             //A linha horizontal
             if (@$this->getInfo('hRow,title') != '') {
                 if (@$bar[$aa][$hRowIndex]['value'] != @$bar[$aa - 1][$hRowIndex]['value']) {
                     $xml .= str_replace("{{value}}", utf8_encode(@$bar[$aa][$hRowIndex]['value']), $this->_temp['wordx']->hRow());
                 }
             }
             $xml .= $this->_temp['wordx']->loopStart();
             $a = 1;
             foreach ($row as $value) {
                 $value['value'] = strip_tags($value['value']);
                 if (isset($value['field']) && $value['field'] != $this->getInfo('hRow,field') && $this->getInfo('hRow,title') != '' || $this->getInfo('hRow,title') == '') {
                     $xml .= str_replace("{{value}}", utf8_encode($value['value']), $this->_temp['wordx']->loopLoop());
                 }
                 $a++;
             }
             $xml .= $this->_temp['wordx']->loopEnd();
             $aa++;
             $i++;
         }
     }
     if (is_array($sql)) {
         $xml .= $this->_temp['wordx']->sqlExpStart();
         foreach ($sql as $value) {
             $xml .= str_replace("{{value}}", utf8_encode($value['value']), $this->_temp['wordx']->sqlExpLoop());
         }
         $xml .= $this->_temp['wordx']->sqlExpEnd();
     }
     $xml .= $this->_temp['wordx']->globalEnd();
     file_put_contents($this->_deploy['dir'] . "word/document.xml", $xml);
     $final = Bvb_Grid_Deploy_Helper_File::scan_directory_recursively($this->_deploy['dir']);
     $f = explode('|', Bvb_Grid_Deploy_Helper_File::zipPaths($final));
     array_pop($f);
     $zip = new ZipArchive();
     $filename = $this->_deploy['dir'] . $this->_deploy['name'] . ".zip";
     if ($zip->open($filename, ZIPARCHIVE::CREATE) !== TRUE) {
         exit("cannot open <{$filename}>\n");
     }
     foreach ($f as $value) {
         $zip->addFile($value, str_replace($this->_deploy['dir'], '', $value));
     }
     $zip->close();
     rename($filename, $this->inicialDir . $this->_deploy['name'] . '.docx');
     if ($this->_deploy['download'] == 1) {
         header('Content-type: application/word');
         header('Content-Disposition: attachment; filename="' . $this->_deploy['name'] . '.docx"');
         readfile($this->inicialDir . $this->_deploy['name'] . '.docx');
     }
     if ($this->_deploy['save'] != 1) {
         unlink($this->inicialDir . $this->_deploy['name'] . '.docx');
     }
     Bvb_Grid_Deploy_Helper_File::deldir($this->_deploy['dir']);
     die;
 }
示例#6
0
文件: Word.php 项目: Aeryris/grid
 public function deploy()
 {
     $this->checkExportRights();
     $this->setRecordsPerPage(0);
     parent::deploy();
     if (!$this->_temp['word'] instanceof Bvb_Grid_Template_Word) {
         $this->setTemplate('word', 'word');
     }
     $titles = parent::_buildTitles();
     $wsData = parent::_buildGrid();
     $sql = parent::_buildSqlExp();
     $xml = $this->_temp['word']->globalStart();
     $xml .= $this->_temp['word']->titlesStart();
     foreach ($titles as $value) {
         if ($value['field'] != $this->getInfo('hRow,field') && $this->getInfo('hRow,title') != '' || $this->getInfo('hRow,title') == '') {
             $xml .= str_replace("{{value}}", $value['value'], $this->_temp['word']->titlesLoop());
         }
     }
     $xml .= $this->_temp['word']->titlesEnd();
     if (is_array($wsData)) {
         if ($this->getInfo('hRow,title') != '') {
             $bar = $wsData;
             $hbar = trim($this->getInfo('hRow,title'));
             $p = 0;
             foreach ($wsData[0] as $value) {
                 if ($value['field'] == $hbar) {
                     $hRowIndex = $p;
                 }
                 $p++;
             }
             $aa = 0;
         }
         $i = 1;
         $aa = 0;
         foreach ($wsData as $row) {
             //A linha horizontal
             if ($this->getInfo('hRow,title') != '') {
                 if (!isset($bar[$aa - 1][$hRowIndex])) {
                     $bar[$aa - 1][$hRowIndex]['value'] = '';
                 }
                 if ($bar[$aa][$hRowIndex]['value'] != $bar[$aa - 1][$hRowIndex]['value']) {
                     $xml .= str_replace("{{value}}", $bar[$aa][$hRowIndex]['value'], $this->_temp['word']->hRow());
                 }
             }
             $xml .= $this->_temp['word']->loopStart();
             $a = 1;
             foreach ($row as $value) {
                 $value['value'] = strip_tags($value['value']);
                 if (@$value['field'] != $this->getInfo('hRow,field') && $this->getInfo('hRow,title') != '' || $this->getInfo('hRow,title') == '') {
                     $xml .= str_replace("{{value}}", $value['value'], $this->_temp['word']->loopLoop(2));
                 }
                 $a++;
             }
             $xml .= $this->_temp['word']->loopEnd();
             $aa++;
             $i++;
         }
     }
     if (is_array($sql)) {
         $xml .= $this->_temp['word']->sqlExpStart();
         foreach ($sql as $value) {
             $xml .= str_replace("{{value}}", $value['value'], $this->_temp['word']->sqlExpLoop());
         }
         $xml .= $this->_temp['word']->sqlExpEnd();
     }
     $xml .= $this->_temp['word']->globalEnd();
     if (!isset($this->_deploy['save'])) {
         $this->_deploy['save'] = false;
     }
     if (!isset($this->_deploy['download'])) {
         $this->_deploy['download'] = false;
     }
     if ($this->_deploy['save'] != 1 && $this->_deploy['download'] != 1) {
         throw new Exception('Nothing to do. Please specify download&&|save options');
     }
     if (empty($this->_deploy['name'])) {
         $this->_deploy['name'] = date('H_m_d_H_i_s');
     }
     if (substr($this->_deploy['name'], -4) == '.doc') {
         $this->_deploy['name'] = substr($this->_deploy['name'], 0, -4);
     }
     $this->_deploy['dir'] = rtrim($this->_deploy['dir'], '/') . '/';
     if (!is_dir($this->_deploy['dir']) && $this->_deploy['save'] == 1) {
         throw new Bvb_Grid_Exception($this->_deploy['dir'] . ' is not a dir');
     }
     if (!is_writable($this->_deploy['dir']) && $this->_deploy['save'] == 1) {
         throw new Bvb_Grid_Exception($this->_deploy['dir'] . ' is not writable');
     }
     if ($this->_deploy['save'] == 1) {
         file_put_contents($this->_deploy['dir'] . $this->_deploy['name'] . ".doc", $xml);
     }
     if ($this->_deploy['download'] == 1) {
         header('Content-type: application/word');
         header('Content-Disposition: attachment; filename="' . $this->_deploy['name'] . '.doc"');
         echo $xml;
     }
     die;
 }
示例#7
0
 public function deploy()
 {
     $this->checkExportRights();
     $this->setRecordsPerPage(0);
     parent::deploy();
     if (!$this->_temp['ods'] instanceof Bvb_Grid_Template_Ods) {
         $this->setTemplate('ods', 'ods');
     }
     $this->templateInfo = $this->_temp['ods']->options;
     if (!isset($this->_deploy['title'])) {
         $this->_deploy['title'] = '';
     }
     if (!isset($this->_deploy['subtitle'])) {
         $this->_deploy['subtitle'] = '';
     }
     if (!isset($this->_deploy['logo'])) {
         $this->_deploy['logo'] = '';
     }
     if (!isset($this->_deploy['footer'])) {
         $this->_deploy['footer'] = '';
     }
     if (!isset($this->_deploy['save'])) {
         $this->_deploy['save'] = false;
     }
     if (!isset($this->_deploy['download'])) {
         $this->_deploy['download'] = false;
     }
     if ($this->_deploy['save'] != 1 && $this->_deploy['download'] != 1) {
         throw new Exception('Nothing to do. Please specify download&&|save options');
     }
     $this->_deploy['dir'] = rtrim($this->_deploy['dir'], '/') . '/';
     $this->inicialDir = $this->_deploy['dir'];
     if (empty($this->_deploy['name'])) {
         $this->_deploy['name'] = date('H_m_d_H_i_s');
     }
     if (substr($this->_deploy['name'], -5) == '.docx') {
         $this->_deploy['name'] = substr($this->_deploy['name'], 0, -5);
     }
     if (!is_dir($this->_deploy['dir'])) {
         throw new Bvb_Grid_Exception($this->_deploy['dir'] . ' is not a dir');
     }
     if (!is_writable($this->_deploy['dir'])) {
         throw new Bvb_Grid_Exception($this->_deploy['dir'] . ' is not writable');
     }
     $this->templateDir = explode('/', $this->templateInfo['dir']);
     array_pop($this->templateDir);
     $this->templateDir = ucfirst(end($this->templateDir));
     $this->_deploy['dir'] = rtrim($this->_deploy['dir'], '/') . '/' . ucfirst($this->_deploy['name']) . '/';
     if (!defined(APPLICATION_PATH)) {
         $pathTemplate = substr($this->templateInfo['dir'], 0, -4) . '/';
     } else {
         $pathTemplate = APPLICATION_PATH . '/../' . rtrim($this->getLibraryDir(), '/') . '/' . substr($this->templateInfo['dir'], 0, -4) . '/';
     }
     Bvb_Grid_Deploy_Helper_File::deldir($this->_deploy['dir']);
     Bvb_Grid_Deploy_Helper_File::copyDir($pathTemplate, $this->_deploy['dir']);
     $xml = $this->_temp['ods']->globalStart();
     $titles = parent::_buildTitles();
     $wsData = parent::_buildGrid();
     $sql = parent::_buildSqlExp();
     // START CONTENT.XML
     $xml = $this->_temp['ods']->globalStart();
     $xml .= $this->_temp['ods']->titlesStart();
     foreach ($titles as $value) {
         $xml .= str_replace("{{value}}", utf8_encode($value['value']), $this->_temp['ods']->titlesLoop());
     }
     $xml .= $this->_temp['ods']->titlesEnd();
     if (is_array($wsData)) {
         foreach ($wsData as $row) {
             $xml .= $this->_temp['ods']->loopStart();
             foreach ($row as $value) {
                 $xml .= str_replace("{{value}}", utf8_encode(strip_tags($value['value'])), $this->_temp['ods']->loopLoop());
             }
             $xml .= $this->_temp['ods']->loopEnd();
         }
     }
     if (is_array($sql)) {
         $xml .= $this->_temp['ods']->sqlExpStart();
         foreach ($sql as $value) {
             $xml .= str_replace("{{value}}", utf8_encode($value['value']), $this->_temp['ods']->sqlExpLoop());
         }
         $xml .= $this->_temp['ods']->sqlExpEnd();
     }
     $xml .= $this->_temp['ods']->globalEnd();
     file_put_contents($this->_deploy['dir'] . "content.xml", $xml);
     $final = Bvb_Grid_Deploy_Helper_File::scan_directory_recursively($this->_deploy['dir']);
     $f = explode('|', Bvb_Grid_Deploy_Helper_File::zipPaths($final));
     array_pop($f);
     $zip = new ZipArchive();
     $filename = $this->_deploy['dir'] . $this->_deploy['name'] . ".zip";
     if ($zip->open($filename, ZIPARCHIVE::CREATE) !== TRUE) {
         exit("cannot open <{$filename}>\n");
     }
     foreach ($f as $value) {
         $zip->addFile($value, str_replace($this->_deploy['dir'], '', $value));
     }
     $zip->close();
     rename($filename, $this->inicialDir . $this->_deploy['name'] . '.ods');
     if ($this->_deploy['download'] == 1) {
         header('Content-type: application/vnd.oasis.opendocument.spreadsheet');
         header('Content-Disposition: attachment; filename="' . $this->_deploy['name'] . '.ods"');
         readfile($this->inicialDir . $this->_deploy['name'] . '.ods');
     }
     if ($this->_deploy['save'] != 1) {
         unlink($this->inicialDir . $this->_deploy['name'] . '.ods');
     }
     Bvb_Grid_Deploy_Helper_File::deldir($this->_deploy['dir']);
     die;
 }
示例#8
0
文件: Ofc.php 项目: Aeryris/grid
    public function deploy()
    {
        $this->checkExportRights();
        if ($this->_filesLocation === null) {
            throw new Bvb_Grid_Exception($this->__("Please set Javascript and Flash file locations using SetFilesLocation()"));
        }
        $grid = array();
        $newData = array();
        $label = array();
        $result = array();
        parent::deploy();
        $data = parent::_buildGrid();
        if (count($data) == 0) {
            $this->_deploymentContent = '';
            return;
        }
        foreach ($data as $value) {
            foreach ($value as $final) {
                $result[$final['field']][] = is_numeric($final['value']) ? $final['value'] : strip_tags($final['value']);
            }
        }
        if (is_string($this->_xLabels) && isset($result[$this->_xLabels])) {
            $this->_xLabels = $result[$this->_xLabels];
        }
        $graph = new OFC_Chart();
        $title = new OFC_Elements_Title($this->_title);
        $title->set_style($this->_style);
        $graph->set_title($title);
        foreach ($this->_chartOptions as $key => $value) {
            $graph->{$key}($value);
        }
        if (count($this->_xLabels) > 0) {
            $x = new OFC_Elements_Axis_X();
            $x_axis_labels = new OFC_Elements_Axis_X_Label_Set();
            foreach ($this->_xAxisOptions as $key => $value) {
                $x_axis_labels->{$key}($value);
            }
            $x_axis_labels->set_labels($this->_xLabels);
            $x->set_labels($x_axis_labels);
            foreach ($this->_xLabelsOptions as $key => $value) {
                $x->{$key}($value);
            }
            $graph->set_x_axis($x);
        }
        if (!empty($this->_xLegendText) && !empty($this->_xLegendStyle)) {
            $x_legend = new OFC_Elements_Legend_X($this->_xLegendText);
            $x_legend->set_style($this->_xLegendStyle);
            $graph->set_x_legend($x_legend);
        }
        $min = 0;
        $max = 0;
        if (count($this->_values) == 0) {
            $this->setValues(key($result));
        }
        foreach ($this->_values as $key => $value) {
            if (is_array($value)) {
                $support = $value;
                sort($support);
                if (reset($support) < $min) {
                    $min = reset($support);
                }
                if (end($support) > $max) {
                    $max = end($support);
                }
                unset($support);
                $options = $this->_chartOptionsValues[$value];
                if (isset($options['chartType'])) {
                    $this->setChartType($options['chartType']);
                }
                $bar = new $this->_type();
                foreach ($options as $key => $prop) {
                    $bar->{$key}($prop);
                }
                $this->_type();
                $pie = array();
                if ($this->_type == 'Pie') {
                    foreach ($value as $key => $title) {
                        $pie[] = array('value' => $title, 'label' => $this->_xLabels[$key]);
                    }
                    $bar->set_values($pie);
                } else {
                    $bar->set_values($value);
                }
                $graph->add_element($bar);
            } elseif (is_string($value) && isset($result[$value])) {
                $options = $this->_chartOptionsValues[$value];
                if (isset($options['chartType'])) {
                    $this->setChartType($options['chartType']);
                }
                $bar = new $this->_type();
                foreach ($options as $key => $prop) {
                    $bar->{$key}($prop);
                }
                $value = array_map(create_function('$item', ' return (float)$item; '), $result[$value]);
                $support = $value;
                sort($support);
                if (reset($support) < $min) {
                    $min = reset($support);
                }
                if (end($support) > $max) {
                    $max = end($support);
                }
                unset($support);
                $pie = array();
                if ($this->_type == 'OFC_Charts_Pie') {
                    foreach ($value as $key => $title) {
                        $pie[] = array('value' => $title, 'label' => $this->_xLabels[$key]);
                    }
                    $bar->set_values($pie);
                } else {
                    $bar->set_values($value);
                }
                $graph->add_element($bar);
            }
        }
        $max = $max * 1.05;
        $y = new OFC_Elements_Axis_Y();
        $y->set_range($min, $max, ceil($max / 4));
        $graph->add_y_axis($y);
        $final = $graph->toPrettyString();
        if (!is_string($this->_chartId)) {
            $this->_chartId = 'chart_' . rand(1, 10000);
        }
        $script = '
        swfobject.embedSWF(
        "' . $this->_filesLocation['flash'] . '", "' . $this->_chartId . '",
        "' . $this->_chartDimensions['x'] . '", "' . $this->_chartDimensions['y'] . '", "9.0.0", "expressInstall.swf",{"id":"' . $this->_chartId . '"},{"z-index":"1","wmode":"transparent"} );

        function open_flash_chart_data(id)
        {
            return JSON.stringify(window[id]);
        }

        function findSWF(movieName) {
          if (navigator.appName.indexOf("Microsoft")!= -1) {
            return window[movieName];
          } else {
            return document[movieName];
          }
        }
        var ' . $this->_chartId . ' = ' . $final . ';';
        $final = '<div id="' . $this->_chartId . '" >
        loading...
        <br/>
        <p>
        Please note that this content requires flash player 9.0.0</br>
        To test for your version of flash, <a href="http://www.bobbyvandersluis.com/swfobject/testsuite_2_1/test_api_getflashplayerversion.html" target="_blank">click here</a>
        </p>
        </div>';
        if (!$this->_multiple) {
            $final = '<div style="width: 100%;text-align: center">' . $final . '</div>';
        }
        $this->getView()->headScript()->appendFile($this->_filesLocation['js']);
        $this->getView()->headScript()->appendFile($this->_filesLocation['json']);
        $this->getView()->headScript()->appendScript($script);
        $this->_deploymentContent = $final;
        return $this;
    }
示例#9
0
 /**
  * Return data in JSON format
  *
  * @return string
  */
 public function renderPartData()
 {
     // clarify the values
     $page = $this->getParam('page');
     // get the requested page
     $limit = $this->getRecordsPerPage();
     // get how many rows we want to have into the grid
     $count = $this->_totalRecords;
     // decide if we should pass PK as ID to each row
     $passPk = false;
     if (isset($this->_bvbParams['id']) && count($this->_result) > 0) {
         $pkName = $this->_bvbParams['id'];
         if (isset($this->_result[0][$pkName])) {
             // only if that field exists
             $passPk = true;
         } else {
             $this->log("field '{$pkName}' defined as jqg>reader>id option does not exists in result set", Zend_Log::WARN);
         }
     }
     // build rows
     $data = new stdClass();
     $data->rows = array();
     foreach (parent::_buildGrid() as $i => $row) {
         $dataRow = new stdClass();
         // collect data for cells
         $d = array();
         foreach ($row as $key => $val) {
             $d[] = $val['value'];
         }
         if ($passPk) {
             // set PK to row
             // TODO works only if _buildGrid() results are in same order as $this->_result
             $dataRow->id = $this->_result[$i][$pkName];
         }
         $dataRow->cell = $d;
         $data->rows[] = $dataRow;
     }
     // set some other information
     if ($count > 0) {
         $totalPages = ceil($count / $limit);
     } else {
         $totalPages = 0;
     }
     $data->page = $page;
     $data->total = $totalPages;
     $data->records = $count;
     return Zend_Json::encode($data);
 }