
Improved issue display Add component::prepend Add switches to form html Updated form html to Bootstrap 5. Updated navigation html to Bootstrap 5.
147 lines
3.5 KiB
PHP
147 lines
3.5 KiB
PHP
<?php
|
|
/**
|
|
* core/template/issues.php
|
|
*
|
|
* This class is for managing template issues.
|
|
*
|
|
* @version 3.0
|
|
* @author Joey Kimsey <Joey@thetempusproject.com>
|
|
* @link https://TheTempusProject.com/Core
|
|
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
|
|
*/
|
|
namespace TheTempusProject\Houdini\Classes;
|
|
|
|
use TheTempusProject\Houdini\Classes\Template;
|
|
|
|
class Issues {
|
|
private static $hasIssues = false;
|
|
private static $success = [];
|
|
private static $notice = [];
|
|
private static $error = [];
|
|
private static $info = [];
|
|
|
|
/**
|
|
* Returns the prepared message html.
|
|
*
|
|
* @return {string}
|
|
*/
|
|
public static function add( $type, $messages, $parse = true ) {
|
|
if ( ! is_array( $messages ) ) {
|
|
$messages = [ $messages => '' ];
|
|
}
|
|
foreach ( $messages as $parent => $child ) {
|
|
$out = self::filters( $parent );
|
|
if ( !empty( $child ) ) {
|
|
$out .= '<ul>';
|
|
if ( ! is_array( $child ) ) {
|
|
$child = [ $child ];
|
|
}
|
|
foreach ( $child as $children ) {
|
|
if ( ! is_string( $children ) ) {
|
|
$children = var_export( $children, true );
|
|
}
|
|
$out .= '<li>' . $children . '</li>';
|
|
}
|
|
$out .= '</ul>';
|
|
}
|
|
if ( $parse ) {
|
|
$out = Template::parse( $out );
|
|
}
|
|
self::$type( $out );
|
|
}
|
|
}
|
|
|
|
private static function filters( $data ) {
|
|
$data = preg_replace( '#\{#', '{', $data );
|
|
$data = preg_replace( '#\}#', '}', $data );
|
|
$data = preg_replace( '#\$#', '$', $data );
|
|
return $data;
|
|
}
|
|
|
|
/**
|
|
* Adds a success message to the issues list.
|
|
*
|
|
* @param {string} [$message]
|
|
*/
|
|
private static function success( $message ) {
|
|
self::$hasIssues = true;
|
|
self::$success[] = $message;
|
|
}
|
|
|
|
/**
|
|
* Adds a warning message to the issues list.
|
|
*
|
|
* @param {string} [$message]
|
|
*/
|
|
private static function notice( $message ) {
|
|
self::$hasIssues = true;
|
|
self::$notice[] = $message;
|
|
}
|
|
|
|
/**
|
|
* Adds an info message to the issues list.
|
|
*
|
|
* @param {string} [$message]
|
|
*/
|
|
private static function info( $message ) {
|
|
self::$hasIssues = true;
|
|
self::$info[] = $message;
|
|
}
|
|
|
|
/**
|
|
* Adds an error message to the issues list.
|
|
*
|
|
* @param {string} [$message]
|
|
*/
|
|
private static function error( $message ) {
|
|
self::$hasIssues = true;
|
|
self::$error[] = $message;
|
|
}
|
|
|
|
/**
|
|
* This is the function that tells the application if we have
|
|
* have any messages to display or not.
|
|
*
|
|
* @return {bool}
|
|
*/
|
|
public static function hasIssues() {
|
|
return self::$hasIssues;
|
|
}
|
|
|
|
/**
|
|
* Returns the success message array.
|
|
*
|
|
* @return {string}
|
|
*/
|
|
public static function getSuccessMessages() {
|
|
return self::$success;
|
|
}
|
|
|
|
/**
|
|
* Returns the warning message array.
|
|
*
|
|
* @return {string}
|
|
*/
|
|
public static function getNoticeMessages() {
|
|
return self::$notice;
|
|
}
|
|
|
|
/**
|
|
* Returns the error message array.
|
|
*
|
|
* @return {string}
|
|
*/
|
|
public static function getErrorMessages() {
|
|
return self::$error;
|
|
}
|
|
|
|
/**
|
|
* Returns the info message array.
|
|
*
|
|
* @return {string}
|
|
*/
|
|
public static function getInfoMessages() {
|
|
return self::$info;
|
|
}
|
|
}
|