public/wordpress/wp-content/plugins/wp-courseware/includes/legacy/builder/easyform.php
/**
		 * Convert an array of details into a form element.
		 *
		 * @param String $fieldName The name of the form element
		 * @param Array $fieldDetails The list of details for the form element.
		 */
Convert an array of details into a form element.
@param String $fieldName The name of the form element
@param Array $fieldDetails The list of details for the form element.
Convert an array of details into a form element . @param String $fieldName The name of the form element @param Array $fieldDetails The list of details for the form element .
protected function createElementObject( $fieldName, $fieldDetails ) {
			$label = $this->formObj->getArrayValue( $fieldDetails, 'label' );
			$type  = $this->formObj->getArrayValue( $fieldDetails, 'type' );
			$required = $this->formObj->getArrayValue( $fieldDetails, 'required' );
			$required = ( $required == 'true' || $required == '1' );
			$labelPosition = $this->formObj->getArrayValue( $fieldDetails, 'labelposition' );
			$labelPosition = ( $labelPosition ) ? $labelPosition : 'left';
			$elem = false;
			if ( $type != 'break' ) {
				$elem = new FormElement( $fieldName, $label, $required, $labelPosition );
			}
			switch ( $type ) {
				case 'textarea':
					$rows = absint( $this->formObj->getArrayValue( $fieldDetails, 'rows' ) );
					if ( $rows == 0 ) {
						$rows = 5;
					}
					$elem->setTypeAsTextArea( $rows, 70 );
					break;
				case 'select':
					$options = false;
					if ( isset( $fieldDetails['data'] ) && is_array( $fieldDetails['data'] ) ) {
						$options = $fieldDetails['data'];
					}
					$elem->setTypeAsComboBox( $options );
					break;
				case 'radio':
					$options = false;
					if ( isset( $fieldDetails['data'] ) && is_array( $fieldDetails['data'] ) ) {
						$options = $fieldDetails['data'];
					}
					$elem->setTypeAsRadioButtons( $options );
					break;
				case 'checkbox':
					$label = false;
					if ( isset( $fieldDetails['extralabel'] ) ) {
						$label = $fieldDetails['extralabel'];
					}
					$elem->setTypeAsCheckbox( $label );
					break;
				 List
				case 'checkboxlist':
					$options = false;
					if ( isset( $fieldDetails['data'] ) && is_array( $fieldDetails['data'] ) ) {
						$options = $fieldDetails['data'];
					}
					$elem->setTypeAsCheckboxList( $options );
					break;
				case 'merge':
					$elementList = array();
					if ( ! empty( $fieldDetails['merge'] ) ) {
						foreach ( $fieldDetails['merge'] as $fieldName => $fieldDetails ) {
							$elementList[] = $this->createElementObject( $fieldName, $fieldDetails );
						}
					}
					$elem->setTypeAsMergedElements( $elementList );
					break;
				case 'uploadfile':
					$elem->setTypeAsUploadFile( $this->formObj->getArrayValue( $fieldDetails, 'show_existing' ), $this->formObj->getArrayValue( $fieldDetails, 'valid_if_value' ) );
					break;
				case 'custom':
					$elem->setTypeAsCustom( $this->formObj->getArrayValue( $fieldDetails, 'html' ) );
					break;
				case 'header':
					$elem->setTypeAsHeader( $this->formObj->getArrayValue( $fieldDetails, 'html' ) );
					break;
				case 'hidden':
					$elem->setTypeAsHidden();
					break;
				case 'break':
					$this->formObj->addBreak( $fieldName, $this->formObj->getArrayValue( $fieldDetails, 'html' ) );
					break;
				default:
					break;
			}
			if ( $type != 'break' ) {
				if ( $desc = $this->formObj->getArrayValue( $fieldDetails, 'desc' ) ) {
					$elem->description = $desc;
				}
				if ( $cssclass = $this->formObj->getArrayValue( $fieldDetails, 'cssclass' ) ) {
					$elem->cssclass = $cssclass;
				}
				$extraHTML = $this->formObj->getArrayValue( $fieldDetails, 'extrahtml' );
				if ( $extraHTML ) {
					$elem->afterFormElementHTML = $extraHTML;
				}
				$elem->errorMessage = $this->formObj->getArrayValue( $fieldDetails, 'errormsg' );
				if ( isset( $fieldDetails['validate'] ) && is_array( $fieldDetails['validate'] ) ) {
					if ( $this->formObj->getArrayValue( $fieldDetails['validate'], 'type' ) == 'function' ) {
						$elem->validationFn = $this->formObj->getArrayValue( $fieldDetails['validate'], 'fname' );
						$elem->errorMessage = $this->formObj->getArrayValue( $fieldDetails['validate'], 'error' );
					} 
					else {
						$elem->setValidationRules( $fieldDetails['validate'] );
					}
				}
				if ( ! empty( $fieldDetails['suffix_subitems'] ) ) {
					$suffixItems = array();
					foreach ( $fieldDetails['suffix_subitems'] as $position => $elementDetails ) {
						$suffixItems[ $position ] = array();
						foreach ( $elementDetails as $fieldName => $fieldDetails ) {
							$suffixItems[ $position ][] = $this->createElementObject( $fieldName, $fieldDetails );
						}
					}
					$elem->setSuffixItems( $suffixItems );
				}
			}
			return $elem;
		}
protected function createElementObject ( $ fieldName , $ fieldDetails ) { $ label = $ this -> formObj -> getArrayValue ( $ fieldDetails , 'label' ) ; $ type = $ this -> formObj -> getArrayValue ( $ fieldDetails , 'type' ) ; $ required = $ this -> formObj -> getArrayValue ( $ fieldDetails , 'required' ) ; $ required = ( $ required == 'true' || $ required == '1' ) ; $ labelPosition = $ this -> formObj -> getArrayValue ( $ fieldDetails , 'labelposition' ) ; $ labelPosition = ( $ labelPosition ) ? $ labelPosition : 'left' ; $ elem = false ; if ( $ type != 'break' ) { $ elem = new FormElement ( $ fieldName , $ label , $ required , $ labelPosition ) ; } switch ( $ type ) { case 'textarea' : $ rows = absint ( $ this -> formObj -> getArrayValue ( $ fieldDetails , 'rows' ) ) ; if ( $ rows == 0 ) { $ rows = 5 ; } $ elem -> setTypeAsTextArea ( $ rows , 70 ) ; break ; case 'select' : $ options = false ; if ( isset ( $ fieldDetails [ 'data' ] ) && is_array ( $ fieldDetails [ 'data' ] ) ) { $ options = $ fieldDetails [ 'data' ] ; } $ elem -> setTypeAsComboBox ( $ options ) ; break ; case 'radio' : $ options = false ; if ( isset ( $ fieldDetails [ 'data' ] ) && is_array ( $ fieldDetails [ 'data' ] ) ) { $ options = $ fieldDetails [ 'data' ] ; } $ elem -> setTypeAsRadioButtons ( $ options ) ; break ; case 'checkbox' : $ label = false ; if ( isset ( $ fieldDetails [ 'extralabel' ] ) ) { $ label = $ fieldDetails [ 'extralabel' ] ; } $ elem -> setTypeAsCheckbox ( $ label ) ; break ; case 'checkboxlist' : $ options = false ; if ( isset ( $ fieldDetails [ 'data' ] ) && is_array ( $ fieldDetails [ 'data' ] ) ) { $ options = $ fieldDetails [ 'data' ] ; } $ elem -> setTypeAsCheckboxList ( $ options ) ; break ; case 'merge' : $ elementList = array ( ) ; if ( ! empty ( $ fieldDetails [ 'merge' ] ) ) { foreach ( $ fieldDetails [ 'merge' ] as $ fieldName => $ fieldDetails ) { $ elementList [ ] = $ this -> createElementObject ( $ fieldName , $ fieldDetails ) ; } } $ elem -> setTypeAsMergedElements ( $ elementList ) ; break ; case 'uploadfile' : $ elem -> setTypeAsUploadFile ( $ this -> formObj -> getArrayValue ( $ fieldDetails , 'show_existing' ) , $ this -> formObj -> getArrayValue ( $ fieldDetails , 'valid_if_value' ) ) ; break ; case 'custom' : $ elem -> setTypeAsCustom ( $ this -> formObj -> getArrayValue ( $ fieldDetails , 'html' ) ) ; break ; case 'header' : $ elem -> setTypeAsHeader ( $ this -> formObj -> getArrayValue ( $ fieldDetails , 'html' ) ) ; break ; case 'hidden' : $ elem -> setTypeAsHidden ( ) ; break ; case 'break' : $ this -> formObj -> addBreak ( $ fieldName , $ this -> formObj -> getArrayValue ( $ fieldDetails , 'html' ) ) ; break ; default : break ; } if ( $ type != 'break' ) { if ( $ desc = $ this -> formObj -> getArrayValue ( $ fieldDetails , 'desc' ) ) { $ elem -> description = $ desc ; } if ( $ cssclass = $ this -> formObj -> getArrayValue ( $ fieldDetails , 'cssclass' ) ) { $ elem -> cssclass = $ cssclass ; } $ extraHTML = $ this -> formObj -> getArrayValue ( $ fieldDetails , 'extrahtml' ) ; if ( $ extraHTML ) { $ elem -> afterFormElementHTML = $ extraHTML ; } $ elem -> errorMessage = $ this -> formObj -> getArrayValue ( $ fieldDetails , 'errormsg' ) ; if ( isset ( $ fieldDetails [ 'validate' ] ) && is_array ( $ fieldDetails [ 'validate' ] ) ) { if ( $ this -> formObj -> getArrayValue ( $ fieldDetails [ 'validate' ] , 'type' ) == 'function' ) { $ elem -> validationFn = $ this -> formObj -> getArrayValue ( $ fieldDetails [ 'validate' ] , 'fname' ) ; $ elem -> errorMessage = $ this -> formObj -> getArrayValue ( $ fieldDetails [ 'validate' ] , 'error' ) ; } else { $ elem -> setValidationRules ( $ fieldDetails [ 'validate' ] ) ; } } if ( ! empty ( $ fieldDetails [ 'suffix_subitems' ] ) ) { $ suffixItems = array ( ) ; foreach ( $ fieldDetails [ 'suffix_subitems' ] as $ position => $ elementDetails ) { $ suffixItems [ $ position ] = array ( ) ; foreach ( $ elementDetails as $ fieldName => $ fieldDetails ) { $ suffixItems [ $ position ] [ ] = $ this -> createElementObject ( $ fieldName , $ fieldDetails ) ; } } $ elem -> setSuffixItems ( $ suffixItems ) ; } } return $ elem ; }
Convert an array of details into a form element.
Convert an array of details into a form element .
// Extract fields // Required 'true' or true are valid // Label Position // Start creating form element if anything other than a break. // Handle specific types // Text Area // Select/Dropdown // Radio Buttons // Checkbox // Checkbox List // Merged Fields - process each sub element // File upload // Custom HTML // Header // Hidden field // Section break // Text box // Add optional fields // Element description // Extra CSS // Add extra HTML if provided. // Add custom error message if there is one // Validation rules // Is it a custom function? If so, get the function name. // Ah, no, it's not. Just a text-based validation. // See if there are any suffix items? If so, parse them. // See wiki for documentation on how to structure this. // suffix_subitems contains a list of 'position' => array(fieldName => fieldDetails) // Need to process each field now we know the position. // Add the position of this item (in order), with the object for this element. // Update the form element with the subitems