1<?php
2
3/* Copyright (c) 1998-2018 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5/**
6 * Common settings form adapter. Helps to add and save common object settings for repository objects.
7 *
8 * @author killing@leifos.de
9 * @ingroup ServicesObject
10 */
11class ilObjectCommonSettingFormAdapter implements ilObjectCommonSettingFormAdapterInterface
12{
13    /**
14     * @var ilObjectService
15     */
16    protected $service;
17
18    /**
19     * @var ilPropertyFormGUI
20     */
21    protected $legacy_form;
22
23    /**
24     * @var ilObject
25     */
26    protected $object;
27
28    /**
29     * Constructor
30     */
31    public function __construct(ilObjectService $service, ilObject $object, ilPropertyFormGUI $legacy_form = null)
32    {
33        $this->service = $service;
34        $this->legacy_form = $legacy_form;
35        $this->object = $object;
36
37        $lng = $this->service->language();
38        $lng->loadLanguageModule("obj");
39        $lng->loadLanguageModule("cntr");
40    }
41
42    /**
43     * @inheritdoc
44     */
45    public function addIcon() : ilPropertyFormGUI
46    {
47        global $DIC;
48
49        if ($this->service->settings()->get('custom_icons')) {
50            if (!is_null($this->legacy_form)) {
51                // we do not clone for legacy forms, since initEditCustomForm relies on "call by reference" behaviour
52                //$this->legacy_form = clone $this->legacy_form;
53                require_once 'Services/Object/Icon/classes/class.ilObjectCustomIconConfigurationGUI.php';
54                $gui = new \ilObjectCustomIconConfigurationGUI($DIC, null, $this->object);
55                $gui->addSettingsToForm($this->legacy_form);
56            }
57        }
58        return $this->legacy_form;
59    }
60
61    /**
62     * @inheritdoc
63     */
64    public function saveIcon()
65    {
66        global $DIC;
67
68        if ($this->service->settings()->get('custom_icons')) {
69            if (!is_null($this->legacy_form)) {
70                $this->legacy_form = clone $this->legacy_form;
71                require_once 'Services/Object/Icon/classes/class.ilObjectCustomIconConfigurationGUI.php';
72                $gui = new \ilObjectCustomIconConfigurationGUI($DIC, null, $this->object);
73                $gui->saveIcon($this->legacy_form);
74            }
75        }
76    }
77
78    /**
79     * @inheritdoc
80     */
81    public function addTileImage() : ilPropertyFormGUI
82    {
83        $lng = $this->service->language();
84        $tile_image_fac = $this->service->commonSettings()->tileImage();
85
86        if (!is_null($this->legacy_form)) {
87            // we do not clone for legacy forms, since initEditCustomForm relies on "call by reference" behaviour
88            //$this->legacy_form = clone $this->legacy_form;
89
90            $tile_image = $tile_image_fac->getByObjId($this->object->getId());
91            $timg = new \ilImageFileInputGUI($lng->txt('obj_tile_image'), 'tile_image');
92            $timg->setInfo($lng->txt('obj_tile_image_info'));
93            $timg->setSuffixes($tile_image_fac->getSupportedFileExtensions());
94            $timg->setUseCache(false);
95            if ($tile_image->exists()) {
96                $timg->setImage($tile_image->getFullPath());
97            } else {
98                $timg->setImage('');
99            }
100            $this->legacy_form->addItem($timg);
101
102            /*
103            $file = new ilFileStandardDropzoneInputGUI($lng->txt('obj_tile_image'), 'tile_image');
104            $file->setRequired(false);
105            $file->setSuffixes($tile_image_fac->getSupportedFileExtensions());
106            $this->legacy_form->addItem($file);*/
107        }
108
109        return $this->legacy_form;
110    }
111
112    /**
113     * @inheritdoc
114     */
115    public function saveTileImage()
116    {
117        $tile_image_fac = $this->service->commonSettings()->tileImage();
118
119        if (!is_null($this->legacy_form)) {
120            $tile_image = $tile_image_fac->getByObjId($this->object->getId());
121
122            /** @var \ilImageFileInputGUI $item */
123            $item = $this->legacy_form->getItemByPostVar('tile_image');
124            if ($item->getDeletionFlag()) {
125                $tile_image->delete();
126            }
127
128            $file_data = $this->legacy_form->getInput('tile_image');
129            if ($file_data['tmp_name']) {
130                $tile_image->saveFromHttpRequest($file_data['tmp_name']);
131            }
132        }
133    }
134
135    /**
136     * @inheritdoc
137     */
138    public function addTitleIconVisibility() : ilPropertyFormGUI
139    {
140        $lng = $this->service->language();
141        $hide = new ilCheckboxInputGUI($lng->txt("obj_show_title_and_icon"), "show_header_icon_and_title");
142        $hide->setChecked(!ilContainer::_lookupContainerSetting($this->object->getId(), "hide_header_icon_and_title"));
143        $this->legacy_form->addItem($hide);
144        return $this->legacy_form;
145    }
146
147    /**
148     * @inheritdoc
149     */
150    public function saveTitleIconVisibility()
151    {
152        if (!is_null($this->legacy_form)) {
153            // hide icon/title
154            ilContainer::_writeContainerSetting(
155                $this->object->getId(),
156                "hide_header_icon_and_title",
157                !$this->legacy_form->getInput("show_header_icon_and_title")
158            );
159        }
160    }
161
162    /**
163     * @inheritdoc
164     */
165    public function addTopActionsVisibility() : ilPropertyFormGUI
166    {
167        $lng = $this->service->language();
168        $hide = new ilCheckboxInputGUI($lng->txt("obj_show_header_actions"), "show_top_actions");
169        $hide->setChecked(!ilContainer::_lookupContainerSetting($this->object->getId(), "hide_top_actions"));
170        $this->legacy_form->addItem($hide);
171        return $this->legacy_form;
172    }
173
174    /**
175     * @inheritdoc
176     */
177    public function saveTopActionsVisibility()
178    {
179        if (!is_null($this->legacy_form)) {
180            // hide icon/title
181            ilContainer::_writeContainerSetting(
182                $this->object->getId(),
183                "hide_top_actions",
184                !$this->legacy_form->getInput("show_top_actions")
185            );
186        }
187    }
188}
189