Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 26
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
taoItems_actions_form_Item
0.00% covered (danger)
0.00%
0 / 26
0.00% covered (danger)
0.00%
0 / 1
42
0.00% covered (danger)
0.00%
0 / 1
 initElements
0.00% covered (danger)
0.00%
0 / 26
0.00% covered (danger)
0.00%
0 / 1
42
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
24use oat\taoItems\model\ItemModelStatus;
25
26/**
27 * Short description of class taoItems_actions_form_Item
28 *
29 * @access public
30 * @author Bertrand Chevrier, <bertrand.chevrier@tudor.lu>
31 * @package taoItems
32
33 */
34class taoItems_actions_form_Item extends tao_actions_form_Instance
35{
36    /**
37     * (non-PHPdoc)
38     * @see tao_actions_form_Instance::initElements()
39     */
40    protected function initElements()
41    {
42        parent::initElements();
43
44        $elementId = tao_helpers_Uri::encode(taoItems_models_classes_ItemsService::PROPERTY_ITEM_MODEL);
45        $ele = $this->form->getElement($elementId);
46        $ele->feed();
47        $modelUri = $ele->getEvaluatedValue();
48
49        if (empty($modelUri)) {
50            // remove deprecated models
51            $statusProperty = new core_kernel_classes_Property(ItemModelStatus::CLASS_URI);
52            $options = [];
53            foreach ($ele->getOptions() as $optUri => $optLabel) {
54                $model = new core_kernel_classes_Resource(tao_helpers_Uri::decode($optUri));
55                $status = $model->getOnePropertyValue($statusProperty);
56                if (!is_null($status) && $status->getUri() != ItemModelStatus::INSTANCE_DEPRECATED) {
57                    $options[$optUri] = $optLabel;
58                }
59            }
60            $ele->setOptions($options);
61            if (count($options) === 1) {
62                reset($options);
63                $ele->setValue(key($options));
64            }
65        } else {
66            // replace radio with hidden element
67            $this->form->removeElement($elementId);
68            $itemModelElt = tao_helpers_form_FormFactory::getElement($elementId, 'Hidden');
69            $itemModelElt->setValue($modelUri);
70            $this->form->addElement($itemModelElt, true);
71
72            // display model label
73            $model = new core_kernel_classes_Resource($modelUri);
74            $itemModelLabelElt = tao_helpers_form_FormFactory::getElement('itemModelLabel', 'Label');
75            $itemModelLabelElt->setDescription(__('Item Model'));
76            $itemModelLabelElt->setValue($model->getLabel());
77            $this->form->addElement($itemModelLabelElt, true);
78        }
79    }
80}