Project

General

Profile

1
<?php
2

    
3
/*
4
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
5
 *
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
 */
19

    
20
/**
21
 * msgQueue.php
22
 *
23
 * @category     Core
24
 * @package      Core_Helpers
25
 * @copyright    Manuela v.d.Decken <manuela@isteam.de>
26
 * @author       Manuela v.d.Decken <manuela@isteam.de>
27
 * @license      http://www.gnu.org/licenses/gpl.html   GPL License
28
 * @version      0.0.1
29
 * @revision     $Revision: 2131 $
30
 * @link         $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/framework/msgQueue.php $
31
 * @lastmodified $Date: 2015-06-23 13:38:43 +0200 (Tue, 23 Jun 2015) $
32
 * @since        File available since 09.05.2015
33
 * @description  provides a message queue to display system messages on each screens
34
 */
35
class msgQueue {
36

    
37
/** define type of retval */
38
    const RETVAL_ARRAY  = 0;
39
    const RETVAL_STRING = 1; // (default)
40
/** */
41
    const LOG      = 0;
42
    const ERROR    = 1; // (default)
43
    const SUCCESS  = 2;
44
    const OK       = 2;
45
    const WARN     = 4;
46
    const SHOW_ALL = 0;
47
    const ALL      = 0;
48
/**  */
49
    private static $_instance;
50
/**  */
51
    private $aLogs    = array();
52
/**
53
 * constructor
54
 */
55
    protected function __construct() {
56
        self::clear();
57
    }
58
/** disable cloning */
59
    private function __clone() { }
60
/**
61
 * get handle for active instance
62
 */
63
    public static function getInstance()
64
    {
65
        if (!isset(self::$_instance)) {
66
            $c = __CLASS__;
67
            self::$_instance = new $c;
68
        }
69
        return self::$_instance;
70
    }
71
/**
72
 * push new message in queue
73
 * @param string $sMessage
74
 * @param int $iStatus (default: self::FAIL)
75
 */
76
    public static function add($sMessage = '', $iStatus = self::ERROR)
77
    {
78
        $iStatus =
79
            ($iStatus === true ? self::OK : ($iStatus === false ? self::ERROR : $iStatus)) ?: self::ERROR;
80
        self::getInstance()->aLogs[self::LOG][] = array('status'=>self::WARN, 'msg'=>$sMessage);
81
        self::getInstance()->aLogs[$iStatus][]  = $sMessage;
82
    }
83
/**
84
 *
85
 * @param int $iStatus
86
 */
87
    public static function clear($iStatus = self::ALL)
88
    {
89
        if ($iStatus == self::ALL) {
90
            self::getInstance()->aLogs = array(
91
                self::ERROR   => array(),
92
                self::SUCCESS => array(),
93
                self::WARN    => array(),
94
                self::LOG     => array()
95
            );
96
        } else {
97
            if (isset(self::getInstance()->aLogs[$iStatus])) {
98
                self::getInstance()->aLogs[$iStatus] = array();
99
            }
100
        }
101
    }
102
/**
103
 *
104
 * @param int $iStatus (default: self::ALL)
105
 * @return bool
106
 */
107
    public static function isEmpty($iStatus = self::ALL)
108
    {
109
        if ($iStatus == self::ALL) {
110
            return (sizeof(self::getInstance()->aLogs[self::LOG]) == 0);
111
        } else {
112
            return (isset(self::getInstance()->aLogs[$iStatus]) == false);
113
        }
114
    }
115
/**
116
 * returns selected kind of messages
117
 * @param type $iStatus  which messages
118
 * @param type $iRetvalType  return as string or array(default)
119
 * @return mixed  string|array
120
 */
121
    public static function getMessages($iStatus = self::ERROR, $iRetvalType = self::RETVAL_Array)
122
    {
123
        $aRetval = array();
124
        if ($iStatus == self::SHOW_ALL) {
125
            return self::getInstance()->aLogs[self::LOG];
126
        } else {
127
            if (isset(self::getInstance()->aLogs[$iStatus])) {
128
                foreach (self::getInstance()->aLogs[$iStatus] as $aItem) {
129
                    $aRetval[] = $aItem['msg'];
130
                }
131
            }
132
        }
133
        return ($iRetvalType == self::RETVAL_STRING ? implode("\n", $aRetval) : $aRetval);
134
    }
135
/**
136
 *
137
 * @param int $iType
138
 * @return mixed
139
 * @deprecated set deprecated since 2.8.4 and removed in next version
140
 */
141
    public static function getError($iType = self::RETVAL_STRING)
142
    {
143
        return self::getMessages(self::ERROR, $iType);
144
    }
145
/**
146
 *
147
 * @param int $iType
148
 * @return mixed
149
 * @deprecated set deprecated since 2.8.4 and removed in next version
150
 */
151
    public static function getSuccess($iType = self::RETVAL_STRING)
152
    {
153
        return self::getMessages(self::OK, $iType);
154
    }
155

    
156
} // end of class msgQueue
(38-38/38)