Completed
Branch develop-3.0 (ed7e6a)
by Mohamed
03:51
created

ExportIssues::extraFields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 9

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 9
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Tinyissue package.
5
 *
6
 * (c) Mohamed Alsharaf <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Tinyissue\Form;
13
14
use Tinyissue\Services\Exporter;
15
16
/**
17
 * ExportIssues is a class to defines fields & rules for project issues export form.
18
 *
19
 * @author Mohamed Alsharaf <[email protected]>
20
 */
21
class ExportIssues extends FilterIssue
22
{
23
    /**
24
     * @return array
25
     */
26
    public function actions()
27
    {
28
        return [
29
            'export-issue' => [
30
                'name'  => 'export-issue',
31
                'label' => 'export',
32
                'type'  => 'info_submit',
33
            ],
34
        ];
35
    }
36
37
    /**
38
     * @return array
39
     */
40
    public function fields()
41
    {
42
        // Inherited fields
43
        $fields = parent::fields();
44
45
        // Remove unwanted fields
46
        $fields = $this->removeUnwantedFields($fields);
47
48
        // Add extra fields for export
49
        return $this->extraFields($fields);
50
    }
51
52
    /**
53
     * @param array $fields
54
     *
55
     * @return array
56
     */
57
    protected function extraFields(array $fields)
58
    {
59
        // Add extra fields
60
        $fields['format'] = [
61
            'type'        => 'select',
62
            'placeholder' => trans('tinyissue.export_format'),
63
            'options'     => [
64
                Exporter::TYPE_XLS  => trans('tinyissue.xls'),
65
                Exporter::TYPE_XLSX => trans('tinyissue.xlsx'),
66
                Exporter::TYPE_CSV  => trans('tinyissue.csv'),
67
            ],
68
        ];
69
70
        return $fields;
71
    }
72
73
    /**
74
     * @param array $fields
75
     *
76
     * @return array
77
     */
78
    protected function removeUnwantedFields(array $fields)
79
    {
80
        // Remove sort fields
81
        unset($fields['sort']);
82
83
        // Remove extra group class
84
        $fields = array_map(function ($field) {
85
            unset($field['onGroupAddClass']);
86
87
            return $field;
88
        }, $fields);
89
90
        return $fields;
91
    }
92
93
    /**
94
     * @return string
95
     */
96
    public function openType()
97
    {
98
        return 'open';
99
    }
100
}
101