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

90 lines
2.2 KiB
PHP
Raw 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
* @category lnApp/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();
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);
Session::instance()->set('sessionmsgs',static::$_data);
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'))
2013-04-22 05:50:28 +00:00
static::$_data = $msgs;
parent::add($msg);
2013-04-25 00:22:36 +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
Session::instance()->set('sessionmsgs',static::$_data);
}
/**
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() {
$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
2013-04-25 00:22:36 +00:00
$output .= sprintf('<div class="alert %s">',empty($record['type']) ? '' : 'alert-'.$record['type']);
$output .= '<button type="button" class="close" data-dismiss="alert">&times;</button>';
switch ($record['type']) {
2013-04-22 05:50:28 +00:00
case 'error':
2013-04-25 00:22:36 +00:00
$output .= '<i class="icon-ban-circle"></i>';
2013-04-22 05:50:28 +00:00
break;
2013-04-25 00:22:36 +00:00
case 'success':
$output .= '<i class="icon-check"></i>';
2013-04-22 05:50:28 +00:00
break;
case 'warning':
2013-04-25 00:22:36 +00:00
$output .= '<i class="icon-warning-sign"></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:
2013-04-25 00:22:36 +00:00
$output .= '<i class="icon-info-sign"></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
2013-04-25 00:22:36 +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'))
2013-04-22 05:50:28 +00:00
static::$_data = $msgs;
2013-04-25 00:22:36 +00:00
return parent::render_all();
}
2013-04-22 05:50:28 +00:00
}
?>