SearchForm::defineProperties()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 10
nc 1
nop 0
1
<?php namespace PKleindienst\BlogSearch\Components;
2
3
use Cms\Classes\ComponentBase;
4
use Cms\Classes\Page;
5
use RainLab\Blog\Models\Category as BlogCategory;
6
7
/**
8
 * Search Form Component
9
 * @package PKleindienst\BlogSearch\Components
10
 */
11
class SearchForm extends ComponentBase
12
{
13
    /**
14
     * @var string Reference to the search results page.
15
     */
16
    public $resultPage;
17
18
    /**
19
     * @var array
20
     */
21
    public $categories = [];
22
23
    /**
24
     * @var bool
25
     */
26
    public $categoryFilter = false;
27
28
    /**
29
     * @return array
30
     */
31
    public function componentDetails()
32
    {
33
        return [
34
            'name'        => 'Search Form',
35
            'description' => 'Outputs a search form for the blog.'
36
        ];
37
    }
38
39
    /**
40
     * @return array
41
     */
42
    public function defineProperties()
43
    {
44
        return [
45
            'resultPage' => [
46
                'title'   => 'Search Results Page',
47
                'type'    => 'dropdown',
48
                'default' => 'blog/search'
49
            ],
50
            'categoryFilter' => [
51
                'title'   => 'Show Category Filter',
52
                'type'    => 'checkbox',
53
                'default' => 0
54
            ]
55
        ];
56
    }
57
58
    /**
59
     * @return mixed
60
     */
61
    public function getResultPageOptions()
62
    {
63
        return Page::sortBy('baseFileName')->lists('baseFileName', 'baseFileName');
64
    }
65
66
    /**
67
     * Prepare vars
68
     */
69
    public function onRun()
70
    {
71
        $this->resultPage = $this->page[ 'resultPage' ] = $this->property('resultPage');
72
        $this->categories = $this->page[ 'categories' ] = BlogCategory::lists('name', 'id');
73
        $this->categoryFilter = $this->page[ 'categoryFilter' ] = $this->property('categoryFilter');
74
    }
75
}
76