1<?php 2include_once("./Services/Style/System/classes/class.ilSystemStyleSettings.php"); 3include_once("./Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php"); 4 5 6include_once("./Services/Table/classes/class.ilTable2GUI.php"); 7 8/** 9 * TableGUI class for system styles 10 * 11 * @author Alex Killing <alex.killing@gmx.de> 12 * @author Timon Amstutz <timon.amstutz@ilub.unibe.ch> 13 14 * @version $Id$ 15 * 16 * @ingroup ServicesStyle 17 */ 18class ilSystemStylesTableGUI extends ilTable2GUI 19{ 20 /** 21 * @var ilCtrl 22 */ 23 protected $ctrl; 24 25 /** 26 * @var ilLanguage 27 */ 28 protected $lng; 29 30 /** 31 * @var bool 32 */ 33 protected $with_actions = false; 34 35 /** 36 * @var bool 37 */ 38 protected $management_enabled = false; 39 40 /** 41 * @var bool 42 */ 43 protected $read_documentation = true; 44 45 /** 46 * ilSystemStylesTableGUI constructor. 47 * @param int $a_parent_obj 48 * @param string $a_parent_cmd 49 */ 50 public function __construct($a_parent_obj, $a_parent_cmd) 51 { 52 global $DIC; 53 54 $this->ctrl = $DIC->ctrl(); 55 $this->lng = $DIC->language(); 56 57 parent::__construct($a_parent_obj, $a_parent_cmd); 58 $this->getStyles(); 59 60 $this->setLimit(9999); 61 $this->setTitle($this->lng->txt("manage_system_styles")); 62 $this->addColumn($this->lng->txt("")); 63 $this->addColumn($this->lng->txt("style_name"), "style_name"); 64 $this->addColumn($this->lng->txt("skin_name"), "skin_name"); 65 $this->addColumn($this->lng->txt("sty_substyle_of")); 66 $this->addColumn($this->lng->txt("scope")); 67 $this->addColumn($this->lng->txt("default")); 68 $this->addColumn($this->lng->txt("active")); 69 $this->addColumn($this->lng->txt("users"), "users"); 70 $this->setRowTemplate("tpl.sys_styles_row.html", "Services/Style/System"); 71 $this->setEnableHeader(true); 72 } 73 74 /** 75 * @param $management_enabled 76 * @param bool|true $read_documentation 77 */ 78 public function addActions($management_enabled, $read_documentation = true) 79 { 80 $this->setManagementEnabled($management_enabled); 81 $this->setReadDocumentation($read_documentation); 82 83 $this->setFormAction($this->ctrl->getFormAction($this->getParentObject())); 84 $this->addCommandButton("saveStyleSettings", $this->lng->txt("save")); 85 $this->setRowTemplate("tpl.sys_styles_row_with_actions.html", "Services/Style/System"); 86 87 if ($read_documentation || $management_enabled) { 88 $this->setWithActions(true); 89 90 $this->addColumn($this->lng->txt("actions")); 91 } 92 if ($management_enabled) { 93 $this->addMultiCommand("deleteStyles", $this->lng->txt("delete")); 94 } 95 } 96 97 /** 98 * 99 */ 100 public function getStyles() 101 { 102 // get all user assigned styles 103 $all_user_styles = ilObjUser::_getAllUserAssignedStyles(); 104 105 // output "other" row for all users, that are not assigned to 106 // any existing style 107 $users_missing_styles = 0; 108 foreach ($all_user_styles as $skin_style_id) { 109 $style_arr = explode(":", $skin_style_id); 110 if (!ilStyleDefinition::styleExists($style_arr[1])) { 111 $users_missing_styles += ilObjUser::_getNumberOfUsersForStyle($style_arr[0], $style_arr[1]); 112 } 113 } 114 $all_styles = ilStyleDefinition::getAllSkinStyles(); 115 if ($users_missing_styles > 0) { 116 $all_styles["other"] = 117 array( 118 "title" => $this->lng->txt("other"), 119 "id" => "other", 120 "template_id" => "", 121 "skin_id" => "other", 122 "style_id" => "", 123 "skin_name" => "other", 124 "style_name" => "", 125 "users" => $users_missing_styles 126 ); 127 } 128 129 $this->setData($all_styles); 130 } 131 132 133 /** 134 * @param array $a_set 135 */ 136 protected function fillRow($a_set) 137 { 138 global $DIC; 139 140 $this->tpl->setVariable("STYLE_NAME", $a_set["style_name"]); 141 $this->tpl->setVariable("SKIN_NAME", $a_set["skin_name"]); 142 $is_substyle = $a_set["substyle_of"] != ""; 143 144 if (!$is_substyle) { 145 $this->tpl->setVariable("USERS", $a_set["users"]); 146 } else { 147 $this->tpl->setVariable("USERS", "-"); 148 } 149 150 if ($a_set["id"] != "other") { 151 $this->tpl->setCurrentBlock("default_input"); 152 153 if (!$is_substyle) { 154 $this->tpl->setVariable("DEFAULT_ID", $a_set["id"]); 155 if (ilSystemStyleSettings::getCurrentDefaultSkin() == $a_set["skin_id"] && 156 ilSystemStyleSettings::getCurrentDefaultStyle() == $a_set["style_id"] 157 ) { 158 $this->tpl->setVariable("CHECKED_DEFAULT", ' checked="checked" '); 159 } else { 160 $this->tpl->setVariable("CHECKED_DEFAULT", ''); 161 } 162 $this->tpl->parseCurrentBlock(); 163 } 164 165 $this->tpl->setCurrentBlock("active_input"); 166 $this->tpl->setVariable("ACTIVE_ID", $a_set["id"]); 167 168 if ($is_substyle) { 169 $this->tpl->setVariable("DISABLED_ACTIVE", 'disabled'); 170 171 if (ilSystemStyleSettings::_lookupActivatedStyle($a_set["skin_id"], $a_set["substyle_of"])) { 172 $this->tpl->setVariable("CHECKED_ACTIVE", ' checked="checked" '); 173 } else { 174 $this->tpl->setVariable("CHECKED_ACTIVE", ''); 175 } 176 } else { 177 if (ilSystemStyleSettings::_lookupActivatedStyle($a_set["skin_id"], $a_set["style_id"])) { 178 $this->tpl->setVariable("CHECKED_ACTIVE", ' checked="checked" '); 179 } else { 180 $this->tpl->setVariable("CHECKED_ACTIVE", ''); 181 } 182 } 183 184 $this->tpl->parseCurrentBlock(); 185 } 186 187 if ($is_substyle) { 188 $this->tpl->setVariable("SUB_STYLE_OF", $a_set["substyle_of_name"]); 189 190 $assignments = ilSystemStyleSettings::getSubStyleCategoryAssignments( 191 $a_set["skin_id"], 192 $a_set["substyle_of"], 193 $a_set["style_id"] 194 ); 195 196 $categories = []; 197 198 foreach ($assignments as $assignment) { 199 $category_title = ilObject::_lookupTitle(ilObject::_lookupObjId($assignment["ref_id"])); 200 if ($category_title) { 201 $categories[] = $category_title; 202 } 203 } 204 205 $listing = $DIC->ui()->factory()->listing()->unordered($categories); 206 $this->tpl->setVariable( 207 "CATEGORIES", 208 $this->lng->txt("local") . $DIC->ui()->renderer()->render($listing) 209 ); 210 } else { 211 $this->tpl->setVariable("SUB_STYLE_OF", ""); 212 $this->tpl->setVariable("CATEGORIES", $this->lng->txt("global")); 213 } 214 215 if ($this->isWithActions()) { 216 if ($a_set["skin_id"] == "other") { 217 $this->tpl->setCurrentBlock("actions"); 218 $this->tpl->setVariable("ACTIONS", ""); 219 $this->tpl->parseCurrentBlock(); 220 } else { 221 $action_list = new ilAdvancedSelectionListGUI(); 222 $action_list->setId("id_action_list_" . $a_set["id"]); 223 $action_list->setListTitle($this->lng->txt("actions")); 224 225 if ($this->isReadDocumentation()) { 226 $DIC->ctrl()->setParameterByClass('ilSystemStyleDocumentationGUI', 'skin_id', $a_set["skin_id"]); 227 $DIC->ctrl()->setParameterByClass('ilSystemStyleDocumentationGUI', 'style_id', $a_set["style_id"]); 228 $action_list->addItem( 229 $this->lng->txt('open_documentation'), 230 'documentation', 231 $this->ctrl->getLinkTargetByClass('ilSystemStyleDocumentationGUI', 'entries') 232 ); 233 } 234 235 if ($this->isManagementEnabled()) { 236 $this->ctrl->setParameterByClass('ilSystemStyleSettingsGUI', 'skin_id', $a_set["skin_id"]); 237 $this->ctrl->setParameterByClass('ilSystemStyleSettingsGUI', 'style_id', $a_set["style_id"]); 238 239 $this->ctrl->setParameterByClass('ilSystemStyleOverviewGUI', 'skin_id', $a_set["skin_id"]); 240 $this->ctrl->setParameterByClass('ilSystemStyleOverviewGUI', 'style_id', $a_set["style_id"]); 241 242 $config = new ilSystemStyleConfig(); 243 if ($a_set["skin_id"] != $config->getDefaultSkinId()) { 244 $this->addManagementActionsToList($action_list); 245 $this->addMultiActions($a_set["id"]); 246 } 247 if (!$is_substyle && $a_set["skin_id"] != "default") { 248 $action_list->addItem($this->lng->txt('export'), 'export', $this->ctrl->getLinkTargetByClass('ilSystemStyleOverviewGUI', 'export')); 249 } 250 } 251 252 253 $this->tpl->setCurrentBlock("actions"); 254 $this->tpl->setVariable("ACTIONS", $action_list->getHTML()); 255 $this->tpl->parseCurrentBlock(); 256 } 257 } 258 } 259 260 protected function addManagementActionsToList(ilAdvancedSelectionListGUI $action_list) 261 { 262 $action_list->addItem($this->lng->txt('edit'), 'edit', $this->ctrl->getLinkTargetByClass('ilSystemStyleSettingsGUI')); 263 $action_list->addItem($this->lng->txt('delete'), 'delete', $this->ctrl->getLinkTargetByClass('ilSystemStyleOverviewGUI', 'deleteStyle')); 264 } 265 266 protected function addMultiActions($id) 267 { 268 $this->tpl->setCurrentBlock("multi_actions"); 269 $this->tpl->setVariable("MULTI_ACTIONS_ID", $id); 270 $this->tpl->parseCurrentBlock(); 271 } 272 273 /** 274 * @return boolean 275 */ 276 public function isWithActions() 277 { 278 return $this->with_actions; 279 } 280 281 /** 282 * @param boolean $with_actions 283 */ 284 public function setWithActions($with_actions) 285 { 286 $this->with_actions = $with_actions; 287 } 288 289 /** 290 * @return boolean 291 */ 292 public function isManagementEnabled() 293 { 294 return $this->management_enabled; 295 } 296 297 /** 298 * @param boolean $management_enabled 299 */ 300 public function setManagementEnabled($management_enabled) 301 { 302 $this->management_enabled = $management_enabled; 303 } 304 305 /** 306 * @return boolean 307 */ 308 public function isReadDocumentation() 309 { 310 return $this->read_documentation; 311 } 312 313 /** 314 * @param boolean $read_documentation 315 */ 316 public function setReadDocumentation($read_documentation) 317 { 318 $this->read_documentation = $read_documentation; 319 } 320} 321