';
$retObj->html = $grp;
return $retObj;
}
}
/**
* display a star rating (jquery plugin)
* RATY (http://wbotelhos.com/raty)
* Make sure you include the jquery and raty js files.
* Note that the big png files are stored in js/img path
*/
Form::macro ( 'star', function ($name, $value = '') {
$markup = '
';
$markup .= '' . errorMessage ( $name );
// scoreName does not help with storing data between submits.. so use another hidden
$markup .= Form::hidden ( $name, $value, array (
'id' => "$name-field"
) );
$markup .= "
";
$markup .= "";
return $markup;
} );
/**
* render a linear scale using radio buttons
* the data array must contain the following keys
* leftAnchor : text to be displayed on left
* rightAnchor: text to be displayed on right
* count : the number of radio buttons to be displayed
* name : the name of the control
* The default order is descending.. passing in 'asc' as the second parameter
* displays radios in ascending order
*/
Form::macro ( 'radioScale', function ($data, $value = 0, $order = 'desc') {
$leftAnchor = $data ['leftAnchor'];
$rightAnchor = $data ['rightAnchor'];
$count = $data ['count'];
$name = $data ['name'];
// generate the scale class='.fieldError($name).
$str = '
' . errorMessage ( $name );
return $str;
} );
/**
* Displays a slider using Jquery ui
* http://jqueryui.com/slider/
* the data array must contain the following keys
* leftAnchor : text to be displayed on left
* rightAnchor: text to be displayed on right
* min : minimum value of slider
* max: maximum value of slider
* name : the name of the control
*/
Form::macro ( 'slider', function ($data, $value = '') {
$leftAnchor = $data ['leftAnchor'];
$rightAnchor = $data ['rightAnchor'];
$min = $data ['min'];
$max = $data ['max'];
$name = $data ['name'];
$sliderid = $name . '-slider';
// generate the slider
$str = '
' . errorMessage ( $name );
$str .= "";
return $str;
} );
/**
* Return the html to render an individual radio control
*
* @param string $name
* - name of the radio
* @param string $displayName
* - display name of the radio
* @param string $value
* - value of control if selected
* @param string $checked
* - is the radio selected?
* @param array $attributes
* - other attributes (class, id etc)
* @return string - The html rendering of the radio control
*/
if (! function_exists ( 'radio' )) {
function radio($name, $displayName, $value, $checked = null, $attributes = array()) {
$out = '';
$attributes = array_merge ( array (
'id' => 'id-field-' . $name.'-'.$displayName
), $attributes );
$out .= '';
return $out;
}
}
/**
* Return the html to render an individual checkbox control
*
* @param string $name
* - Name of the checkbox
* @param string $displayName
* - Display name of the checkbox
* @param string $value
* - Value if control is checked
* @param string $checked
* - Is the checkbox checked by default
* @param array $attributes
* - other attributes (class, id etc)
* @return string - html rendering of the checkbox control. Note that
* it includes a hidden field. This simplifies form processing when checkbox is unchecked
*/
if (! function_exists ( 'checkBox' )) {
function checkBox($name, $displayName, $value = 1, $checked = null, $attributes = array()) {
$out = '';
$attributes = array_merge ( array (
'id' => 'id-field-' . $name
), $attributes );
$out .= '';
return $out;
}
}
/**
* Wrap an element with twitter bootstrap 3.0 specific code for proper rendering
*
* @param string $field
* - field name
* @param string $element
* - html rendering of internal form element to be output
* @param string $label
* - label that is displayed to the left
* @return string - formatted html with all divs etc for final display on screen
*/
if (! function_exists ( 'fieldWrapper' )) {
function fieldWrapper($field, $element, $label = null) {
$out = '
'; // set error class
$out .= fieldLabel ( $field, $label ); // gen label
$out .= '
';
return $out;
}
}
/**
* return formatted error message associated with a field
*
* @param string $field
* - name of the field to be checked for errors
* @return string - TBS 3.0 formatted span tag that is to be displayed alongside the field
*/
if (! function_exists ( 'errorMessage' )) {
function errorMessage($field) {
if ($errors = Session::get ( 'errors' )) {
return '' . $errors->first ( $field ) . '';
}
}
}
/**
* Return string 'has-error' that can be tagged to element div to signal erroneous entry
*
* @param string $field
* - the field name
* @return string - 'has-error' in case the field has a validation error
*/
if (! function_exists ( 'fieldError' )) {
function fieldError($field) {
$error = '';
if ($errors = Session::get ( 'errors' )) {
$error = $errors->first ( $field ) ? ' has-error' : '';
}
return $error;
}
}
/**
* html required for displaying the field label.
* In case an explicit label is not passed,
* generate one
*
* @param unknown $name
* - field name
* @param unknown $label
* - label to be used
* @return string - html for the label (TBS 3.0 formatted)
*/
if (! function_exists ( 'fieldLabel' )) {
function fieldLabel($name, $label) {
$out = '';
return $out;
}
}
/**
* helper function to add required classes (TBS 3.0) for "text input" fields
*
* @param string $name
* - field name
* @param array $attributes
* - control attribs passed by user
* @return array - attributes array merged with TBS specific classes
*/
if (! function_exists ( 'fieldAttributes' )) {
function fieldAttributes($name, $attributes = array()) {
return array_merge ( array (
'class' => 'form-control',
'id' => 'id-field-' . $name
), $attributes );
}
}
/**
* **************************************************************
* HTML MACROS
* **************************************************************
*/
/**
* Display a progressbar using jquery ui
* http://jqueryui.com/progressbar/
* $current is the current step of the slider
* $total is the total number of steps
*/
HTML::macro ( 'progress', function ($current, $total) {
$pctValue = number_format ( $current / $total * 100, 0 );
$str = '';
$str .= '
' . $pctValue . '% Complete
';
$str .= '';
return $str;
} );
/**
* Generate content required to display swf videos on page
* http://code.google.com/p/swfobject/
* It is assumed that an swf encoded file named $name is in public subdir swf/
*/
HTML::macro ( 'swfobject', function ($name) {
$swfPath = URL::to("/swf/$name");
$expressInstallPath = URL::to( "js/expressInstall.swf");
$version = "9.0.0";
$headScript = <<
var flashvars = {};
var params = {};
params.play = "true";
params.loop = "true";
params.allowfullscreen = "true";
var attributes = {};
swfobject.embedSWF("$swfPath", "myAlternativeContent", "640",
"480", "$version", "$expressInstallPath",
flashvars, params, attributes);