Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
tao_helpers_form_elements_xhtml_JsonObject
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 1
20
0.00% covered (danger)
0.00%
0 / 1
 render
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 1
20
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 *               2013
23 */
24
25use oat\tao\helpers\form\elements\xhtml\XhtmlRenderingTrait;
26
27/**
28 * An XHTML Form Element enabling the edition of JSON strings.
29 */
30class tao_helpers_form_elements_xhtml_JsonObject extends tao_helpers_form_elements_JsonObject
31{
32    use XhtmlRenderingTrait;
33
34    /**
35     * Render the JSON String as a collection of key/value pairs
36     *
37     * @return string
38     */
39    public function render()
40    {
41        $returnValue = $this->renderLabel();
42
43        if (empty($this->value) === true) {
44            // @todo should be in a blue info box.
45            $returnValue .= "No values to display.";
46        } elseif (($jsonObject = @json_decode($this->value)) === null) {
47            // @todo should be in a red error box.
48            $returnValue .= "Invalid value.";
49        } else {
50            // Valid JSON to be displayed.
51            $returnValue .= "<ul class=\"json-object-list\">";
52
53            foreach ($jsonObject as $jsonKey => $jsonValue) {
54                $returnValue .= "<li>";
55
56                $returnValue .= "<div class=\"widget-jsonobject-key\">" . _dh($jsonKey) . ":</div>";
57                $returnValue .= "<div><input class=\"widget-jsonobject-value\" type=\"text\" disabled=\"disabled\" "
58                    . "value=\"${jsonValue}\" /></</div>";
59
60                $returnValue .= "</li>";
61            }
62
63            $returnValue .= "</ul>\n";
64        }
65
66        return $returnValue;
67    }
68}