1<?php
2include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
3include_once("Services/Style/System/classes/Utilities/class.ilSkinXML.php");
4include_once("Services/Style/System/classes/Utilities/class.ilSystemStyleSkinContainer.php");
5include_once("Services/Style/System/classes/class.ilStyleDefinition.php");
6include_once("Services/Style/System/classes/class.ilSystemStyleSettings.php");
7include_once("Services/Style/System/classes/Exceptions/class.ilSystemStyleException.php");
8include_once("Services/Style/System/classes/Utilities/class.ilSystemStyleMessageStack.php");
9include_once("Services/Style/System/classes/Utilities/class.ilSystemStyleMessage.php");
10include_once("Services/Style/System/classes/Settings/class.ilSysStyleCatAssignmentTableGUI.php");
11
12/**
13 *
14 * @author            Timon Amstutz <timon.amstutz@ilub.unibe.ch>
15 * @version           $Id$*
16 */
17class ilSubStyleAssignmentGUI
18{
19    /**
20     * @var ilCtrl
21     */
22    protected $ctrl;
23
24    /**
25     * @var ilLanguage
26     */
27    protected $lng;
28
29    /**
30     * @var ilTemplate
31     */
32    protected $tpl;
33
34    /**
35     * @var ilToolbarGUI
36     */
37    protected $toolbar;
38
39    /**
40     * @var ilSystemStyleSettingsGUI
41     */
42    protected $parent_gui;
43
44    /**
45     * @var ilTree
46     */
47    protected $tree;
48
49
50    /**
51     * Constructor
52     */
53    public function __construct(ilSystemStyleSettingsGUI $parent_gui)
54    {
55        global $DIC;
56
57        $this->ctrl = $DIC->ctrl();
58        $this->lng = $DIC->language();
59        $this->toolbar = $DIC->toolbar();
60        $this->tpl = $DIC["tpl"];
61        $this->parent_gui = $parent_gui;
62        $this->tree = $DIC["tree"];
63    }
64
65    /**
66     * Assign styles to categories
67     *
68     * @param ilSkinXML $skin
69     * @param ilSkinStyleXML $substyle
70     * @throws ilSystemStyleException
71     */
72    public function assignStyle(ilSkinXML $skin, ilSkinStyleXML $substyle)
73    {
74        $style = $skin->getStyle($substyle->getSubstyleOf());
75
76        $this->toolbar->addFormButton($this->lng->txt("sty_add_assignment"), "addAssignment");
77        $this->toolbar->setFormAction($this->ctrl->getFormAction($this->getParentGui()));
78
79        $tab = new ilSysStyleCatAssignmentTableGUI(
80            $this->getParentGui(),
81            "assignStyleToCat",
82            $skin->getId(),
83            $style->getId(),
84            $substyle->getId()
85        );
86
87        $this->tpl->setContent($tab->getHTML());
88    }
89
90
91    /**
92     * Add style category assignment
93     */
94    public function addAssignment()
95    {
96        include_once 'Services/Search/classes/class.ilSearchRootSelector.php';
97        $exp = new ilSearchRootSelector(
98            $this->ctrl->getLinkTarget($this->getParentGui(), 'addStyleCatAssignment')
99        );
100        $exp->setExpand($_GET["search_root_expand"] ? $_GET["search_root_expand"] : $this->tree->readRootId());
101        $exp->setExpandTarget($this->ctrl->getLinkTarget($this->getParentGui(), 'addAssignment'));
102        $exp->setTargetClass(get_class($this->getParentGui()));
103        $exp->setCmd('saveAssignment');
104        $exp->setClickableTypes(["cat"]);
105
106        $exp->setOutput(0);
107        $this->tpl->setContent($exp->getOutput());
108    }
109
110
111    /**
112     * Save style category assignment
113     *
114     * @param ilSkinXML $skin
115     * @param ilSkinStyleXML $substyle
116     */
117    public function saveAssignment(ilSkinXML $skin, ilSkinStyleXML $substyle)
118    {
119        $style = $skin->getStyle($substyle->getSubstyleOf());
120        try {
121            ilSystemStyleSettings::writeSystemStyleCategoryAssignment(
122                $skin->getId(),
123                $style->getId(),
124                $substyle->getId(),
125                $_GET["root_id"]
126            );
127            ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
128        } catch (ilSystemStyleException $e) {
129            ilUtil::sendFailure($this->lng->txt("msg_assignment_failed") . $e->getMessage(), true);
130        }
131
132
133        $this->ctrl->redirect($this->getParentGui(), "assignStyle");
134    }
135
136    /**
137     * Delete system style to category assignments
138     *
139     * @param ilSkinXML $skin
140     * @param ilSkinStyleXML $substyle
141     */
142    public function deleteAssignments(ilSkinXML $skin, ilSkinStyleXML $substyle)
143    {
144        $style = $skin->getStyle($substyle->getSubstyleOf());
145
146
147        if (is_array($_POST["id"])) {
148            foreach ($_POST["id"] as $id) {
149                $id_arr = explode(":", $id);
150                ilSystemStyleSettings::deleteSystemStyleCategoryAssignment(
151                    $skin->getId(),
152                    $style->getId(),
153                    $substyle->getId(),
154                    $id_arr[1]
155                );
156            }
157            ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
158        } else {
159            ilUtil::sendFailure($this->lng->txt("no_style_selected"), true);
160        }
161
162        $this->ctrl->redirect($this->getParentGui(), "assignStyle");
163    }
164
165    /**
166     * @return ilSystemStyleSettingsGUI
167     */
168    public function getParentGui()
169    {
170        return $this->parent_gui;
171    }
172
173    /**
174     * @param ilSystemStyleSettingsGUI $parent_gui
175     */
176    public function setParentGui($parent_gui)
177    {
178        $this->parent_gui = $parent_gui;
179    }
180}
181