File: D:/HostingSpaces/SBogers59/ferrumbv.nl/wwwroot/kms/lib/form/form_block.class.php
<?php
/**
* form_blocks.class.php
* Created by Komma Mediadesign.
* Author: mike
* Date: 4/3/13
*/
class Form_Block
{
/*
* Info (for example name, width, extra classes
*/
private $_data;
/*
* Blocks inside this block
*/
private $_children;
/*
* Fields inside this block
*/
private $_fields;
/*
* Construct
*/
public function construct(){}
/*
* Add a child block to this block
*/
public function addChild($string)
{
if( ! empty($string))
{
$this->_children[] = $string;
}
}
/*
* Add a child field to this block
*/
public function addField($Field)
{
if( ! empty($Field))
{
$this->_fields[] = $Field;
}
}
/*
* Configure Block
*/
public function setData($key,$value)
{
if( ! empty($key))
{
$this->_data[$key] = $value;
}
}
/*
* Return output block
*/
public function display()
{
$output = '';
$output .= '<div class="column';
if(isset($this->_data['last'])) $output .= ' last';
if(isset($this->_data['width']))
{
switch($this->_data['width'])
{
case 2 : $output .= ' double';
break;
case 3 : $output .= ' triple';
break;
case 4 : $output .= ' quadruple';
break;
}
}
$output .= '">';
// check if this block has children blocks
foreach($this->_children as $child)
{
$output .= $child;
}
// check if this block contains any fields
foreach($this->_fields as $Field)
{
// Get field data
$data = $Field->get();
if( ! empty($data['name']))
{
$output .= '<div class="input_holder';
// Get errors
$errorKey = array($data['form_name'] . '_errors',$data['name']);
$error = '';
$error .= Session::get($errorKey);
if(! empty($error))
{
$output .= ' input_error';
// clean up error
Session::destroy($errorKey);
}
$output .= '">';
// Label
$output .= '<label for="' . $data['id'] . '">' . $data['label'];
if(isset($data['validation'][1]))
{
if(is_object($data['validation'][1]))
{
$validation = $data['validation'][1]->getName();
if($validation == 'required') $output .= ' *';
};
}
$output .= '</label>';
// Get specified object
isset($data['object']) ? $object = $data['object'] : $object = 'Field_Type_Text_Field';
$file = DOCUMENT_ROOT . 'lib/form/types/' . $object . '.class.php';
if(is_file($file))
{
if( ! class_exists($object)) require $file;
$TypeObject = new $object($data['label']);
$TypeObject->set($data);
$output .= $TypeObject->createInput();
}
$output .= '</div>';
}
}
$output .= '</div>';
if(isset($this->_data['clear'])) $output .= '<div class="clear"></div>';
return $output;
}
}