type = $type;
$this->name = $name;
$this->value = $value;
$this->setCssClass('input');
if ($type == 'textarea')
{
$this->setStyle(array('width' => '100%', 'height' => '50px'));
}
}
/**
* Makes a new instance of the object in a static fashion
*
* @return object
*/
public static function make()
{
$obj = new ReflectionClass(__CLASS__);
$args = func_get_args();
return $obj->newInstanceArgs($args);
}
/**
* If the type is either checkbox, radio, or option then this will
* set the selected/checked attribute
*
* @param boolean Active?
*
* @return fluent interface
*/
public function setActive($active)
{
if (!in_array($this->type, array('checkbox', 'radio', 'option')))
{
throw new Exception('BSPrinterElement::setActive() can only be used on elements of type checkbox, radio, or option');
}
$this->active = $active;
return $this;
}
/**
* Sets the JavaScript onclick action
*
* @param string onClick attribute value
*
* @return fluent interface
*/
public function setOnClick($onClick)
{
$this->onClick = $onClick;
return $this;
}
/**
* Sets the accesskey attribute value
*
* @param string Access key
*
* @return fluent interface
*/
public function setAccessKey($accessKey)
{
$this->accessKey = $accessKey;
return $this;
}
/**
* Returns the type
*
* @return string Element type
*/
public function getType()
{
return $this->type;
}
/**
* Returns the name of the element
*
* @return string Name
*/
public function getName()
{
return $this->name;
}
/**
* Sets the name of the element
*
* @param string A new name
*
* @return fluent interface
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Returns the output HTML
*
* @return string Output HTML
*/
public function paint()
{
$name = ' name="' . $this->name . '"';
$value = ' value="' . $this->value . '"';
$onclick = ($this->onClick ? ' onclick="' . $this->onClick . '"' : '');
$accesskey = ($this->accessKey ? ' accesskey="' . $this->accessKey . '"' : '');
$attrs = $name . $value . $onclick . $accesskey;
switch ($this->type)
{
case 'text':
case 'password':
case 'button':
case 'submit':
case 'reset':
return 'type == 'text' || $this->type == 'password') ? ' size="35" maxlength="255"' : ''). $this->_prepareStyle() . ' />';
break;
case 'hidden':
return '';
break;
case 'checkbox':
case 'radio':
return 'active ? ' checked="checked"' : '') . $this->_prepareStyle() . ' />';
break;
case 'upload':
return '_prepareStyle() . ' />';
break;
case 'option':
return '';
break;
case 'select':
return '';
break;
case 'textarea':
if (!isset($this->style['height']) || !isset($this->style['width']))
{
throw new Exception('BSPrinterElement of type "textarea" require a "height" and "width" style attribute');
}
return '';
break;
default:
throw new Exception('Invalid BSPrinterElement type "' . $this->type . '"');
break;
}
}
}
?>