/**
* The required files
*/
require_once(HTML_BASIC_UTIL_PATH.'/Singleton.php');
require_once(HTML_FORM_ELEMENTS_PAGE_PATH.'/ControlEmail.php');
require_once(HTML_FORM_ELEMENTS_PAGE_PATH.'/ControlPassword.php');
require_once(HTML_FORM_ELEMENTS_PAGE_PATH.'/ControlFileupload.php');
require_once(HTML_FORM_ELEMENTS_PAGE_PATH.'/ControlAccept.php');
require_once(HTML_FORM_COMPONENT_PATH.'/ElementFactory.php');
require_once(HTML_LANGUAGE_UTIL_PATH.'/Translate.php');
if (defined('HTML_LOG_UTIL_PATH')) {
require_once(HTML_LOG_UTIL_PATH.'/Log.php');
}
/**
* The Control Factory is used to return a complete populated
* element object, consisting of a label object and a input object.
* The element is returned as a singleton.
* <code>
* Usage:
* $factory = new ControlFactory();
* $element = $factory->getInstance($label,$name,$classname,$useLabel);
* print $element->getHtml(); // Use the object
* Or
* $element = ControlFactory::getInstance($label,$name,$classname,$useLabel);
* print $element->getHtml(); // Use the object
* </code>
* @package form-element
*/
class ControlFactory {
/**
* Constructor
*/
function ControlFactory() {
}
/**
* Return the control as an object
* @static
* @param Label $label The Label object
* @param Text field $control The Control object
* @param String $classname The class name of the control
* @return Object The html as an Object
*/
function getSingleton($label,$control,$classname) {
$element = & Singleton::getInstance($classname);
$element->set(CLASS_VAR_LABEL,$label);
$element->set(CLASS_VAR_CONTROL,$control);
return $element;
}
/**
* Return the control as an singleton instance object
* @static
* @param Label $label The Label object
* @param String $name The name of the control
* @param String $classname The class name of the control
* @param boolean $useLabel The Control has a label (true) or not (false)
* @return Object The html as an Object
*/
function getInstance($label,$name,$classname,$useLabel=true) {
$required = ''; // Debug
$type = 'UNKNOWN';
switch ($classname) {
case CLASS_NAME_CONTROL_EMAIL:
$type = 'text';
break;
case CLASS_NAME_CONTROL_PASSWORD:
$type = 'password';
break;
case CLASS_NAME_CONTROL_FILEUPLOAD:
$type = 'fileupload';
break;
case CLASS_NAME_CONTROL_ACCEPT:
$type = 'checkbox';
break;
default:
die('File: '.__FILE__."<br />\r\nLine: ".__LINE__."<br />\r\n"."ControlFactory::getInstance(type,..), unknown classname, found classname=".$classname);
break;
}
/**
* Checkbox and Label objects MUST be constructed in reverse order
* because of the automatic id and label association
* @see Element
*/
if ($useLabel && $type != 'checkbox') {
// Must be instanciated BEFORE the text field
$label = ElementFactory::newLabel($type,$label,$required);
}
$value = '';
$len = '';
$debug = '';
$control = ElementFactory::newInput($type,$name,$value,$len,$debug);
if (!$useLabel) {
$control->setId('');
}
/**
* Checkbox and Label objects MUST be constructed in reverse order
* because of the automatic id and label association
* @see Element
*/
if ($useLabel && $type == 'checkbox') {
// Must be instanciated BEFORE the text field
$label = ElementFactory::newLabel($type,$label,$required);
}
return ControlFactory::getSingleton($label,$control,$classname);
}
}
?>
HTML source code
Den fulde HTML kildekode for ControlFactory klassen
Der er ikke fundet noget
Class methods
Her er 'klasse metoderne' for ControlFactory klassen:
controlfactory
getsingleton
getinstance
Object vars
Her er 'objekt variable' for ControlFactory klassen: