Base class for the report and data entry helpers.
Provides several generally useful methods and also includes resource management.
package | Client |
---|
add_resource(string $resource)
This is normally called internally by the control methods to ensure the required files are linked into the page so does not need to be called directly. However it can be useful when writing custom code that uses one of these standard libraries such as jQuery. Ensures each file is only linked once.
string
Name of resource to link. The following options are available:
apply_template(string $template, array $options)
Outputs the prefix template, a label (if in the options), a control, the control's errors and a suffix template.
string
Name of the control template, from the global $indicia_templates variable.
array
Options array containing the control replacement values for the templates. Options can contain a setting for prefixTemplate or suffixTemplate to override the standard templates.
array_to_query_string(array $array, boolean $encodeValues) : string
This is like http_build_query but it does not url encode the & separator, and gives control over urlencoding the array values.
array
Associative array to convert.
boolean
Default false. Set to true to URL encode the values being added to the string.
string
The query string.build_params_form(array $options, boolean $hasVisibleContent)
Returns the HTML required for a parameters form, e.g. the form defined for input of report parameters or the default values for a csv import.
array
Options array with the following possibilities:
<
ul>
boolean
On completion, this is set to true if there are visible controls in the params form. If not, then it may be appropriate to skip the displaying of this params form since it is not necessary.
check_errors(string $fieldname, boolean $plaintext)
string
Fieldname of the control to retrieve errors for.
boolean
Set to true to return just the error text, otherwise it is wrapped in a span.
client_helper_path()
dump_header(\$resources $resources) : string
The advantage of dump_javascript is that it intelligently builds the required links depending on what is on your form. dump_header is not intelligent because the form is not built yet, but placing links in the header leads to cleaner code which validates better.
\$resources
List of resources to include in the header. The available options are described in the documentation for the add_resource method. The default for this is jquery_ui and defaultStylesheet.
string
Text to place in the head section of the html file.dump_javascript() : string
Should be called at the end of each HTML page which uses the data entry helper so output all JavaScript required by previous calls.
link | http://code.google.com/p/indicia/wiki/TutorialBuildingBasicPage#Build_a_data_entry_page |
---|
string
JavaScript to insert into the page for all the controls added to the page so far.enable_validation(string $form_id)
To specify validation on each control, set the control's options array to contain a 'validation' entry. This must be set to an array of validation rules in Indicia validation format. For example, 'validation' => array('required', 'email').
string
@form_id Id of the form the validation is being attached to.
explode_lines(string $value) : array
Tolerates any line ending.
string
A multi-line string to be split.
array
An array with one entry per line in $value.explode_lines_key_value_pairs(string $value) : array
Tolerates any line ending.
string
A multi-line string to be split.
array
An associative array with one entry per line in $value. Array keys are the items before the = on each line,
and values are the data after the = on each line.getRootFolder()
get_auth(string $website_id, string $password)
string
Indicia ID for the website.
string
Indicia password for the website.
get_read_auth(string $website_id, string $password)
string
Indicia ID for the website.
string
Indicia password for the website.
get_read_write_auth(string $website_id, string $password) : \Returns
string
Indicia ID for the website.
string
Indicia password for the website.
\Returns
an array containing:
'read' => the read authorisation array,
'write' => the write authorisation input controls to insert into your form.
'write_tokens' => the write authorisation array, if needed as separate tokens rather than just placing in form.get_reload_link_parts() : array
array
Associative array containing path and params (itself a key/value paired associative array).get_resources()
get_scripts(string $javascript, string $late_javascript, string $onload_javascript, bool $includeWrapper)
Can optionally include the script tags wrapper around the script generated.
string
JavaScript to run when the page is ready, i.e. in $(document).ready.
string
JavaScript to run at the end of $(document).ready.
string
JavaScript to run in the window.onLoad handler which comes later in the page load process.
bool
If true then includes script tags around the script.
get_termlist_terms(array $auth, mixed $termlist, array $filter) : array
array
Read authorisation array.
mixed
Either the id or external_key of the termlist to load.
array
List of the terms that are required, or null for all terms.
array
Output of the Warehouse data services request for the terms.get_uploaded_image_folder()
http_post(string $url, string $postargs, boolean $output_errors) : array
string
The URL the POST request is sent to.
string
Arguments to include in the POST data.
boolean
Set to false to prevent echoing of errors. Defaults to true.
array
An array with a result element set to true or false for successful or failed posts respectively.
The output is returned in an output element in the array. If there is an error, then an errorno element gives the
cUrl error number (as generated by the cUrl library used for the post).link_default_stylesheet()
This gives a basic form layout. This also adds default JavaScript to the page to cause buttons to highlight when you hover the mouse over them.
mergeParamsIntoTemplate(array $params, string $template, boolean $useTemplateAsIs, boolean $allowHtml, boolean $allowEscapeQuotes) : string
This is used to build the output for each item in a list, such as a species checklist grid or a radio group.
array
Array holding the parameters to merge into the template.
string
Name of the template to use, or actual template text if $useTemplateAsIs is set to true.
boolean
If true then the template parameter contains the actual template text, otherwise it is the name of a template in the $indicia_templates array. Default false.
boolean
If true then HTML is emitted as is from the parameter values inserted into the template, otherwise they are escaped.
boolean
If true then parameter names can be suffixes -esape-quote, -escape-dblquote, -escape-htmlquote or -escape-htmldblquote to insert backslashes or html entities into the replacements for string escaping.
string
HTML for the item labelrelative_client_helper_path()
setup_jquery_validation_js()
This JavaScript must be added at the end of form preparation otherwise we would not know all the control messages. It will normally be called by dump_javascript automatically, but is exposed here as a public method since the iform Drupal module does not call dump_javascript, but is responsible for adding JavaScript to the page via drupal_add_js.
_cacheResponse(string $file, array $response, array $options)
string
Cache file to be removed, includes path - will be false if no caching to take place
array
http_post return value
array
Options array : contents used to tag what this data is.
_getCacheFileName(string $path, array $options, \number $timeout) : string
string
directory path for file
array
Options array : contents are used along with md5 to generate the filename.
\number
string
filename, else FALSE if data is not to be cached._getCacheTimeOut(array $options) : \Timeout
array
Options array with the following possibilities:
\Timeout
in number of seconds, else FALSE if data is not to be cached._getCachedResponse(string $file, \number $timeout, array $options) : array
string
Cache file to be used, includes path
\number
array
Options array : contents used to confirm what this data is.
array
equivalent of call to http_post, else FALSE if data is not to be cached._timeOutCacheFile(string $file, \number $timeout)
string
Cache file to be removed, includes path
\number
apply_replacements_to_template(string $template, string $options)
<
div id="{id}">) and replaces the tokens with the equivalent values looked up from the $options array.
string
The templatable string.
string
The array of items which can be merged into the template.
apply_static_template(string $name, array $options) : string
string
The static template type. e.g. prefix or suffix.
array
Array of options which may contain a template name.
string
Template value.build_validation_class(\$options. $options) : string
\$options.
Control options array. For validation to be applied should contain a validation entry, containing a single validation string or an array of strings.
string
The validation rules formatted as a class.get_help_text(array $options, string $pos) : string
array
Control's options array. Can specify the class for the help text item using option helpTextClass.
string
Either before or after. Defines the position that is being requested.
string
Templated help text, or nothing.internal_dump_resources(array $resources)
access | private |
---|
array
List of resources to include.
jq_esc(string $name) : string
string
The string to be escaped.
string
escaped name.send_file_to_warehouse(string $path, boolean $persist_auth, array $readAuth, string $service) : string
string
Path to the file to upload, relative to the interim image path folder (normally the client_helpers/upload folder.
boolean
Allows the write nonce to be preserved after sending the file, useful when several files are being uploaded.
array
readAuth Read authorisation tokens, if not supplied then the $_POST array should contain them.
string
Path to the service URL used. Default is data/handle_media, but could be import/upload_csv.
string
Error message, or true if successful.apply_error_template(string $error, string $fieldname)
string
The error message.
string
The name of the field which the error is being attached to.
get_params_form_control(string $key, array $info, array $options, array $tools) : string
string
The unique identifier of this control.
array
Configuration options for the parameter as defined in the report, including the description, display (label), default and datatype.
array
Control options array
array
Any tools to be embedded in the map toolbar are returned in this parameter rather than as the return result of the function.
string
The HTML for the form parameter.get_preset_param(array $options, string $name)
Returns empty string if not defined.
array
The options array, containing a presetParams entry that the parameter should be found in.
string
The key identifying the preset parameter to look for.
$cache_allowed_file_count : integer
$cache_chance_purge : integer
$cache_chance_refresh_file : integer
$cache_timeout : integer
$css_path : string
$default_validation_rules : Array
todo | This array could be auto-populated with validation rules for a survey's fields from the Warehouse. |
---|
$dumped_resources : array
$form_mode : string
$helpTextPos : string
$images_path : string
$is_ajax : boolean
$javascript : string
$js_path : string
$late_javascript : string
$nocache : boolean
$onload_javascript : string
$required_resources : Array
$resource_list : Array
$validated_form_id : array
$validation_errors : array
$validation_mode : array
Options are message, message, hint, icon, colour, inline. The inline option specifies that the message should appear on the same line as the control. Otherwise it goes on the next line, indented by the label width. Because in many cases, controls on an Indicia form occupy the full available width, it is often more appropriate to place error messages on the next line so this is the default behaviour.
$warehouse_proxy : string
$default_styles : Boolean
$displayed_errors : array
$html_attributes
When replacing items in a template, these get automatically wrapped. E.g. a template replacement for the class will be converted to class="value". The key is the parameter name, and the value is the html attribute it will be wrapped into.
$using_locking : Boolean
$website_id : integer