1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class CustomerGalleryPage extends Page |
|
|
|
|
4
|
|
|
{ |
5
|
|
|
private static $icon = 'mysite/images/treeicons/CustomerGalleryPage'; |
|
|
|
|
6
|
|
|
|
7
|
|
|
private static $description = 'Gallery of Customer Feedback and Images'; |
|
|
|
|
8
|
|
|
|
9
|
|
|
private static $can_be_root = false; |
|
|
|
|
10
|
|
|
|
11
|
|
|
private static $allow_children = 'none'; |
|
|
|
|
12
|
|
|
|
13
|
|
|
public function canCreate($member = null) |
14
|
|
|
{ |
15
|
|
|
return CustomerGalleryPage::get()->count() ? true : false; |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
public function getCMSFields() |
|
|
|
|
19
|
|
|
{ |
20
|
|
|
$fields = parent::getCMSFields(); |
21
|
|
|
$fields->removeByName('FolderID'); |
22
|
|
|
$fields->removeByName('Extensions'); |
23
|
|
|
return $fields; |
24
|
|
|
} |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
class CustomerGalleryPage_Controller extends Page_Controller |
|
|
|
|
28
|
|
|
{ |
29
|
|
|
private static $allowed_actions = array( |
|
|
|
|
30
|
|
|
"show", |
31
|
|
|
"Form" |
32
|
|
|
); |
33
|
|
|
|
34
|
|
|
protected $filter = '', $filterType = '', $filterValue = '', $join = ''; |
|
|
|
|
35
|
|
|
|
36
|
|
|
public function init() |
37
|
|
|
{ |
38
|
|
|
parent::init(); |
39
|
|
|
PrettyPhoto::include_code(); |
40
|
|
|
Requirements::javascript("mysite/javascript/MediaArticles.js"); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function PhotoUploadPage() |
|
|
|
|
44
|
|
|
{ |
45
|
|
|
return PhotoUploadPage::get()->First(); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
|
49
|
|
|
public function HasFilter() |
50
|
|
|
{ |
51
|
|
|
return $this->filter ? true : false; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function Location() |
55
|
|
|
{ |
56
|
|
|
$countries = DB::query("SELECT DISTINCT(\"PictureLocation\") FROM \"CustomerImage\" WHERE \"CustomerImage\".\"Status\" = 'Approved' ORDER BY \"PictureLocation\" ")->keyedColumn(); |
57
|
|
|
return $this->makeDos("location", $countries); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/* |
|
|
|
|
61
|
|
|
function MyPictures() { |
62
|
|
|
$mypictures = array(); |
63
|
|
|
$member = Member::currentUser(); |
64
|
|
|
if($member) { |
65
|
|
|
$dos = CustomerImage::get()->filter(array("Status" => 'Approved', "OwnerID" => $member->ID)); |
66
|
|
|
if($dos->count()) { |
67
|
|
|
foreach($dos as $do) { |
68
|
|
|
$mypictures[$member->ID] = "My pictures (".$dos->count().")"; |
69
|
|
|
} |
70
|
|
|
return $this->makeDos("mypictures", $mypictures); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
*/ |
75
|
|
|
|
76
|
|
|
public function Product() |
77
|
|
|
{ |
78
|
|
|
$stage = Versioned::current_stage(); |
79
|
|
|
$productTable = "SiteTree"; |
80
|
|
|
if ($stage) { |
81
|
|
|
$productTable .= "_".$stage; |
82
|
|
|
} |
83
|
|
|
$row = DB::query("SELECT DISTINCT(\"ProductPageID\") AS ProductPageID FROM \"CustomerImage\" INNER JOIN \"$productTable\" ON \"$productTable\".\"ID\" = \"CustomerImage\".\"ProductPageID\" WHERE \"CustomerImage\".\"Status\" = 'Approved' ORDER BY \"$productTable\".\"Title\""); |
84
|
|
|
$newArray = array(); |
85
|
|
|
foreach ($row as $dataArray) { |
86
|
|
|
$page = SiteTree::get()->byID($dataArray["ProductPageID"]); |
|
|
|
|
87
|
|
|
if ($page) { |
88
|
|
|
$key = $page->ID; |
89
|
|
|
$value = $page->Title; |
90
|
|
|
} |
91
|
|
|
$newArray[$key] = $value; |
|
|
|
|
92
|
|
|
} |
93
|
|
|
return $this->makeDos("product", $newArray); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function Years() |
97
|
|
|
{ |
98
|
|
|
$years = DB::query("SELECT DISTINCT(YEAR(\"Created\")) FROM \"CustomerImage\" INNER JOIN \"File\" ON \"File\".\"ID\" = \"CustomerImage\".\"ID\" WHERE \"CustomerImage\".\"Status\" = 'Approved' ORDER BY \"Created\" DESC")->keyedColumn(); |
99
|
|
|
return $this->makeDos("year", $years); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
protected function makeDos($title, $data) |
103
|
|
|
{ |
104
|
|
|
$dos = new ArrayList(); |
105
|
|
|
//sort($data); |
106
|
|
|
if ($data && count($data)) { |
107
|
|
|
foreach ($data as $key => $value) { |
108
|
|
|
if ($key && $value) { |
109
|
|
|
$key = urlencode(preg_replace("/[^a-zA-Z0-9\s]/", "", $key)); |
110
|
|
|
$do = new DataObject(); |
111
|
|
|
$do->Code = $key; |
112
|
|
|
$do->Name = $value; |
113
|
|
|
$do->LinkingMode = (($this->filterType == $title) && ($this->filterValue == $key)) ? "current" : "link"; |
114
|
|
|
$do->filter = (($this->filterType == $title) && ($this->filterValue == $key)) ? "alwaysfilter" : "filter"; |
115
|
|
|
$do->Link = $this->Link("show/$title/".$key."/"); |
116
|
|
|
$dos->push($do); |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
if ($dos->count()) { |
121
|
|
|
return $dos; |
122
|
|
|
} |
123
|
|
|
return null; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
|
127
|
|
|
public function Items($limit = 0) |
|
|
|
|
128
|
|
|
{ |
129
|
|
|
if ($this->SortBy == 'Title') { |
130
|
|
|
$sort = array("File.Title", "ASC"); |
131
|
|
|
} elseif ($this->SortBy == 'UploadDate ASC') { |
132
|
|
|
$sort = array("File.Created", "ASC"); |
133
|
|
|
} elseif ($this->SortBy == 'UploadDate DESC') { |
134
|
|
|
$sort = array("File.Created", "DESC"); |
135
|
|
|
} else { |
136
|
|
|
$sort = array(); |
137
|
|
|
} |
138
|
|
|
if ($this->filter) { |
139
|
|
|
$this->filter .= " AND "; |
140
|
|
|
} |
141
|
|
|
$this->filter .= "\"CustomerImage\".\"Status\" = 'Approved' "; |
142
|
|
|
return CustomerImage::get()->where($this->filter)->sort($sort)->limit($limit); |
|
|
|
|
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
|
146
|
|
|
|
147
|
|
|
public function Form() |
148
|
|
|
{ |
149
|
|
|
$fields = new FieldList( |
150
|
|
|
new TextField('Keyword', 'Keyword(s)', $this->value) |
151
|
|
|
//$date = new DateField('Date') |
|
|
|
|
152
|
|
|
); |
153
|
|
|
//$date->setConfig('showcalendar', true); |
|
|
|
|
154
|
|
|
$actions = new FieldList(new FormAction('search', 'Search')); |
|
|
|
|
155
|
|
|
return new Form($this, 'Form', $fields, $actions); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
|
159
|
|
|
public function search($data, $form) |
160
|
|
|
{ |
161
|
|
|
user_error("Not yet updated to 3.0"); |
162
|
|
|
$this->value = $data['Keyword']; |
163
|
|
|
$data = Convert::raw2sql($data); |
164
|
|
|
if ($data['Keyword']) { |
165
|
|
|
$stage = Versioned::current_stage(); |
166
|
|
|
$productTable = "SiteTree"; |
167
|
|
|
if ($stage) { |
168
|
|
|
$productTable .= "_".$stage; |
169
|
|
|
} |
170
|
|
|
$kwords = trim($data['Keyword']); |
171
|
|
|
$kwordsKWArray=split(" ", $kwords);//Breaking the string to array of words |
172
|
|
|
// Now let us generate the sql |
173
|
|
|
$kwordsFilter = array(); |
174
|
|
|
while (list($key, $val) = each($kwordsKWArray)) { |
|
|
|
|
175
|
|
|
$val = trim($val); |
176
|
|
|
if ($val<>" " and strlen($val) > 0) { |
|
|
|
|
177
|
|
|
$kwordsFilter[] = " \"Member\".\"ScreenName\" LIKE '%$val%' OR \"$productTable\".\"Title\" LIKE '%$val%' OR \"PictureLocation\" LIKE '%$val%' "; |
178
|
|
|
} |
179
|
|
|
} |
180
|
|
|
$this->filter = " (". implode(" AND ", $kwordsFilter).") "; |
181
|
|
|
$this->join .= " LEFT JOIN \"$productTable\" ON \"ProductPageID\" = \"$productTable\".\"ID\" " ; |
182
|
|
|
$this->join .= " INNER JOIN \"Member\" ON \"OwnerID\" = \"Member\".\"ID\" " ; |
183
|
|
|
} |
184
|
|
|
return array(); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
public function show($request) |
188
|
|
|
{ |
189
|
|
|
$action = $request->param("ID"); |
190
|
|
|
$value = Convert::raw2sql($request->param("OtherID")); |
191
|
|
|
switch ($action) { |
192
|
|
|
case "year": |
193
|
|
|
$where = "Year(\"File\".\"Created\") = '$value'"; |
194
|
|
|
break; |
195
|
|
|
case "location": |
196
|
|
|
$where = "\"PictureLocation\" = '$value'"; |
197
|
|
|
break; |
198
|
|
|
case "product": |
199
|
|
|
$where = "\"ProductPageID\" = '$value'"; |
200
|
|
|
break; |
201
|
|
|
case "mypictures": |
202
|
|
|
$where = "\"OwnerID\" = '$value'"; |
203
|
|
|
break; |
204
|
|
|
default: |
205
|
|
|
$where = ""; |
206
|
|
|
} |
207
|
|
|
$this->filter = $where; |
208
|
|
|
$this->filterType = $action; |
209
|
|
|
$this->filterValue = $value; |
210
|
|
|
return array(); |
211
|
|
|
} |
212
|
|
|
} |
213
|
|
|
|
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.