|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SilverStripe\CKANRegistry\Model; |
|
4
|
|
|
|
|
5
|
|
|
use SilverStripe\Forms\CheckboxField; |
|
6
|
|
|
use SilverStripe\Forms\FieldGroup; |
|
7
|
|
|
use SilverStripe\i18n\i18n; |
|
8
|
|
|
use SilverStripe\ORM\DataObject; |
|
9
|
|
|
use SilverStripe\ORM\FieldType\DBString; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Represents a generic field on a CKAN Resource, e.g. a column in a spreadsheet. |
|
13
|
|
|
* It is intentionally generic, as the resource may not be a tabular one, e.g. geospatal data to be rendered in a map. |
|
14
|
|
|
*/ |
|
15
|
|
|
class ResourceField extends DataObject |
|
16
|
|
|
{ |
|
17
|
|
|
private static $table_name = 'CKANResourceField'; |
|
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
private static $db = [ |
|
|
|
|
|
|
20
|
|
|
'Name' => 'Varchar', |
|
21
|
|
|
'Type' => 'Varchar', |
|
22
|
|
|
'ReadableName' => 'Varchar', |
|
23
|
|
|
'ShowInSummaryView' => 'Boolean', |
|
24
|
|
|
'ShowInDetailView' => 'Boolean', |
|
25
|
|
|
'RemoveDuplicates' => 'Boolean', |
|
26
|
|
|
'Order' => 'Int', |
|
27
|
|
|
'DisplayConditions' => 'Text', |
|
28
|
|
|
]; |
|
29
|
|
|
|
|
30
|
|
|
private static $has_one = [ |
|
|
|
|
|
|
31
|
|
|
'Resource' => Resource::class, |
|
32
|
|
|
]; |
|
33
|
|
|
|
|
34
|
|
|
private static $summary_fields = [ |
|
|
|
|
|
|
35
|
|
|
'Order', |
|
36
|
|
|
'ReadableName', |
|
37
|
|
|
'Name', |
|
38
|
|
|
'Type', |
|
39
|
|
|
'ShowInSummaryView', |
|
40
|
|
|
'ShowInDetailView', |
|
41
|
|
|
]; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Always display the 'ReadableName' unless it's unset, then display the name that is returned by CKAN |
|
45
|
|
|
* @return string|DBString |
|
46
|
|
|
*/ |
|
47
|
|
|
public function getReadableName() |
|
48
|
|
|
{ |
|
49
|
|
|
return $this->getField('ReadableName') ?: $this->Name; |
|
|
|
|
|
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function getCMSFields() |
|
53
|
|
|
{ |
|
54
|
|
|
$fields = parent::getCMSFields(); |
|
55
|
|
|
|
|
56
|
|
|
$fields->removeByName('Name'); |
|
57
|
|
|
|
|
58
|
|
|
$fields->removeByName('Type'); |
|
59
|
|
|
$fields->dataFieldByName('ReadableName') |
|
60
|
|
|
->setAttribute('placeholder', $this->Name); |
|
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
$summary = $fields->dataFieldByName('ShowInSummaryView'); |
|
63
|
|
|
$detail = $fields->dataFieldByName('ShowInDetailView'); |
|
64
|
|
|
$duplicates = $fields->dataFieldByName('RemoveDuplicates'); |
|
65
|
|
|
|
|
66
|
|
|
$fields->removeByName(['ShowInSummaryView', 'ShowInDetailView', 'RemoveDuplicates',]); |
|
67
|
|
|
$fields->insertBefore(FieldGroup::create('Visibility', [$summary, $detail, $duplicates]), 'Order'); |
|
|
|
|
|
|
68
|
|
|
|
|
69
|
|
|
$fields->removeByName('ResourceID'); |
|
70
|
|
|
return $fields; |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|