|
1
|
|
|
<?php namespace Modules\Translation\Http\Controllers\Api; |
|
2
|
|
|
|
|
3
|
|
|
use Illuminate\Database\Eloquent\Collection; |
|
4
|
|
|
use Illuminate\Http\Request; |
|
5
|
|
|
use Illuminate\Routing\Controller; |
|
6
|
|
|
use Modules\Translation\Repositories\TranslationRepository; |
|
7
|
|
|
|
|
8
|
|
|
class TranslationController extends Controller |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* @var TranslationRepository |
|
12
|
|
|
*/ |
|
13
|
|
|
private $translation; |
|
14
|
|
|
|
|
15
|
|
|
public function __construct(TranslationRepository $translation) |
|
16
|
|
|
{ |
|
17
|
|
|
$this->translation = $translation; |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
public function update(Request $request) |
|
21
|
|
|
{ |
|
22
|
|
|
$this->translation->saveTranslationForLocaleAndKey( |
|
23
|
|
|
$request->get('locale'), |
|
24
|
|
|
$request->get('key'), |
|
25
|
|
|
$request->get('value') |
|
26
|
|
|
); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function clearCache() |
|
30
|
|
|
{ |
|
31
|
|
|
$this->translation->clearCache(); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function revisions(Request $request) |
|
35
|
|
|
{ |
|
36
|
|
|
$translation = $this->translation->findTranslationByKey($request->get('key')); |
|
37
|
|
|
$translation = $translation->translate($request->get('locale')); |
|
38
|
|
|
|
|
39
|
|
|
return response()->json($this->formatRevisionHistory($translation->revisionHistory)); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
private function formatRevisionHistory(Collection $revisionHistory) |
|
43
|
|
|
{ |
|
44
|
|
|
$formattedHistory = []; |
|
45
|
|
|
|
|
46
|
|
|
foreach ($revisionHistory as $history) { |
|
47
|
|
|
$timeAgo = $history->created_at->diffForHumans(); |
|
48
|
|
|
$revertRoute = route('admin.translation.translation.update', [$history->revisionable_id, 'oldValue' => $history->oldValue()]); |
|
49
|
|
|
$formattedHistory[] = <<<HTML |
|
50
|
|
|
<tr> |
|
51
|
|
|
<td>{$history->oldValue()}</td> |
|
52
|
|
|
<td>{$history->userResponsible()->first_name} {$history->userResponsible()->last_name}</td> |
|
53
|
|
|
<td><a data-toggle="tooltip" title="{$history->created_at}">{$timeAgo}</a></td> |
|
54
|
|
|
<td><a href="{$revertRoute}"><i class="fa fa-history"></i></a></td> |
|
55
|
|
|
</tr> |
|
56
|
|
|
HTML; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
return $formattedHistory; |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|