|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the ONGR package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) NFQ Technologies UAB <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace ONGR\TranslationsBundle\Controller; |
|
13
|
|
|
|
|
14
|
|
|
use ONGR\TranslationsBundle\Service\TranslationChecker; |
|
15
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
|
16
|
|
|
use Symfony\Component\Console\Input\ArrayInput; |
|
17
|
|
|
use Symfony\Component\Console\Output\NullOutput; |
|
18
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
|
19
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
20
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
21
|
|
|
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Controller used for api's actions. |
|
25
|
|
|
*/ |
|
26
|
|
|
class ApiController extends Controller |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* Action for editing translation objects. |
|
30
|
|
|
* |
|
31
|
|
|
* @param Request $request Http request object. |
|
32
|
|
|
* @param string $id |
|
33
|
|
|
* |
|
34
|
|
|
* @return JsonResponse |
|
35
|
|
|
*/ |
|
36
|
|
|
public function editAction(Request $request, $id) |
|
37
|
|
|
{ |
|
38
|
|
|
$response = ['error' => false]; |
|
39
|
|
|
|
|
40
|
|
|
try { |
|
41
|
|
|
$this->get('ongr_translations.translation_manager')->edit($id, $request); |
|
42
|
|
|
} catch (\LogicException $e) { |
|
43
|
|
|
$response = ['error' => true]; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
return new JsonResponse($response); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Action for getting translation. |
|
51
|
|
|
* |
|
52
|
|
|
* @param Request $request Http request object. |
|
53
|
|
|
* @param string $id |
|
54
|
|
|
* |
|
55
|
|
|
* @return JsonResponse |
|
56
|
|
|
*/ |
|
57
|
|
|
public function getAction(Request $request, $id) |
|
|
|
|
|
|
58
|
|
|
{ |
|
59
|
|
|
return new JsonResponse($this->get('ongr_translations.translation_manager')->getTranslation($id)); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Action for executing export command. |
|
64
|
|
|
* |
|
65
|
|
|
* @return JsonResponse |
|
66
|
|
|
*/ |
|
67
|
|
|
public function exportAction() |
|
68
|
|
|
{ |
|
69
|
|
|
$cwd = getcwd(); |
|
70
|
|
|
if (substr($cwd, -3) === 'web') { |
|
71
|
|
|
chdir($cwd . DIRECTORY_SEPARATOR . '..'); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
$output = ['error' => false]; |
|
75
|
|
|
|
|
76
|
|
|
if ($this->get('ongr_translations.command.export')->run(new ArrayInput([]), new NullOutput()) != 0) { |
|
77
|
|
|
$output['error'] = true; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
return new JsonResponse($output); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Action for executing history command. |
|
85
|
|
|
* |
|
86
|
|
|
* @param Request $request Http request object. |
|
87
|
|
|
* @param string $id |
|
88
|
|
|
* |
|
89
|
|
|
* @return JsonResponse |
|
90
|
|
|
*/ |
|
91
|
|
|
public function historyAction(Request $request, $id) |
|
|
|
|
|
|
92
|
|
|
{ |
|
93
|
|
|
$document = $this->get('ongr_translations.translation_manager')->getTranslation($id); |
|
94
|
|
|
|
|
95
|
|
|
if (empty($document)) { |
|
96
|
|
|
return new JsonResponse(['error' => true, 'message' => 'translation not found']); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
return new JsonResponse($this->get('ongr_translations.history_manager')->getHistory($document)); |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.