Apr 29, 2024 11:59:41 AM avatar

The Workflow-FormsToPDF module

I) Introduction

The Workflow-FormsToPDF module is used for exporting responses to the Forms plugin questionnaire in a template (or model) created by the user. Responses can be exported individually in the response viewing tab.

II) Use

1. Creating an export with the formstopdf workflow

You have created a form with at least one question and you have verified that your user has the necessary rights to use workflows.

a. Create a new workflow

In the menu select: system > workflow management

menu

Click on create a workflow.

create_workflow

b. Create one or two steps

If only one step is created, it will be possible to export the same response several times. If two are created, a response will be exportable only once.

create_state

c. Create an action associated with your step

Click on "Add an action".

create_action

In the modify action page, select the task "Export a form to a pdf edition", click on the "plus" icon to add.

Click on modify the workflow.

modify_workflow

d. Create a new Template

In modify the workflow then in modify the task, click on "Manage templates".

modify_task

Click on "Add a template".

new_template

Give a name to the new template and associate the template with a form then save.

associate_template

Click to modify the newly created template. The questions and other elements associated with the form (Bookmark) are now displayed in the section to the right of the page. Click on one of the Bookmarks to copy it and paste it into the template being created. The Bookmark will be replaced by the corresponding data when generating the PDF.

booksmarks

Save the template.

e. Associate the new template with the form

Save the template with the associated form:

associate_form_template

f. Activate the workflow

In the menu select: system > workflow management Activate the workflow.

activate_workflow

g. Associate the Workflow with the form

On the form modification page, associate the workflow with the form

associate_form_workflow

h. Export a response in PDF format

It is now possible to export the form responses according to the Template that was created. Go to the response viewing page and click on a response.

view_responses

Click on the action that was named earlier.

export_responses

i. Download the PDF

In System > My file requests Click on download

download_pdf

III) Customize the display of question types (entrytype)

The Form plugin offers different types of questions: date, text, image, file etc. To adapt the display of responses according to their type (Entrytype), the module-workflow-formstopdf uses Freemarker macros (wiki macro links). In the source code of the module, there is a macro whose role is to call the macro that corresponds to the Entrytype of the question. This macro is located here: lutece-wf-module-workflow-formstopdf/webapp/WEB-INF/templates/admin/plugins/workflow/modules/formspdf/display_entries/displayEntry.ftl

<#macro displayEntry q>
    <#if q??>
        <#assign entry=q.question.entry >
        <#assign list_responses=q.getEntryResponse() >

        <#if entry.entryType.beanName == "forms.entryTypeArray">
            <@displayEntryTypeArray entry=entry list_responses=list_responses  />
        <#elseif entry.entryType.beanName == "forms.entryTypeAutomaticFileReading">
            <@displayEntryTypeAutoFileReading entry=entry list_responses=list_responses  />
        <#elseif entry.entryType.beanName == "forms.entryTypeCamera">
            <@displayEntryTypeCamera entry=entry list_responses=list_responses  />
        <#elseif entry.entryType.beanName == "forms.entryTypeCartography">
            <@displayEntryTypeCartography entry=entry list_responses=list_responses  />
        <#elseif entry.entryType.beanName == "forms.entryTypeCheckbox">
            <@displayEntryTypeCheckbox entry=entry list_responses=list_responses  />
        <#elseif entry.entryType.beanName == "forms.entryTypeComment">
            <@displayEntryTypeComment entry=entry list_responses=list_responses  />
        <#elseif entry.entryType.beanName == "forms.entryTypeDate">
            <@displayEntryTypeDate entry=entry list_responses=list_responses  />
        <#elseif entry.entryType.beanName == "forms.entryTypeFile">
            <@displayEntryTypeFile entry=entry list_responses=list_responses  />
        <#elseif entry.entryType.beanName == "forms.entryTypeGalleryImage">
            <@displayEntryTypeGalleryImage entry=entry list_responses=list_responses  />
        <#elseif entry.entryType.beanName == "forms.entryTypeGeolocation">
            <@displayEntryTypeGeolocation entry=entry list_responses=list_responses  />
        <#elseif entry.entryType.beanName == "forms.entryTypeImage">
            <@displayEntryTypeImage entry=entry list_responses=list_responses  />
        <#elseif entry.entryType.beanName == "forms.entryTypeMyLuteceUser">
            <@displayEntryTypeMyLuteceUser entry=entry list_responses=list_responses  />
        <#elseif entry.entryType.beanName == "forms.entryTypeNumber">
            <@displayEntryTypeNumber entry=entry list_responses=list_responses  />
        <#elseif entry.entryType.beanName == "forms.entryTypeNumbering">
            <@displayEntryTypeNumbering entry=entry list_responses=list_responses  />
        <#elseif entry.entryType.beanName == "forms.entryTypeRadioButton">
            <@displayEntryTypeRadioButton entry=entry list_responses=list_responses  />
        <#elseif entry.entryType.beanName == "forms.entryTypeSelect">
 <#elseif entry.entryType.beanName == "forms.entryTypeSelect">
            <@displayEntryTypeSelect entry=entry list_responses=list_responses  />
        <#elseif entry.entryType.beanName == "forms.entryTypeSelectOrder">
            <@displayEntryTypeSelectOrder entry=entry list_responses=list_responses  />
        <#elseif entry.entryType.beanName == "forms.entryTypeTelephoneNumber">
            <@displayEntryTypeTelephoneNumber entry=entry list_responses=list_responses  />
        <#elseif entry.entryType.beanName == "forms.entryTypeTermsOfService">
            <@displayEntryTypeTermsOfService entry=entry list_responses=list_responses  />
        <#elseif entry.entryType.beanName == "forms.entryTypeText">
            <@displayEntryTypeText entry=entry list_responses=list_responses  />
        <#elseif entry.entryType.beanName == "forms.entryTypeTextArea">
            <@displayEntryTypeTextArea entry=entry list_responses=list_responses  />
        <#else>
            <@displayEntryTypeText entry=entry list_responses=list_responses  />
        </#if>
    </#if>
</#macro>

This redirection macro takes a parameter q which corresponds to the value of the response contained in position_X To call it according to the chosen syntax:

<#@displayEntry q=position_7/>

or

[#@displayEntry q=position_7/]

The Bookmark of a question is actually a call to the redirection macro.

bookmarks_hooks

Configuration of Freemarker Macros Syntax

Freemarker tags are usually defined in a way similar to that of html with < and >. For example, to define a macro: <#macro maMacro arg1/>. And to call it: <@maMacro arg1= arg1/>.

This syntax is incompatible with the use of the RichTextEditor which reformats elements to prevent display bugs and XSS attacks. For example: <@maMacro arg1= arg1/> becomes <p><@maMacro arg1= arg1/></p>. To use the response Bookmarks (which are actually calls to macros) with the RTE, you need to modify the Freemarker syntax.

Adding [#ftl] at the very beginning of the template makes it possible to use Freemarker macros with a different syntax that is compatible with the RichTextEditor. To define a macro: [#macro macro maMacro arg1 /]. To call a macro: [@maMacro arg1= arg1/]. The module automatically adds and removes the [#ftl] header when modifying the option below.

with_rte

Without the RTE, it is possible to configure the display of a macro, because the RTE reformats the HTML. It is also easier to customize a macro without RTE with the <> syntax, because you can then copy and paste the existing display macros that you want to modify.

Example of customization

At the template editing stage, we have to select the without Rich Text editor option. You need to retrieve the macro of the Entrytype that you want to modify in the source code of the module-workflow-formstopdf. Here, we identify the macro: DisplayEntryTypeText. We copy/paste the content of the macro into the template form.

template_macro

You can now modify the macro to have the desired display.

customize_template

In this example, the color and style are customized.

As a result, we have the response whose style has been customized.

customized_res