1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @author Nicolaas [at] sunnysideup.co.nz |
5
|
|
|
* |
6
|
|
|
* |
7
|
|
|
* |
8
|
|
|
* |
9
|
|
|
* |
10
|
|
|
* |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
class WebPortfolioItem extends DataObject |
|
|
|
|
14
|
|
|
{ |
15
|
|
|
private static $db = array( |
|
|
|
|
16
|
|
|
"WebAddress" => "Varchar(255)", |
17
|
|
|
"NoLongerActive" => "Boolean", |
18
|
|
|
"NotPubliclyAvailable" => "Boolean", |
19
|
|
|
"Favourites" => "Boolean", |
20
|
|
|
"Notes" => "Varchar(255)", |
21
|
|
|
"Client" => "Varchar(255)", |
22
|
|
|
"Design" => "Varchar(255)", |
23
|
|
|
"CodingFrontEnd" => "Varchar(255)", |
24
|
|
|
"CodingBackEnd" => "Varchar(255)", |
25
|
|
|
"Copy" => "Varchar(255)", |
26
|
|
|
"Photography" => "Varchar(255)", |
27
|
|
|
"ScreenshotTaken" => "Date", |
28
|
|
|
"StartDate" => "Date", |
29
|
|
|
"EndDate" => "Date" |
30
|
|
|
); |
31
|
|
|
|
32
|
|
|
private static $has_one = array( |
|
|
|
|
33
|
|
|
"Agent" => "WebPortfolioAgent", |
34
|
|
|
"Screenshot" => "Image", |
35
|
|
|
); |
36
|
|
|
|
37
|
|
|
private static $many_many = array( |
|
|
|
|
38
|
|
|
"WhatWeDid" => "WebPortfolioWhatWeDidDescriptor", |
39
|
|
|
); |
40
|
|
|
|
41
|
|
|
private static $belongs_many_many = array( |
|
|
|
|
42
|
|
|
"WhatWeDid" => "WebPortfolioWhatWeDidDescriptor", |
43
|
|
|
); |
44
|
|
|
|
45
|
|
|
private static $defaults = array( |
|
|
|
|
46
|
|
|
"WebAddress" => "http", |
47
|
|
|
"NoLongerActive" => false, |
48
|
|
|
"Favourites" => false |
49
|
|
|
); |
50
|
|
|
|
51
|
|
|
private static $default_sort = "Favourites DESC, Created DESC"; |
|
|
|
|
52
|
|
|
|
53
|
|
|
private static $searchable_fields = array( |
|
|
|
|
54
|
|
|
"WebAddress", |
55
|
|
|
"Client", |
56
|
|
|
"NoLongerActive", |
57
|
|
|
"NotPubliclyAvailable", |
58
|
|
|
"Favourites", |
59
|
|
|
"Agent.Name" |
60
|
|
|
); |
61
|
|
|
|
62
|
|
|
private static $summary_fields = array( |
|
|
|
|
63
|
|
|
"WebAddress", |
64
|
|
|
"Client", |
65
|
|
|
"Thumbnail" |
66
|
|
|
); |
67
|
|
|
|
68
|
|
|
private static $casting = array( |
|
|
|
|
69
|
|
|
"Title" => "Varchar", |
70
|
|
|
"Thumbnail" => "HTMLText", |
71
|
|
|
"HeadLine" => "Varchar" |
72
|
|
|
); |
73
|
|
|
|
74
|
|
|
private static $singular_name = "Item"; |
|
|
|
|
75
|
|
|
|
76
|
|
|
private static $plural_name = "Items"; |
|
|
|
|
77
|
|
|
|
78
|
|
|
|
79
|
|
|
public function getCMSFields() |
80
|
|
|
{ |
81
|
|
|
$fields = parent::getCMSFields(); |
82
|
|
|
$dos = WebPortfolioWhatWeDidDescriptor::get(); |
83
|
|
|
if ($dos->count() && $this->ID) { |
84
|
|
|
$dosArray = $dos->map()->toArray(); |
85
|
|
|
$fields->addFieldsToTab( |
86
|
|
|
"Root.WhatWeDid", |
87
|
|
|
array( |
88
|
|
|
new CheckboxSetField("WhatWeDid", "Select work done", $dosArray), |
89
|
|
|
new TextField("AddWhatWeDid", "Add a job") |
90
|
|
|
) |
91
|
|
|
); |
92
|
|
|
} |
93
|
|
|
if (class_exists("DataObjectOneFieldUpdateController")) { |
94
|
|
|
$editableFields = array_keys($this->Config()->get("db")); |
95
|
|
|
foreach ($editableFields as $editableField) { |
96
|
|
|
$link = DataObjectOneFieldUpdateController::popup_link( |
97
|
|
|
$ClassName = $this->ClassName, |
98
|
|
|
$FieldName = $editableField, |
99
|
|
|
$where = '', |
100
|
|
|
$sort = '"'.$editableField.'" DESC', |
101
|
|
|
$linkText = $editableField |
102
|
|
|
); |
103
|
|
|
$fields->addFieldToTab("Root.QuickEdits", new LiteralField("QuickEdit".$editableField, "<h2>".$link."</h2>")); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
return $fields; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
public function getHeadLine() |
|
|
|
|
110
|
|
|
{ |
111
|
|
|
$searchArray = array( |
112
|
|
|
"https://www.", |
113
|
|
|
"http://www.", |
114
|
|
|
"https://", |
115
|
|
|
"http://", |
116
|
|
|
"." |
117
|
|
|
); |
118
|
|
|
$replaceArray = array( |
119
|
|
|
"", |
120
|
|
|
"", |
121
|
|
|
"", |
122
|
|
|
"", |
123
|
|
|
" . " |
124
|
|
|
); |
125
|
|
|
return str_replace($searchArray, $replaceArray, $this->WebAddress); |
|
|
|
|
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
protected $newWhatWeDid = null; |
129
|
|
|
|
130
|
|
|
public function onAfterWrite() |
|
|
|
|
131
|
|
|
{ |
132
|
|
|
parent::onAfterWrite(); |
133
|
|
|
if ($this->newWhatWeDid) { |
134
|
|
|
$this->newWhatWeDid->WebPortfolioItem()->add($this); |
135
|
|
|
$this->WhatWeDid()->add($this->newWhatWeDid); |
|
|
|
|
136
|
|
|
} |
137
|
|
|
if (isset($_REQUEST["AddWhatWeDid"])) { |
138
|
|
|
unset($_REQUEST["AddWhatWeDid"]); |
139
|
|
|
} |
140
|
|
|
$this->newWhatWeDid = null; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
public function onBeforeWrite() |
|
|
|
|
144
|
|
|
{ |
145
|
|
|
parent::onBeforeWrite(); |
146
|
|
|
if (isset($_REQUEST["AddWhatWeDid"])) { |
147
|
|
|
$name = Convert::raw2sql($_REQUEST["AddWhatWeDid"]); |
148
|
|
|
if ($name) { |
149
|
|
|
$this->newWhatWeDid = WebPortfolioWhatWeDidDescriptor::get() |
150
|
|
|
->filter(array("Name" => $name))->first(); |
151
|
|
|
if (!$this->newWhatWeDid) { |
152
|
|
|
$this->newWhatWeDid = new WebPortfolioWhatWeDidDescriptor(); |
153
|
|
|
$this->newWhatWeDid->Name = $name; |
|
|
|
|
154
|
|
|
$this->newWhatWeDid->write(); |
155
|
|
|
//TO DO - does not work!!! |
156
|
|
|
} |
157
|
|
|
} |
158
|
|
|
} |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
public function Title() |
|
|
|
|
162
|
|
|
{ |
163
|
|
|
return $this->getTitle(); |
164
|
|
|
} |
165
|
|
|
public function getTitle() |
|
|
|
|
166
|
|
|
{ |
167
|
|
|
return $this->WebAddress; |
|
|
|
|
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
|
171
|
|
|
public function Link() |
|
|
|
|
172
|
|
|
{ |
173
|
|
|
$link = ""; |
174
|
|
|
$page = WebPortfolioPage::get()->first(); |
175
|
|
|
if ($page) { |
176
|
|
|
$link = $page->Link("show/".$this->ID."/"); |
177
|
|
|
} elseif ($this->ScreenshotID) { |
|
|
|
|
178
|
|
|
if ($screenshot = $this->Screenshot()) { |
|
|
|
|
179
|
|
|
$link = $screenshot->Link(); |
180
|
|
|
} |
181
|
|
|
} |
182
|
|
|
return $link; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
public function getThumbnail() |
|
|
|
|
186
|
|
|
{ |
187
|
|
|
return $this->Thumbnail(); |
188
|
|
|
} |
189
|
|
|
public function Thumbnail() |
|
|
|
|
190
|
|
|
{ |
191
|
|
|
if ($this->ScreenshotID) { |
|
|
|
|
192
|
|
|
if ($image = $this->Screenshot()) { |
|
|
|
|
193
|
|
|
if ($image->exists()) { |
194
|
|
|
return $image->CroppedImage(100, 100); |
195
|
|
|
} |
196
|
|
|
} |
197
|
|
|
return "image can not be found"; |
198
|
|
|
} |
199
|
|
|
return "no image"; |
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.