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

95 lines
2.4 KiB
PHP
Raw Permalink Normal View History

2013-04-22 05:50:28 +00:00
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class is for rendering system information messages.
*
* @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
*/
abstract class lnApp_SystemMessage 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','title','type');
2013-04-22 05:50:28 +00:00
protected static $_required_keys = array('title','body','type');
2013-04-25 00:22:36 +00:00
public function __call($name,$args=NULL) {
parent::__call($name,$args);
2013-12-04 10:36:46 +00:00
// If we are a CLI session, then we have no session
if (PHP_SAPI !== 'cli')
2014-10-03 14:35:26 +00:00
Session::instance()->set('sessionmsgs',static::$_data);
2013-12-04 10:36:46 +00:00
2013-04-25 00:22:36 +00:00
return $this;
}
2013-04-22 05:50:28 +00:00
/**
* Add a system message to be rendered
*
* @param array System Message attributes
2013-04-25 00:22:36 +00:00
* @deprecated
2013-04-22 05:50:28 +00:00
*/
public static function add($msg,$prepend=FALSE) {
2013-04-25 00:22:36 +00:00
if ($msgs = Session::instance()->get_once('sessionmsgs'))
2014-10-03 14:35:26 +00:00
static::$_data = $msgs;
2013-04-22 05:50:28 +00:00
parent::add($msg);
2014-10-03 14:35:26 +00:00
static::$_c = count(static::$_data);
2013-04-22 05:50:28 +00:00
// Save our messages in our session, so that we get them for redirects
2014-10-03 14:35:26 +00:00
Session::instance()->set('sessionmsgs',static::$_data);
2013-04-22 05:50:28 +00:00
}
/**
2013-04-25 00:22:36 +00:00
* Render this system message
2013-04-22 05:50:28 +00:00
*
2013-04-25 00:22:36 +00:00
* @see HTMLRender::render()
2013-04-22 05:50:28 +00:00
*/
2013-04-25 00:22:36 +00:00
protected function render() {
2014-10-03 14:35:26 +00:00
$record = static::$_data[$this->_x];
2013-04-22 05:50:28 +00:00
2013-04-25 00:22:36 +00:00
$output = '';
2013-04-22 05:50:28 +00:00
$output .= sprintf('<div class="alert %s">',empty($record['type']) ? '' : 'alert-'.($record['type'] == 'error' ? 'danger' : $record['type']));
2013-04-25 00:22:36 +00:00
$output .= '<button type="button" class="close" data-dismiss="alert">&times;</button>';
switch ($record['type']) {
2013-04-22 05:50:28 +00:00
case 'error':
2014-10-03 14:35:26 +00:00
$output .= '<i class="fa fa-exclamation-circle"></i>';
2013-04-22 05:50:28 +00:00
break;
2013-04-25 00:22:36 +00:00
case 'success':
2014-10-03 14:35:26 +00:00
$output .= '<i class="fa fa-check"></i>';
2013-04-22 05:50:28 +00:00
break;
case 'warning':
2014-10-03 14:35:26 +00:00
$output .= '<i class="fa fa-warning"></i>';
2013-04-22 05:50:28 +00:00
break;
2013-04-25 00:22:36 +00:00
case 'info':
2013-04-22 05:50:28 +00:00
default:
2014-10-03 14:35:26 +00:00
$output .= '<i class="fa fa-info"></i>';
2013-04-22 05:50:28 +00:00
}
2013-04-25 00:22:36 +00:00
$output .= sprintf(' <strong>%s</strong>: %s',$record['title'],$record['body']);
$output .= '</div> <!-- /alert -->';
2013-04-22 05:50:28 +00:00
2013-04-25 00:22:36 +00:00
return $output;
}
2013-04-22 05:50:28 +00:00
/**
* Render all of these items
*/
public function render_all() {
2013-04-22 05:50:28 +00:00
// Reload our message from the session
2013-04-25 00:22:36 +00:00
if ($msgs = Session::instance()->get_once('sessionmsgs'))
2014-10-03 14:35:26 +00:00
static::$_data = $msgs;
2013-04-22 05:50:28 +00:00
2013-04-25 00:22:36 +00:00
return parent::render_all();
}
2014-10-03 14:35:26 +00:00
public function dump() {
}
2013-04-22 05:50:28 +00:00
}
?>