setTranslationsForKeyFromService()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 4
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/*
3
 * Copyright (c) 2012-2015 Marc Teyssier
4
 *
5
 * See the file LICENSE.txt for copying permission.
6
 */
7
namespace Mouf\Utils\I18n\Fine\Common\Ui;
8
9
use Mouf\InstanceProxy;
10
11
/**
12
 * This trait help you to create your own human interface in Mouf.
13
 * It make a bind to the translator to retrieve, add, edit or remove a translation
14
 *
15
 * @author Marc TEYSSIER
16
 *
17
 */
18
trait EditTranslationProxyTrait
19
{
20
21
    /**
22
     * Returns the list of all messages in all languages by making a CURL call. It is possible to set a language to retrieve only the associated message.
23
     *
24
     * @param  bool      $selfEdit
25
     * @param  string    $msgInstanceName
26
     * @param  string    $language
27
     * @return array
28
     * @throws Exception
29
     */
30
    protected function getAllMessagesFromService($selfEdit, $msgInstanceName = "defaultTranslationService", $language = null)
31
    {
32
        $translationService = new InstanceProxy($msgInstanceName, $selfEdit);
33
34
        return $translationService->getAllTranslationByLanguage($language);
35
    }
36
37
    /**
38
     * Returns all the translation of one key by making a CURL call.
39
     *
40
     * @param  bool      $selfEdit
41
     * @param  string    $msgInstanceName
42
     * @param  string    $key
43
     * @return array
44
     * @throws Exception
45
     */
46
    protected function getTranslationsForKeyFromService($selfEdit, $msgInstanceName, $key)
47
    {
48
        $translationService = new InstanceProxy($msgInstanceName, $selfEdit);
49
50
        return $translationService->getTranslationsForKey($key);
51
    }
52
53
    protected function setTranslationsForKeyFromService($selfEdit, $msgInstanceName, $key, $translations)
54
    {
55
        $translationService = new InstanceProxy($msgInstanceName, $selfEdit);
56
57
        return $translationService->setTranslationsForKey($translations, $key);
58
    }
59
60
    /**
61
     * Saves many translations for one key and one language using CURL.
62
     *
63
     * @param  bool      $selfEdit
64
     * @param  string    $msgInstanceName
65
     * @param  string    $language
66
     * @param  array     $translations
67
     * @return boolean
68
     * @throws Exception
69
     */
70
    protected function setTranslationsForMessageFromService($selfEdit, $msgInstanceName, $language, $translations)
71
    {
72
        $translationService = new InstanceProxy($msgInstanceName, $selfEdit);
73
74
        return $translationService->setMessages($translations, $language);
75
    }
76
77
    /**
78
     * Saves the translation for one key and one language using CURL.
79
     *
80
     * @param  bool      $selfEdit
81
     * @param  string    $msgInstanceName
82
     * @param  string    $key
83
     * @param  string    $label
84
     * @param  string    $language
85
     * @param  string    $delete
86
     * @return boolean
87
     * @throws Exception
88
     */
89
    protected function setTranslationForMessageFromService($selfEdit, $msgInstanceName, $key, $label, $language, $delete)
90
    {
91
        if ($delete) {
92
            $translationService = new InstanceProxy($msgInstanceName, $selfEdit);
93
94
            return $translationService->deleteMessage($key, $language);
95
        } else {
96
            $translationService = new InstanceProxy($msgInstanceName, $selfEdit);
97
98
            return $translationService->setMessage($key, $label, $language);
99
        }
100
    }
101
102
    /**
103
     * Adds a new translation language using CURL.
104
     *
105
     * @param  bool      $selfEdit
106
     * @param  string    $msgInstanceName
107
     * @param  string    $language
108
     * @return boolean
109
     * @throws Exception
110
     */
111
    protected function deleteTranslationFromService($selfEdit, $msgInstanceName, $key, $language = null)
112
    {
113
        $finePhpArrayTranslationService = new InstanceProxy($msgInstanceName, $selfEdit);
114
        $finePhpArrayTranslationService->deleteTranslation($key, $language);
115
    }
116
}
117