File: D:/HostingSpaces/SBogers10/komma-mediadesign.nl/wwwroot/beheer/app/models/m_button.php
<?php
/*
Button Class
Creates and displays a button
*/
class Button
{
private $_label;
private $_type;
private $_name;
private $_href;
private $_classes;
private $_id;
public function __construct($options)
{
isset($options['type']) ? $this->_type = $options['type'] : $this->_type = 'submit';
isset($options['label']) ? $this->_label = $options['label'] : $this->_label = 'button';
isset($options['name']) ? $this->_name = $options['name'] : $this->_name = 'submit';
isset($options['href']) ? $this->_href = $options['href'] : $this->_href = '#';
$this->_classes = array();
$this->_id = '';
}
/**
* Adds classes to the button
*
* @access public
* @param array
* @return null
*/
public function addClasses($classes = NULL)
{
foreach($classes as $class){
$this->_classes[] = $class;
}
}
/**
* Adds id to the button
*
* @access public
* @param array
* @return null
*/
public function addId($id = NULL)
{
if( ! empty($id))
{
$this->_id = $id;
}
}
/**
* Returns a string containing a submit button
*
* @access private
* @param
* @return string
*/
private function createInputButton()
{
$str = '';
$str .= '<input type="'.$this->_type.'" name="'.$this->_name.'" value="'.$this->_label.'" ';
$str .= 'class="rounded ';
if( ! empty($this->_classes))
{
foreach($this->_classes as $class)
{
$str.= $class.' ';
}
$str = substr($str,0,-1);
}
$str .= '" ';
if( ! empty($this->_id))
{
$str .= 'id="'.$this->_id.'" ';
}
$str .= '/>';
return $str;
}
/**
* Returns a string containing an <a> link
*
* @access private
* @param
* @return string
*/
private function createLinkButton()
{
$str = '';
$str .= '<a href="'.$this->_href.'" title="'.$this->_label.'" ';
$str .= 'class="btn rounded ';
if( ! empty($this->_classes))
{
foreach($this->_classes as $class)
{
$str.= $class.' ';
}
$str = substr($str,0,-1);
}
$str .= '" ';
if( ! empty($this->_id))
{
$str .= '"'.$this->_id.'" ';
}
$str .= '>'.$this->_label.'</a>';
return $str;
}
/**
* returns a string containing the button
*
* @access
* @param
* @return
*/
public function display($echo = TRUE)
{
$output = '';
switch($this->_type)
{
case 'submit':
case 'button':
$output .= $this->createInputButton();
break;
case 'link':
$output .= $this->createLinkButton();
break;
}
if($echo)
{
echo $output;
}
else
{
return $output;
}
}
}