|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
*@author nicolaas [at] sunnysideup.co.nz |
|
5
|
|
|
* |
|
6
|
|
|
* |
|
7
|
|
|
**/ |
|
8
|
|
|
|
|
9
|
|
|
class AdvertisementDecorator extends SiteTreeExtension |
|
|
|
|
|
|
10
|
|
|
{ |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* load an alternative collection of JS file to power your |
|
14
|
|
|
* slideslow |
|
15
|
|
|
* see yml files for example |
|
16
|
|
|
* @var Array |
|
17
|
|
|
*/ |
|
18
|
|
|
private static $alternative_javascript_file_array = array(); |
|
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* load an alternative collection of JS file to power your |
|
22
|
|
|
* slideslow |
|
23
|
|
|
* see yml files for example |
|
24
|
|
|
* @var Array |
|
25
|
|
|
*/ |
|
26
|
|
|
private static $add_advertisements_shown_on_no_pages_to_all_pages = true; |
|
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
public static function add_requirements($alternativeFileLocation = null) |
|
29
|
|
|
{ |
|
30
|
|
|
Requirements::javascript(THIRDPARTY_DIR."/jquery/jquery.js"); |
|
31
|
|
|
$jsFileArray = Config::inst()->get("AdvertisementDecorator", "alternative_javascript_file_array"); |
|
32
|
|
|
|
|
33
|
|
|
if (count($jsFileArray)) { |
|
34
|
|
|
foreach ($jsFileArray as $file) { |
|
|
|
|
|
|
35
|
|
|
Requirements::javascript($file); |
|
36
|
|
|
} |
|
37
|
|
|
} else { |
|
38
|
|
|
Requirements::javascript("advertisements/javascript/Advertisements.js"); |
|
39
|
|
|
$file = ""; |
|
40
|
|
|
$customJavascript = Config::inst()->get("AdvertisementDecorator", "use_custom_javascript"); |
|
41
|
|
|
if ($customJavascript == 1) { |
|
42
|
|
|
$file = project()."/javascript/AdvertisementsExecutive.js"; |
|
43
|
|
|
} elseif ($alternativeFileLocation) { |
|
44
|
|
|
$file = $alternativeFileLocation; |
|
45
|
|
|
} |
|
46
|
|
|
if (!$file) { |
|
47
|
|
|
$file = "advertisements/javascript/AdvertisementsExecutive.js"; |
|
48
|
|
|
} |
|
49
|
|
|
Requirements::javascript($file); |
|
50
|
|
|
Requirements::themedCSS("Advertisements", "advertisements"); |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
private static $db = array( |
|
|
|
|
|
|
55
|
|
|
"UseParentAdvertisements" => "Boolean" |
|
56
|
|
|
); |
|
57
|
|
|
|
|
58
|
|
|
private static $has_one = array( |
|
|
|
|
|
|
59
|
|
|
"AdvertisementsFolder" => "Folder", |
|
60
|
|
|
"AdvertisementStyle" => "AdvertisementStyle" |
|
61
|
|
|
); |
|
62
|
|
|
|
|
63
|
|
|
private static $many_many = array( |
|
|
|
|
|
|
64
|
|
|
"Advertisements" => "Advertisement" |
|
65
|
|
|
); |
|
66
|
|
|
|
|
67
|
|
|
private static $use_custom_javascript = false; |
|
|
|
|
|
|
68
|
|
|
|
|
69
|
|
|
private static $page_classes_without_advertisements = array(); |
|
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
private static $specific_name_for_advertisements = "Advertisements"; |
|
|
|
|
|
|
72
|
|
|
|
|
73
|
|
|
private static $page_classes_with_advertisements = array(); |
|
|
|
|
|
|
74
|
|
|
|
|
75
|
|
|
private static $advertisements_dos = null; |
|
|
|
|
|
|
76
|
|
|
|
|
77
|
|
|
public function updateCMSFields(FieldList $fields) |
|
78
|
|
|
{ |
|
79
|
|
|
if ($this->classHasAdvertisements($this->owner->ClassName) && $this->owner->exists()) { |
|
|
|
|
|
|
80
|
|
|
$tabName = $this->MyTabName(); |
|
81
|
|
|
//advertisements shown... |
|
82
|
|
|
$where = '1 = 1'; |
|
83
|
|
|
if ($this->owner->AdvertisementsFolderID) { |
|
84
|
|
|
$images = Image::get()->filter("ParentID", $this->owner->AdvertisementsFolderID); |
|
|
|
|
|
|
85
|
|
|
if ($images->count()) { |
|
86
|
|
|
$where = "\"AdvertisementImageID\" IN (".implode(",", $images->column("ID")).")"; |
|
87
|
|
|
} else { |
|
88
|
|
|
$where = " 1 = 2"; |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
$source = Advertisement::get(); |
|
93
|
|
|
if ($source && $source->count()) { |
|
94
|
|
|
$newSource = []; |
|
95
|
|
|
foreach ($source as $ad) { |
|
96
|
|
|
$newSource[$ad->ID] = $ad->getFullTitle('width: 75px!important;'); |
|
97
|
|
|
} |
|
98
|
|
|
$fields->addFieldToTab($tabName, CheckboxSetField::create( |
|
99
|
|
|
'Advertisements', |
|
100
|
|
|
'Select '.Config::inst()->get("Advertisement", "plural_name"), |
|
101
|
|
|
$newSource |
|
102
|
|
|
)); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
//$advertisementsCount = DB::query("SELECT COUNT(ID) FROM \"Advertisement\" $whereDB ;")->value(); |
|
|
|
|
|
|
106
|
|
|
$advertisements = $this->owner->Advertisements()->where($where); |
|
107
|
|
|
$txt = sprintf(_t("AdvertisementDecorator.ACTUAL", 'Current %1$s Shown'), Config::inst()->get("Advertisement", "plural_name")); |
|
108
|
|
|
$fields->addFieldToTab($tabName, $this->MyHeaderField($txt)); |
|
109
|
|
|
$txt = sprintf(_t("AdvertisementDecorator.SELECT", 'Select %1$s to show ... '), Config::inst()->get("Advertisement", "plural_name")); |
|
110
|
|
|
$advertisementsGridField = new GridField('AdvertisementsList', $txt, $this->owner->Advertisements(), GridFieldConfig_RelationEditor::create()); |
|
111
|
|
|
$fields->addFieldToTab($tabName, $advertisementsGridField); |
|
112
|
|
|
if (Config::inst()->get("Advertisement", "resize_images") == 'no') { |
|
113
|
|
|
$totalSize = 0; |
|
114
|
|
|
foreach ($this->owner->Advertisements() as $advertisement) { |
|
115
|
|
|
$totalSize += $advertisement->AdvertisementImage()->getAbsoluteSize(); |
|
116
|
|
|
} |
|
117
|
|
|
$seconds = round(($totalSize + 1) / 524288) ; |
|
118
|
|
|
$fields->addFieldToTab($tabName, new LiteralField("TotalSize", '<p><em>Total download size: '.File::format_size($totalSize).', good reception 3G network download time less than ~'.($seconds+1).' seconds.</em></p>')); |
|
119
|
|
|
} |
|
120
|
|
|
if (class_exists("DataObjectSorterController")) { |
|
121
|
|
|
$shownAdvertisements = $this->owner->getManyManyComponents('Advertisements'); |
|
122
|
|
|
if ($shownAdvertisements) { |
|
123
|
|
|
$array = $shownAdvertisements->column("ID"); |
|
124
|
|
|
$idString = implode(",", $array); |
|
125
|
|
|
$link = DataObjectSorterController::popup_link("Advertisement", $filterField = "ID", $filterValue = $idString, $linkText = "sort ".Config::inst()->get("Advertisement", "plural_name"), $titleField = "FullTitle"); |
|
126
|
|
|
$fields->addFieldToTab($tabName, new LiteralField("AdvertisementsSorter", $link)); |
|
127
|
|
|
} |
|
128
|
|
|
} |
|
129
|
|
|
if ($advertisements->count()) { |
|
|
|
|
|
|
130
|
|
|
} else { |
|
131
|
|
|
$txt = sprintf( |
|
132
|
|
|
_t("AdvertisementDecorator.CREATE", '<p>Please <a href="admin/%1$s/">create %2$s</a> on the <a href="admin/%1$s/">%3$s tab</a> first, or see below on how to create %2$s from a folder.</p>'), |
|
133
|
|
|
Config::inst()->get("AdvertisementAdmin", "url_segment"), |
|
134
|
|
|
Config::inst()->get("Advertisement", "plural_name"), |
|
135
|
|
|
Config::inst()->get("AdvertisementAdmin", "menu_title") |
|
136
|
|
|
); |
|
137
|
|
|
$fields->addFieldToTab($tabName, new LiteralField("AdvertisementsHowToCreate", $txt)); |
|
138
|
|
|
} |
|
139
|
|
|
if ($parent = $this->advertisementParent()) { |
|
140
|
|
|
$txt = sprintf(_t("AdvertisementDecorator.ORUSE", 'OR ... use %1$s from <i>%2$s</i>.'), Config::inst()->get("Advertisement", "plural_name"), $parent->Title); |
|
141
|
|
|
$fields->addFieldToTab($tabName, new CheckboxField("UseParentAdvertisements", $txt)); |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
|
|
145
|
|
|
$txt = _t('AdvertisementDecorator.ADVANCED', 'Advanced'); |
|
146
|
|
|
$fields->addFieldToTab($tabName, $this->MyHeaderFieldLarge($txt)); |
|
147
|
|
|
|
|
148
|
|
|
//create new advertisements |
|
149
|
|
|
$txt = sprintf(_t("AdvertisementDecorator.CREATE", 'Create new %1$s'), Config::inst()->get("Advertisement", "plural_name")); |
|
150
|
|
|
$fields->addFieldToTab($tabName, $this->MyHeaderField($txt)); |
|
151
|
|
|
$txt = sprintf( |
|
152
|
|
|
_t( |
|
153
|
|
|
"AdvertisementDecorator.CREATENEWFROMFOLDER_EXPLANATION", |
|
154
|
|
|
'Create New %1$s from images in the folder selected - each image in the folder will be used to create a %3$s. %2$s' |
|
155
|
|
|
), |
|
156
|
|
|
Config::inst()->get("Advertisement", "plural_name"), |
|
157
|
|
|
Advertisement::recommended_image_size_statement(), |
|
158
|
|
|
Config::inst()->get("Advertisement", "singular_name") |
|
159
|
|
|
); |
|
160
|
|
|
if (Folder::get()->count()) { |
|
161
|
|
|
$fields->addFieldToTab( |
|
162
|
|
|
$tabName, |
|
163
|
|
|
$treeDropdownField = new TreeDropdownField( |
|
164
|
|
|
'AdvertisementsFolderID', |
|
165
|
|
|
_t("AdvertisementDecorator.CREATENEWFROMFOLDER", "Create from folder"), |
|
166
|
|
|
'Folder' |
|
167
|
|
|
) |
|
168
|
|
|
); |
|
169
|
|
|
$treeDropdownField->setRightTitle($txt); |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
$styles = AdvertisementStyle::get(); |
|
173
|
|
|
if ($styles->count()) { |
|
174
|
|
|
$fields->addFieldToTab($tabName, $this->MyHeaderField("Style")); |
|
175
|
|
|
$list = $styles->map("ID", "Title", $emptyString = _t("AdvertisementDecorator.SELECTSTYLE", "--select style--"), $sortByTitle = true); |
|
|
|
|
|
|
176
|
|
|
$fields->addFieldToTab( |
|
177
|
|
|
$tabName, |
|
178
|
|
|
$selectStyleField = new DropdownField( |
|
179
|
|
|
"AdvertisementStyleID", |
|
180
|
|
|
_t("AdvertisementDecorator.STYLECREATED", "Select style"), |
|
181
|
|
|
$list |
|
182
|
|
|
) |
|
183
|
|
|
); |
|
184
|
|
|
$selectStyleField->setRightTitle(_t("AdvertisementDecorator.STYLECREATED_EXPLANATION", "Styles are created by your developer")); |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
|
|
188
|
|
|
$txt = sprintf(_t("AdvertisementDecorator.EDIT", 'Edit %1$s'), Config::inst()->get("Advertisement", "plural_name")); |
|
|
|
|
|
|
189
|
|
|
$txt = sprintf( |
|
190
|
|
|
_t("AdvertisementDecorator.PLEASEMANAGEEXISTING", '<p>Please manage existing %1$s on the <a href="admin/%2$s/">%3$s tab</a>.</p>'), |
|
191
|
|
|
Config::inst()->get("Advertisement", "plural_name"), |
|
192
|
|
|
Config::inst()->get("AdvertisementAdmin", "url_segment"), |
|
193
|
|
|
Config::inst()->get("AdvertisementAdmin", "menu_title") |
|
194
|
|
|
); |
|
195
|
|
|
$fields->addFieldToTab($tabName, new LiteralField("ManageAdvertisements", $txt)); |
|
196
|
|
|
$txt = sprintf(_t("AdvertisementDecorator.DELETE", 'Delete %1$s'), Config::inst()->get("Advertisement", "plural_name")); |
|
197
|
|
|
$fields->addFieldToTab($tabName, $this->MyHeaderField($txt)); |
|
198
|
|
|
$page = SiteTree::get()->byID($this->owner->ID); |
|
|
|
|
|
|
199
|
|
|
|
|
200
|
|
|
$txtRemove = sprintf(_t("AdvertisementDecorator.REMOVE", 'Remove all %1$s from this page (%1$s will not be deleted but are not longer associated with this page)'), Config::inst()->get("Advertisement", "plural_name")); |
|
201
|
|
|
$txtConfirmRemove = sprintf(_t("AdvertisementDecorator.CONFIRMREMOVE", 'Are you sure you want to remove all %1$s from this page?'), Config::inst()->get("Advertisement", "plural_name")); |
|
202
|
|
|
$removeallLink = 'advertisements/removealladvertisements/'.$this->owner->ID.'/'; |
|
203
|
|
|
$jquery = 'if(confirm(\''.$txtConfirmRemove.'\')) {jQuery(\'#removealladvertisements\').load(\''.$removeallLink.'\');} return false;'; |
|
204
|
|
|
$fields->addFieldToTab($tabName, new LiteralField("removealladvertisements", '<p class="message warning"><a href="'.$removeallLink.'" onclick="'.$jquery.'" id="removealladvertisements" class="ss-ui-button">'.$txtRemove.'</a></p>')); |
|
205
|
|
|
|
|
206
|
|
|
$txtDelete = sprintf(_t("AdvertisementDecorator.DELETE", 'Delete all %1$s from this website (but not the images associated with them)'), Config::inst()->get("Advertisement", "plural_name")); |
|
207
|
|
|
$txtConfirmDelete = sprintf(_t("AdvertisementDecorator.CONFIRMDELETE", 'Are you sure you want to delete all %1$s - there is no UNDO?'), Config::inst()->get("Advertisement", "plural_name")); |
|
208
|
|
|
$deleteallLink = 'advertisements/deletealladvertisements/'.$this->owner->ID.'/'; |
|
209
|
|
|
$jquery = 'if(confirm(\''.$txtConfirmDelete.'\')) {jQuery(\'#deletealladvertisements\').load(\''.$deleteallLink.'\');} return false;'; |
|
210
|
|
|
$fields->addFieldToTab($tabName, new LiteralField("deletealladvertisements", '<p class="message bad"><a href="'.$deleteallLink.'" onclick="'.$jquery.'" id="deletealladvertisements" class="ss-ui-button">'.$txtDelete.'</a></p>')); |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
return $fields; |
|
214
|
|
|
} |
|
215
|
|
|
|
|
216
|
|
|
protected function MyTabName() |
|
217
|
|
|
{ |
|
218
|
|
|
$code = preg_replace("/[^a-zA-Z0-9\s]/", " ", Config::inst()->get("AdvertisementAdmin", "menu_title")); |
|
219
|
|
|
$code = str_replace(" ", "", $code); |
|
220
|
|
|
return "Root.".$code; |
|
221
|
|
|
} |
|
222
|
|
|
|
|
223
|
|
|
protected function MyHeaderField($title) |
|
224
|
|
|
{ |
|
225
|
|
|
$code = preg_replace("/[^a-zA-Z0-9\s]/", "", $title); |
|
226
|
|
|
$code = str_replace(" ", "", $code); |
|
227
|
|
|
return new LiteralField($code, "<h4 style='margin-top: 20px'>$title</h4>"); |
|
228
|
|
|
} |
|
229
|
|
|
|
|
230
|
|
|
protected function MyHeaderFieldLarge($title) |
|
231
|
|
|
{ |
|
232
|
|
|
$code = preg_replace("/[^a-zA-Z0-9\s]/", "", $title); |
|
233
|
|
|
$code = str_replace(" ", "", $code); |
|
234
|
|
|
return new LiteralField($code, "<h2 style='margin-top: 40px'>$title</h2>"); |
|
235
|
|
|
} |
|
236
|
|
|
|
|
237
|
|
|
public function AdvertisementSet($style = null) |
|
|
|
|
|
|
238
|
|
|
{ |
|
239
|
|
|
if ($this->classHasAdvertisements($this->owner->ClassName)) { |
|
|
|
|
|
|
240
|
|
|
$browseSet = $this->owner->advertisementsToShow(); |
|
241
|
|
|
if ($browseSet) { |
|
242
|
|
|
$file = null; |
|
243
|
|
|
if ($this->owner->AdvertisementStyleID) { |
|
|
|
|
|
|
244
|
|
|
$style = $this->owner->AdvertisementStyle(); |
|
245
|
|
|
} |
|
246
|
|
|
if ($style) { |
|
247
|
|
|
$file = $style->FileLocation; |
|
248
|
|
|
} |
|
249
|
|
|
self::add_requirements($file); |
|
250
|
|
|
|
|
251
|
|
|
return $browseSet; |
|
252
|
|
|
} |
|
253
|
|
|
} |
|
254
|
|
|
} |
|
255
|
|
|
|
|
256
|
|
|
protected function advertisementParent() |
|
|
|
|
|
|
257
|
|
|
{ |
|
258
|
|
|
$parent = null; |
|
259
|
|
|
if ($this->owner->ParentID) { |
|
260
|
|
|
$parent = SiteTree::get()->byID($this->owner->ParentID); |
|
|
|
|
|
|
261
|
|
|
} elseif ($this->owner->URLSegment != "home") { |
|
|
|
|
|
|
262
|
|
|
$parent = SiteTree::get()->where("URLSegment = 'home' AND \"ClassName\" <> 'RedirectorPage'")->First(); |
|
263
|
|
|
if (!$parent) { |
|
264
|
|
|
if (class_exists("HomePage")) { |
|
265
|
|
|
$parent = HomePage::get()->First(); |
|
266
|
|
|
} else { |
|
267
|
|
|
$parent = Page::get()->filter(array("URLSegment" => "home"))->First(); |
|
268
|
|
|
} |
|
269
|
|
|
} |
|
270
|
|
|
} |
|
271
|
|
|
if ($parent) { |
|
272
|
|
|
if ($this->classHasAdvertisements($parent->ClassName)) { |
|
273
|
|
|
return $parent; |
|
274
|
|
|
} |
|
275
|
|
|
} |
|
276
|
|
|
} |
|
277
|
|
|
|
|
278
|
|
|
public function onBeforeWrite() |
|
279
|
|
|
{ |
|
280
|
|
|
parent::onBeforeWrite(); |
|
281
|
|
|
$bt = defined('DB::USE_ANSI_SQL') ? "\"" : "`"; |
|
|
|
|
|
|
282
|
|
|
if ($this->classHasAdvertisements($this->owner->ClassName)) { |
|
|
|
|
|
|
283
|
|
|
$objects = array(0 => 0); |
|
284
|
|
|
$images = array(0 => 0); |
|
285
|
|
|
$dos1 = $this->advertisementsToShow(); |
|
286
|
|
|
if ($dos1) { |
|
287
|
|
|
foreach ($dos1 as $obj) { |
|
288
|
|
|
$images[$obj->ID] = $obj->AdvertisementImageID; |
|
289
|
|
|
$objects[$obj->ID] = $obj->ID; |
|
290
|
|
|
} |
|
291
|
|
|
} |
|
292
|
|
|
//check for non-existing images and delete advertisements associated with it |
|
293
|
|
|
|
|
294
|
|
|
foreach ($images as $objectID => $imageID) { |
|
295
|
|
|
if (!Image::get()->byID($imageID)) { |
|
296
|
|
|
$obj = Advertisement::get()->byID($objectID); |
|
297
|
|
|
if ($obj) { |
|
298
|
|
|
$obj->delete(); |
|
299
|
|
|
$obj->destroy(); |
|
300
|
|
|
unset($objects[$objectID]); |
|
301
|
|
|
} |
|
302
|
|
|
} |
|
303
|
|
|
} |
|
304
|
|
|
//check if a folder has been set and create objects |
|
305
|
|
|
if ($this->owner->AdvertisementsFolderID) { |
|
306
|
|
|
$dos2 = Image::get() |
|
307
|
|
|
->where("\"File\".\"ParentID\" = ".$this->owner->AdvertisementsFolderID." AND \"Advertisement\".\"AdvertisementImageID\" IS NULL ") |
|
|
|
|
|
|
308
|
|
|
->leftJoin("Advertisement", "\"Advertisement\".\"AdvertisementImageID\" = \"File\".\"ID\" "); |
|
309
|
|
|
if ($dos2->count()) { |
|
310
|
|
|
$advertisementsToAdd = array(); |
|
|
|
|
|
|
311
|
|
|
foreach ($dos2 as $image) { |
|
312
|
|
|
$newAdvertisement = new Advertisement(); |
|
313
|
|
|
$newAdvertisement->AdvertisementImageID = $image->ID; |
|
|
|
|
|
|
314
|
|
|
$newAdvertisement->Title = $image->Title; |
|
|
|
|
|
|
315
|
|
|
$newAdvertisement->AutoAdded = true; |
|
|
|
|
|
|
316
|
|
|
$newAdvertisement->write(); |
|
317
|
|
|
$objects[$newAdvertisement->ID] = $newAdvertisement->ID; |
|
318
|
|
|
} |
|
319
|
|
|
$this->owner->Advertisements()->addMany($objects); |
|
320
|
|
|
} |
|
321
|
|
|
} |
|
322
|
|
|
if ($this->owner->AdvertisementStyleID) { |
|
323
|
|
|
if (!AdvertisementStyle::get()->byID($this->owner->AdvertisementStyleID)) { |
|
324
|
|
|
$this->owner->AdvertisementStyleID = 0; |
|
|
|
|
|
|
325
|
|
|
} |
|
326
|
|
|
} |
|
327
|
|
|
//remove advdertisements if parent is being used... |
|
328
|
|
|
if ($this->owner->UseParentAdvertisements) { |
|
329
|
|
|
if ($this->advertisementParent()) { |
|
330
|
|
|
$combos = $this->owner->Advertisements(); |
|
331
|
|
|
if ($combos) { |
|
332
|
|
|
$combos->removeAll(); |
|
333
|
|
|
} |
|
334
|
|
|
} else { |
|
335
|
|
|
$this->owner->UseParentAdvertisements = false; |
|
|
|
|
|
|
336
|
|
|
} |
|
337
|
|
|
} |
|
338
|
|
|
} |
|
339
|
|
|
} |
|
340
|
|
|
|
|
341
|
|
|
/** |
|
342
|
|
|
* |
|
343
|
|
|
* |
|
344
|
|
|
* @return DataList |
|
345
|
|
|
*/ |
|
346
|
|
|
public function advertisementsToShow() |
|
347
|
|
|
{ |
|
348
|
|
|
$array = array(0 => 0); |
|
349
|
|
|
if ($this->owner->exists()) { |
|
350
|
|
|
if ($this->owner->UseParentAdvertisements) { |
|
|
|
|
|
|
351
|
|
|
$parent = $this->owner->advertisementParent(); |
|
352
|
|
|
if ($parent) { |
|
353
|
|
|
return $parent->advertisementsToShow(); |
|
354
|
|
|
} |
|
355
|
|
|
} |
|
356
|
|
|
//from page |
|
357
|
|
|
$objects1 = $this->owner->Advertisements(); |
|
358
|
|
|
if ($objects1->count()) { |
|
359
|
|
|
$array += $objects1->map('ID', 'ID')->toArray(); |
|
360
|
|
|
} |
|
361
|
|
|
if (Config::inst()->get(self::class, 'add_advertisements_shown_on_no_pages_to_all_pages')) { |
|
362
|
|
|
//shown on all pages ... |
|
363
|
|
|
$objects2 = Advertisement::get() |
|
364
|
|
|
->leftJoin('SiteTree_Advertisements', 'Advertisement.ID = AdvertisementID') |
|
365
|
|
|
->where('AdvertisementID IS NULL'); |
|
366
|
|
|
if ($objects2->count()) { |
|
367
|
|
|
$array += $objects2->map('ID', 'ID')->toArray(); |
|
368
|
|
|
} |
|
369
|
|
|
} |
|
370
|
|
|
} |
|
371
|
|
|
return Advertisement::get()->filter(array('ID' => $array)); |
|
372
|
|
|
} |
|
373
|
|
|
|
|
374
|
|
|
/* |
|
|
|
|
|
|
375
|
|
|
protected function getResizedAdvertisements(){ |
|
376
|
|
|
|
|
377
|
|
|
} |
|
378
|
|
|
*/ |
|
379
|
|
|
|
|
380
|
|
|
protected function classHasAdvertisements($className) |
|
381
|
|
|
{ |
|
382
|
|
|
//assumptions: |
|
383
|
|
|
//1. in general YES |
|
384
|
|
|
//2. if list of WITH is shown then it must be in that |
|
385
|
|
|
//3. otherwise check if it is specifically excluded (WITHOUT) |
|
386
|
|
|
$result = true; |
|
387
|
|
|
$inc = Config::inst()->get("AdvertisementDecorator", "page_classes_with_advertisements"); |
|
388
|
|
|
$exc = Config::inst()->get("AdvertisementDecorator", "page_classes_without_advertisements"); |
|
389
|
|
|
if (is_array($inc) && count($inc)) { |
|
390
|
|
|
$result = false; |
|
391
|
|
|
if (in_array($className, $inc)) { |
|
392
|
|
|
$result = true; |
|
393
|
|
|
} |
|
394
|
|
|
} elseif (is_array($exc) && count($exc) && in_array($className, $exc)) { |
|
395
|
|
|
$result = false; |
|
396
|
|
|
} |
|
397
|
|
|
return $result; |
|
398
|
|
|
} |
|
399
|
|
|
} |
|
400
|
|
|
|
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.