Handles call like an openRosa compliant server. Implements the api as described on https://bitbucket.org/javarosa/javarosa/wiki/OpenRosaAPI

To implement, place the controller in the right directory and allow access without login to the following actions: formList - Lists the forms available submission - Handles receiving a submitted form download - Download a form

package Gems
subpackage Default
author Menno Dekker
copyright Copyright (c) 2014 Erasmus MC
license New BSD License
inherited_from \Gems_Controller_BrowseEditAction

 Methods

Hook to alter the formdata just before the form is populated

afterFormLoad(array $data, boolean $isNew) 
Inherited

Parameters

$data

array

$isNew

boolean

Hook to perform action after a record (with changes) was saved

afterSave(array $data, boolean $isNew) : boolean
Inherited

As the data was already saved, it can NOT be changed anymore

Parameters

$data

array

$isNew

boolean

Returns

booleanTrue when you want to display the default 'saved' messages

Get the afterSaveRoute and execute it

afterSaveRoute(mixed $data) : boolean
Inherited

Parameters

$data

mixed

data array or Zend Request

Returns

boolean

autofilterAction()

autofilterAction() 
Inherited

This can be used to generate barcodes, use the action

barcodeAction() 

/openrosa/barcode/code/

example: /openrosa/barocde/code/22pq-grkq

The image will be a png

Perform some actions on the form, right before it is displayed but already populated

beforeFormDisplay(\Zend_Form $form, boolean $isNew) : \Zend_Form
Inherited

Here we add the table display to the form.

Parameters

$form

\Zend_Form

$isNew

boolean

Returns

\Zend_Form

Hook to alter formdata before saving

beforeSave(array $data, boolean $isNew, \Zend_Form $form = null) : boolean
Inherited

Parameters

$data

array

The data that will be saved.

$isNew

boolean

$param \Zend_Form $form

$form

Returns

booleanReturns true if flow should continue

Creates a form for a new record

createAction() 
Inherited

Uses $this->getModel() $this->addFormElements()

Creates a form to delete a record

deleteAction() 
Inherited

Uses $this->getModel() $this->addFormElements()

This action should serve the right form to the downloading application it should also handle expiration / availability of forms

downloadAction() 

Creates a form to edit

editAction() 
Inherited

Uses $this->getModel() $this->addFormElements()

Outputs the model to excel, applying all filters and searches needed

excelAction() 
Inherited

When you want to change the output, there are two places to check:

  1. $this->addExcelColumns($model), where the model can be changed to have labels for columns you need exported

  2. $this->getExcelData($data, $model) where the supplied data and model are merged to get output (by default all fields from the model that have a label)

Accessible via formList as defined in the menu and standard for openRosa clients

formlistAction() 

Return an array with route options depending on de $data given.

getAfterSaveRoute(mixed $data) : mixed
Inherited

Parameters

$data

mixed

array or \Zend_Controller_Request_Abstract

Returns

mixedarray with route options or false when no redirect is found

Creates from the model a \MUtil_Html_TableElement that can display multiple items.

getBrowseTable(array $baseUrl = array(), $sort = null, $model = null) : \MUtil_Html_TableElement
Inherited

Overruled to add css classes for Gems

Parameters

$baseUrl

array

$sort

$model

Returns

\MUtil_Html_TableElement

getCachedRequestData()

getCachedRequestData(boolean $includeDefaults = true, string $sourceAction = null, boolean $readonly = false, boolean $filterEmpty = true) : array
Inherited

Parameters

$includeDefaults

boolean

Include the default values (yes for filtering, no for urls

$sourceAction

string

The action to get the cache from if not the current one.

$readonly

boolean

Optional, tell the cache not to store any new values

$filterEmpty

boolean

Optional, filter empty values from cache

Returns

array

Returns the default search values for this class instance.

getDefaultSearchData() : array
Inherited

Used to specify the filter when no values have been entered by the user.

Returns

array

Return the current request ID, if any.

getInstanceId() : mixed
Inherited

Overrule this function if the last item in the page title should be something other than te value of \MUtil_Model::REQUEST_ID.

Returns

mixed

Creates from the model a \Zend_Form using createForm and adds elements using addFormElements().

getModelForm(array $data, \optional $new = false) : \Zend_Form
Inherited

Parameters

$data

array

The data that will later be loaded into the form, can be changed

$new

\optional

boolean $new Form should be for a new element

Returns

\Zend_Form

Creates from the model a \MUtil_Html_TableElement for display of a single item.

getShowTable(integer $columns = 1, mixed $filter = null, mixed $sort = null) : \MUtil_Html_TableElement
Inherited

Overruled to add css classes for Gems

Parameters

$columns

integer

The number of columns to use for presentation

$filter

mixed

A valid filter for \MUtil_Model_ModelAbstract->load()

$sort

mixed

A valid sort for \MUtil_Model_ModelAbstract->load()

Returns

\MUtil_Html_TableElement

Returns the current html/head/title for this page.

getTitle(string $separator = null) : string
Inherited

If the title is an array the seperator concatenates the parts.

Parameters

$separator

string

Returns

string

getTopic()

getTopic($count = 1

Parameters

$count

Helper function to allow generalized statements about the items in the model.

getTopic(integer $count = 1) : \$string
Inherited

Parameters

$count

integer

Returns

\$string

getTopicTitle()

getTopicTitle() 

Helper function to allow generalized treatment of the header.

getTopicTitle() 
Inherited

return $string

imageAction()

imageAction() 

Generic model based import action

importAction() 
Inherited

indexAction()

indexAction() 
Inherited

init()

init() 

Intializes the html component.

initHtml(boolean $reset = false) : void
Inherited

Parameters

$reset

boolean

Throws away any existing html output when true

isConfirmedItem()

isConfirmedItem($title, $question = null, $info = null
Inherited

Parameters

$title

$question

$info

Performs actions when the form is submitted, but the submit button was not checked

onFakeSubmit(\Zend_Form $form, array $data) 
Inherited

When not rerouted, the form will be populated afterwards

Parameters

$form

\Zend_Form

The populated form

$data

array

The data-array we are working on

Implements HTTP Basic auth

preDispatch() 

scanresponsesAction()

scanresponsesAction() 

Shows a table displaying a single record from the model

showAction() 
Inherited

Uses: $this->getModel() $this->getShowTable();

Accepts the form

submissionAction() 

Takes two roundtrips:

  • first we get a HEAD request that should be answerd with responsecode 204
  • then we get a post that only submits $_FILES (so actual $_POST will be empty) this will be an xml file for the actuel response and optionally images and/or video proper responses are 201 received and stored 202 received ok, not stored

_applySearchParameters()

_applySearchParameters(\MUtil_Model_ModelAbstract $model, $useStored = false
Inherited

Parameters

$model

$useStored

Creates a \Zend_Form_Element_Select

_createSelectElement(string $name, string|array $options, string $empty = null) : \Zend_Form_Element_Select
Inherited

Parameters

$name

string

Name of the select element

$options

stringarray

Can be a SQL select string or key/value array of options

$empty

string

Text to display for the empty selector

Returns

\Zend_Form_Element_Select

_createTable()

_createTable() 
Inherited

Adds columns from the model to the bridge that creates the browse table.

addBrowseTableColumns(\MUtil_Model_Bridge_TableBridge $bridge, \MUtil_Model_ModelAbstract $model) : void
Inherited

Adds a button column to the model, if such a button exists in the model.

Parameters

$bridge

\MUtil_Model_Bridge_TableBridge

$model

\MUtil_Model_ModelAbstract

This is where you can modify the model for excel export

addExcelColumns(\MUtil_Model_ModelAbstract $model) 
Inherited

Only columns that have a label will be exported.

example: $model->set('columnname', 'label', $this->_('Excel label'));

Parameters

$model

\MUtil_Model_ModelAbstract

Set the action key in request

aliasAction(string $alias) 
Inherited

Use this when an action is a Ajax action for retrieving information for use within the screen of another action

Parameters

$alias

string

createForm()

createForm(mixed $options = array()) : \Gems_Form
Inherited

Parameters

$options

mixed

Returns

\Gems_Form

createModel()

createModel($detailed, $action) 

Parameters

$detailed

$action

findAllowedMenuItem()

findAllowedMenuItem($action) 
Inherited

Parameters

$action

Returns a text element for autosearch. Can be overruled.

getAutoSearchElements(\MUtil_Model_ModelAbstract $model, array $data) : array
Inherited

The form / html elements to search on. Elements can be grouped by inserting null's between them. That creates a distinct group of elements

Parameters

$model

\MUtil_Model_ModelAbstract

$data

array

The $form field values (can be usefull, but no need to set them)

Returns

arrayOf \Zend_Form_Element's or static tekst to add to the html or null for group breaks.

Creates an autosearch form for indexAction.

getAutoSearchForm(string $targetId) : \Gems_Form | null
Inherited

Parameters

$targetId

string

Returns

\Gems_Formnull

getAutoSearchHref()

getAutoSearchHref() 
Inherited

Creates a reset button for the search form

getAutoSearchReset() : \Zend_Form_Element_Submit
Inherited

Returns

\Zend_Form_Element_Submit

getAutoSearchSubmit()

getAutoSearchSubmit(\MUtil_Model_ModelAbstract $model, \MUtil_Form $form) 
Inherited

Parameters

$model

$form

Additional data filter statements for the user input.

getDataFilter(array $data) : array
Inherited

User input that has the same name as a model field is automatically used as a filter, but if the name is different processing is needed. That processing should happen here.

Parameters

$data

array

The current user input

Returns

arrayNew filter statements

Returns an array with all columns from the model that have a label

getExcelData(array $data, \MUtil_Model_ModelAbstract $model) : array
Inherited

Parameters

$data

array

$model

\MUtil_Model_ModelAbstract

Returns

array

Create an xml response

getXml(string $rootNode) : \SimpleXMLElement

Parameters

$rootNode

string

Returns

\SimpleXMLElement

Stub for overruling default snippet loader initiation.

loadSnippetLoader() 
Inherited

Each rosa response should have the x-openrosa-version header and disable the layout to allow for xml repsonses if needed. We don't need a menu etc. on the openrosa responses

makeRosaResponse() 

Handles a form, including population and saving to the model

processForm(string $saveLabel = null, array $data = null) : \Zend_Form | null
Inherited

Parameters

$saveLabel

string

A label describing the form

$data

array

An array of data to use, adding to the data from the post

Returns

\Zend_FormnullReturns a form to display or null when finished

Set the page title on top of a page, also store it in a public var

setPageTitle(string $title) 
Inherited

Parameters

$title

string

Title

Handles receiving and storing the data from a form, files are stored on actual upload process this only handles storing form data and can be used for resubmission too.

processReceivedForm($answerXmlFile) : string

Parameters

$answerXmlFile

Returns

stringResultID or false on failure

 Properties

 

$autoFilter

$autoFilter 

Default

true
 

$db

$db : \Zend_Db_Adapter_Abstract

Default

 

$filterStandard

$filterStandard 

Default

 

This holds the path to the location where the form definitions will be stored.

$formDir : string

Default

Will be set on init to: GEMS_ROOT_DIR . '/var/uploads/openrosa/forms/';

 

Should Excel output contain formatted data (date fields, select lists)

$formatExcelData : boolean

Default

true
 

$loader

$loader : \Gems_Loader

Default

 

$menu

$menu : \Gems_Menu

Default

 

$menuCreateIncludeLevel

$menuCreateIncludeLevel 

Default

0
 

$menuEditIncludeLevel

$menuEditIncludeLevel 

Default

10
 

$menuIndexIncludeLevel

$menuIndexIncludeLevel 

Default

4
 

$menuShowIncludeLevel

$menuShowIncludeLevel 

Default

2
 

The page title at the top of each page

$pageTitle : string

Default

 

$requestCache

$requestCache : \Gems_Util_RequestCache

Default

 

This holds the path to the location where the uploaded responses and their backups will be stored.

$responseDir : string

Default

Will be set on init to: GEMS_ROOT_DIR . '/var/uploads/openrosa/';

 

$sortKey

$sortKey 

Default

 

$summarizedActions

$summarizedActions 

Default

array('index', 'autofilter')
 

$tableSnippets

$tableSnippets 

Default

 

Use csrf token on form for protection against Cross Site Request Forgery

$useCsrf : boolean

Default

true
 

$useKeyboardSelector

$useKeyboardSelector 

Default

true
 

$useMultiRowForm

$useMultiRowForm 

Default

false
 

$usePreviousFilter

$usePreviousFilter 

Default

true
 

$useTabbedForms

$useTabbedForms 

Default

false
 

$util

$util : \Gems_Util

Default

 

$auth

$auth : \Zend_Auth

Default

 

This lists the actions that need http-auth. Only applies to the actions that the openRosa application needs.

$authActions : array

Default

array('formlist', 'submission', 'download')
 

Field id for crsf protection field.

$csrfId : string

Default

'no_csrfx'
 

The timeout for crsf, 300 is default

$csrfTimeout : integer

Default

300
 

The snippets used for the import action

$importSnippets : mixed

Default

'ModelImportSnippet'
 

The id to the last processed received form (gof_id)

$openrosaFormID : integer

Default

null

 Constants

 

RESET_PARAM

RESET_PARAM = 'reset' 
 

SEARCH_BUTTON

SEARCH_BUTTON = 'AUTO_SEARCH_TEXT_BUTTON'