Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 57
0.00% covered (danger)
0.00%
0 / 14
CRAP
0.00% covered (danger)
0.00%
0 / 1
tao_actions_Translation
0.00% covered (danger)
0.00%
0 / 57
0.00% covered (danger)
0.00%
0 / 14
462
0.00% covered (danger)
0.00%
0 / 1
 update
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 1
6
 delete
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
6
 translate
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
6
 translations
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
6
 translatable
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
6
 sync
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
6
 status
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
6
 getResourceTranslationRetriever
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getResourceTranslatableRetriever
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getTranslationCreationService
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getTranslationUpdateService
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getTranslationSyncService
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getTranslationDeletionService
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getResourceTranslatableStatusRetriever
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
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) 2024 (original work) Open Assessment Technologies SA;
19 */
20
21declare(strict_types=1);
22
23use oat\tao\model\http\HttpJsonResponseTrait;
24use oat\tao\model\Translation\Command\UpdateTranslationCommand;
25use oat\tao\model\Translation\Service\ResourceTranslationRetriever;
26use oat\tao\model\Translation\Service\ResourceTranslatableRetriever;
27use oat\tao\model\Translation\Service\ResourceTranslatableStatusRetriever;
28use oat\tao\model\Translation\Service\TranslationCreationService;
29use oat\tao\model\Translation\Service\TranslationDeletionService;
30use oat\tao\model\Translation\Service\TranslationSyncService;
31use oat\tao\model\Translation\Service\TranslationUpdateService;
32
33class tao_actions_Translation extends tao_actions_CommonModule
34{
35    use HttpJsonResponseTrait;
36
37    /**
38     * @requiresRight id WRITE
39     */
40    public function update(): void
41    {
42        try {
43            $resource = $this->getTranslationUpdateService()->update(
44                new UpdateTranslationCommand(
45                    $this->getRequestParameter('id'),
46                    $this->getRequestParameter('progress'),
47                )
48            );
49
50            $this->setSuccessJsonResponse(
51                [
52                    'resourceUri' => $resource->getUri()
53                ]
54            );
55        } catch (Throwable $exception) {
56            $this->setErrorJsonResponse($exception->getMessage());
57        }
58    }
59
60    /**
61     * @requiresRight id WRITE
62     */
63    public function delete(): void
64    {
65        try {
66            $resource = $this->getTranslationDeletionService()->deleteByRequest($this->getPsrRequest());
67
68            $this->setSuccessJsonResponse(
69                [
70                    'resourceUri' => $resource->getUri()
71                ]
72            );
73        } catch (Throwable $exception) {
74            $this->setErrorJsonResponse($exception->getMessage());
75        }
76    }
77
78    /**
79     * @requiresRight id WRITE
80     */
81    public function translate(): void
82    {
83        try {
84            $newResource = $this->getTranslationCreationService()->createByRequest($this->getPsrRequest());
85
86            $this->setSuccessJsonResponse(
87                [
88                    'resourceUri' => $newResource->getUri()
89                ]
90            );
91        } catch (Throwable $exception) {
92            $this->setErrorJsonResponse($exception->getMessage());
93        }
94    }
95
96    /**
97     * @requiresRight id READ
98     */
99    public function translations(): void
100    {
101        try {
102            $this->setSuccessJsonResponse(
103                $this->getResourceTranslationRetriever()->getByRequest($this->getPsrRequest())
104            );
105        } catch (Throwable $exception) {
106            $this->setErrorJsonResponse($exception->getMessage());
107        }
108    }
109
110    /**
111     * @requiresRight id READ
112     */
113    public function translatable(): void
114    {
115        try {
116            $this->setSuccessJsonResponse(
117                $this->getResourceTranslatableRetriever()->getByRequest($this->getPsrRequest())
118            );
119        } catch (Throwable $exception) {
120            $this->setErrorJsonResponse($exception->getMessage());
121        }
122    }
123
124    /**
125     * @requiresRight id WRITE
126     */
127    public function sync(): void
128    {
129        try {
130            $test = $this->getTranslationSyncService()->syncByRequest($this->getPsrRequest());
131
132            $this->setSuccessJsonResponse([
133                'resourceUri' => $test->getUri(),
134            ]);
135        } catch (Throwable $exception) {
136            $this->setErrorJsonResponse($exception->getMessage());
137        }
138    }
139
140    /**
141     * @requiresRight id READ
142     */
143    public function status(): void
144    {
145        try {
146            $this->setSuccessJsonResponse(
147                $this->getResourceTranslatableStatusRetriever()->retrieveByRequest($this->getPsrRequest())
148            );
149        } catch (Throwable $exception) {
150            $this->setErrorJsonResponse($exception->getMessage());
151        }
152    }
153
154    private function getResourceTranslationRetriever(): ResourceTranslationRetriever
155    {
156        return $this->getPsrContainer()->get(ResourceTranslationRetriever::class);
157    }
158
159    private function getResourceTranslatableRetriever(): ResourceTranslatableRetriever
160    {
161        return $this->getPsrContainer()->get(ResourceTranslatableRetriever::class);
162    }
163
164    private function getTranslationCreationService(): TranslationCreationService
165    {
166        return $this->getPsrContainer()->get(TranslationCreationService::class);
167    }
168
169    private function getTranslationUpdateService(): TranslationUpdateService
170    {
171        return $this->getPsrContainer()->get(TranslationUpdateService::class);
172    }
173
174    private function getTranslationSyncService(): TranslationSyncService
175    {
176        return $this->getPsrContainer()->get(TranslationSyncService::class);
177    }
178
179    private function getTranslationDeletionService(): TranslationDeletionService
180    {
181        return $this->getPsrContainer()->get(TranslationDeletionService::class);
182    }
183
184    private function getResourceTranslatableStatusRetriever(): ResourceTranslatableStatusRetriever
185    {
186        return $this->getPsrContainer()->get(ResourceTranslatableStatusRetriever::class);
187    }
188}