Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 28 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 1 |
tao_helpers_translation_RDFTranslationFile | |
0.00% |
0 / 28 |
|
0.00% |
0 / 7 |
272 | |
0.00% |
0 / 1 |
addTranslationUnit | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
42 | |||
setNamespaces | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
addNamespace | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
12 | |||
removeNamespace | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
12 | |||
getNamespaces | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
setBase | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getBase | |
0.00% |
0 / 3 |
|
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) 2008-2010 (original work) Deutsche Institut für Internationale Pädagogische Forschung |
19 | * (under the project TAO-TRANSFER); |
20 | * 2009-2012 (update and modification) Public Research Centre Henri Tudor |
21 | * (under the project TAO-SUSTAIN & TAO-DEV); |
22 | * |
23 | */ |
24 | |
25 | /** |
26 | * Short description of class tao_helpers_translation_RDFTranslationFile |
27 | * |
28 | * @access public |
29 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
30 | * @package tao |
31 | |
32 | */ |
33 | class tao_helpers_translation_RDFTranslationFile extends tao_helpers_translation_TaoTranslationFile |
34 | { |
35 | // --- ASSOCIATIONS --- |
36 | |
37 | |
38 | // --- ATTRIBUTES --- |
39 | |
40 | /** |
41 | * Short description of attribute namespaces |
42 | * |
43 | * @access private |
44 | * @var array |
45 | */ |
46 | private $namespaces = [['rdf', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#']]; |
47 | |
48 | /** |
49 | * The namespace to which the translations belongs to. |
50 | * |
51 | * @access private |
52 | * @var string |
53 | */ |
54 | private $base = ''; |
55 | |
56 | // --- OPERATIONS --- |
57 | |
58 | /** |
59 | * Short description of method addTranslationUnit |
60 | * |
61 | * @access public |
62 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
63 | * @param TranslationUnit translationUnit |
64 | * @return mixed |
65 | */ |
66 | public function addTranslationUnit(tao_helpers_translation_TranslationUnit $translationUnit) |
67 | { |
68 | |
69 | // We override the default behaviour because for RDFTranslationFiles, TranslationUnits are |
70 | // unique by concatening the following attributes: |
71 | // - RDFTranslationUnit::subject |
72 | // - RDFTranslationUnit::predicate |
73 | // - RDFTranslationUnit::targetLanguage |
74 | foreach ($this->getTranslationUnits() as $tu) { |
75 | if ( |
76 | $tu->hasSameTranslationUnitSubject($translationUnit) && |
77 | $tu->hasSameTranslationUnitPredicate($translationUnit) && |
78 | $tu->hasSameTranslationUnitTargetLanguage($translationUnit) |
79 | ) { |
80 | // This TU already exists. We change its target if the new one |
81 | // has one. |
82 | if ($translationUnit->getTarget() != $translationUnit->getSource()) { |
83 | $tu->setTarget($translationUnit->getTarget()); |
84 | } |
85 | return; |
86 | } |
87 | } |
88 | |
89 | // If we are executing this, we can add the TranslationUnit to this TranslationFile. |
90 | $translationUnit->setSourceLanguage($this->getSourceLanguage()); |
91 | $translationUnit->setTargetLanguage($this->getTargetLanguage()); |
92 | $tus = $this->getTranslationUnits(); |
93 | array_push($tus, $translationUnit); |
94 | $this->setTranslationUnits($tus); |
95 | } |
96 | |
97 | /** |
98 | * Sets the namespaces list of the TranslationFile. The namespace array must |
99 | * an array of array formated like this: array(array('nsprefix' => 'URI'), |
100 | * Former namespaces will be removed. |
101 | * |
102 | * @access public |
103 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
104 | * @param array namespaces |
105 | * @return void |
106 | */ |
107 | public function setNamespaces($namespaces) |
108 | { |
109 | |
110 | $this->namespaces = $namespaces; |
111 | } |
112 | |
113 | /** |
114 | * Adds a namespace to the namespaces list. The $namespace array must be |
115 | * like array('nsprefix' => 'uri'). If the 'nsprefix' value matches an |
116 | * set namespace, it will be updated with the new 'uri'. |
117 | * |
118 | * @access public |
119 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
120 | * @param array namespace |
121 | * @return void |
122 | */ |
123 | public function addNamespace($namespace) |
124 | { |
125 | |
126 | foreach ($this->getNamespaces() as $ns) { |
127 | if ($ns['prefix'] == $namespace['prefix']) { |
128 | // This namespace is already registered. |
129 | return; |
130 | } |
131 | } |
132 | |
133 | array_push($this->namespaces, $namespace); |
134 | } |
135 | |
136 | /** |
137 | * Removes a namespace in the list of namespaces. The $namespace array must |
138 | * formatted like array('nsprefix' => 'uri'). If the 'nsprefix' cannot be |
139 | * nothing happens. If found, the related namespace will be removed from the |
140 | * namespace list. |
141 | * |
142 | * @access public |
143 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
144 | * @param array namespace |
145 | * @return void |
146 | */ |
147 | public function removeNamespace($namespace) |
148 | { |
149 | |
150 | foreach ($this->getNamespaces() as $ns) { |
151 | if ($ns['prefix'] == $namespace['prefix']) { |
152 | unset($ns); |
153 | break; |
154 | } |
155 | } |
156 | } |
157 | |
158 | /** |
159 | * Gets the current namespaces list. |
160 | * |
161 | * @access public |
162 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
163 | * @return array |
164 | */ |
165 | public function getNamespaces() |
166 | { |
167 | $returnValue = []; |
168 | |
169 | |
170 | $returnValue = $this->namespaces; |
171 | |
172 | |
173 | return (array) $returnValue; |
174 | } |
175 | |
176 | /** |
177 | * Sets the base namespace to which the RDFTranslationUnits belong to. |
178 | * |
179 | * @access public |
180 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
181 | * @param string base |
182 | * @return void |
183 | */ |
184 | public function setBase($base) |
185 | { |
186 | |
187 | $this->base = $base; |
188 | } |
189 | |
190 | /** |
191 | * Gets the current base namespace to which the RDFTranslationUnits belong |
192 | * |
193 | * @access public |
194 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
195 | * @return string |
196 | */ |
197 | public function getBase() |
198 | { |
199 | $returnValue = (string) ''; |
200 | |
201 | |
202 | $returnValue = $this->base; |
203 | |
204 | |
205 | return (string) $returnValue; |
206 | } |
207 | } |