Jump to content

AtkDocumentWriter

From NusaATK
Revision as of 07:22, 29 September 2006 by bahtiar (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

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).