Jump to content

AtkDocumentWriter

From NusaATK
Revision as of 16:24, 30 November 2006 by Guido (talk | contribs)

Description

The atkDocumentWriter is the general DocumentWriter framework class. It Should be extended to support specific file formats.

Params

The constructor of the atkDocumentWriter is not directly called. &atkDocumentWriter::getInstance($format) must be used to get a singleton instance for any format used.

Examples

Template

The basic idea is that tags in a template-document are replaced by specified values. For now, the only document type supported is Open Office.

A simple template will look like this:

Dear [name],
Thank you for testing this template.
Greetings,
[sender]

This is just a regular Open Office .odt document.


In your code, $tplvars is an array which contains 'tags' and 'values'.

$tplvars["name"] = "Jeroen";
$tplvars["sender"] = "Santa";

In the generated document, the tags are replaced:

Dear Jeroen,
Thank you for testing this template.
Greetings,
Santa

Available codes

If you want to know which codes are available in a document, you can use the [taglist] tag in a template document. When using the documentwriter on this template, the resulting document will contain a list of all available tags (including loops which can be used in tables).

Code

Use the atkDocumentWriter in an action for example. When a button is pressed, a document will be generated:

$template_filename = "template.odt";           
$template_file = &$handler->getFilenameForTemplate($template_filename);

The location of the template can be configured in config.inc.php: $config_doctemplatedir = "doctemplates/";

atkimport("atk.document.atkdocumentwriter");
$dw = &atkDocumentWriter::getInstance("opendocument");
$dw->display($template_file, "output.odt", $tplvars);

A 'Save as..' dialog will popup in your browser to save the document (or it will be displayed inline, when configured in the browser).