This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
lnapp/classes/lnApp/Block.php
2014-02-18 15:27:08 +11:00

88 lines
2.5 KiB
PHP

<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class is for rendering HTML blocks or widget.
*
* It will provide a title and body for the content.
*
* @package lnApp
* @category Helpers
* @author Deon George
* @copyright (c) 2009-2013 Deon George
* @license http://dev.leenooks.net/license.html
* @uses Style
*/
abstract class lnApp_Block extends HTMLRender {
protected static $_data = array();
protected static $_spacer = '';
protected static $_c = 0;
protected $_items = array('body','id','scrollable','span','title','title_icon','type');
protected static $_required_keys = array('body');
/**
* Add a block to be rendered
*
* @param array Block attributes
* @deprecated
*/
public static function add($block,$prepend=FALSE) {
// Any body objects should be converted to a string, so that any calls to Style/Script are processed
if (isset($block['body']))
$block['body'] = (string)$block['body'];
parent::add($block);
// Detect any style sheets.
if (! empty($block['style']) && is_array($block['style']))
foreach ($block['style'] as $data=>$media)
Style::add(array(
'type'=>'file',
'data'=>$data,
'media'=>$media,
));
}
/**
* Render this Block
*/
protected function render() {
$record = self::$_data[$this->_x];
$output = '';
$output .= sprintf('<div class="span%s %s">',empty($record['span']) ? '12' : $record['span'],empty($record['scrollable']) ? '' : 'scrollable');
$output .= '<div class="widget stacked">';
if (! empty($record['title']))
$output .= sprintf('<div class="widget-header">%s<h3>%s</h3></div>',empty($record['title_icon']) ? '' : sprintf(' <i class="%s"></i>',$record['title_icon']),$record['title']);
$output .= '<div class="widget-content">';
if (! empty($record['type']))
switch ($record['type']) {
case 'form': $output .= Form::open(NULL,(empty($record['id']) ? NULL : array('id'=>$record['id'])));
$output .= (string)$record['body'];
$output .= Form::close();
break;
case 'form-horizontal': $output .= Form::open(NULL,Arr::merge(array('class'=>'form-horizontal'),(empty($record['id']) ? array() : array('id'=>$record['id']))));
$output .= (string)$record['body'];
$output .= Form::close();
break;
default:
$output .= (string)$record['body'];
}
else
$output .= (string)$record['body'];
$output .= '</div> <!-- /widget-content -->';
$output .= '</div> <!-- /widget-stacked -->';
$output .= '</div> <!-- /span -->';
return $output;
}
}
?>