|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class EcommerceDashboardPanel_FavouriteProducts extends EcommerceDashboardPanel |
|
|
|
|
|
|
4
|
|
|
{ |
|
5
|
|
|
private static $icon = "ecommerce_dashboard/images/icons/EcommerceDashboardPanel_FavouriteProducts.png"; |
|
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
private static $db = array( |
|
|
|
|
|
|
8
|
|
|
'NumberOfProducts' => 'Int' |
|
9
|
|
|
); |
|
10
|
|
|
|
|
11
|
|
|
private static $defaults = array( |
|
|
|
|
|
|
12
|
|
|
'NumberOfProducts' => 7 |
|
13
|
|
|
); |
|
14
|
|
|
|
|
15
|
|
|
public function getLabelPrefix() |
|
16
|
|
|
{ |
|
17
|
|
|
return 'Favourite sellers'; |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
public function getTitle() |
|
21
|
|
|
{ |
|
22
|
|
|
return parent::getTitle(); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public function getConfiguration() |
|
26
|
|
|
{ |
|
27
|
|
|
$fields = parent::getConfiguration(); |
|
28
|
|
|
$fields->push(NumericField::create('NumberOfProducts', 'Number of products to show')); |
|
29
|
|
|
return $fields; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function Content() |
|
33
|
|
|
{ |
|
34
|
|
|
$submittedOrders = $this->submittedOrders(); |
|
35
|
|
|
$html = ' |
|
36
|
|
|
<ul>'; |
|
37
|
|
|
$buyableArray = array(); |
|
38
|
|
|
$count = $submittedOrders->count(); |
|
39
|
|
|
if ($count < $this->maxOrdersForLoop() && $count > 0) { |
|
40
|
|
|
foreach ($submittedOrders as $order) { |
|
41
|
|
|
foreach ($order->Items() as $item) { |
|
42
|
|
|
$key = $item->BuyableClassName.".".$item->BuyableID; |
|
43
|
|
|
if (! isset($buyableArray[$key])) { |
|
44
|
|
|
$buyableArray[$key] = 0; |
|
45
|
|
|
} |
|
46
|
|
|
$buyableArray[$key]++; |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
arsort($buyableArray, SORT_NUMERIC); |
|
50
|
|
|
for ($i = 0; $i < $this->NumberOfProducts; $i++) { |
|
|
|
|
|
|
51
|
|
|
$oneRow = array_slice($buyableArray, $i, 1); |
|
52
|
|
|
foreach ($oneRow as $key => $count) { |
|
53
|
|
|
list($className, $id) = explode('.', $key); |
|
54
|
|
|
$buyable = $className::get()->byID($id); |
|
55
|
|
|
if ($buyable) { |
|
56
|
|
|
$html .= '<li class="pos'.$i.'"><span><strong>'.$count.'</strong> × </span><a href="'.$buyable->Link().'">'.$buyable->FullName.'</a></li>'; |
|
57
|
|
|
} else { |
|
58
|
|
|
$html .= '<li class="pos'.$i.'">Error with '.$key.'</li>'; |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
} elseif ($count >= $this->maxOrdersForLoop()) { |
|
63
|
|
|
$html .= ' |
|
64
|
|
|
<li>There are too many orders to work out the favourite products, please reduce the time period.</li>'; |
|
65
|
|
|
} else { |
|
66
|
|
|
$html .= ' |
|
67
|
|
|
<li>There are no favourite sellers.</li>'; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
$html .= ' |
|
72
|
|
|
</ul>'; |
|
73
|
|
|
|
|
74
|
|
|
return $html; |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
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.