Passed
Push — hans/elevation ( ec80bc )
by Simon
06:00
created

Elevation::getCMSFields()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 16
rs 9.9666
cc 2
nc 2
nop 0
1
<?php
2
3
namespace Firesphere\SolrSearch\Models;
4
5
use Firesphere\SolrSearch\Indexes\BaseIndex;
6
use Firesphere\SolrSearch\Services\SolrCoreService;
7
use SilverStripe\Forms\DropdownField;
8
use SilverStripe\ORM\DataObject;
9
use SilverStripe\ORM\ManyManyList;
10
11
/**
12
 * Class \Firesphere\SolrSearch\Models\Elevation
13
 *
14
 * @property string $Keyword
15
 * @property string $Index
16
 * @method ManyManyList|ElevatedItem[] Items()
17
 */
18
class Elevation extends DataObject
19
{
20
    private static $table_name = 'Elevation';
21
22
    private static $db = [
23
        'Keyword' => 'Varchar(255)',
24
        'Index'   => 'Varchar(255)',
25
    ];
26
27
    private static $many_many = [
28
        'Items' => ElevatedItem::class,
29
    ];
30
31
    private static $summary_fields = [
32
        'ID',
33
        'Keyword',
34
    ];
35
36
    public function getCMSFields()
37
    {
38
        $fields = parent::getCMSFields();
39
        $indexes = (new SolrCoreService())->getValidIndexes();
40
        $indexList = [];
41
        /** @var BaseIndex $index */
42
        foreach ($indexes as $index) {
43
            $indexList[$index] = (new $index())->getIndexName();
44
        }
45
46
        $fields->addFieldToTab(
47
            'Root.Main',
48
            DropdownField::create('Index', _t(self::class . '.INDEXNAME', 'Solr core'), $indexList)
49
        );
50
51
        return $fields;
52
    }
53
}
54