Passed
Pull Request — master (#35)
by Tihran
39:40
created

getSelectCheckboxColumn()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 11
c 0
b 0
f 0
rs 9.9666
cc 1
nc 1
nop 1
1
<?php
2
3
/**
4
 * Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace Pyz\Zed\ProductLabelGui\Communication\Table;
9
10
use Orm\Zed\Product\Persistence\Map\SpyProductAbstractLocalizedAttributesTableMap;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\Product\Persiste...lizedAttributesTableMap was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Orm\Zed\Product\Persistence\Map\SpyProductAbstractTableMap;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\Product\Persiste...ProductAbstractTableMap was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Orm\Zed\Product\Persistence\SpyProductAbstract;
13
use Spryker\Zed\Gui\Communication\Table\TableConfiguration;
14
use Spryker\Zed\ProductLabelGui\Communication\Table\RelatedProductTableQueryBuilder;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Pyz\Zed\ProductLabelGui\...roductTableQueryBuilder. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
15
16
abstract class AbstractRelatedProductRelationTable extends AbstractRelatedProductTable
17
{
18
    /**
19
     * @param \Spryker\Zed\Gui\Communication\Table\TableConfiguration $config
20
     *
21
     * @return \Spryker\Zed\Gui\Communication\Table\TableConfiguration
22
     */
23
    protected function configure(TableConfiguration $config)
24
    {
25
        $this->configureHeader($config);
26
        $this->configureRawColumns($config);
27
        $this->configureSorting($config);
28
        $this->configureSearching($config);
29
        $this->configureUrl($config);
30
31
        return $config;
32
    }
33
34
    /**
35
     * @param \Spryker\Zed\Gui\Communication\Table\TableConfiguration $config
36
     *
37
     * @return void
38
     */
39
    protected function configureHeader(TableConfiguration $config)
40
    {
41
        $config->setHeader([
42
            static::COL_SELECT_CHECKBOX => 'Select',
43
            SpyProductAbstractTableMap::COL_ID_PRODUCT_ABSTRACT => 'ID',
44
            SpyProductAbstractTableMap::COL_SKU => 'SKU',
45
            SpyProductAbstractLocalizedAttributesTableMap::COL_NAME => 'Name',
46
            RelatedProductTableQueryBuilder::RESULT_FIELD_PRODUCT_ABSTRACT_CATEGORY_NAMES_CSV => 'Categories',
47
            RelatedProductTableQueryBuilder::RESULT_FIELD_PRODUCT_ABSTRACT_PRICE => 'Price',
48
            RelatedProductTableQueryBuilder::RESULT_FIELD_PRODUCT_CONCRETE_STATES_CSV => 'Status',
49
        ]);
50
    }
51
52
    /**
53
     * @param \Spryker\Zed\Gui\Communication\Table\TableConfiguration $config
54
     *
55
     * @return void
56
     */
57
    protected function configureRawColumns(TableConfiguration $config)
58
    {
59
        $config->setRawColumns([
60
            static::COL_SELECT_CHECKBOX,
61
            RelatedProductTableQueryBuilder::RESULT_FIELD_PRODUCT_CONCRETE_STATES_CSV,
62
        ]);
63
    }
64
65
    /**
66
     * @param \Spryker\Zed\Gui\Communication\Table\TableConfiguration $config
67
     *
68
     * @return void
69
     */
70
    protected function configureSorting(TableConfiguration $config)
71
    {
72
        $config->setDefaultSortField(
73
            SpyProductAbstractTableMap::COL_ID_PRODUCT_ABSTRACT,
74
            TableConfiguration::SORT_ASC
75
        );
76
77
        $config->setSortable([
78
            SpyProductAbstractTableMap::COL_ID_PRODUCT_ABSTRACT,
79
            SpyProductAbstractTableMap::COL_SKU,
80
            SpyProductAbstractLocalizedAttributesTableMap::COL_NAME,
81
        ]);
82
    }
83
84
    /**
85
     * @param \Spryker\Zed\Gui\Communication\Table\TableConfiguration $config
86
     *
87
     * @return void
88
     */
89
    protected function configureSearching(TableConfiguration $config)
90
    {
91
        $config->setSearchable([
92
            SpyProductAbstractTableMap::COL_SKU,
93
            SpyProductAbstractLocalizedAttributesTableMap::COL_NAME,
94
        ]);
95
    }
96
97
    /**
98
     * @param \Spryker\Zed\Gui\Communication\Table\TableConfiguration $config
99
     *
100
     * @return void
101
     */
102
    protected function configureUrl(TableConfiguration $config)
103
    {
104
        $config->setUrl(sprintf(
105
            '%s?%s=%s',
106
            $this->defaultUrl,
107
            static::PARAM_ID_PRODUCT_LABEL,
108
            (int)$this->idProductLabel
109
        ));
110
    }
111
112
    /**
113
     * @param \Orm\Zed\Product\Persistence\SpyProductAbstract $productAbstractEntity
114
     *
115
     * @return string
116
     */
117
    protected function getSelectCheckboxColumn(SpyProductAbstract $productAbstractEntity)
118
    {
119
        return sprintf(
120
            '<input class="%s" type="checkbox" name="abstractProduct[]" value="%s" %s data-info="%s"/>',
121
            'js-abstract-product-checkbox',
122
            $productAbstractEntity->getIdProductAbstract(),
123
            $this->getCheckboxCheckedAttribute(),
124
            htmlspecialchars(json_encode([
125
                'id' => $productAbstractEntity->getIdProductAbstract(),
126
                'sku' => $productAbstractEntity->getSku(),
127
                'name' => $this->getNameColumn($productAbstractEntity),
128
            ]))
129
        );
130
    }
131
132
    /**
133
     * @return string
134
     */
135
    abstract protected function getCheckboxCheckedAttribute();
136
}
137