|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @author Nicolaas [at] sunnysideup.co.nz |
|
5
|
|
|
* @package webportfolio |
|
6
|
|
|
* @sub-packages webportfolio |
|
7
|
|
|
* |
|
8
|
|
|
* |
|
9
|
|
|
* |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
class WebPortfolioPage extends Page |
|
|
|
|
|
|
13
|
|
|
{ |
|
14
|
|
|
private static $icon = "webportfolio/images/treeicons/WebPortfolioPage"; |
|
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
private static $db = array( |
|
|
|
|
|
|
17
|
|
|
'HighlightsOnly' => 'Boolean' |
|
18
|
|
|
); |
|
19
|
|
|
|
|
20
|
|
|
private static $has_one = array(); |
|
|
|
|
|
|
21
|
|
|
|
|
22
|
|
|
private static $many_many = array( |
|
|
|
|
|
|
23
|
|
|
"WebPortfolioItems" => "WebPortfolioItem" |
|
24
|
|
|
); |
|
25
|
|
|
|
|
26
|
|
|
public function getCMSFields() |
|
|
|
|
|
|
27
|
|
|
{ |
|
28
|
|
|
$fields = parent::getCMSFields(); |
|
29
|
|
|
$itemOptionSet = WebPortfolioItem::get(); |
|
30
|
|
|
$itemOptionSetMap = ($itemOptionSet->count()) ? $itemOptionSet->map('ID', 'Title')->toArray() : array(); |
|
31
|
|
|
$fields->addFieldsToTab( |
|
32
|
|
|
"Root.Portfolio", |
|
33
|
|
|
array( |
|
34
|
|
|
CheckboxField::create( |
|
35
|
|
|
'HighlightsOnly', |
|
36
|
|
|
'Highlights Only' |
|
37
|
|
|
), |
|
38
|
|
|
LiteralField::create("UpdatePortfolio", "<h3>Update Portfolio</h3>"), |
|
39
|
|
|
LiteralField::create("EditPortfolio", "<p><a href=\"/admin/webportfolio\" target=\"_blank\">edit portfolio</a></p>"), |
|
40
|
|
|
LiteralField::create("RefreshPortfolio", "<p><a href=\"".$this->Link("json/?flush=json")."\" target=\"_blank\">clear portfolio cache</a> (portfolio data is cached to increase loading speed)</p>"), |
|
41
|
|
|
CheckboxSetField::create( |
|
42
|
|
|
$name = "WebPortfolioItems", |
|
43
|
|
|
$title = "Items shown", |
|
44
|
|
|
$source = $itemOptionSetMap |
|
45
|
|
|
) |
|
46
|
|
|
) |
|
47
|
|
|
); |
|
48
|
|
|
return $fields; |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
class WebPortfolioPage_Controller extends Page_Controller |
|
|
|
|
|
|
53
|
|
|
{ |
|
54
|
|
|
private static $allowed_actions = array( |
|
|
|
|
|
|
55
|
|
|
"show" |
|
56
|
|
|
); |
|
57
|
|
|
|
|
58
|
|
View Code Duplication |
public function init() |
|
|
|
|
|
|
59
|
|
|
{ |
|
60
|
|
|
parent::init(); |
|
61
|
|
|
Requirements::javascript(THIRDPARTY_DIR."/jquery/jquery.js"); |
|
62
|
|
|
if (class_exists("PrettyPhoto")) { |
|
63
|
|
|
PrettyPhoto::include_code(); |
|
64
|
|
|
} else { |
|
65
|
|
|
user_error("It is recommended that you include the PrettyPhoto Module", E_USER_NOTICE); |
|
66
|
|
|
} |
|
67
|
|
|
Requirements::javascript("webportfolio/javascript/webportfolio.js"); |
|
68
|
|
|
Requirements::themedCSS("WebPortfolioPage", "webportfolio"); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
protected $IDArray = array(); |
|
72
|
|
|
protected $hasFilter = false; |
|
73
|
|
|
protected $currentCode = ""; |
|
74
|
|
|
protected $currentDescription = ""; |
|
75
|
|
|
|
|
76
|
|
|
public function index() |
|
77
|
|
|
{ |
|
78
|
|
|
if (!$this->HighlightsOnly) { |
|
79
|
|
|
$this->Title .= " - Favourites"; |
|
80
|
|
|
} |
|
81
|
|
|
return array(); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function show() |
|
85
|
|
|
{ |
|
86
|
|
|
$this->hasFilter = true; |
|
87
|
|
|
$code = Convert::raw2sql($this->request->param("ID")); |
|
88
|
|
|
if (is_numeric($code) && intval($code) > 0) { |
|
89
|
|
|
$this->currentCode = $code; |
|
|
|
|
|
|
90
|
|
|
$item = WebPortfolioItem::get()->byID(intval($code)); |
|
91
|
|
|
if ($item) { |
|
92
|
|
|
$this->IDArray = array($item->ID => $item->ID); |
|
93
|
|
|
$this->Title .= " - ".$item->getHeadLine(); |
|
94
|
|
|
$this->currentDescription = $item->Notes; |
|
95
|
|
|
} |
|
96
|
|
|
} elseif ($code) { |
|
97
|
|
|
$this->currentCode = $code; |
|
98
|
|
|
$obj = WebPortfolioWhatWeDidDescriptor::get()->filter(array("Code" => $code))->first(); |
|
99
|
|
|
$this->Title .= " - ".$obj->Name; |
|
100
|
|
|
if ($obj) { |
|
101
|
|
|
$this->currentDescription = $obj->Description; |
|
102
|
|
|
$components = $obj->getManyManyComponents('WebPortfolioItem'); |
|
103
|
|
|
if ($components && $components->count()) { |
|
104
|
|
|
$this->IDArray = $components->column("ID"); |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
return array(); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
public function SelectedWebPortfolioItems() |
|
|
|
|
|
|
112
|
|
|
{ |
|
113
|
|
|
if ($this->HighlightsOnly) { |
|
114
|
|
|
return $this->WebPortfolioItems() |
|
115
|
|
|
->sort(array("Favourites" => "DESC", "RAND()" => "ASC")); |
|
116
|
|
|
} |
|
117
|
|
|
if ($this->hasFilter) { |
|
|
|
|
|
|
118
|
|
|
} else { |
|
119
|
|
|
$components = $this->getManyManyComponents('WebPortfolioItems'); |
|
120
|
|
|
if ($components && $components->count()) { |
|
121
|
|
|
$this->IDArray = $components->column("ID"); |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
$reset = false; |
|
125
|
|
|
if (!$this->IDArray) { |
|
126
|
|
|
$reset = true; |
|
127
|
|
|
} elseif (!is_array($this->IDArray)) { |
|
128
|
|
|
$reset = true; |
|
129
|
|
|
} elseif (!count($this->IDArray)) { |
|
130
|
|
|
$reset = true; |
|
131
|
|
|
} |
|
132
|
|
|
if ($reset) { |
|
133
|
|
|
$this->IDArray = array(0 => 0); |
|
134
|
|
|
} |
|
135
|
|
|
$extraWhere = ""; |
|
136
|
|
|
if (!$this->hasFilter) { |
|
137
|
|
|
$extraWhere = " AND \"Favourites\" = 1"; |
|
138
|
|
|
} |
|
139
|
|
|
return WebPortfolioItem::get() |
|
140
|
|
|
->where("\"WebPortfolioItem\".\"ID\" IN (".implode(",", $this->IDArray).") AND \"WebPortfolioPage_WebPortfolioItems\".\"WebPortfolioPageID\" = ".$this->ID.$extraWhere) |
|
141
|
|
|
->sort(array("Favourites" => "DESC", "RAND()" => "ASC")) |
|
142
|
|
|
->innerJoin("WebPortfolioPage_WebPortfolioItems", "\"WebPortfolioPage_WebPortfolioItems\".\"WebPortfolioItemID\" = \"WebPortfolioItem\".\"ID\""); |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
public function HasFilter() |
|
146
|
|
|
{ |
|
147
|
|
|
return $this->hasFilter; |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
public function CurrentDescription() |
|
151
|
|
|
{ |
|
152
|
|
|
return $this->currentDescription; |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
public function FilterList() |
|
156
|
|
|
{ |
|
157
|
|
|
if ($this->HighlightsOnly) { |
|
158
|
|
|
return null; |
|
159
|
|
|
} |
|
160
|
|
|
$items = WebPortfolioWhatWeDidDescriptor::get() |
|
161
|
|
|
->innerJoin("WebPortfolioItem_WhatWeDid", " \"WebPortfolioItem_WhatWeDid\".\"WebPortfolioWhatWeDidDescriptorID\" = \"WebPortfolioWhatWeDidDescriptor\".\"ID\""); |
|
162
|
|
|
foreach ($items as $item) { |
|
163
|
|
|
if ($item->Code == $this->currentCode) { |
|
164
|
|
|
$item->LinkingMode = "current"; |
|
165
|
|
|
} else { |
|
166
|
|
|
$item->LinkingMode = "link"; |
|
167
|
|
|
} |
|
168
|
|
|
} |
|
169
|
|
|
return $items; |
|
170
|
|
|
} |
|
171
|
|
|
} |
|
172
|
|
|
|
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.