• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

contributte / datagrid / 7048127238

30 Nov 2023 02:47PM UTC coverage: 34.081%. First build
7048127238

Pull #1060

github

paveljanda
Minor CSS changes for the next verison of datagrid
Pull Request #1060: [7.x] Next

118 of 431 new or added lines in 54 files covered. (27.38%)

1125 of 3301 relevant lines covered (34.08%)

0.34 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Column/MultiAction.php
1
<?php declare(strict_types = 1);
2

3
namespace Contributte\Datagrid\Column;
4

5
use Contributte\Datagrid\Datagrid;
6
use Contributte\Datagrid\Exception\DatagridException;
7
use Contributte\Datagrid\Row;
8
use Contributte\Datagrid\Traits\TButtonCaret;
9
use Contributte\Datagrid\Traits\TButtonClass;
10
use Contributte\Datagrid\Traits\TButtonIcon;
11
use Contributte\Datagrid\Traits\TButtonText;
12
use Contributte\Datagrid\Traits\TButtonTitle;
13
use Contributte\Datagrid\Traits\TButtonTryAddIcon;
14
use Contributte\Datagrid\Traits\TLink;
15
use Nette\Utils\Html;
16

17
class MultiAction extends Column
18
{
19

20
        use TButtonTryAddIcon;
21
        use TButtonIcon;
22
        use TButtonClass;
23
        use TButtonTitle;
24
        use TButtonText;
25
        use TButtonCaret;
26
        use TLink;
27

28
        protected Datagrid $grid;
29

30
        protected string $name;
31

32
        /** @var array */
33
        protected array $actions = [];
34

35
        /** @var array|callable[] */
36
        private array $rowConditions = [];
37

38
        public function __construct(Datagrid $grid, string $key, string $name)
39
        {
40
                parent::__construct($grid, $key, '', $name);
×
41

42
                $this->setTemplate(__DIR__ . '/../templates/column_multi_action.latte');
×
43
        }
44

45
        public function renderButton(): Html
46
        {
47
                $button = Html::el('button')
×
48
                        ->setAttribute('type', 'button')
×
NEW
49
                        ->data('bs-toggle', 'dropdown');
×
50

51
                $this->tryAddIcon($button, $this->getIcon(), $this->getName());
×
52

53
                $button->addText($this->grid->getTranslator()->translate($this->name));
×
54

55
                if ($this->hasCaret()) {
×
56
                        $button->addHtml('&nbsp;');
×
57
                        $button->addHtml('<i class="caret"></i>');
×
58
                }
59

60
                if ($this->getTitle() !== null) {
×
61
                        $button->setAttribute(
×
62
                                'title',
×
63
                                $this->grid->getTranslator()->translate($this->getTitle())
×
64
                        );
65
                }
66

67
                if ($this->getClass() !== '') {
×
68
                        $button->setAttribute('class', $this->getClass() . ' dropdown-toggle');
×
69
                }
70

71
                return $button;
×
72
        }
73

74
        /**
75
         * @return static
76
         */
77
        public function addAction(
78
                string $key,
79
                string $name,
80
                ?string $href = null,
81
                ?array $params = null
82
        ): self
83
        {
84
                if (isset($this->actions[$key])) {
×
NEW
85
                        throw new DatagridException(
×
86
                                sprintf('There is already action at key [%s] defined for MultiAction.', $key)
×
87
                        );
88
                }
89

NEW
90
                $href ??= $key;
×
91

92
                if ($params === null) {
×
93
                        $params = [$this->grid->getPrimaryKey()];
×
94
                }
95

96
                $action = new Action($this->grid, $key, $href, $name, $params);
×
97

98
                $action->setClass('dropdown-item datagrid-multiaction-dropdown-item');
×
99

100
                $this->actions[$key] = $action;
×
101

102
                return $this;
×
103
        }
104

105
        /**
106
         * @return array<Action>
107
         */
108
        public function getActions(): array
109
        {
110
                return $this->actions;
×
111
        }
112

113
        public function getAction(string $key): Action
114
        {
115
                if (!isset($this->actions[$key])) {
×
NEW
116
                        throw new DatagridException(
×
117
                                sprintf('There is no action at key [%s] defined for MultiAction.', $key)
×
118
                        );
119
                }
120

121
                return $this->actions[$key];
×
122
        }
123

124
        /**
125
         * Column can have variables that will be passed to custom template scope
126
         */
127
        public function getTemplateVariables(): array
128
        {
129
                return array_merge($this->templateVariables, [
×
130
                        'multiAction' => $this,
×
131
                ]);
132
        }
133

134
        public function setRowCondition(
135
                string $actionKey,
136
                callable $rowCondition
137
        ): void
138
        {
139
                $this->rowConditions[$actionKey] = $rowCondition;
×
140
        }
141

142
        public function testRowCondition(string $actionKey, Row $row): bool
143
        {
144
                if (!isset($this->rowConditions[$actionKey])) {
×
145
                        return true;
×
146
                }
147

148
                return (bool) call_user_func($this->rowConditions[$actionKey], $row->getItem());
×
149
        }
150

151
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc