1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author Nicolaas [at] sunnysideup.co.nz |
4
|
|
|
* @package Webquote |
5
|
|
|
* @sub-package Webquote |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
class WebPortfolioWhatWeDidDescriptor extends DataObject |
|
|
|
|
9
|
|
|
{ |
10
|
|
|
private static $db = array( |
|
|
|
|
11
|
|
|
"Name" => "Varchar(255)", |
12
|
|
|
"Code" => "Varchar(255)", |
13
|
|
|
"Description" => "Text" |
14
|
|
|
); |
15
|
|
|
|
16
|
|
|
private static $belongs_many_many = array( |
|
|
|
|
17
|
|
|
"WebPortfolioItem" => "WebPortfolioItem" |
18
|
|
|
); |
19
|
|
|
|
20
|
|
|
private static $default_sort = "Name"; |
|
|
|
|
21
|
|
|
|
22
|
|
|
private static $searchable_fields = array( |
|
|
|
|
23
|
|
|
"Name" => "PartialMatchFilter", |
24
|
|
|
"Description" => "PartialMatchFilter" |
25
|
|
|
); |
26
|
|
|
|
27
|
|
|
private static $summary_fields = array( |
|
|
|
|
28
|
|
|
"Name", |
29
|
|
|
"Description" |
30
|
|
|
); |
31
|
|
|
|
32
|
|
|
private static $indexes = array( |
|
|
|
|
33
|
|
|
"Code" => true |
34
|
|
|
); |
35
|
|
|
|
36
|
|
|
private static $singular_name = "What We Did Descriptor"; |
|
|
|
|
37
|
|
|
|
38
|
|
|
private static $plural_name = "What We Did Descriptors"; |
|
|
|
|
39
|
|
|
|
40
|
|
|
public function Link() |
41
|
|
|
{ |
42
|
|
|
$link = ''; |
43
|
|
View Code Duplication |
if ($page = WebPortfolioPage::get()->first()) { |
|
|
|
|
44
|
|
|
if (!$this->Code) { |
|
|
|
|
45
|
|
|
$this->Code = $page->generateURLSegment($this->Name); |
|
|
|
|
46
|
|
|
$this->write(); |
47
|
|
|
} |
48
|
|
|
$link = $page->Link().'show/'.$this->Code."/"; |
|
|
|
|
49
|
|
|
} |
50
|
|
|
return $link; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function getCMSFields() |
54
|
|
|
{ |
55
|
|
|
$fields = parent::getCMSFields(); |
56
|
|
|
$fields->removeByName("Code"); |
57
|
|
|
if ($this->ID) { |
58
|
|
|
$dos = WebPortfolioWhatWeDidDescriptor::get() |
59
|
|
|
->exclude(array("ID" => $this->ID)); |
60
|
|
|
if ($dos->count()) { |
61
|
|
|
$dosArray = array("" => "--- do not merge ---"); |
62
|
|
|
$dosArray += $dos->map("ID", "Name")->toArray(); |
63
|
|
|
$fields->addFieldToTab("Root.Merge", new DropdownField("MergeID", "Merge <i>$this->Name</i> into:", $dosArray)); |
|
|
|
|
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
$dos = WebPortfolioItem::get(); |
67
|
|
|
if ($dos->count() && $this->ID) { |
68
|
|
|
$dosArray = $dos->map()->toArray(); |
69
|
|
|
$fields->addFieldsToTab( |
70
|
|
|
"Root.WebPortfolioItem", |
71
|
|
|
array( |
72
|
|
|
new CheckboxSetField("WebPortfolioItem", "Carried out for", $dosArray) |
73
|
|
|
) |
74
|
|
|
); |
75
|
|
|
} |
76
|
|
|
if (class_exists("DataObjectOneFieldUpdateController")) { |
77
|
|
|
$link = DataObjectOneFieldUpdateController::popup_link( |
78
|
|
|
$ClassName = $this->ClassName, |
79
|
|
|
$FieldName = "Description", |
80
|
|
|
$where = '', |
81
|
|
|
$sort = 'Description DESC', |
82
|
|
|
$linkText = 'Edit Description' |
83
|
|
|
); |
84
|
|
|
$fields->addFieldToTab("Root.Main", new LiteralField("EditDescription", $link), "Description"); |
85
|
|
|
} |
86
|
|
|
return $fields; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
|
90
|
|
|
protected $mergeInto = null; |
91
|
|
|
|
92
|
|
|
public function onAfterWrite() |
|
|
|
|
93
|
|
|
{ |
94
|
|
|
parent::onAfterWrite(); |
95
|
|
|
if ($this->mergeInto) { |
96
|
|
|
DB::query("UPDATE \"WebPortfolioItem_WhatWeDid\" SET \"WebPortfolioWhatWeDidDescriptorID\" = ".$this->mergeInto->ID." WHERE \"WebPortfolioWhatWeDidDescriptorID\" = ".$this->ID); |
97
|
|
|
$this->delete(); |
98
|
|
|
} |
99
|
|
|
if (isset($_REQUEST["MergeID"])) { |
100
|
|
|
unset($_REQUEST["MergeID"]); |
101
|
|
|
} |
102
|
|
|
$this->mergeInto = null; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function onBeforeWrite() |
|
|
|
|
106
|
|
|
{ |
107
|
|
|
parent::onBeforeWrite(); |
108
|
|
|
if (isset($_REQUEST["MergeID"])) { |
109
|
|
|
$mergeID = intval($_REQUEST["MergeID"]); |
110
|
|
|
if ($mergeID) { |
111
|
|
|
$this->mergeInto = WebPortfolioWhatWeDidDescriptor::get()->byID($mergeID); |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
View Code Duplication |
if ($page = WebPortfolioPage::get()->first()) { |
|
|
|
|
115
|
|
|
$link = $page->Link().'show/'.$this->Code."/"; |
|
|
|
|
116
|
|
|
$this->Code = $page->generateURLSegment($this->Name); |
|
|
|
|
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|
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.