PunchoutCatalogsTransactionLogTable   A
last analyzed

Complexity

Total Complexity 15

Size/Duplication

Total Lines 212
Duplicated Lines 0 %

Importance

Changes 4
Bugs 1 Features 0
Metric Value
eloc 77
c 4
b 1
f 0
dl 0
loc 212
rs 10
wmc 15

10 Methods

Rating   Name   Duplication   Size   Complexity  
A addCompanyBusinessUnitColumn() 0 5 2
A mapPunchoutCatalogTransactions() 0 9 2
A addConnectionNameColumn() 0 9 2
A prepareData() 0 14 2
A getStatusLabel() 0 7 2
A buildLinks() 0 7 1
A configure() 0 36 1
A mapPunchoutCatalogTransaction() 0 14 1
A prepareQuery() 0 3 1
A __construct() 0 4 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 SprykerEco\Zed\PunchoutCatalogs\Communication\Table;
9
10
use Orm\Zed\PunchoutCatalog\Persistence\Map\PgwPunchoutCatalogConnectionTableMap;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\PunchoutCatalog\...talogConnectionTableMap 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\PunchoutCatalog\Persistence\Map\PgwPunchoutCatalogTransactionTableMap;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\PunchoutCatalog\...alogTransactionTableMap 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\PunchoutCatalog\Persistence\PgwPunchoutCatalogTransaction;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\PunchoutCatalog\...choutCatalogTransaction 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...
13
use Orm\Zed\PunchoutCatalog\Persistence\PgwPunchoutCatalogTransactionQuery;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\PunchoutCatalog\...CatalogTransactionQuery 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...
14
use Propel\Runtime\Collection\ObjectCollection;
15
use Spryker\Service\UtilText\Model\Url\Url;
16
use Spryker\Zed\Gui\Communication\Table\AbstractTable;
17
use Spryker\Zed\Gui\Communication\Table\TableConfiguration;
18
use SprykerEco\Zed\PunchoutCatalogs\Dependency\Service\PunchoutCatalogsToUtilDateTimeServiceInterface;
19
20
class PunchoutCatalogsTransactionLogTable extends AbstractTable
21
{
22
    protected const STATUS_SUCCESSFUL = 'Successful';
23
    protected const STATUS_UNSUCCESSFUL = 'Unsuccessful';
24
25
    protected const COL_ID_PUNCHOUT_CATALOG_TRANSACTION = 'id_punchout_catalog_transaction';
26
    protected const COL_TYPE = 'type';
27
    protected const COL_BUSINESS_UNIT = PgwPunchoutCatalogTransactionTableMap::COL_FK_COMPANY_BUSINESS_UNIT;
28
    protected const COL_CONNECTION_NAME = PgwPunchoutCatalogConnectionTableMap::COL_NAME;
29
    protected const COL_STATUS = 'status';
30
    protected const COL_CREATED_AT = 'created_at';
31
    protected const COL_SESSION_ID = 'connection_session_id';
32
    protected const COL_ACTIONS = 'actions';
33
34
    protected const URL_PARAM_ID_PUNCHOUT_CATALOG_TRANSACTION = 'id-punchout-catalog-transaction';
35
36
    /**
37
     * @see \SprykerEco\Zed\PunchoutCatalogs\Communication\Controller\TransactionController::viewAction()
38
     */
39
    protected const URL_PUNCHOUT_CATALOG_TRANSACTION_VIEW = '/punchout-catalogs/transaction/view';
40
41
    /**
42
     * @var \Orm\Zed\PunchoutCatalog\Persistence\PgwPunchoutCatalogTransactionQuery
43
     */
44
    protected $punchoutCatalogTransactionPropelQuery;
45
46
    /**
47
     * @var \SprykerEco\Zed\PunchoutCatalogs\Dependency\Service\PunchoutCatalogsToUtilDateTimeServiceInterface
48
     */
49
    protected $utilDateTimeService;
50
51
    /**
52
     * @param \Orm\Zed\PunchoutCatalog\Persistence\PgwPunchoutCatalogTransactionQuery $punchoutCatalogTransactionPropelQuery
53
     * @param \SprykerEco\Zed\PunchoutCatalogs\Dependency\Service\PunchoutCatalogsToUtilDateTimeServiceInterface $utilDateTimeService
54
     */
55
    public function __construct(PgwPunchoutCatalogTransactionQuery $punchoutCatalogTransactionPropelQuery, PunchoutCatalogsToUtilDateTimeServiceInterface $utilDateTimeService)
56
    {
57
        $this->punchoutCatalogTransactionPropelQuery = $punchoutCatalogTransactionPropelQuery;
58
        $this->utilDateTimeService = $utilDateTimeService;
59
    }
60
61
    /**
62
     * @param \Spryker\Zed\Gui\Communication\Table\TableConfiguration $config
63
     *
64
     * @return \Spryker\Zed\Gui\Communication\Table\TableConfiguration
65
     */
66
    protected function configure(TableConfiguration $config): TableConfiguration
67
    {
68
        $config->setHeader([
69
            static::COL_ID_PUNCHOUT_CATALOG_TRANSACTION => 'ID',
70
            static::COL_TYPE => 'Message Type',
71
            static::COL_BUSINESS_UNIT => 'Business Unit',
72
            static::COL_CONNECTION_NAME => 'Connection Name',
73
            static::COL_STATUS => 'Status',
74
            static::COL_SESSION_ID => 'Session ID',
75
            static::COL_CREATED_AT => 'Created At',
76
            static::COL_ACTIONS => 'Actions',
77
        ]);
78
79
        $config->setSortable([
80
            static::COL_ID_PUNCHOUT_CATALOG_TRANSACTION,
81
            static::COL_TYPE,
82
            static::COL_BUSINESS_UNIT,
83
            static::COL_CONNECTION_NAME,
84
            static::COL_STATUS,
85
            static::COL_SESSION_ID,
86
            static::COL_CREATED_AT,
87
        ]);
88
89
        $config->setSearchable([
90
            PgwPunchoutCatalogTransactionTableMap::COL_ID_PUNCHOUT_CATALOG_TRANSACTION,
91
            PgwPunchoutCatalogTransactionTableMap::COL_TYPE,
92
            PgwPunchoutCatalogTransactionTableMap::COL_CONNECTION_SESSION_ID,
93
            PgwPunchoutCatalogConnectionTableMap::COL_NAME,
94
        ]);
95
96
        $config->setRawColumns([
97
            static::COL_STATUS,
98
            static::COL_ACTIONS,
99
        ]);
100
101
        return $config;
102
    }
103
104
    /**
105
     * @param \Spryker\Zed\Gui\Communication\Table\TableConfiguration $config
106
     *
107
     * @return array
108
     */
109
    protected function prepareData(TableConfiguration $config): array
110
    {
111
        /** @var \Propel\Runtime\Collection\ObjectCollection|\Orm\Zed\PunchoutCatalog\Persistence\PgwPunchoutCatalogTransaction[] $punchoutCatalogTransactionCollection */
112
        $punchoutCatalogTransactionCollection = $this->runQuery(
113
            $this->prepareQuery($this->punchoutCatalogTransactionPropelQuery),
114
            $config,
115
            true
116
        );
117
118
        if ($punchoutCatalogTransactionCollection->count() === 0) {
119
            return [];
120
        }
121
122
        return $this->mapPunchoutCatalogTransactions($punchoutCatalogTransactionCollection);
123
    }
124
125
    /**
126
     * @module Company
127
     * @module CompanyBusinessUnit
128
     *
129
     * @param \Orm\Zed\PunchoutCatalog\Persistence\PgwPunchoutCatalogTransactionQuery $punchoutCatalogTransactionPropelQuery
130
     *
131
     * @return \Orm\Zed\PunchoutCatalog\Persistence\PgwPunchoutCatalogTransactionQuery
132
     */
133
    protected function prepareQuery(PgwPunchoutCatalogTransactionQuery $punchoutCatalogTransactionPropelQuery): PgwPunchoutCatalogTransactionQuery
134
    {
135
        return $punchoutCatalogTransactionPropelQuery->leftJoinWithPunchoutCatalogConnection();
136
    }
137
138
    /**
139
     * @param \Propel\Runtime\Collection\ObjectCollection|\Orm\Zed\PunchoutCatalog\Persistence\PgwPunchoutCatalogTransaction[] $punchoutCatalogTransactions
140
     *
141
     * @return array
142
     */
143
    protected function mapPunchoutCatalogTransactions(ObjectCollection $punchoutCatalogTransactions): array
144
    {
145
        $punchoutCatalogConnectionRows = [];
146
147
        foreach ($punchoutCatalogTransactions as $punchoutCatalogTransaction) {
148
            $punchoutCatalogConnectionRows[] = $this->mapPunchoutCatalogTransaction($punchoutCatalogTransaction);
149
        }
150
151
        return $punchoutCatalogConnectionRows;
152
    }
153
154
    /**
155
     * @param \Orm\Zed\PunchoutCatalog\Persistence\PgwPunchoutCatalogTransaction $punchoutCatalogTransaction
156
     *
157
     * @return array
158
     */
159
    protected function mapPunchoutCatalogTransaction(PgwPunchoutCatalogTransaction $punchoutCatalogTransaction): array
160
    {
161
        $punchoutCatalogTransactionRow = $punchoutCatalogTransaction->toArray();
162
163
        $punchoutCatalogTransactionRow[static::COL_STATUS] = $this->getStatusLabel($punchoutCatalogTransaction);
164
        $punchoutCatalogTransactionRow[static::COL_CREATED_AT] = $this->utilDateTimeService->formatDateTime(
165
            $punchoutCatalogTransaction->getCreatedAt()
166
        );
167
        $punchoutCatalogTransactionRow = $this->addCompanyBusinessUnitColumn($punchoutCatalogTransaction, $punchoutCatalogTransactionRow);
168
        $punchoutCatalogTransactionRow = $this->addConnectionNameColumn($punchoutCatalogTransaction, $punchoutCatalogTransactionRow);
169
170
        $punchoutCatalogTransactionRow[static::COL_ACTIONS] = $this->buildLinks($punchoutCatalogTransaction);
171
172
        return $punchoutCatalogTransactionRow;
173
    }
174
175
    /**
176
     * @param \Orm\Zed\PunchoutCatalog\Persistence\PgwPunchoutCatalogTransaction $punchoutCatalogTransaction
177
     *
178
     * @return string
179
     */
180
    protected function buildLinks(PgwPunchoutCatalogTransaction $punchoutCatalogTransaction): string
181
    {
182
        return $this->generateViewButton(
183
            Url::generate(static::URL_PUNCHOUT_CATALOG_TRANSACTION_VIEW, [
184
                static::URL_PARAM_ID_PUNCHOUT_CATALOG_TRANSACTION => $punchoutCatalogTransaction->getIdPunchoutCatalogTransaction(),
185
            ]),
186
            'View'
187
        );
188
    }
189
190
    /**
191
     * @param \Orm\Zed\PunchoutCatalog\Persistence\PgwPunchoutCatalogTransaction $punchoutCatalogTransaction
192
     *
193
     * @return string
194
     */
195
    protected function getStatusLabel(PgwPunchoutCatalogTransaction $punchoutCatalogTransaction): string
196
    {
197
        if (!$punchoutCatalogTransaction->getStatus()) {
198
            return $this->generateLabel(static::STATUS_UNSUCCESSFUL, 'label-danger');
199
        }
200
201
        return $this->generateLabel(static::STATUS_SUCCESSFUL, 'label-info');
202
    }
203
204
    /**
205
     * @param \Orm\Zed\PunchoutCatalog\Persistence\PgwPunchoutCatalogTransaction $punchoutCatalogTransaction
206
     * @param array $punchoutCatalogTransactionRow
207
     *
208
     * @return array
209
     */
210
    protected function addCompanyBusinessUnitColumn(PgwPunchoutCatalogTransaction $punchoutCatalogTransaction, array $punchoutCatalogTransactionRow): array
211
    {
212
        $punchoutCatalogTransactionRow[static::COL_BUSINESS_UNIT] = $punchoutCatalogTransaction->getFkCompanyBusinessUnit() ?: 'NULL';
213
214
        return $punchoutCatalogTransactionRow;
215
    }
216
217
    /**
218
     * @param \Orm\Zed\PunchoutCatalog\Persistence\PgwPunchoutCatalogTransaction $punchoutCatalogTransaction
219
     * @param array $punchoutCatalogTransactionRow
220
     *
221
     * @return array
222
     */
223
    protected function addConnectionNameColumn(PgwPunchoutCatalogTransaction $punchoutCatalogTransaction, array $punchoutCatalogTransactionRow): array
224
    {
225
        $punchoutCatalogTransactionRow[static::COL_CONNECTION_NAME] = '';
226
        if ($punchoutCatalogTransaction->getPunchoutCatalogConnection()) {
227
            $punchoutCatalogTransactionRow[static::COL_CONNECTION_NAME] = $punchoutCatalogTransaction->getPunchoutCatalogConnection()
228
                ->getName();
229
        }
230
231
        return $punchoutCatalogTransactionRow;
232
    }
233
}
234