ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilObjPortfolioAdministrationGUI.php
Go to the documentation of this file.
1 <?php
2 
27 {
28  protected \ILIAS\DI\UIServices $ui;
30 
31  public function __construct(
32  $a_data,
33  int $a_id,
34  bool $a_call_by_reference = true,
35  bool $a_prepare_output = true
36  ) {
37  global $DIC;
38 
39  $this->rbac_system = $DIC->rbac()->system();
40  $this->lng = $DIC->language();
41  $this->settings = $DIC->settings();
42  $this->ctrl = $DIC->ctrl();
43  $this->access = $DIC->access();
44  $this->type = "prfa";
45  $this->ui = $DIC->ui();
46  $this->request = $DIC->http()->request();
47  parent::__construct($a_data, $a_id, $a_call_by_reference, $a_prepare_output);
48 
49  $this->declaration_authorship = new ilPortfolioDeclarationOfAuthorship();
50 
51  $this->lng->loadLanguageModule("prtf");
52  }
53 
54  public function executeCommand(): void
55  {
56  $next_class = $this->ctrl->getNextClass($this);
57  $cmd = $this->ctrl->getCmd();
58 
59  $this->prepareOutput();
60 
61  switch ($next_class) {
62  case 'ilpermissiongui':
63  $this->tabs_gui->activateTab('perm_settings');
64  $perm_gui = new ilPermissionGUI($this);
65  $this->ctrl->forwardCommand($perm_gui);
66  break;
67 
68  case 'ilportfolioroleassignmentgui':
69  $this->tabs_gui->activateTab('role_assignment');
70  $gui = new ilPortfolioRoleAssignmentGUI();
71  $this->ctrl->forwardCommand($gui);
72  break;
73 
74  default:
75  if (!$cmd || $cmd === 'view') {
76  $cmd = "editSettings";
77  }
78 
79  $this->$cmd();
80  break;
81  }
82  }
83 
84  public function getAdminTabs(): void
85  {
86  $lng = $this->lng;
87  $tabs = $this->tabs_gui;
88 
89 
90  if ($this->hasReadPermission()) {
91  $tabs->addTab(
92  "settings",
93  $lng->txt("settings"),
94  $this->ctrl->getLinkTarget($this, "editSettings")
95  );
96  $tabs->addTab(
97  "role_assignment",
98  $lng->txt("prtf_role_assignment"),
99  $this->ctrl->getLinkTargetByClass("ilPortfolioRoleAssignmentGUI", "")
100  );
101  $tabs->addTab(
102  "authorship",
103  $lng->txt("prtf_decl_authorship"),
104  $this->ctrl->getLinkTarget($this, "editDeclarationOfAuthorship")
105  );
106  }
107 
108  if ($this->checkPermissionBool('edit_permission')) {
109  $tabs->addTab(
110  "perm_settings",
111  $lng->txt("perm_settings"),
112  $this->ctrl->getLinkTargetByClass('ilpermissiongui', "perm")
113  );
114  }
115  }
116 
117  public function editSettings($a_form = null): void
118  {
119  $this->tabs_gui->activateTab('settings');
120  if (!$a_form) {
121  $a_form = $this->initFormSettings();
122  }
123  $this->tpl->setContent($a_form->getHTML());
124  }
125 
126  public function saveSettings(): void
127  {
128  $ilCtrl = $this->ctrl;
130 
131  if ($this->hasWritePermission()) {
132  $form = $this->initFormSettings();
133  if ($form->checkInput()) {
134  $ilSetting->set('user_portfolios', (int) $form->getInput("prtf"));
135 
136  $banner = (bool) $form->getInput("banner");
137 
138  $prfa_set = new ilSetting("prfa");
139  $prfa_set->set("banner", $banner);
140  $prfa_set->set("banner_width", (int) $form->getInput("width"));
141  $prfa_set->set("banner_height", (int) $form->getInput("height"));
142  $prfa_set->set("mask", (bool) $form->getInput("mask"));
143  $prfa_set->set("mycrs", (bool) $form->getInput("mycrs"));
144 
145  $this->tpl->setOnScreenMessage('success', $this->lng->txt("settings_saved"), true);
146  $ilCtrl->redirect($this, "editSettings");
147  }
148  $form->setValuesByPost();
149  $this->editSettings($form);
150  }
151  }
152 
153  public function cancel(): void
154  {
155  $ilCtrl = $this->ctrl;
156 
157  $ilCtrl->redirect($this, "view");
158  }
159 
160  protected function hasWritePermission(): bool
161  {
162  return $this->rbac_system->checkAccess("write", $this->object->getRefId());
163  }
164 
165  protected function hasReadPermission(): bool
166  {
167  return $this->rbac_system->checkAccess("read", $this->object->getRefId());
168  }
169 
170  protected function initFormSettings(): ilPropertyFormGUI
171  {
172  $lng = $this->lng;
174 
175  $form = new ilPropertyFormGUI();
176  $form->setFormAction($this->ctrl->getFormAction($this));
177  $form->setTitle($this->lng->txt('prtf_settings'));
178 
179  if ($this->hasWritePermission()) {
180  $form->addCommandButton('saveSettings', $this->lng->txt('save'));
181  $form->addCommandButton('cancel', $this->lng->txt('cancel'));
182  }
183 
184  // Enable 'Portfolios'
185  $lng->loadLanguageModule('pd');
186  $lng->loadLanguageModule('user');
187  $prtf_prop = new ilCheckboxInputGUI($lng->txt('pd_enable_prtf'), 'prtf');
188  $prtf_prop->setValue('1');
189  $prtf_prop->setInfo($lng->txt('user_portfolios_desc'));
190  $prtf_prop->setChecked((bool) $ilSetting->get('user_portfolios'));
191  $form->addItem($prtf_prop);
192 
193  $prfa_set = new ilSetting("prfa");
194 
195  $banner = new ilCheckboxInputGUI($lng->txt("prtf_preview_banner"), "banner");
196  $banner->setInfo($lng->txt("prtf_preview_banner_info"));
197  $form->addItem($banner);
198 
199  $width = new ilNumberInputGUI($lng->txt("prtf_preview_banner_width"), "width");
200  $width->setRequired(true);
201  $width->setSize(4);
202  $banner->addSubItem($width);
203 
204  $height = new ilNumberInputGUI($lng->txt("prtf_preview_banner_height"), "height");
205  $height->setRequired(true);
206  $height->setSize(4);
207  $banner->addSubItem($height);
208 
209  $banner->setChecked($prfa_set->get("banner", false));
210  if ($prfa_set->get("banner")) {
211  $width->setValue($prfa_set->get("banner_width"));
212  $height->setValue($prfa_set->get("banner_height"));
213  } else {
214  $width->setValue(1370);
215  $height->setValue(100);
216  }
217 
218  $mycourses = new ilCheckboxInputGUI($lng->txt("prtf_allow_my_courses"), "mycrs");
219  $mycourses->setInfo($lng->txt("prtf_allow_my_courses_info"));
220  $mycourses->setChecked($prfa_set->get("mycrs", true));
221  $form->addItem($mycourses);
222 
223  return $form;
224  }
225 
226  public function addToExternalSettingsForm(int $a_form_id): array
227  {
229 
231  $fields = array('pd_enable_prtf' => array($ilSetting->get('user_portfolios'),
233  )
234  );
235 
236  return array(array("editSettings", $fields));
237  }
238  return [];
239  }
240 
241  //
242  // Declaration of authorship
243  //
244 
245  protected function editDeclarationOfAuthorship(): void
246  {
247  $main_tpl = $this->tpl;
248  $renderer = $ui = $this->ui->renderer();
249  $form = $this->initAuthorshipForm();
250 
251  $this->tabs_gui->activateTab("authorship");
252 
253  $main_tpl->setContent($renderer->render($form));
254  }
255 
256  public function initAuthorshipForm(): \ILIAS\UI\Component\Input\Container\Form\Standard
257  {
258  $ui = $this->ui;
259  $f = $ui->factory();
260  $ctrl = $this->ctrl;
261  $lng = $this->lng;
262 
263  $lng->loadLanguageModule("meta");
264  $fields = [];
265 
266  foreach ($lng->getInstalledLanguages() as $l) {
267  $txt = $lng->txt("meta_l_" . $l);
268  if ($lng->getDefaultLanguage() == $l) {
269  $txt .= " (" . $lng->txt("default") . ")";
270  }
271  $fields["decl_" . $l] = $f->input()->field()->textarea($txt)
272  ->withRequired(false)
273  ->withValue($this->declaration_authorship->getForLanguage($l));
274  }
275 
276  // section
277  $section1 = $f->input()->field()->section($fields, $lng->txt("prtf_decl_authorship"), "");
278 
279  $form_action = $ctrl->getLinkTarget($this, "saveAuthorship");
280  return $f->input()->container()->form()->standard($form_action, ["sec" => $section1]);
281  }
282 
283  public function saveAuthorship(): void
284  {
286  $form = $this->initAuthorshipForm();
287  $lng = $this->lng;
288  $ctrl = $this->ctrl;
289 
290  if ($this->hasWritePermission()) {
291  if ($request->getMethod() === "POST") {
292  $form = $form->withRequest($request);
293  $data = $form->getData();
294  if (is_array($data["sec"])) {
295  foreach ($lng->getInstalledLanguages() as $l) {
296  $this->declaration_authorship->setForLanguage($l, $data["sec"]["decl_" . $l]);
297  }
298 
299  $this->tpl->setOnScreenMessage('info', $lng->txt("msg_obj_modified"), true);
300  }
301  }
302  } else {
303  $this->tpl->setOnScreenMessage('failure', $lng->txt("msg_no_perm_write"), true);
304  }
305  $ctrl->redirect($this, "editDeclarationOfAuthorship");
306  }
307 }
ilPortfolioRoleAssignmentGUI: ilPropertyFormGUI
ilTabsGUI $tabs_gui
Class Factory.
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
redirect(object $a_gui_obj, string $a_cmd=null, string $a_anchor=null, bool $is_async=false)
getDefaultLanguage()
Return default language.
prepareOutput(bool $show_sub_objects=true)
Class ChatMainBarProvider .
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a checkbox property in a property form.
loadLanguageModule(string $a_module)
Load language module.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
ilPortfolioDeclarationOfAuthorship $declaration_authorship
ilLanguage $lng
ilGlobalTemplateInterface $tpl
This class represents a number property in a property form.
ServerRequestInterface $request
Class ilObjectGUI Basic methods of all Output classes.
getInstalledLanguages()
Get installed languages.
$txt
Definition: error.php:13
setRequired(bool $a_required)
checkPermissionBool(string $perm, string $cmd="", string $type="", ?int $ref_id=null)
getLinkTarget(object $a_gui_obj, string $a_cmd=null, string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
global $ilSetting
Definition: privfeed.php:17
__construct(Container $dic, ilPlugin $plugin)
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
__construct( $a_data, int $a_id, bool $a_call_by_reference=true, bool $a_prepare_output=true)
ilSetting $settings
addTab(string $a_id, string $a_text, string $a_link, string $a_frame="")
Add a Tab.