Completed
Push — master ( 0411a3...0f768a )
by Alex
03:32
created

Base::__construct()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 7
c 1
b 0
f 0
nc 5
nop 2
dl 0
loc 14
rs 10
1
<?php
2
namespace Mezon\Gui\ListBuilder;
3
4
use Mezon\Gui\WidgetsRegistry\BootstrapWidgets;
5
6
class Base
7
{
8
9
    // TODO make private
10
    /**
11
     * Fields
12
     *
13
     * @var array
14
     */
15
    protected $fields = [];
16
17
    // TODO make private
18
    /**
19
     * Service logic adapter
20
     *
21
     * @var \Mezon\Gui\ListBuilder\ListBuilderAdapter
22
     */
23
    protected $listBuilderAdapter = false;
24
25
    // TODO make private
26
    /**
27
     * List item transformation callback
28
     *
29
     * @var array
30
     */
31
    protected $recordTransformer = [];
32
33
    /**
34
     * List title
35
     *
36
     * @var string
37
     */
38
    public $listTitle = 'Список записей';
39
40
    /**
41
     * List description
42
     *
43
     * @var string
44
     */
45
    public $listDescription = 'Выберите необходимое действие';
46
47
    /**
48
     * Constructor
49
     *
50
     * @param array $fields
51
     *            List of fields
52
     * @param \Mezon\Gui\ListBuilder\ListBuilderAdapter $listBuilderAdapter
53
     *            Adapter for the data source
54
     */
55
    public function __construct(array $fields, ListBuilderAdapter $listBuilderAdapter)
56
    {
57
        $transformedFields = [];
58
59
        foreach ($fields as $i => $field) {
60
            $key = is_array($field) ? $i : $field;
61
            $transformedFields[$key] = is_array($field) ? $field : [
62
                'title' => $field
63
            ];
64
        }
65
66
        $this->fields = $transformedFields;
67
68
        $this->listBuilderAdapter = $listBuilderAdapter;
69
    }
70
71
    /**
72
     * Method returns content for the case when no items were found
73
     *
74
     * @return string content for the case when no items were found
75
     */
76
    public function getNoItemsContent(): string
77
    {
78
        return str_replace([
79
            '{list-description}',
80
            '{list-title}'
81
        ], [
82
            'Ни одной записи не найдено',
83
            $this->listTitle
84
        ], BootstrapWidgets::get('listing-no-items'));
85
    }
86
87
    /**
88
     * Setting record transformer
89
     *
90
     * @param mixed $recordTransformer
91
     *            callable record transformer
92
     * @codeCoverageIgnore
93
     */
94
    public function setRecordTransformer($recordTransformer): void
95
    {
96
        $this->recordTransformer = $recordTransformer;
97
    }
98
} 
99