1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Nexcess.net Turpentine Extension for Magento |
5
|
|
|
* Copyright (C) 2012 Nexcess.net L.L.C. |
6
|
|
|
* |
7
|
|
|
* This program is free software; you can redistribute it and/or modify |
8
|
|
|
* it under the terms of the GNU General Public License as published by |
9
|
|
|
* the Free Software Foundation; either version 2 of the License, or |
10
|
|
|
* (at your option) any later version. |
11
|
|
|
* |
12
|
|
|
* This program is distributed in the hope that it will be useful, |
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15
|
|
|
* GNU General Public License for more details. |
16
|
|
|
* |
17
|
|
|
* You should have received a copy of the GNU General Public License along |
18
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc., |
19
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
class Nexcessnet_Turpentine_Model_Session extends Mage_Core_Model_Session_Abstract { |
23
|
|
|
protected $_namespace = 'turpentine'; |
24
|
|
|
|
25
|
|
|
public function __construct($data = array()) { |
26
|
|
|
$sessionName = isset($data['name']) ? $data['name'] : null; |
27
|
|
|
$this->init($this->_namespace, $sessionName); |
28
|
|
|
Mage::dispatchEvent( |
29
|
|
|
sprintf('%s_session_init', $this->_namespace), |
30
|
|
|
array(sprintf('%s_session', $this->_namespace) => $this) ); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Save the messages for a given block to the session |
35
|
|
|
* |
36
|
|
|
* @param string $blockName |
37
|
|
|
* @param array $messages |
38
|
|
|
* @return null |
39
|
|
|
*/ |
40
|
|
|
public function saveMessages($blockName, $messages) { |
41
|
|
|
$allMessages = $this->getMessages(); |
42
|
|
|
$allMessages[$blockName] = array_merge( |
43
|
|
|
$this->loadMessages($blockName), $messages ); |
44
|
|
|
$this->setMessages($allMessages); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Retrieve the messages for a given messages block |
49
|
|
|
* |
50
|
|
|
* @param string $blockName |
51
|
|
|
* @return array |
52
|
|
|
*/ |
53
|
|
|
public function loadMessages($blockName) { |
54
|
|
|
$messages = $this->getMessages(); |
55
|
|
|
if (is_array(@$messages[$blockName])) { |
56
|
|
|
return $messages[$blockName]; |
57
|
|
|
} else { |
58
|
|
|
return array(); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Clear the messages stored for a block |
64
|
|
|
* |
65
|
|
|
* @param string $blockName |
66
|
|
|
* @return null |
67
|
|
|
*/ |
68
|
|
|
public function clearMessages($blockName) { |
69
|
|
|
$messages = $this->getMessages(); |
70
|
|
|
unset($messages[$blockName]); |
71
|
|
|
$this->setMessages($messages); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Retrieve the stored messages |
76
|
|
|
* |
77
|
|
|
* @return array |
78
|
|
|
*/ |
79
|
|
|
public function getMessages($clear = false) { |
80
|
|
|
$messages = $this->getData('messages'); |
81
|
|
|
if ( ! is_array($messages)) { |
82
|
|
|
$messages = array(); |
83
|
|
|
} |
84
|
|
|
return $messages; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Store messages |
89
|
|
|
* |
90
|
|
|
* @param array $messages |
91
|
|
|
*/ |
92
|
|
|
public function setMessages($messages) { |
93
|
|
|
$this->setData('messages', $messages); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|