Quick Search:

View

Revision:

Diff

Diff from 1863 to:

Annotations

Annotate by Age | Author | Mixed | None
/fisheye/browse/osCommerce/branches/hpdl/oscommerce/includes/classes/message_stack.php

Annotated File View

hpdl
1
1 <?php
2 /*
mattice
151
3   $Id: message_stack.php 1863 2009-03-06 23:53:49Z hpdl $
hpdl
1
4
5   osCommerce, Open Source E-Commerce Solutions
6   http://www.oscommerce.com
7
hpdl
1863
8   Copyright (c) 2009 osCommerce
hpdl
1
9
hpdl
1498
10   This program is free software; you can redistribute it and/or modify
11   it under the terms of the GNU General Public License v2 (1991)
12   as published by the Free Software Foundation.
hpdl
1
13 */
14
hpdl
1863
15 /**
16  * The osC_MessageStack class manages information messages to be displayed.
17  * Messages that are shown are automatically removed from the stack.
18  */
hpdl
1
19
hpdl
1863
20   class osC_MessageStack {
21
22 /**
23  * A reference to the messages stored in the session messageToStack variable
24  *
25  * @var array
26  * @access private
27  */
28
29     private $_data = array();
30
31 /**
32  * Constructor, references the session data to the private $_data variable
33  *
34  * @access public
35  */
36
37     public function __construct() {
38       if ( !isset($_SESSION['messageToStack']) ) {
39         $_SESSION['messageToStack'] = array();
40       }
41
42       $this->_data =& $_SESSION['messageToStack'];
hpdl
1
43     }
44
hpdl
1863
45 /**
46  * Add a message to the stack
47  *
48  * @param string $group The group the message belongs to
49  * @param string $message The message information text
50  * @param string $type The type of message: error, warning, success
51  * @access public
52  */
53
54     public function add($group, $message, $type = 'error') {
55       $this->_data[$group][] = array('text' => $message,
56                                      'type' => $type);
hpdl
1
57     }
58
hpdl
1863
59 /**
60  * Reset the message stack
61  *
62  * @access public
63  */
hpdl
1
64
hpdl
1863
65     public function reset() {
66       $this->_data = array();
67     }
hpdl
1
68
hpdl
1863
69 /**
70  * Checks to see if a group in the stack contains messages
71  *
72  * @param string $group The name of the group to check
73  * @access public
74  */
hpdl
1
75
hpdl
1863
76     public function exists($group) {
77       return ( isset($this->_data[$group]) && !empty($this->_data[$group]) );
hpdl
1
78     }
79
hpdl
1863
80 /**
81  * Checks to see if the message stack contains messages
82  *
83  * @access public
84  */
85
86     public function hasContent() {
87       return !empty($this->_data);
hpdl
1
88     }
89
hpdl
1863
90 /**
91  * Get the messages belonging to a group. The messages are placed into an
92  * unsorted list wrapped in a DIV element with the "messageStack" style sheet
93  * class.
94  *
95  * @param string $group The name of the group to get the messages from
96  * @access public
97  */
98
99     public function get($group) {
100       $result = false;
101
102       if ( $this->exists($group) ) {
103         $result = '<div class="messageStack"><ul>';
104
105         foreach ( $this->_data[$group] as $message ) {
106           switch ( $message['type'] ) {
hpdl
1
107             case 'error':
hpdl
1863
108               $bullet_image = 'error.gif';
hpdl
1
109               break;
hpdl
1863
110
hpdl
1
111             case 'warning':
hpdl
1863
112               $bullet_image = 'warning.gif';
hpdl
1
113               break;
hpdl
1863
114
hpdl
1
115             case 'success':
hpdl
1863
116               $bullet_image = 'success.gif';
hpdl
1
117               break;
hpdl
1863
118
hpdl
1
119             default:
hpdl
1863
120               $bullet_image = 'bullet_default.gif';
hpdl
1
121           }
122
hpdl
1863
123           $result .= '<li style="list-style-image: url(\'' . DIR_WS_IMAGES . 'icons/' . $bullet_image . '\')">' . osc_output_string($message['text']) . '</li>';
hpdl
1
124         }
hpdl
1863
125
126         $result .= '</ul></div>';
127
128         unset($this->_data[$group]);
hpdl
1
129       }
130
hpdl
1863
131       return $result;
hpdl
1
132     }
133
hpdl
1863
134 /**
135  * Get the messages belonging to a group. The messages are separated by a new
136  * line character.
137  *
138  * @param string $group The name of the group to get the messages from
139  * @access public
140  */
hpdl
1
141
hpdl
1863
142     public function getRaw($group) {
143       $result = false;
144
145       if ( $this->exists($group) ) {
146         $result = '';
147
148         foreach ( $this->_data[$group] as $message ) {
149           $result .= osc_output_string($message['text']) . "\n";
hpdl
1
150         }
hpdl
1863
151
152         unset($this->_data[$group]);
hpdl
1
153       }
154
hpdl
1863
155       return $result;
hpdl
1
156     }
157
hpdl
1863
158 /**
159  * Get the message stack array data set
160  *
161  * @access public
162  */
hpdl
1
163
hpdl
1863
164     public function getAll() {
165       return $this->_data;
hpdl
1
166     }
167
hpdl
1863
168 /**
169  * Get the number of messages belonging to a group
170  *
171  * @param string $group The name of the group to check
172  * @access public
173  */
hpdl
1
174
hpdl
1863
175     public function size($group) {
176       $size = 0;
hpdl
1
177
hpdl
1863
178       if ( $this->exists($group) ) {
179         $size = sizeof($this->_data[$group]);
hpdl
1
180       }
hpdl
1863
181
182       return $size;
hpdl
1
183     }
184   }
185 ?>