Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
ColumnLabelProvider
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
4 / 4
9
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 provide
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
1 / 1
6
 provideFromColumnArray
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 createLabel
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3/**
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; under version 2
7 * of the License (non-upgradable).
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17 *
18 * Copyright (c) 2022 (original work) Open Assessment Technologies SA;
19 */
20
21declare(strict_types=1);
22
23namespace oat\taoOutcomeUi\model\table\ColumnDataProvider;
24
25use oat\taoOutcomeUi\model\ItemResultStrategy;
26use oat\taoOutcomeUi\model\table\VariableColumn;
27use tao_models_classes_table_Column;
28
29class ColumnLabelProvider
30{
31    private const LABEL_SEPARATOR = '-';
32
33    private ItemResultStrategy $itemResultStrategy;
34
35    public function __construct(ItemResultStrategy $itemResultStrategy)
36    {
37        $this->itemResultStrategy = $itemResultStrategy;
38    }
39
40    public function provide(tao_models_classes_table_Column $column): string
41    {
42        if ($column instanceof VariableColumn) {
43            if (
44                $this->itemResultStrategy->isItemInstanceLabelItemRefBased()
45                && $column->getRefId() !== null
46            ) {
47                return $this->createLabel(
48                    $column->getRefId(),
49                    $column->getContextLabel(),
50                    $column->getIdentifier()
51                );
52            }
53
54            if (
55                $this->itemResultStrategy->isItemInstanceItemRefBased()
56                && $column->getRefId() !== null
57            ) {
58                return $this->createLabel($column->getRefId(), $column->getIdentifier());
59            }
60        }
61
62        return $column->getLabel();
63    }
64
65    public function provideFromColumnArray(array $columnArray): string
66    {
67        return $this->provide(tao_models_classes_table_Column::buildColumnFromArray($columnArray));
68    }
69
70    public function createLabel(string ...$elements): string
71    {
72        return implode(self::LABEL_SEPARATOR, $elements);
73    }
74}