Passed
Push — master ( 3cb69a...782ded )
by Nicolaas
03:32
created

getIncludedClassFieldCombos()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace Sunnysideup\SiteWideSearch\QuickSearches;
4
5
use SilverStripe\Control\Controller;
6
use SilverStripe\Core\ClassInfo;
7
use SilverStripe\Core\Config\Configurable;
8
use SilverStripe\Core\Injector\Injector;
9
use SilverStripe\Forms\Form;
10
11
abstract class QuickSearchBaseClass
12
{
13
    use Configurable;
14
15
    private static $is_enabled = true;
16
    public static function available_quick_searches()
17
    {
18
        return ClassInfo::subclassesFor(self::class, false);
19
    }
20
    public function IsEnabled(): bool
21
    {
22
        return $this->Config()->get('is_enabled');
23
    }
24
25
    abstract public function getTitle(): string;
26
    abstract public function getClassesToSearch(): array;
27
    abstract public function getFieldsToSearch(): array;
28
    public function getSortOverride(): ?array
29
    {
30
        return null;
31
    }
32
33
    /**
34
     * Should return it like this:
35
     * ```php
36
     * [
37
     *     'ClassName' => [
38
     *          'MyRelation.Title' => 'Varchar',
39
     *      ]
40
     *
41
     * ]
42
     * ```
43
     * @return array
44
     */
45
    public function getIncludedClassFieldCombos(): array
46
    {
47
        return [];
48
    }
49
    public static function get_list_of_quick_searches(): array
50
    {
51
        $array = [
52
            'all' => 'All',
53
            'limited' => 'Limited search',
54
        ];
55
        $availableSearchClasses = self::available_quick_searches();
56
        if(!empty($availableSearchClasses) > 0) {
57
            foreach($availableSearchClasses as $availableSearchClass) {
58
                $array[$availableSearchClass] =  Injector::inst()->get($availableSearchClass)->getTitle();
59
            }
60
        }
61
        return $array;
62
63
    }
64
65
}
66