|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class EcommerceDashboardPanel extends DashboardPanel |
|
|
|
|
|
|
4
|
|
|
{ |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* @var bool Show the configure form after creating. Used for panels that require |
|
9
|
|
|
* configuration in order to show data |
|
10
|
|
|
*/ |
|
11
|
|
|
private static $configure_on_create = true; |
|
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
private static $db = array( |
|
|
|
|
|
|
15
|
|
|
'DaysBack' => 'Int' |
|
16
|
|
|
); |
|
17
|
|
|
|
|
18
|
|
|
private static $defaults = array( |
|
|
|
|
|
|
19
|
|
|
'DaysBack' => 7 |
|
20
|
|
|
); |
|
21
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
private static $icon = "ecommerce_dashboard/images/icons"; |
|
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
public function getLabel() |
|
26
|
|
|
{ |
|
27
|
|
|
return $this->getLabelPrefix(); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function getTitle() |
|
31
|
|
|
{ |
|
32
|
|
|
$str = $this->getLabelPrefix(); |
|
33
|
|
|
if ($this->DaysBack) { |
|
|
|
|
|
|
34
|
|
|
$str .= ' '.sprintf(_t('EcommerceDashboardPanel.IN_THE_LAST_XXX_DAYS', 'in the last %s days.'), $this->DaysBack); |
|
|
|
|
|
|
35
|
|
|
} |
|
36
|
|
|
return $str; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function getLabelPrefix() |
|
40
|
|
|
{ |
|
41
|
|
|
return 'please set in '.$this->ClassName; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function getConfiguration() |
|
45
|
|
|
{ |
|
46
|
|
|
$fields = parent::getConfiguration(); |
|
47
|
|
|
$fields->push(NumericField::create("DaysBack", "Number of days back")); |
|
48
|
|
|
$fields->replaceField('Title', ReadonlyField::create('Title', '')); |
|
49
|
|
|
|
|
50
|
|
|
return $fields; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* |
|
55
|
|
|
* |
|
56
|
|
|
* @return DataList |
|
57
|
|
|
*/ |
|
58
|
|
|
protected function openOrders($numberOfDaysBack = 7) |
|
|
|
|
|
|
59
|
|
|
{ |
|
60
|
|
|
$firstStep = DataObject::get_one('OrderStep'); |
|
61
|
|
|
$orders = Order::get() |
|
62
|
|
|
->LeftJoin('OrderStatusLog', '"Order"."ID" = "OrderStatusLog"."OrderID"') |
|
63
|
|
|
->LeftJoin($submittedOrderStatusLogClassName, '"OrderStatusLog"."ID" = "'.$submittedOrderStatusLogClassName.'"."ID"') |
|
|
|
|
|
|
64
|
|
|
->filter(array('StatusID' => $firstStep->ID)) |
|
65
|
|
|
->exclude(array('MemberID' => $this->excludedMembers())); |
|
|
|
|
|
|
66
|
|
|
|
|
67
|
|
|
return $orders; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* |
|
72
|
|
|
* |
|
73
|
|
|
* @return DataList |
|
74
|
|
|
*/ |
|
75
|
|
|
protected function submittedOrders($numberOfDaysBack = 0) |
|
76
|
|
|
{ |
|
77
|
|
|
$orders = Order::get_datalist_of_orders_with_submit_record(); |
|
78
|
|
|
$orders = $orders |
|
79
|
|
|
->exclude(array('MemberID' => $this->excludedMembersArray())) |
|
80
|
|
|
->where($this->daysBackWhereStatement($numberOfDaysBack)); |
|
81
|
|
|
|
|
82
|
|
|
return $orders; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* |
|
87
|
|
|
* |
|
88
|
|
|
* @return DataList |
|
89
|
|
|
*/ |
|
90
|
|
|
protected function archivedOrders($numberOfDaysBack = 0) |
|
91
|
|
|
{ |
|
92
|
|
|
$submittedOrderStatusLogClassName = EcommerceConfig::get('OrderStatusLog', 'order_status_log_class_used_for_submitting_order'); |
|
93
|
|
|
$lastStep = OrderStep::last_order_step(); |
|
94
|
|
|
return Order::get() |
|
95
|
|
|
->LeftJoin('OrderStatusLog', '"Order"."ID" = "OrderStatusLog"."OrderID"') |
|
96
|
|
|
->LeftJoin($submittedOrderStatusLogClassName, '"OrderStatusLog"."ID" = "'.$submittedOrderStatusLogClassName.'"."ID"') |
|
97
|
|
|
->filter(array('StatusID' => $lastStep->ID)) |
|
98
|
|
|
->exclude(array('MemberID' => $this->excludedMembersArray())) |
|
99
|
|
|
->where($this->daysBackWhereStatement($numberOfDaysBack)); |
|
100
|
|
|
return $orders; |
|
|
|
|
|
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
|
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* An accessor to the Dashboard controller |
|
107
|
|
|
* |
|
108
|
|
|
* @return Dashboard |
|
109
|
|
|
*/ |
|
110
|
|
|
public function getDashboard() |
|
111
|
|
|
{ |
|
112
|
|
|
return Injector::inst()->get("EcommerceDashboard"); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* |
|
117
|
|
|
* |
|
118
|
|
|
* @var array |
|
119
|
|
|
*/ |
|
120
|
|
|
private static $_excluded_members_array = array(); |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* |
|
124
|
|
|
* |
|
125
|
|
|
* @return array array of member IDs |
|
126
|
|
|
*/ |
|
127
|
|
|
protected function excludedMembersArray() |
|
128
|
|
|
{ |
|
129
|
|
|
if (! count(self::$_excluded_members_array)) { |
|
130
|
|
|
self::$_excluded_members_array = array(-1 => -1); |
|
131
|
|
|
$adminGroup = EcommerceRole::get_admin_group(); |
|
132
|
|
|
$assitantGroup = EcommerceRole::get_assistant_group(); |
|
133
|
|
|
if ($adminGroup) { |
|
134
|
|
|
foreach ($adminGroup->Members() as $member) { |
|
135
|
|
|
self::$_excluded_members_array[$member->ID] = $member->ID; |
|
136
|
|
|
} |
|
137
|
|
|
} |
|
138
|
|
|
if ($assitantGroup) { |
|
139
|
|
|
foreach ($assitantGroup->Members() as $member) { |
|
140
|
|
|
self::$_excluded_members_array[$member->ID] = $member->ID; |
|
141
|
|
|
} |
|
142
|
|
|
} |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
return self::$_excluded_members_array; |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* |
|
150
|
|
|
* |
|
151
|
|
|
* @return string where statement for orders that have been submitted. |
|
152
|
|
|
*/ |
|
153
|
|
|
protected function daysBackWhereStatement($daysBack = 0) |
|
154
|
|
|
{ |
|
155
|
|
|
if (! $daysBack) { |
|
156
|
|
|
$daysBack = $this->DaysBack ? $this->DaysBack : $this->Config()->defaults['DaysBack']; |
|
|
|
|
|
|
157
|
|
|
} |
|
158
|
|
|
return '"OrderStatusLog"."Created" > ( NOW() - INTERVAL '.($daysBack).' DAY )'; |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
/** |
|
162
|
|
|
* @var int The "weight" of the dashboard panel when listed in the available panels. |
|
163
|
|
|
* Higher is lower in the list. |
|
164
|
|
|
*/ |
|
165
|
|
|
//private static $priority = 100; |
|
|
|
|
|
|
166
|
|
|
|
|
167
|
|
|
|
|
168
|
|
|
|
|
169
|
|
|
/** |
|
170
|
|
|
* @var string The name of the template used for the contents of this panel. |
|
171
|
|
|
*/ |
|
172
|
|
|
//protected $template; |
|
173
|
|
|
|
|
174
|
|
|
public function maxOrdersForLoop() |
|
175
|
|
|
{ |
|
176
|
|
|
return 500; |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
|
|
180
|
|
|
/** |
|
181
|
|
|
* Allows the panel to be added |
|
182
|
|
|
* |
|
183
|
|
|
* @return string |
|
184
|
|
|
*/ |
|
185
|
|
|
public function registered() |
|
186
|
|
|
{ |
|
187
|
|
|
$enabled = Config::inst()->get($this->ClassName, 'enabled'); |
|
188
|
|
|
if (is_bool($enabled)) { |
|
189
|
|
|
return self::config()->enabled; |
|
190
|
|
|
} |
|
191
|
|
|
if (strtolower(self::config()->enabled) == 'no') { |
|
|
|
|
|
|
192
|
|
|
return false; |
|
193
|
|
|
} |
|
194
|
|
|
return true; |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
|
|
protected function CalculatedDaysBack() |
|
|
|
|
|
|
198
|
|
|
{ |
|
199
|
|
|
return $this->DaysBack ? : 7; |
|
|
|
|
|
|
200
|
|
|
} |
|
201
|
|
|
} |
|
202
|
|
|
|
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.