Project

General

Profile

Revision 2126

Added by Manuela over 7 years ago

! /framework/msgQueue
Methods ::getError() and ::getSuccess() are deprecated and have
been replaced replaced by ::getMessages(). See inline documentation for further information

View differences:

branches/2.8.x/CHANGELOG
11 11
! = Update/Change
12 12
===============================================================================
13 13

  
14
18 Jun -2015 Build 2126 Manuela v.d.Decken(DarkViper)
15
! /framework/msgQueue
16
Methods  ::getError() and ::getSuccess() are deprecated and have
17
been replaced replaced by ::getMessages(). See inline documentation for further information
14 18
17 Jun -2015 Build 2125 Manuela v.d.Decken(DarkViper)
15 19
! /framework/class.Login.php
16 20
! /account/ ~login_form.php  ~login.php
branches/2.8.x/wb/admin/interface/version.php
51 51

  
52 52
// check if defined to avoid errors during installation (redirect to admin panel fails if PHP error/warnings are enabled)
53 53
if(!defined('VERSION')) define('VERSION', '2.8.4');
54
if(!defined('REVISION')) define('REVISION', '2124');
54
if(!defined('REVISION')) define('REVISION', '2126');
55 55
if(!defined('SP')) define('SP', '');
branches/2.8.x/wb/framework/msgQueue.php
6 6
 */
7 7
class msgQueue {
8 8

  
9
	const RETVAL_ARRAY  = 0;
10
	const RETVAL_STRING = 1; // (default)
11

  
12
	private static $_instance;
13

  
14
	private $_error = array();
15
	private $_success = array();
16

  
17
	protected function __construct() {
18
		$this->_error = array();
19
		$this->_success = array();
20
	}
21
	private function __clone() { throw new Exception('cloning Class '.__CLASS__.' is illegal'); }
22

  
23
    public static function handle()
9
/** define type of retval */
10
    const RETVAL_ARRAY  = 0;
11
    const RETVAL_STRING = 1; // (default)
12
/** */
13
    const LOG      = 0;
14
    const ERROR    = 1; // (default)
15
    const SUCCESS  = 2;
16
    const OK       = 2;
17
    const WARN     = 4;
18
    const SHOW_ALL = 0;
19
    const ALL      = 0;
20
/**  */
21
    private static $_instance;
22
/**  */
23
    private $aLogs    = array();
24
/**
25
 * constructor
26
 */
27
    protected function __construct() {
28
        $this->aLogs = array();
29
    }
30
/** disable cloning */
31
    private function __clone() { }
32
/**
33
 * get handle for active instance
34
 */
35
    public static function getInstance()
24 36
    {
25 37
        if (!isset(self::$_instance)) {
26 38
            $c = __CLASS__;
27 39
            self::$_instance = new $c;
28 40
        }
29 41
        return self::$_instance;
30
	}
42
    }
43
/**
44
 * push new message in queue
45
 * @param string $sMessage
46
 * @param int $iStatus (default: self::FAIL)
47
 */
48
    public static function add($sMessage = '', $iStatus = self::ERROR)
49
    {
50
        $iStatus =
51
            ($iStatus === true ? self::OK : ($iStatus === false ? self::ERROR : $iStatus)) ?: self::ERROR;
52
        self::getInstance()->aLogs[self::LOG][] = array('status'=>self::WARN, 'msg'=>$sMessage);
53
        self::getInstance()->aLogs[$iStatus][]  = $sMessage;
54
    }
55
/**
56
 *
57
 * @param int $iStatus
58
 */
59
    public static function clear($iStatus = self::ALL)
60
    {
61
        if ($iStatus == self::ALL) {
62
            self::getInstance()->aLogs = array();
63
        } else {
64
            if (isset(self::getInstance()->aLogs[$iStatus])) {
65
                self::getInstance()->aLogs[$iStatus] = array();
66
            }
67
        }
68
    }
69
/**
70
 *
71
 * @param int $iStatus (default: self::ALL)
72
 * @return bool
73
 */
74
    public static function isEmpty($iStatus = self::ALL)
75
    {
76
        if ($iStatus == self::ALL) {
77
            return (sizeof(self::getInstance()->aLogs[self::LOG]) == 0);
78
        } else {
79
            return (isset(self::getInstance()->aLogs[$iStatus]) == false);
80
        }
81
    }
82
/**
83
 * returns selected kind of messages
84
 * @param type $iStatus  which messages
85
 * @param type $iRetvalType  return as string or array(default)
86
 * @return mixed  string|array
87
 */
88
    public static function getMessages($iStatus = self::ERROR, $iRetvalType = self::RETVAL_Array)
89
    {
90
        $aRetval = array();
91
        if ($iStatus == self::SHOW_ALL) {
92
            return self::getInstance()->aLogs[self::LOG];
93
        } else {
94
            if (isset(self::getInstance()->aLogs[$iStatus])) {
95
                foreach (self::getInstance()->aLogs[$iStatus] as $aItem) {
96
                    $aRetval[] = $aItem['msg'];
97
                }
98
            }
99
        }
100
        return ($iRetvalType == self::RETVAL_STRING ? implode("\n", $aRetval) : $aRetval);
101
    }
102
/**
103
 *
104
 * @param int $iType
105
 * @return mixed
106
 * @deprecated set deprecated since 2.8.4 and removed in next version
107
 */
108
    public static function getError($iType = self::RETVAL_STRING)
109
    {
110
        return self::getMessages(self::ERROR, $iType);
111
    }
112
/**
113
 *
114
 * @param int $iType
115
 * @return mixed
116
 * @deprecated set deprecated since 2.8.4 and removed in next version
117
 */
118
    public static function getSuccess($iType = self::RETVAL_STRING)
119
    {
120
        return self::getMessages(self::OK, $iType);
121
    }
31 122

  
32
	public static function add($message = '', $type = false)
33
	{
34
		if($type)
35
		{
36
			self::handle()->_success[] = $message;
37
		}else
38
		{
39
			self::handle()->_error[] = $message;
40
		}
41
	}
42

  
43
	public static function clear()
44
	{
45
		self::handle()->_error = array();
46
		self::handle()->_success = array();
47
	}
48

  
49
	public static function isEmpty()
50
	{
51
		return (sizeof(self::handle()->_success) == 0 && sizeof(self::handle()->_error) == 0 );
52
	}
53

  
54
	public static function getError($retval_type = self::RETVAL_STRING)
55
	{
56
		if(sizeof(self::handle()->_error))
57
		{
58
			if($retval_type == self::RETVAL_STRING)
59
			{
60
				return implode('<br />', self::handle()->_error);
61
			}else
62
			{
63
				return self::handle()->_error;
64
			}
65
		}
66
	}
67

  
68
	public static function getSuccess($retval_type = self::RETVAL_STRING)
69
	{
70
		if(sizeof(self::handle()->_success))
71
		{
72
			if($retval_type == self::RETVAL_STRING)
73
			{
74
				return implode('<br />', self::handle()->_success);
75
			}else
76
			{
77
				return self::handle()->_success;
78
			}
79
		}
80
	}
81

  
82

  
83
}
123
} // end of class msgQueue

Also available in: Unified diff