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

88 lines
2.5 KiB
PHP
Raw Normal View History

2013-04-22 05:50:28 +00:00
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
2013-04-25 00:22:36 +00:00
* This class is for rendering HTML blocks or widget.
2013-04-22 05:50:28 +00:00
*
2013-04-25 00:22:36 +00:00
* It will provide a title and body for the content.
2013-04-22 05:50:28 +00:00
*
* @package lnApp
2013-10-08 23:24:11 +00:00
* @category Helpers
2013-04-22 05:50:28 +00:00
* @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();
2013-04-25 00:22:36 +00:00
protected static $_spacer = '';
protected static $_c = 0;
protected $_items = array('body','id','scrollable','span','title','title_icon','type');
2013-04-25 00:22:36 +00:00
2013-04-22 05:50:28 +00:00
protected static $_required_keys = array('body');
/**
* Add a block to be rendered
*
* @param array Block attributes
2013-04-25 00:22:36 +00:00
* @deprecated
2013-04-22 05:50:28 +00:00
*/
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,
));
}
/**
2013-04-25 00:22:36 +00:00
* Render this Block
2013-04-22 05:50:28 +00:00
*/
protected function render() {
2013-04-25 00:22:36 +00:00
$record = static::$_data[$this->_x];
2013-04-22 05:50:28 +00:00
2013-04-25 00:22:36 +00:00
$output = '';
$output .= sprintf('<div class="span%s %s">',empty($record['span']) ? '12' : $record['span'],empty($record['scrollable']) ? '' : 'scrollable');
2013-04-25 00:22:36 +00:00
$output .= '<div class="widget stacked">';
2013-04-22 05:50:28 +00:00
2013-04-25 00:22:36 +00:00
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']);
2013-04-22 05:50:28 +00:00
2013-04-25 00:22:36 +00:00
$output .= '<div class="widget-content">';
2013-04-22 05:50:28 +00:00
2013-04-25 00:22:36 +00:00
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']))));
2013-04-25 00:22:36 +00:00
$output .= (string)$record['body'];
$output .= Form::close();
break;
2013-04-22 05:50:28 +00:00
2013-04-25 00:22:36 +00:00
default:
$output .= (string)$record['body'];
}
2013-04-22 05:50:28 +00:00
2013-04-25 00:22:36 +00:00
else
$output .= (string)$record['body'];
2013-04-22 05:50:28 +00:00
2013-04-25 00:22:36 +00:00
$output .= '</div> <!-- /widget-content -->';
$output .= '</div> <!-- /widget-stacked -->';
$output .= '</div> <!-- /span -->';
2013-04-22 05:50:28 +00:00
return $output;
}
}
?>