1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
5include_once("class.ilCloudUtil.php");
6
7/**
8 * Class ilCloudPluginSettingsGUI
9 *
10 * Base class for the settings. Needs to be overwritten if the plugin needs custom settings.
11 *
12 * @author  Timon Amstutz <timon.amstutz@ilub.unibe.ch>
13 * @version $Id:
14 * @ingroup ModulesCloud
15 */
16class ilCloudPluginSettingsGUI extends ilCloudPluginGUI
17{
18
19    /**
20     * @var ilObjCloud
21     */
22    protected $cloud_object;
23    /**
24     * @var ilPropertyFormGUI
25     */
26    protected $form;
27
28
29    /**
30     * ilCloudPluginSettingsGUI constructor.
31     *
32     * @param $plugin_service_class
33     */
34    public function __construct($plugin_service_class)
35    {
36        global $DIC;
37        parent::__construct($plugin_service_class);
38
39        $DIC->language()->loadLanguageModule('content');
40        $DIC->language()->loadLanguageModule('obj');
41        $DIC->language()->loadLanguageModule('cntr');
42    }
43
44
45    /**
46     * @param ilObjCloud $object
47     */
48    public function setCloudObject(ilObjCloud $object)
49    {
50        $this->cloud_object = $object;
51    }
52
53
54    /**
55     * Edit Settings. This commands uses the form class to display an input form.
56     */
57    public function editSettings()
58    {
59        global $DIC;
60        $tpl = $DIC['tpl'];
61        $ilTabs = $DIC['ilTabs'];
62
63        $ilTabs->activateTab("settings");
64
65        try {
66            $this->initSettingsForm();
67            $this->getSettingsValues();
68            $tpl->setContent($this->form->getHTML());
69        } catch (Exception $e) {
70            ilUtil::sendFailure($e->getMessage());
71        }
72    }
73
74
75    /**
76     *
77     */
78    public function initSettingsForm()
79    {
80        global $DIC;
81        $ilCtrl = $DIC['ilCtrl'];
82        $lng = $DIC['lng'];
83
84        $this->form = new ilPropertyFormGUI();
85
86        // title
87        $ti = new ilTextInputGUI($lng->txt("title"), "title");
88        $ti->setRequired(true);
89        $this->form->addItem($ti);
90
91        // description
92        $ta = new ilTextAreaInputGUI($lng->txt("description"), "desc");
93        $this->form->addItem($ta);
94
95        // online
96        $cb = new ilCheckboxInputGUI($lng->txt("online"), "online");
97        $this->form->addItem($cb);
98
99        $folder = new ilTextInputGUI($lng->txt("cld_root_folder"), "root_folder");
100        if (!$this->cloud_object->currentUserIsOwner()) {
101            $folder->setDisabled(true);
102            $folder->setInfo($lng->txt("cld_only_owner_has_permission_to_change_root_path"));
103        }
104
105        $folder->setMaxLength(255);
106        $folder->setSize(50);
107        $this->form->addItem($folder);
108
109        $this->createPluginSection();
110        $this->initPluginSettings();
111
112        $this->initPresentationSection();
113
114        $this->form->addCommandButton("updateSettings", $lng->txt("save"));
115
116        $this->form->setTitle($lng->txt("cld_edit_Settings"));
117        $this->form->setFormAction($ilCtrl->getFormActionByClass("ilCloudPluginSettingsGUI"));
118    }
119
120
121    /**
122     *
123     */
124    protected function createPluginSection()
125    {
126        if (get_class($this) != "ilCloudPluginSettingsGUI" && $this->getMakeOwnPluginSection()) {
127            global $DIC;
128            $lng = $DIC['lng'];
129            $section = new ilFormSectionHeaderGUI();
130            $section->setTitle($this->cloud_object->getServiceName() . " " . $lng->txt("cld_service_specific_settings"));
131            $this->form->addItem($section);
132        }
133    }
134
135
136    /**
137     *
138     */
139    protected function initPluginSettings()
140    {
141    }
142
143
144    /**
145     *
146     */
147    protected function initPresentationSection()
148    {
149        global $DIC;
150        $section_appearance = new ilFormSectionHeaderGUI();
151        $section_appearance->setTitle($DIC->language()->txt('cont_presentation'));
152        $this->form->addItem($section_appearance);
153        $DIC->object()->commonSettings()->legacyForm($this->form, $this->cloud_object)->addTileImage();
154    }
155
156
157    /**
158     * @return bool
159     */
160    protected function getMakeOwnPluginSection()
161    {
162        return true;
163    }
164
165
166    /**
167     * Get values for edit Settings form
168     */
169    public function getSettingsValues()
170    {
171        $values["title"] = $this->cloud_object->getTitle();
172        $values["desc"] = $this->cloud_object->getDescription();
173        $values["online"] = $this->cloud_object->getOnline();
174        $values["root_folder"] = $this->cloud_object->getRootFolder();
175        $this->getPluginSettingsValues($values);
176        $this->form->setValuesByArray($values, true);
177    }
178
179
180    /**
181     * @param $values
182     */
183    protected function getPluginSettingsValues(&$values)
184    {
185    }
186
187
188    /**
189     * Update Settings
190     */
191    public function updateSettings()
192    {
193        global $DIC;
194        $tpl = $DIC['tpl'];
195        $lng = $DIC['lng'];
196        $ilCtrl = $DIC['ilCtrl'];
197        $ilTabs = $DIC['ilTabs'];
198
199        $ilTabs->activateTab("settings");
200
201        try {
202            $this->initSettingsForm();
203            $this->initPresentationSection();
204            if ($this->form->checkInput()) {
205                $this->cloud_object->setTitle($this->form->getInput("title"));
206                $this->cloud_object->setDescription($this->form->getInput("desc"));
207                $this->updatePluginSettings();
208                if (ilCloudUtil::normalizePath($this->form->getInput("root_folder")) != $this->cloud_object->getRootFolder()) {
209                    $this->cloud_object->setRootFolder($this->form->getInput("root_folder"));
210                    $this->cloud_object->setRootId($this->getService()->getRootId($this->cloud_object->getRootFolder()));
211                }
212
213                $this->cloud_object->setOnline($this->form->getInput("online"));
214                $this->cloud_object->update();
215
216                $DIC->object()->commonSettings()->legacyForm($this->form, $this->cloud_object)->saveTileImage();
217
218                ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
219                $ilCtrl->redirect($this, 'editSettings');
220            }
221        } catch (Exception $e) {
222            ilUtil::sendFailure($e->getMessage());
223        }
224
225        $this->form->setValuesByPost();
226        $tpl->setContent($this->form->getHtml());
227    }
228
229
230    /**
231     *
232     */
233    protected function updatePluginSettings()
234    {
235    }
236}
237