1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4/**
5 * GUI class that manages the editing of general test settings/properties
6 * shown on "general" subtab
7 *
8 * @author		Björn Heyser <bheyser@databay.de>
9 * @version		$Id: class.ilObjTestSettingsGeneralGUI.php 57702 2015-01-31 21:30:34Z bheyser $
10 *
11 * @package		Modules/Test
12 */
13abstract class ilTestSettingsGUI
14{
15    /**
16     * @var ilObjTest $testOBJ
17     */
18    protected $testOBJ = null;
19
20    /**
21     * object instance for currently active settings template
22     *
23     * @var $settingsTemplate ilSettingsTemplate
24     */
25    protected $settingsTemplate = null;
26
27    public function __construct(ilObjTest $testOBJ)
28    {
29        $this->testOBJ = $testOBJ;
30
31        $templateId = $this->testOBJ->getTemplate();
32
33        if ($templateId) {
34            include_once "Services/Administration/classes/class.ilSettingsTemplate.php";
35            $this->settingsTemplate = new ilSettingsTemplate($templateId, ilObjAssessmentFolderGUI::getSettingsTemplateConfig());
36        }
37    }
38
39    protected function getTemplateSettingValue($settingName)
40    {
41        if (!$this->settingsTemplate) {
42            return null;
43        }
44
45        $templateSettings = $this->settingsTemplate->getSettings();
46
47        if (!isset($templateSettings[$settingName])) {
48            return false;
49        }
50
51        return $templateSettings[$settingName]['value'];
52    }
53
54    protected function isHiddenFormItem($formFieldId)
55    {
56        if (!$this->settingsTemplate) {
57            return false;
58        }
59
60        $settings = $this->settingsTemplate->getSettings();
61
62        if (!isset($settings[$formFieldId])) {
63            return false;
64        }
65
66        if (!$settings[$formFieldId]['hide']) {
67            return false;
68        }
69
70        return true;
71    }
72
73    protected function isSectionHeaderRequired($fields)
74    {
75        foreach ($fields as $field) {
76            if (!$this->isHiddenFormItem($field)) {
77                return true;
78            }
79        }
80
81        return false;
82    }
83
84    protected function formPropertyExists(ilPropertyFormGUI $form, $propertyId)
85    {
86        return $form->getItemByPostVar($propertyId) instanceof ilFormPropertyGUI;
87    }
88
89    protected function removeHiddenItems(ilPropertyFormGUI $form)
90    {
91        if ($this->settingsTemplate) {
92            foreach ($this->settingsTemplate->getSettings() as $id => $item) {
93                if ($item["hide"]) {
94                    $form->removeItemByPostVar($id);
95                }
96            }
97        }
98    }
99}
100