1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Class DMSSessionBackend represents a Session-storage DMSDocumentCart backend |
5
|
|
|
*/ |
6
|
|
|
class DMSSessionBackend extends Object implements DMSCartBackendInterface |
|
|
|
|
7
|
|
|
{ |
8
|
|
|
public function getItems() |
9
|
|
|
{ |
10
|
|
|
$items = Session::get('DMSDocumentCart.Items'); |
11
|
|
|
if ($items && is_array($items)) { |
12
|
|
|
foreach ($items as $itemID => $serialObj) { |
13
|
|
|
if ($serialObj == null) { |
14
|
|
|
unset($items[$itemID]); |
15
|
|
|
continue; |
16
|
|
|
} |
17
|
|
|
$items[$itemID] = unserialize($serialObj); |
18
|
|
|
} |
19
|
|
|
} |
20
|
|
|
return $items ? $items : array(); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function addItem(DMSRequestItem $item) |
24
|
|
|
{ |
25
|
|
|
if ($item->getDocument()) { |
26
|
|
|
Session::set("DMSDocumentCart.Items.{$item->getItemID()}", serialize($item)); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
return $this; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function removeItem(DMSRequestItem $item) |
33
|
|
|
{ |
34
|
|
|
Session::clear("DMSDocumentCart.Items.{$item->getItemID()}"); |
35
|
|
|
|
36
|
|
|
return $this; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function emptyCart() |
40
|
|
|
{ |
41
|
|
|
Session::clear('DMSDocumentCart'); |
42
|
|
|
|
43
|
|
|
return $this; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function setBackUrl($backURL) |
47
|
|
|
{ |
48
|
|
|
Session::set('DMSDocumentCart.BackURL', $backURL); |
49
|
|
|
|
50
|
|
|
return $this; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function getBackUrl() |
54
|
|
|
{ |
55
|
|
|
return Session::get('DMSDocumentCart.BackURL'); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function setReceiverInfo(array $receiverInfo = array()) |
59
|
|
|
{ |
60
|
|
|
Session::set('DMSDocumentCart.ReceiverInfo', serialize($receiverInfo)); |
61
|
|
|
|
62
|
|
|
return $this; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function getReceiverInfo() |
66
|
|
|
{ |
67
|
|
|
return unserialize(Session::get('DMSDocumentCart.ReceiverInfo')); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function getItem($id) |
71
|
|
|
{ |
72
|
|
|
$result = false; |
73
|
|
|
if ($items = $this->getItems()) { |
74
|
|
|
if (is_array($items) && array_key_exists($id, $items)) { |
75
|
|
|
$result = $items[$id]; |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
return $result; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function removeItemByID($itemID) |
83
|
|
|
{ |
84
|
|
|
Session::clear("DMSDocumentCart.Items.{$itemID}"); |
85
|
|
|
|
86
|
|
|
return $this; |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.