Development

Changeset 3895

You must first sign up to be able to contribute.

Changeset 3895

Show
Ignore:
Timestamp:
05/02/07 15:36:27 (6 years ago)
Author:
promag
Message:

one XSL for each document type

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfOpenOfficePlugin/README

    r3892 r3895  
    11= sfOpenOffice Plugin = 
    2  
    3 [[PageOutline]] 
    42 
    53== Authors == 
     
    1917This is the ultimate solution for server side report generation! Stop searching and continue to read. Imagine making beatiful reports with dynamic data and charts, easy paging, custom images and more. Just use the !OpenOffice.org suite and add easy PHP code to turn the document dynamic. The integration with Symfony resembles typical templates. Therefore learning to use this plugin is so straightforward as coding Symfony templates. You also have the power to choose the output format such as PDF, Microsoft Word or Excel and much more. 
    2018 
    21 Check out the example on attachments. The !OpenOffice document report.odt resulted in report.pdf. The action executeReport only sets the variable $items. 
     19Check out the example on attachments. The !OpenOffice.org document report.odt resulted in report.pdf. The action executeReport only sets the variable $items. 
    2220 
    2321== Motivation == 
     
    2725== How it  works == 
    2826 
    29 At development time, instead of writing HTML/PHP templates you write !OpenOffice documents with PHP code. See tutorial to learn how to write PHP code in !OpenOffice documents. Then, in order to make the document a template, a new task needs to be executed. Much like propel-build-model, the new task ooffice-create-document will preprocess the !OpenOffice document to ease runtime document generation. 
     27At development time, instead of writing HTML/PHP templates you write !OpenOffice.org documents with PHP code. See tutorial to learn how to write PHP code in !OpenOffice.org documents. Then, in order to make the document a template, a new task needs to be executed. Much like propel-build-model, the new task ooffice-create-document will preprocess the !OpenOffice.org document to ease runtime document generation. 
    3028 
    31 !OpenOffice zips the document content, style and definitions into one file (for instance ODT). One of those files is content.xml which will have the document body (with our styled PHP code). So the new task will unzip it and transform all files inside with a XSLT so that all styled PHP code becomes markup PHP code (which can be evaluated). The task also creates a empty view class associated with the document action. This way the action won't result in a sfPHPView but in a sfOpenOfficeDocumentView. 
     29!OpenOffice.org zips the document content, style and definitions into one file (for instance ODT). One of those files is content.xml which will have the document body (with our styled PHP code). So the new task will unzip it and transform all files inside with a XSLT so that all styled PHP code becomes markup PHP code (which can be evaluated). The task also creates a empty view class associated with the document action. This way the action won't result in a sfPHPView but in a sfOpenOfficeDocumentView. 
    3230 
    33 At runtime all the work is done in the sfOpenOfficeDocumentView. It grabs all the variables defined in the action (much like sfPHPView) and executes all the files mentioned above. Then it zips the executed files (which is an !OpenOffice document with dynamic data) and ask !OpenOffice to do its magic, for instance, rendering the document to PDF. The result can be sent to client, server printer (for office intranets or online store orders), email or just saved. 
     31At runtime all the work is done in the sfOpenOfficeDocumentView. It grabs all the variables defined in the action (much like sfPHPView) and executes all the files mentioned above. Then it zips the executed files (which is an !OpenOffice.org document with dynamic data) and ask !OpenOffice.org to do its magic, for instance, rendering the document to PDF. The result can be sent to client, server printer (for office intranets or online store orders), email or just saved. 
    3432 
    3533== Requirements == 
    3634 
    37   * !OpenOffice 2.0.4 or superior 
     35  * !OpenOffice.org 2.0.4 or superior 
    3836  * Shell zip/unzip commands (configurable on app.yml) 
    39   * Xvfb to allow running !OpenOffice from PHP (I'm not a system administrator so I ask, if you have a better solution please email me) 
     37  * Xvfb to allow running !OpenOffice.org from PHP (I'm not a system administrator so I ask, if you have a better solution please email me) 
    4038 
    4139== Setup == 
     40 
     41First of all take a look to plugins/sfOpenOfficePlugin/config/ooffice-*-env.* scripts. If those settings doesn't match your system then copy the corresponding file to the project config folder and change the necessary settings. 
     42 
     43This plugin is shipped with a module to setup and test the !OpenOffice.org. This module gives you detailed instructions step by step. So , in order to use it you must enable it on settings.yml: 
    4244 
    4345  {{{ 
     
    7274=== Linux === 
    7375 
    74 In order to setup correctly !OpenOffice, you need to activate the license. We suggest that you run OpenOffice in X with the user apache. 
     76In order to setup correctly !OpenOffice.org, you need to activate the license. We suggest that you run OpenOffice in X with the user apache. 
    7577 
    7678Change to the apache user (here apache): 
     
    9092}}} 
    9193 
    92 Then, just run !OpenOffice in display 9 
     94Then, just run !OpenOffice.org in display 9 
    9395{{{ 
    9496$PATH_TO_OOFICE_BIN_DIR/soffice -display :9 
     
    115117== Tutorial == 
    116118 
    117 So you have an !OpenOffice document and you want to make it dynamic. First of all let's assume we are working in the application app and in the module mod. The document we created is report.odt. Now create the documents directory under the module directory: 
     119So you have an !OpenOffice.org document and you want to make it dynamic. First of all let's assume we are working in the application app and in the module mod. The document we created is report.odt. Now create the documents directory under the module directory: 
    118120 
    119121{{{ 
     
    146148If the actions returns other value than sfView::SUCCESS then it won't generate the document. It will fall back to the regular template. For instance, if the return value is sfView::ERROR then it will result in the template reportError.php. 
    147149 
    148 Now we are ready to go. If you try http://servername/app_dev.php/mod/report it should open the PDF document. PDF is the default format but you can change to any format supported by !OpenOffice in the view class (explained later). 
     150Now we are ready to go. If you try http://servername/app_dev.php/mod/report it should open the PDF document. PDF is the default format but you can change to any format supported by !OpenOffice.org in the view class (explained later). 
    149151 
    150152== Issues == 
    151153 
    152 For each document generation the !OpenOffice is executed by the apache user in a virtual X. The overhead of this schema is the !OpenOffice startup, which takes few seconds. We tested other schema where the the virtual X is static and there is one instance of !OpenOffice running. The tests showed great performance improvement. So its a matter of time to get this schema easy to configure. Remember that this is not a Symfony issue but a administration issue. Fell free to drop here suggestions. 
     154For each document generation the !OpenOffice.org is executed by the apache user in a virtual X. The overhead of this schema is the !OpenOffice.org startup, which takes few seconds. We tested other schema where the the virtual X is static and there is one instance of !OpenOffice.org running. The tests showed great performance improvement. So its a matter of time to get this schema easy to configure. Remember that this is not a Symfony issue but a administration issue. Fell free to drop here suggestions. 
    153155 
    154156== Future == 
  • plugins/sfOpenOfficePlugin/config/config.php

    r3891 r3895  
    11<?php 
    22   
    3   $os = substr(strtolower(PHP_OS), 0, 3); 
     3  $phpos = substr(strtolower(PHP_OS), 0, 3); 
    44   
    5   if( $os == 'win') 
     5  if( $phpos == 'win') 
    66  { 
     7    $os = 'win'; 
    78    $ext = 'bat'; 
    89  } 
    9   elseif( $os == 'lin' ) 
     10  elseif( $phpos == 'lin' ) 
    1011  { 
    1112    $os  = 'unix'; 
  • plugins/sfOpenOfficePlugin/config/ooffice-unix-env.sh

    r3891 r3895  
    44 
    55export LANG=pt_PT.UTF-8 
    6 export HOME=/var/www/openoffice #must be writable to the root process 
    7 export TEMP=/var/www/openoffice #must be writable to the root process 
     6export HOME=/var/www/openoffice 
     7export TEMP=/tmp 
    88export LC_ALL=C 
    99 
  • plugins/sfOpenOfficePlugin/data/tasks/sfPakeOpenOffice.php

    r3891 r3895  
    9494 
    9595  $transformation = realpath(dirname(__FILE__).DIRECTORY_SEPARATOR.'..') . DIRECTORY_SEPARATOR . 'transformations' 
    96                                                                          . DIRECTORY_SEPARATOR . 'ooffice2php.xsl'
     96                                                                         . DIRECTORY_SEPARATOR . "$extension.xsl"
    9797 
    9898  $xslt->importStyleSheet( DomDocument::load($transformation) ); 
  • plugins/sfOpenOfficePlugin/data/transformations/odt.xsl

    r3894 r3895  
    5656 
    5757 
    58  
    59  
    60  
    61  
    62 <!-- Charts will fetch data from the cells defined in the action variable with the same name as the object name --> 
    63 <!-- for now that action variable should be something like Sheet1.D9:Sheet1.D9 --> 
    64 <xsl:template match="draw:frame[@draw:name]/draw:object" disable-output-escaping="yes"> 
    65   <xsl:copy> 
    66     <xsl:attribute name="draw:notify-on-update-of-ranges">&lt;?php echo $<xsl:value-of select="../@draw:name" disable-output-escaping="yes"/> ?&gt;</xsl:attribute> 
    67     <xsl:apply-templates select="@*[not(name()='draw:notify-on-update-of-ranges')]" /> 
    68   </xsl:copy> 
    69 </xsl:template> 
    70  
    71  
    72 <xsl:template name="code"> 
    73   <xsl:param name="node" /> 
    74   <xsl:if test="starts-with($node, '&lt;?php') and substring($node, string-length($node)-1, 2)='?&gt;'"> 
    75     &lt;?php <xsl:value-of select="substring($node, 6, string-length($node)-7)" disable-output-escaping="yes"/> ?&gt; 
    76   </xsl:if> 
    77 </xsl:template> 
    78  
    7958</xsl:stylesheet>