ILIAS  trunk Revision v11.0_alpha-1715-g7fc467680fb
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.SettingsGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(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  )
101  $this->obj_id,
102  [
104  ]
105  )
106  ->checkbox(
107  "rating_overall",
108  $lng->txt("rating_activate_rating"),
109  $lng->txt("rating_activate_rating_info"),
110  (bool) $settings->getRatingOverall()
111  )
112  ->optional(
113  "rating",
114  $lng->txt("wiki_activate_rating"),
115  "",
116  (bool) $settings->getRating()
117  )
118  ->checkbox(
119  "rating_new",
120  $lng->txt("wiki_activate_new_page_rating"),
121  "",
122  (bool) $settings->getRatingForNewPages()
123  )
124  ->checkbox(
125  "rating_ext",
126  $lng->txt("wiki_activate_extended_rating"),
127  "",
128  (bool) $settings->getRatingCategories()
129  )
130  ->end();
131 
132  if(!$this->global_settings->get("disable_comments")) {
133  $form = $form
134  ->checkbox(
135  "public_notes",
136  $lng->txt("wiki_public_comments"),
137  "",
138  (bool) $settings->getPublicNotes()
139  );
140  }
141 
142  return $form;
143  }
144 
145  protected function save(): void
146  {
147  $mt = $this->gui->ui()->mainTemplate();
148  $form = $this->getEditForm();
149  $ctrl = $this->gui->ctrl();
150  $lng = $this->domain->lng();
151 
152  $old_settings = $this->domain->wikiSettings()->getById($this->obj_id);
153 
154  if ($form->isValid()) {
155 
156  $form->saveStdTitleAndDescription($this->obj_id, "wiki");
157  $form->saveStdTile($this->obj_id, "wiki");
158  $form->saveOnline($this->obj_id, "wiki");
159  $form->saveStdAvailability($this->ref_id);
160  $form->saveAdditionalFeatures(
161  $this->obj_id,
162  [
164  ]
165  );
166 
167 
168  $settings = $this->data->settings(
169  $this->obj_id,
170  \ilWikiPage::lookupTitle((int) $form->getData("start_page")),
171  $old_settings->getShortTitle(), // obsolete?
172  (bool) $form->getData("rating_overall"),
173  (bool) $form->getData("rating"),
174  $old_settings->getRatingAsBlock(), // obsolete?
175  (bool) $form->getData("rating_new"),
176  (bool) $form->getData("rating_ext"),
177  (bool) $form->getData("public_notes"),
178  $form->getData("introduction"),
179  (bool) $form->getData("page_toc"),
180  $old_settings->getLinkMetadataValues(), // obsolete?
181  $old_settings->getEmptyPageTemplate() // obsolete?
182  );
183  $this->domain->wikiSettings()->update($settings);
184 
185  $mt->setOnScreenMessage("success", $lng->txt("msg_obj_modified"), true);
186  $ctrl->redirectByClass(self::class, "edit");
187  } else {
188  $mt = $this->gui->ui()->mainTemplate();
189  $mt->setContent($form->render());
190  }
191  }
192 }
__construct(protected InternalDataService $data, protected InternalDomainService $domain, protected InternalGUIService $gui, protected int $obj_id, protected int $ref_id)
static lookupTitle(int $a_page_id, string $lang="-")
addAdditionalFeatures(int $obj_id, array $services)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
$ref_id
Definition: ltiauth.php:65
addStdTitleAndDescription(int $obj_id, string $type)
addStdTile(int $obj_id, string $type)
global $lng
Definition: privfeed.php:31
addOnline(int $obj_id, string $type)