Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 32 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
| tao_helpers_translation_POFile | |
0.00% |
0 / 32 |
|
0.00% |
0 / 6 |
272 | |
0.00% |
0 / 1 |
| addHeader | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| removeHeader | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getHeaders | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| getByFlag | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
12 | |||
| getByFlags | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
30 | |||
| addTranslationUnit | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
30 | |||
| 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_POFile |
| 27 | * |
| 28 | * @access public |
| 29 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
| 30 | * @package tao |
| 31 | |
| 32 | */ |
| 33 | class tao_helpers_translation_POFile extends tao_helpers_translation_TaoTranslationFile |
| 34 | { |
| 35 | // --- ASSOCIATIONS --- |
| 36 | |
| 37 | |
| 38 | // --- ATTRIBUTES --- |
| 39 | |
| 40 | /** |
| 41 | * Short description of attribute headers |
| 42 | * |
| 43 | * @access private |
| 44 | * @var array |
| 45 | */ |
| 46 | private $headers = []; |
| 47 | |
| 48 | // --- OPERATIONS --- |
| 49 | |
| 50 | /** |
| 51 | * Short description of method addHeader |
| 52 | * |
| 53 | * @access public |
| 54 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
| 55 | * @param string name |
| 56 | * @param string value |
| 57 | * @return void |
| 58 | */ |
| 59 | public function addHeader($name, $value) |
| 60 | { |
| 61 | |
| 62 | $this->headers[$name] = $value; |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Short description of method removeHeader |
| 67 | * |
| 68 | * @access public |
| 69 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
| 70 | * @param string name |
| 71 | * @return void |
| 72 | */ |
| 73 | public function removeHeader($name) |
| 74 | { |
| 75 | |
| 76 | unset($this->headers[$name]); |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Short description of method getHeaders |
| 81 | * |
| 82 | * @access public |
| 83 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
| 84 | * @return array |
| 85 | */ |
| 86 | public function getHeaders() |
| 87 | { |
| 88 | $returnValue = []; |
| 89 | |
| 90 | |
| 91 | $returnValue = $this->headers; |
| 92 | |
| 93 | |
| 94 | return (array) $returnValue; |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * Get a collection of POTranslationUnits based on the $flag argument |
| 99 | * If no Translation Units are found, an empty array is returned. |
| 100 | * |
| 101 | * @access public |
| 102 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
| 103 | * @param string flag A PO compliant string flag. |
| 104 | * @return array |
| 105 | */ |
| 106 | public function getByFlag($flag) |
| 107 | { |
| 108 | $returnValue = []; |
| 109 | |
| 110 | |
| 111 | foreach ($this->getTranslationUnits() as $tu) { |
| 112 | if ($tu->hasFlag($flag)) { |
| 113 | $returnValue[] = $tu; |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | |
| 118 | return (array) $returnValue; |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * Get a collection of POTranslationUnits that have all the flags referenced |
| 123 | * the $flags array. If no TranslationUnits are found, an empty array is |
| 124 | * |
| 125 | * @access public |
| 126 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
| 127 | * @param array flags An array of PO compliant string flags. |
| 128 | * @return array |
| 129 | */ |
| 130 | public function getByFlags($flags) |
| 131 | { |
| 132 | $returnValue = []; |
| 133 | |
| 134 | |
| 135 | foreach ($this->getTranslationUnits() as $tu) { |
| 136 | $matching = true; |
| 137 | foreach ($flags as $f) { |
| 138 | if (!$tu->hasFlag($f)) { |
| 139 | $matching = false; |
| 140 | break; |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | if ($matching == true) { |
| 145 | $returnValue[] = $tu; |
| 146 | } else { |
| 147 | // Prepare next iteration. |
| 148 | $matching = true; |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | |
| 153 | return (array) $returnValue; |
| 154 | } |
| 155 | |
| 156 | /** |
| 157 | * Adds a TranslationUnit instance to the file. It is appenned at the end of |
| 158 | * collection. |
| 159 | * |
| 160 | * @access public |
| 161 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
| 162 | * @param tao_helpers_translation_TranslationUnit $translationUnit |
| 163 | * @return mixed |
| 164 | */ |
| 165 | public function addTranslationUnit(tao_helpers_translation_TranslationUnit $translationUnit) |
| 166 | { |
| 167 | |
| 168 | // If the translation unit exists, we replace the target with the new one if it exists. |
| 169 | // also now we take care about context |
| 170 | /** @var tao_helpers_translation_TranslationUnit $tu */ |
| 171 | foreach ($this->getTranslationUnits() as $tu) { |
| 172 | if ( |
| 173 | $tu->getSource() == $translationUnit->getSource() && |
| 174 | (!$translationUnit->getContext() || $tu->getContext() == $translationUnit->getContext()) |
| 175 | ) { |
| 176 | $tu->setTarget($translationUnit->getTarget()); |
| 177 | $tu->setAnnotations($translationUnit->getAnnotations()); |
| 178 | |
| 179 | return; |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | // If we are here, it means that this TU does not exist. |
| 184 | $translationUnit->setSourceLanguage($this->getSourceLanguage()); |
| 185 | $translationUnit->setTargetLanguage($this->getTargetLanguage()); |
| 186 | |
| 187 | $tus = $this->getTranslationUnits(); |
| 188 | array_push($tus, $translationUnit); |
| 189 | $this->setTranslationUnits($tus); |
| 190 | } |
| 191 | } |