Adding Composers

Add Composer Form

In order to add composers we need a form to collect the data. A simple Paloose form together with a suitable flow script is needed. The initial form is encoded in a file:

/examples/sql/addComposer-1.xml
<?xml version="1.0" encoding="UTF-8"?> <page:page xmlns:t="http://www.hsfr.org.uk/Schema/Text" xmlns:page="http://www.hsfr.org.uk/Schema/Page" xmlns:list="http://www.hsfr.org.uk/Schema/List" xmlns:link="http://www.hsfr.org.uk/Schema/Link" xmlns:pf="http://www.paloose.org/schemas/Forms/1.0"> <page:meta> <page:title>Paloose &#x2014; SQL Example</page:title> <page:copyright>Copyright 2006 &#x2013; 2010 Hugh Field-Richards. All Rights Reserved.</page:copyright> </page:meta> <page:content> <t:heading level="1">SQL Add Composer</t:heading> <pf:form id="addComposerForm" flow="addComposer" continuation="{flow:continuation.id}" session="{flow:__flowId}"> <pf:label>Enter composer's details:</pf:label> <pf:input ref="name" class="nameField"> <pf:label>Composer name</pf:label> <pf:value>{flow:name}</pf:value> <pf:hint>The composer's surname</pf:hint> <pf:violations/> </pf:input> <pf:input ref="firstNames" class="firstNamesField"> <pf:label>First names</pf:label> <pf:value>{flow:firstNames}</pf:value> <pf:hint>The composer's first names</pf:hint> <pf:violations/> </pf:input> <pf:input ref="birth" class="birthField"> <pf:label>Birth date</pf:label> <pf:value>{flow:birth}</pf:value> <pf:hint>The composer's birth date (yyyy-mm-dd)</pf:hint> <pf:violations/> </pf:input> <pf:input ref="death" class="deathField"> <pf:label>Death date</pf:label> <pf:value>{flow:death}</pf:value> <pf:hint>The composer's death date (yyyy-mm-dd)</pf:hint> <pf:violations/> </pf:input> <pf:submit class="button" id="next"> <pf:label>Next</pf:label> <pf:hint>Check details</pf:hint> </pf:submit> </pf:form> <t:p><link:link type="uri" ref="/examples/sql/sql.html">Return to SQL index</link:link></t:p> <t:p><link:link type="uri" ref="/examples/sql/logout.html">Logout</link:link> from admin pages.</t:p> </page:content> </page:page>

The Flow Script

There must be an associated flow script to support this form:

resources/scripts/AddComposer.php
<?php require_once( PHP_DIR . "/flows/Continuations.php" ); // -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* --> class AddComposer extends Continuations { /** Logger instance for this class */ private $gLogger; private $gAddComposerModel = array ( "name" => "", "firstNames" => "", "birth" => "", "death" => "", ); // -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* --> // -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* --> /** * Make a new instance of the continuation. * * @throws RunException if there is no current session in progress. */ function __construct() { $this->gLogger = Logger::getLogger( __CLASS__ ); parent::__construct( $this->gAddComposerModel ); } // -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* --> // -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* --> function add() { global $gModules; $this->gLogger->debug( "Adding entry, continuation: " . $this->gContinuation ); $requestParameterModule = $gModules[ 'request-param' ]; $this->gViolations = array(); $finished = false; while ( !$finished ) { $errors = false; switch ( $this->gContinuation ) { case 0 : $this->sendPage( "addComposer-1.html", // The page to send to the client $this->gAddComposerModel, // The current data model to send ++$this->gContinuation, // The continuation link for the next stage $this->gViolations ); // Array of errors (keyed by data model keys) $finished = true; break; // Further cases } // switch } // while } // AddComposer::add } // AddComposer ?>

Extending the Sitemap

The sitemap must declare the script:

/examples/sql/sitemap.xmap
<map:flow language="php"> <map:script src="context://resources/scripts/AddComposer.php"/> </map:flow>

The sitemap add composer pipeline is in two parts: an external accessed one and an internal one:

/examples/sql/sitemap.xmap
<map:pipeline> <map:match pattern="addComposer.html"> <map:call function="AddComposer::add"/> </map:match> <map:match pattern="addComposer.kont"> <map:call function="AddComposer::add"/> </map:match> </map:pipeline> <!-- Only called from the add user script AddComposer::add --> <map:pipeline internal-only="true"> <map:match pattern="addComposer-*.html"> <map:aggregate element="root" label="aggr-content"> <map:part src="cocoon:/menus.xml" element="menus" strip-root="true"/> <map:part src="cocoon:/addComposer-{1}.px" element="content" strip-root="true"/> </map:aggregate> <map:transform src="resource://resources/transforms/pforms-violations.xsl" label="pforms-violations"> <map:parameter name="formViolations" value="{session:__violations}"/> </map:transform> <map:transform src="resource://resources/transforms/pforms-default.xsl" label="pforms-default"/> <map:transform src="resource://resources/transforms/pforms2html.xsl" label="pforms-html"/> <map:call resource="outputPage"/> </map:match> <map:match pattern="menus.xml"> <map:generate src="cocoon:/../menus.xml" label="menus-content"/> <map:serialize/> </map:match> <map:match pattern="*.xml"> <map:generate src="cocoon:/{1}.xml" label="xml-content"/> <map:serialize/> </map:match> <map:match pattern="*.px"> <map:generate type="px" src="cocoon:/{1}.xml" label="px-content"/> <map:serialize/> </map:match> </map:pipeline>

The important thing here is that the PXTemplateGenerator must be used for the flow pages.

Using the link "Create Composer" (http://<host>/examples/sql/addComposer.html) the form for entering a new composer is presented:

The next section shows the effect of entry errors and then the confirmation form.

Copyright 2006 — 2010 Hugh Field-Richards. All Rights Reserved.