ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.SettingsGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
27
29{
30 protected \ilSetting $global_settings;
31
32 public function __construct(
33 protected InternalDataService $data,
34 protected InternalDomainService $domain,
35 protected InternalGUIService $gui,
36 protected int $obj_id,
37 protected int $ref_id
38 ) {
39 $this->global_settings = $this->domain->settings();
40 }
41
42 public function executeCommand(): void
43 {
44 $ctrl = $this->gui->ctrl();
45 $next_class = $ctrl->getNextClass($this);
46 $cmd = $ctrl->getCmd("edit");
47
48 switch ($next_class) {
49 default:
50 if (in_array($cmd, ["edit", "save"])) {
51 $this->$cmd();
52 }
53 }
54 }
55
56 protected function edit(): void
57 {
58 $mt = $this->gui->ui()->mainTemplate();
59 $form = $this->getEditForm();
60 $mt->setContent($form->render());
61 }
62
63 protected function getEditForm(): FormAdapterGUI
64 {
65 $settings = $this->domain->wikiSettings()->getById($this->obj_id);
66 $start_page_options = $this->domain->wikiSettings()->getStartPageOptions($this->ref_id);
67 $start_page_id = $this->domain->wikiSettings()->getStartPageId($settings);
68
69 $lng = $this->domain->lng();
70 $lng->loadLanguageModule("rating");
71
72 $form = $this->gui
73 ->form(self::class, "save")
74 ->section("general", $lng->txt("wiki_settings"))
75 ->addStdTitleAndDescription($this->obj_id, "wiki")
76 ->textarea(
77 "introduction",
78 $lng->txt("wiki_introduction"),
79 "",
80 (string) $settings->getIntroduction()
81 )
82 ->select(
83 "start_page",
84 $lng->txt("wiki_start_page"),
85 $start_page_options,
86 "",
87 $start_page_id ? (string) $start_page_id : null
88 )->required()
89 ->section("avail", $lng->txt("rep_activation_availability"))
90 ->addOnline($this->obj_id, "wiki")
91 ->addStdAvailability($this->ref_id)
92 ->section("presentation", $lng->txt("obj_presentation"))
93 ->addStdTile($this->obj_id, "wiki")
94 ->checkbox(
95 "page_toc",
96 $lng->txt("wiki_page_toc"),
97 $lng->txt("wiki_page_toc_info"),
98 (bool) $settings->getPageToc()
99 );
100
101 if (count(\ilAdvancedMDRecord::_getSelectedRecordsByObject("wiki", $this->ref_id, "wpg")) > 0) {
102 $form = $form
103 ->checkbox(
104 "link_md_values",
105 $lng->txt("wiki_link_md_values"),
106 $lng->txt("wiki_link_md_values_info"),
107 (bool) $settings->getLinkMetadataValues()
108 );
109 }
110
111 $form = $form
112 ->addAdditionalFeatures(
113 $this->obj_id,
114 [
116 ]
117 )
118 ->checkbox(
119 "rating_overall",
120 $lng->txt("rating_activate_rating"),
121 $lng->txt("rating_activate_rating_info"),
122 (bool) $settings->getRatingOverall()
123 )
124 ->optional(
125 "rating",
126 $lng->txt("wiki_activate_rating"),
127 "",
128 (bool) $settings->getRating()
129 )
130 ->checkbox(
131 "rating_new",
132 $lng->txt("wiki_activate_new_page_rating"),
133 "",
134 (bool) $settings->getRatingForNewPages()
135 )
136 ->checkbox(
137 "rating_ext",
138 $lng->txt("wiki_activate_extended_rating"),
139 "",
140 (bool) $settings->getRatingCategories()
141 )
142 ->end();
143
144 if (!$this->global_settings->get("disable_comments")) {
145 $form = $form
146 ->checkbox(
147 "public_notes",
148 $lng->txt("wiki_public_comments"),
149 "",
150 (bool) $settings->getPublicNotes()
151 );
152 }
153
154 return $form;
155 }
156
157 protected function save(): void
158 {
159 $mt = $this->gui->ui()->mainTemplate();
160 $form = $this->getEditForm();
161 $ctrl = $this->gui->ctrl();
162 $lng = $this->domain->lng();
163
164 $old_settings = $this->domain->wikiSettings()->getById($this->obj_id);
165
166 if ($form->isValid()) {
167
168 $form->saveStdTitleAndDescription($this->obj_id, "wiki");
169 $form->saveStdTile($this->obj_id, "wiki");
170 $form->saveOnline($this->obj_id, "wiki");
171 $form->saveStdAvailability($this->ref_id);
172 $form->saveAdditionalFeatures(
173 $this->obj_id,
174 [
176 ]
177 );
178
179 $link_md_values = $old_settings->getLinkMetadataValues();
180 if (count(\ilAdvancedMDRecord::_getSelectedRecordsByObject("wiki", $this->ref_id, "wpg")) > 0) {
181 $link_md_values = (bool) $form->getData("link_md_values");
182 }
183
184 $settings = $this->data->settings(
185 $this->obj_id,
186 \ilWikiPage::lookupTitle((int) $form->getData("start_page")),
187 $old_settings->getShortTitle(), // obsolete?
188 (bool) $form->getData("rating_overall"),
189 (bool) $form->getData("rating"),
190 $old_settings->getRatingAsBlock(), // obsolete?
191 (bool) $form->getData("rating_new"),
192 (bool) $form->getData("rating_ext"),
193 (bool) $form->getData("public_notes"),
194 $form->getData("introduction"),
195 (bool) $form->getData("page_toc"),
196 $link_md_values,
197 $old_settings->getEmptyPageTemplate() // obsolete?
198 );
199 $this->domain->wikiSettings()->update($settings);
200
201 $mt->setOnScreenMessage("success", $lng->txt("msg_obj_modified"), true);
202 $ctrl->redirectByClass(self::class, "edit");
203 } else {
204 $mt = $this->gui->ui()->mainTemplate();
205 $mt->setContent($form->render());
206 }
207 }
208}
Repository internal data service.
__construct(protected InternalDataService $data, protected InternalDomainService $domain, protected InternalGUIService $gui, protected int $obj_id, protected int $ref_id)
static _getSelectedRecordsByObject(string $a_obj_type, int $a_id, string $a_sub_type="", bool $is_ref_id=true)
static lookupTitle(int $a_page_id, string $lang="-")
$ref_id
Definition: ltiauth.php:66
global $lng
Definition: privfeed.php:31