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/SystemMessage.php
2016-08-25 23:24:44 +10:00

95 lines
2.4 KiB
PHP

<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class is for rendering system information messages.
*
* @package lnApp
* @category Helpers
* @author Deon George
* @copyright (c) 2009-2013 Deon George
* @license http://dev.leenooks.net/license.html
*/
abstract class lnApp_SystemMessage extends HTMLRender {
protected static $_data = array();
protected static $_spacer = '';
protected static $_c = 0;
protected $_items = array('body','title','type');
protected static $_required_keys = array('title','body','type');
public function __call($name,$args=NULL) {
parent::__call($name,$args);
// If we are a CLI session, then we have no session
if (PHP_SAPI !== 'cli')
Session::instance()->set('sessionmsgs',static::$_data);
return $this;
}
/**
* Add a system message to be rendered
*
* @param array System Message attributes
* @deprecated
*/
public static function add($msg,$prepend=FALSE) {
if ($msgs = Session::instance()->get_once('sessionmsgs'))
static::$_data = $msgs;
parent::add($msg);
static::$_c = count(static::$_data);
// Save our messages in our session, so that we get them for redirects
Session::instance()->set('sessionmsgs',static::$_data);
}
/**
* Render this system message
*
* @see HTMLRender::render()
*/
protected function render() {
$record = static::$_data[$this->_x];
$output = '';
$output .= sprintf('<div class="alert %s">',empty($record['type']) ? '' : 'alert-'.($record['type'] == 'error' ? 'danger' : $record['type']));
$output .= '<button type="button" class="close" data-dismiss="alert">&times;</button>';
switch ($record['type']) {
case 'error':
$output .= '<i class="fa fa-exclamation-circle"></i>';
break;
case 'success':
$output .= '<i class="fa fa-check"></i>';
break;
case 'warning':
$output .= '<i class="fa fa-warning"></i>';
break;
case 'info':
default:
$output .= '<i class="fa fa-info"></i>';
}
$output .= sprintf(' <strong>%s</strong>: %s',$record['title'],$record['body']);
$output .= '</div> <!-- /alert -->';
return $output;
}
/**
* Render all of these items
*/
public function render_all() {
// Reload our message from the session
if ($msgs = Session::instance()->get_once('sessionmsgs'))
static::$_data = $msgs;
return parent::render_all();
}
public function dump() {
}
}
?>