Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 52
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
tao_actions_form_Translate
0.00% covered (danger)
0.00%
0 / 52
0.00% covered (danger)
0.00%
0 / 2
182
0.00% covered (danger)
0.00%
0 / 1
 initForm
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
 initElements
0.00% covered (danger)
0.00%
0 / 47
0.00% covered (danger)
0.00%
0 / 1
156
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
25use oat\generis\model\OntologyRdfs;
26use oat\tao\model\TaoOntology;
27
28/**
29 * Create a form to translate a resource of the ontology
30 *
31 * @access public
32 * @author Bertrand Chevrier, <bertrand.chevrier@tudor.lu>
33 * @package tao
34
35 */
36class tao_actions_form_Translate extends tao_actions_form_Instance
37{
38    // --- ASSOCIATIONS ---
39
40
41    // --- ATTRIBUTES ---
42
43    // --- OPERATIONS ---
44
45    /**
46     * Initialize the form
47     *
48     * @access protected
49     * @author Bertrand Chevrier, <bertrand.chevrier@tudor.lu>
50     * @return mixed
51     */
52    protected function initForm()
53    {
54
55
56        parent::initForm();
57        $this->form->setName('translate_' . $this->form->getName());
58
59        $actions = tao_helpers_form_FormFactory::getCommonActions('top');
60        $this->form->setActions($actions, 'top');
61        $this->form->setActions($actions, 'bottom');
62    }
63
64    /**
65     * Initialize the form elements
66     *
67     * @access protected
68     * @author Bertrand Chevrier, <bertrand.chevrier@tudor.lu>
69     * @return mixed
70     */
71    protected function initElements()
72    {
73
74
75        parent::initElements();
76
77        $elements = $this->form->getElements();
78        $this->form->setElements([]);
79
80
81        $currentLangElt = tao_helpers_form_FormFactory::getElement('current_lang', 'Textbox');
82        $currentLangElt->setDescription(__('Current language'));
83        $currentLangElt->setAttributes(['readonly' => 'true']);
84        // API lang /data lang
85        $currentLangElt->setValue(\common_session_SessionManager::getSession()->getDataLanguage());
86        $this->form->addElement($currentLangElt);
87
88        $dataLangElement = tao_helpers_form_FormFactory::getElement('translate_lang', 'Combobox');
89        $dataLangElement->setDescription(__('Translate to'));
90        $dataLangElement->setOptions(
91            tao_helpers_I18n::getAvailableLangsByUsage(
92                new core_kernel_classes_Resource(tao_models_classes_LanguageService::INSTANCE_LANGUAGE_USAGE_DATA)
93            )
94        );
95        $dataLangElement->setEmptyOption(__('Select a language'));
96        $dataLangElement->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty'));
97        $this->form->addElement($dataLangElement);
98
99        $this->form->createGroup('translation_info', __('Translation parameters'), ['current_lang', 'translate_lang']);
100
101        $dataGroup = [];
102        foreach ($elements as $element) {
103            if (
104                $element instanceof tao_helpers_form_elements_Hidden ||
105                $element->getName() == 'uri' || $element->getName() == 'classUri'
106            ) {
107                $this->form->addElement($element);
108            } else {
109                $propertyUri = tao_helpers_Uri::decode($element->getName());
110                $property = new core_kernel_classes_Property($propertyUri);
111
112                //translate only language dependent properties or Labels
113                //supported widget are: Textbox, TextArea, HtmlArea
114                //@todo support other widgets
115                if (
116                    ($property->isLgDependent() &&
117                      (
118                          $element instanceof tao_helpers_form_elements_Textbox ||
119                       $element instanceof tao_helpers_form_elements_TextArea ||
120                       $element instanceof tao_helpers_form_elements_HtmlArea
121                      )) ||
122                    $propertyUri == OntologyRdfs::RDFS_LABEL
123                ) {
124                    $translatedElt = clone $element;
125
126                    $viewElt = tao_helpers_form_FormFactory::getElement('view_' . $element->getName(), 'Label');
127                    $viewElt->setDescription($element->getDescription());
128                    $viewElt->setValue($element->getValue());
129                    $viewElt->setAttribute('no-format', true);
130                    if ($element instanceof tao_helpers_form_elements_HtmlArea) {
131                        $viewElt->setAttribute('htmlentities', false);
132                    }
133
134                    $this->form->addElement($viewElt);
135
136                    $dataGroup[] = $viewElt->getName();
137
138                    $translatedElt->setDescription(' ');
139                    $translatedElt->setValue('');
140                    if ($propertyUri == OntologyRdfs::RDFS_LABEL) {
141                        $translatedElt->setForcedValid();
142                    }
143
144                    $this->form->addElement($translatedElt);
145
146                    $dataGroup[] = $translatedElt->getName();
147                }
148            }
149        }
150
151        $this->form->createGroup('translation_form', __('Translate'), $dataGroup);
152    }
153}