-
Notifications
You must be signed in to change notification settings - Fork 1
/
SearchPage.php
63 lines (52 loc) · 1.55 KB
/
SearchPage.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
namespace Vulcan\Search\Pages;
use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor;
use SilverStripe\ORM\HasManyList;
use Vulcan\Search\Models\SearchTank;
use Vulcan\Search\Models\SortFilter;
/**
* Class SearchPage
* @package Vulcan\Search\Pages
*
* @property int TankID
*
* @method SearchTank Tank
* @method HasManyList Filters
*/
class SearchPage extends \Page
{
private static $table_name = 'VulcanSearchPage';
private static $has_one = [
'Tank' => SearchTank::class
];
private static $has_many = [
'Filters' => SortFilter::class
];
public function onAfterWrite()
{
parent::onAfterWrite();
if (!$this->Filters()->exists()) {
$record = SortFilter::create();
$record->Title = 'Newest';
$record->SortSql = 'Created DESC';
$record->PageID = $this->ID;
$record->write();
$record = SortFilter::create();
$record->Title = 'Oldest';
$record->SortSql = 'Created ASC';
$record->PageID = $this->ID;
$record->write();
}
}
public function getCMSFields()
{
$fields = parent::getCMSFields();
$fields->addFieldsToTab('Root.Search', [
DropdownField::create('TankID', 'Tank', SearchTank::get()->map()),
GridField::create('Filters', 'Filters', $this->Filters(), GridFieldConfig_RecordEditor::create())
]);
return $fields;
}
}