Test Failed
Push — development ( 07d7f1...a41c7d )
by Philippe
02:16
created

AccountController::unlinkUriAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 2
1
<?php
2
/*
3
 * This program is free software: you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License as published by
5
 * the Free Software Foundation, either version 3 of the License, or
6
 * (at your option) any later version.
7
 *
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 * GNU General Public License for more details.
12
 *
13
 * You should have received a copy of the GNU General Public License
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
 */
16
17
namespace Filoucrackeur\Hubic\Controller\Backend;
18
19
use Filoucrackeur\Hubic\Domain\Model\Account;
20
use Filoucrackeur\Hubic\Service\HubicService;
21
use TYPO3\CMS\Core\Messaging\AbstractMessage;
22
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
23
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
24
25
/**
26
 * Class AccountController
27
 */
28
class AccountController extends ActionController
29
{
30
    /**
31
     * @var \Filoucrackeur\Hubic\Service\HubicService
32
     */
33
    protected $hubicService;
34
35
    public function indexAction(): void
36
    {
37
        $this->view->assign('accounts', $this->hubicService->getAccounts());
38
    }
39
40
    /**
41
     * @param Account $account
42
     */
43
    public function showAction(Account $account): void
44
    {
45
        if ($account->getAccessToken()) {
46
            $this->hubicService->setAccount($account);
47
            $clientAccountQuota = $this->hubicService->getAccountQuota();
48
            $clientAccount = $this->hubicService->getAccount();
49
            $agreement = $this->hubicService->getAgreement();
50
            $links = $this->hubicService->getAllLinks();
51
            $this->view->assignMultiple([
52
                'clientAccount' => $clientAccount,
53
                'clientAccountQuota' => $clientAccountQuota,
54
                'agreement' => $agreement,
55
                'links' => $links
56
            ]);
57
        }
58
59
        $this->view->assign('account', $account);
60
    }
61
62
    /**
63
     * @param Account $account
64
     */
65
    public function refreshTokenAction(Account $account): void
66
    {
67
        $this->hubicService->refreshToken($account);
68
69
        $this->forward('show', null, null, ['account' => $account]);
70
    }
71
72
    /**
73
     * @param Account $account
74
     */
75
    public function accessTokenAction(Account $account): void
76
    {
77
        $this->hubicService->redirectUrlRequestToken($account);
78
    }
79
80
    /**
81
     * @param Account $account
82
     * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
83
     */
84
    public function callbackAction(Account $account): void
85
    {
86
        if ($this->hubicService->accessToken($account)) {
87
            $this->addFlashMessage(LocalizationUtility::translate('flashmessage.token_added', 'hubic'),
88
                LocalizationUtility::translate('flashmessage.authentication', 'hubic'),
89
                AbstractMessage::OK);
90
        } else {
91
            $this->addFlashMessage(LocalizationUtility::translate('flashmessage.missing_client_data', 'hubic'),
92
                LocalizationUtility::translate('flashmessage.authentication', 'hubic'),
93
                AbstractMessage::ERROR);
94
        }
95
        $this->forward('show', null, null, ['account' => $account]);
96
    }
97
98
    /**
99
     * @param Account $account
100
     */
101
    public function deleteAction(Account $account): void
102
    {
103
        $this->hubicService->delete($account);
104
        $this->addFlashMessage(LocalizationUtility::translate('flashmessage.account_deleted', 'hubic'),
105
            LocalizationUtility::translate('account', 'hubic'),
106
            AbstractMessage::OK);
107
        $this->forward('index');
108
    }
109
110
    /**
111
     * @param Account $account
112
     * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
113
     */
114
    public function unlinkAction(Account $account): void
115
    {
116
        $this->hubicService->unlink($account);
117
118
        $this->addFlashMessage(LocalizationUtility::translate('flashmessage.account_unlinked', 'hubic'),
119
            LocalizationUtility::translate('account', 'hubic'),
120
            AbstractMessage::OK);
121
        $this->forward('index');
122
    }
123
124
    /**
125
     * @param Account $account
126
     * @param string $uri
127
     */
128
    public function unlinkUriAction(Account $account, string $uri)
129
    {
130
        $this->hubicService->setAccount($account);
131
        $this->hubicService->deleteLink($uri);
132
        $this->forward('show', null, null, ['account' => $account]);
133
    }
134
135
    /**
136
     * @param HubicService $hubicService
137
     */
138
    public function injectHubicService(HubicService $hubicService): void
139
    {
140
        $this->hubicService = $hubicService;
141
    }
142
}
143