Skip to content
Snippets Groups Projects
Commit a9d7b2ae authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

reformat classes

parent 2023b30d
Branches
No related tags found
1 merge request!18Update renderer class
......@@ -16,25 +16,27 @@
*
* @author Axel
*/
class htmlelements {
class htmlelements
{
/**
* set of auto generated icon prefixes
* @var type
*/
var $_aIcons=array(
// 'fa-'=>'fa ',
);
var $_aIcons = array(
// 'fa-'=>'fa ',
);
var $_sLabel = '';
var $_aAttributes = array();
// ----------------------------------------------------------------------
// CONSTRUCTOR
// ----------------------------------------------------------------------
public function __construct() {
public function __construct()
{
return true;
}
......@@ -43,25 +45,26 @@ class htmlelements {
// PRIVATE FUNCTIONS
//
// ----------------------------------------------------------------------
/**
* generate html attibutes with all internal attributes key -> values
* @return string
*/
protected function _addAttributes() {
protected function _addAttributes()
{
$sReturn = '';
foreach ($this->_aAttributes as $sAttr => $sValue) {
if(is_array($sValue)){
echo "ERROR: an html tag was defined with array in attribute [$sAttr]:<br><pre>".print_r($this->_aAttributes, 1)."</pre>";
if (is_array($sValue)) {
echo "ERROR: an html tag was defined with array in attribute [$sAttr]:<br><pre>" . print_r($this->_aAttributes, 1) . "</pre>";
}
$sReturn .= ' '.$sAttr . '="' . $sValue . '"';
$sReturn .= ' ' . $sAttr . '="' . $sValue . '"';
}
return $sReturn;
}
/**
* internal helper: fetch all attributes from key-value hash;
* Specialties here:
......@@ -71,17 +74,18 @@ class htmlelements {
* @param array $aAttributes
* @return boolean
*/
protected function _setAttributes($aAttributes){
$this->_sLabel='';
if(isset($aAttributes['icon']) && $aAttributes['icon']){
$this->_sLabel.=$this->getIcon($aAttributes['icon']);
protected function _setAttributes($aAttributes)
{
$this->_sLabel = '';
if (isset($aAttributes['icon']) && $aAttributes['icon']) {
$this->_sLabel .= $this->getIcon($aAttributes['icon']);
unset($aAttributes['icon']);
}
if(isset($aAttributes['label']) && $aAttributes['label']){
if (isset($aAttributes['label']) && $aAttributes['label']) {
$this->_sLabel .= $aAttributes['label'];
unset($aAttributes['label']);
}
$this->_aAttributes=$aAttributes;
$this->_aAttributes = $aAttributes;
return true;
}
......@@ -91,7 +95,7 @@ class htmlelements {
// HTML GENERIC
//
// ----------------------------------------------------------------------
/**
* generic function to get html code for a single tag
*
......@@ -100,12 +104,13 @@ class htmlelements {
* @param boolean $bCloseTag optional: set false if tag has no closing tag (= ending with "/>")
* @return type
*/
public function getTag($sTag, $aAttributes, $bCloseTag=true){
public function getTag($sTag, $aAttributes, $bCloseTag = true)
{
$sTpl = $bCloseTag ? "<$sTag%s>%s</$sTag>" : "<$sTag %s/>%s";
$this->_setAttributes($aAttributes);
return sprintf($sTpl, $this->_addAttributes(), $this->_sLabel);
}
// ----------------------------------------------------------------------
//
// PUBLIC FUNCTIONS
......@@ -120,22 +125,23 @@ class htmlelements {
* @param string $sIconclass
* @return boolean
*/
public function getIcon($sIconclass=false){
if(!$sIconclass){
public function getIcon($sIconclass = false)
{
if (!$sIconclass) {
return '';
}
$sPrefix='';
foreach ($this->_aIcons as $sPrefix =>$add) {
if (strpos($sIconclass, $sPrefix)===0){
$sPrefix=$add;
$sPrefix = '';
foreach ($this->_aIcons as $sPrefix => $add) {
if (strpos($sIconclass, $sPrefix) === 0) {
$sPrefix = $add;
continue;
}
}
// do not use this .. it overrides internal attribute vars
// return $this->getTag('i', array('class'=>$sPrefix.$sIconclass));
return '<i class="'.$sPrefix.$sIconclass.'"></i> ';
return '<i class="' . $sPrefix . $sIconclass . '"></i> ';
}
// ----------------------------------------------------------------------
//
......@@ -150,7 +156,8 @@ class htmlelements {
* @param array $aAttributes attributes of the select tag
* @return string
*/
public function getFormInput($aAttributes){
public function getFormInput($aAttributes)
{
$sTpl = '<input %s/>';
$this->_setAttributes($aAttributes);
return sprintf($sTpl, $this->_addAttributes());
......@@ -161,7 +168,8 @@ class htmlelements {
* @param array $aAttributes attributes of the option tag
* @return string
*/
public function getFormOption($aAttributes){
public function getFormOption($aAttributes)
{
$sTpl = '<option %s>%s</option>';
$this->_setAttributes($aAttributes);
return sprintf($sTpl, $this->_addAttributes(), $this->_sLabel);
......@@ -173,18 +181,19 @@ class htmlelements {
* @param array $aOptions array for all option fields
* @return string
*/
public function getFormSelect($aAttributes, $aOptions=array()){
public function getFormSelect($aAttributes, $aOptions = array())
{
// $sTpl = '<select %s>%s</select>';
if(!count($aOptions)){
if (!count($aOptions)) {
return false;
}
$sOptions='';
foreach($aOptions as $aOptionAttributes){
$sOptions = '';
foreach ($aOptions as $aOptionAttributes) {
// $sOptions.=$this->getFormOption($aOptionAttributes);
$sOptions.=$this->getTag('option', $aOptionAttributes);
$sOptions .= $this->getTag('option', $aOptionAttributes);
}
$aAttributes['label']=$sOptions;
$aAttributes['label'] = $sOptions;
return $this->getTag('select', $aAttributes);
/*
$this->_setAttributes($aAttributes);
......@@ -193,30 +202,32 @@ class htmlelements {
*/
}
public function getTable($aHead, $aBody, $aTableAttributes=array()){
$sReturn='';
$sTdata='';
$sThead='';
public function getTable($aHead, $aBody, $aTableAttributes = array())
{
$sReturn = '';
$sTdata = '';
$sThead = '';
$sTpl = '<table %s>'
. '<thead><tr>%s</tr></thead>'
. '<tbody>%s</tbody>'
. '</table>';
foreach($aHead as $sTh){
$sThead.='<th>'.$sTh.'</th>';
. '<thead><tr>%s</tr></thead>'
. '<tbody>%s</tbody>'
. '</table>';
foreach ($aHead as $sTh) {
$sThead .= '<th>' . $sTh . '</th>';
}
foreach($aBody as $aTr){
$sTdata.='<tr>';
foreach($aTr as $sTd){
$sTdata.='<td>'.$sTd.'</td>';
foreach ($aBody as $aTr) {
$sTdata .= '<tr>';
foreach ($aTr as $sTd) {
$sTdata .= '<td>' . $sTd . '</td>';
}
$sTdata.='</tr>';
$sTdata .= '</tr>';
}
$this->_setAttributes($aTableAttributes);
return sprintf($sTpl,
$this->_addAttributes(),
$sThead,
$sTdata
);
return sprintf(
$sTpl,
$this->_addAttributes(),
$sThead,
$sTdata
);
}
}
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment