rendered paste body<?php
// ---------------------------------- \\
// @Zula Framework Event Feedback
// @License: http://www.gnu.org/copyleft/gpl.html GNU/GPL 2
// @Author: Alex Cartwright
// @Created: 24th June 2007
// ---------------------------------- \\
/**
Event Feedback allows controllers to register an event,
such as an error, or succsess message that needs to be
displayed to the user. Such as 'Added Menu Item'.
**/
class Event {
const SHOW_ERRORS = 1;
const SHOW_SUCCESS = 2;
const SHOW_ALL = 3;
//---
// Constructor function
//---
public function __construct() {
$_SESSION['event_feedback']['error'] = array();
$_SESSION['event_feedback']['success'] = array();
}
//---
// Error() stores a error into the session array
// @param string $error
// @return bool
//---
public function error( $error ) {
if ( !is_string( $error ) || empty( $error ) ) {
return false;
}
$_SESSION['event_feedback']['error'][] = $error;
return true;
}
//---
// Success() stores a success message into sesson array
// @param string $message
// @return bool
//---
public function success( $message ) {
if ( !is_string( $message ) || empty( $message ) ) {
return false;
}
$_SESSION['event_feedback']['success'][] = $message;
Log::message( $message, Log::L_EVENT );
return true;
}
//---
// output() formats the stored messages and then returns them
// it can also filter to show only Errors, or only Success - or both.
// [@param int $filter]
// @return string
//---
public function output( $filter=Event::SHOW_ALL ) {
$output = '';
if ( $filter & Event::SHOW_ERRORS && is_array( $_SESSION['event_feedback']['error'] ) && !empty( $_SESSION['event_feedback']['error'] ) ) {
$errors = array_unique( $_SESSION['event_feedback']['error'] );
$output .= '<div id="event-error">'.implode_adv( $errors, '<p>', '</p>' ).'</div>';
unset( $_SESSION['event_feedback']['error'] );
}
if ( $filter & Event::SHOW_ERRORS && isset( $_SESSION['event_feedback']['success'] ) && !empty( $_SESSION['event_feedback']['success'] ) ) {
$success = array_unique( $_SESSION['event_feedback']['success'] );
$output .= '<div id="event-success">'.implode_adv( $success, '<p>', '</p>' ).'</div>';
unset( $_SESSION['event_feedback']['success'] );
}
return $output;
}
}
?>