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