ILIAS  release_8 Revision v8.24
class.ilPCProfileGUI.php
Go to the documentation of this file.
1<?php
2
25{
26 protected \ILIAS\HTTP\Services $http;
28
29 public function __construct(
30 ilPageObject $a_pg_obj,
31 ?ilPageContent $a_content_obj,
32 string $a_hier_id,
33 string $a_pc_id = ""
34 ) {
35 global $DIC;
36
37 $this->tpl = $DIC["tpl"];
38 $this->ctrl = $DIC->ctrl();
39 $this->toolbar = $DIC->toolbar();
40 $this->http = $DIC->http();
41 parent::__construct($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
42 }
43
44 public function executeCommand(): void
45 {
46 // get next class that processes or forwards current command
47 $next_class = $this->ctrl->getNextClass($this);
48
49 // get current command
50 $cmd = $this->ctrl->getCmd();
51
52 switch ($next_class) {
53 default:
54 $this->$cmd();
55 break;
56 }
57 }
58
62 public function insert(ilPropertyFormGUI $a_form = null): void
63 {
65
67
68 if (!$a_form) {
69 $a_form = $this->initForm(true);
70 }
71 $tpl->setContent($a_form->getHTML());
72 }
73
77 public function edit(ilPropertyFormGUI $a_form = null): void
78 {
80
82
83 if (!$a_form) {
84 $a_form = $this->initForm();
85 }
86 $tpl->setContent($a_form->getHTML());
87 }
88
92 protected function initForm(bool $a_insert = false): ilPropertyFormGUI
93 {
94 $ilCtrl = $this->ctrl;
95 $ilToolbar = $this->toolbar;
96
97 $is_template = ($this->getPageConfig()->getEnablePCType("PlaceHolder"));
98
99 if (!$is_template) {
100 $ilToolbar->addButton(
101 $this->lng->txt("cont_edit_personal_data"),
102 $ilCtrl->getLinkTargetByClass("ildashboardgui", "jumptoprofile"),
103 "profile"
104 );
105
106 $lng_suffix = "";
107 } else {
108 $lng_suffix = "_template";
109 }
110
111 $form = new ilPropertyFormGUI();
112 $form->setFormAction($ilCtrl->getFormAction($this));
113 if ($a_insert) {
114 $form->setTitle($this->lng->txt("cont_insert_profile"));
115 } else {
116 $form->setTitle($this->lng->txt("cont_update_profile"));
117 }
118
119 $mode = new ilRadioGroupInputGUI($this->lng->txt("cont_profile_mode"), "mode");
120 $form->addItem($mode);
121
122 $mode_inherit = new ilRadioOption($this->lng->txt("cont_profile_mode_inherit"), "inherit");
123 $mode_inherit->setInfo($this->lng->txt("cont_profile_mode" . $lng_suffix . "_inherit_info"));
124 $mode->addOption($mode_inherit);
125
126 $mode_manual = new ilRadioOption($this->lng->txt("cont_profile_mode_manual"), "manual");
127 $mode_manual->setInfo($this->lng->txt("cont_profile_mode_manual_info"));
128 $mode->addOption($mode_manual);
129
130 $prefs = array();
131 if ($a_insert) {
132 $mode->setValue("inherit");
133 } else {
134 $mode_value = $this->content_obj->getMode();
135 $mode->setValue($mode_value);
136
137 $prefs = array();
138 if ($mode_value == "manual") {
139 foreach ($this->content_obj->getFields() as $name) {
140 $prefs["public_" . $name] = "y";
141 }
142 }
143 }
144
145 $profile = new ilPersonalProfileGUI();
146 $profile->showPublicProfileFields($form, $prefs, $mode_manual, $is_template);
147
148 if ($a_insert) {
149 $form->addCommandButton("create_profile", $this->lng->txt("save"));
150 $form->addCommandButton("cancelCreate", $this->lng->txt("cancel"));
151 } else {
152 $form->addCommandButton("update", $this->lng->txt("save"));
153 $form->addCommandButton("cancelUpdate", $this->lng->txt("cancel"));
154 }
155
156 return $form;
157 }
158
162 protected function getFieldsValues(): array
163 {
164 $fields = array();
165 foreach ($this->http->request()->getParsedBody() as $name => $value) {
166 if (substr($name, 0, 4) == "chk_") {
167 if ($value) {
168 $fields[] = substr($name, 4);
169 }
170 }
171 }
172 return $fields;
173 }
174
178 public function create(): void
179 {
180 $form = $this->initForm(true);
181 if ($form->checkInput()) {
182 $this->content_obj = new ilPCProfile($this->getPage());
183 $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
184 $this->content_obj->setFields(
185 $form->getInput("mode"),
186 $this->getFieldsValues()
187 );
188 $this->updated = $this->pg_obj->update();
189 if ($this->updated === true) {
190 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
191 }
192 }
193
194 $this->insert($form);
195 }
196
200 public function update(): void
201 {
202 $form = $this->initForm(true);
203 if ($form->checkInput()) {
204 $this->content_obj->setFields(
205 $form->getInput("mode"),
206 $this->getFieldsValues()
207 );
208 $this->updated = $this->pg_obj->update();
209 if ($this->updated === true) {
210 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
211 }
212 }
213
214 $this->pg_obj->addHierIDs();
215 $this->edit($form);
216 }
217}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(ilPageObject $a_pg_obj, ?ilPageContent $a_content_obj, string $a_hier_id, string $a_pc_id="")
create()
Create new personal data.
edit(ilPropertyFormGUI $a_form=null)
Edit personal data form.
ILIAS HTTP Services $http
initForm(bool $a_insert=false)
Init profile form.
getFieldsValues()
Gather field values.
insert(ilPropertyFormGUI $a_form=null)
Insert new personal data form.
update()
Update personal data.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
User Interface for Editing of Page Content Objects (Paragraphs, Tables, ...)
ilGlobalTemplateInterface $tpl
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
GUI class for personal profile.
This class represents a property form user interface.
This class represents a property in a property form.
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...
addButton(string $a_txt, string $a_cmd, string $a_target="", ?int $a_acc_key=null, string $a_additional_attrs='', string $a_id="", string $a_class='submit')
global $DIC
Definition: feed.php:28
setContent(string $a_html)
Sets content for standard template.
if($format !==null) $name
Definition: metadata.php:247
static http()
Fetches the global http state from ILIAS.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc