File: D:/HostingSpaces/SBogers10/lab.komma-mediadesign.nl/wwwroot/lab/lib/button.class.php
<?php
/**
* button.class.php
* Created by Komma Mediadesign.
* Author: mike
* Date: 3/21/13
*/
class Button
{
/*
* @property string $_label
* Button Label
*/
private $_label;
/*
* @property string $_button
* A button can be an "a-link" or an "input/submit" or an "input/button"
*/
private $_type;
/*
* @property string $_name
* Name is used in an input button.
*/
private $_name;
/*
* @property string $_href
* Url on an "a-link"
*/
private $_href;
/*
* @property array $_classes
* Class which are added to a button
*/
private $_classes;
/*
* @property string $_id
* An id which is added to the button
*/
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 .= '
<div class="btn rounded ';
if( ! empty($this->_classes))
{
foreach($this->_classes as $class)
{
$str.= $class.' ';
}
$str = substr($str,0,-1);
}
$str .= '">';
$str .= '<input type="'.$this->_type.'" name="'.$this->_name.'" value="'.$this->_label.'" ';
if( ! empty($this->_id))
{
$str .= 'id="'.$this->_id.'" ';
}
$str .= '/>';
$str .= '<span class="over"></span>
<span class="out"></span>
</div>';
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 .= '>
<span class="over">'.$this->_label.'</span>
<span class="out">'.$this->_label.'</span>
</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;
}
}
}