ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilPCProfileGUI.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +-----------------------------------------------------------------------------+
22*/
23
24require_once("./Services/COPage/classes/class.ilPCProfile.php");
25require_once("./Services/COPage/classes/class.ilPageContentGUI.php");
26
38{
42 protected $toolbar;
43
44
49 public function __construct(&$a_pg_obj, &$a_content_obj, $a_hier_id, $a_pc_id = "")
50 {
51 global $DIC;
52
53 $this->tpl = $DIC["tpl"];
54 $this->ctrl = $DIC->ctrl();
55 $this->toolbar = $DIC->toolbar();
56 parent::__construct($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
57 }
58
62 public function executeCommand()
63 {
64 // get next class that processes or forwards current command
65 $next_class = $this->ctrl->getNextClass($this);
66
67 // get current command
68 $cmd = $this->ctrl->getCmd();
69
70 switch ($next_class) {
71 default:
72 $ret = $this->$cmd();
73 break;
74 }
75
76 return $ret;
77 }
78
84 public function insert(ilPropertyFormGUI $a_form = null)
85 {
87
89
90 if (!$a_form) {
91 $a_form = $this->initForm(true);
92 }
93 $tpl->setContent($a_form->getHTML());
94 }
95
101 public function edit(ilPropertyFormGUI $a_form = null)
102 {
104
105 $this->displayValidationError();
106
107 if (!$a_form) {
108 $a_form = $this->initForm();
109 }
110 $tpl->setContent($a_form->getHTML());
111 }
112
119 protected function initForm($a_insert = false)
120 {
122 $ilToolbar = $this->toolbar;
123
124 $is_template = ($this->getPageConfig()->getEnablePCType("PlaceHolder"));
125
126 if (!$is_template) {
127 $ilToolbar->addButton(
128 $this->lng->txt("cont_edit_personal_data"),
129 $ilCtrl->getLinkTargetByClass("ilpersonaldesktopgui", "jumptoprofile"),
130 "profile"
131 );
132
133 $lng_suffix = "";
134 } else {
135 $lng_suffix = "_template";
136 }
137
138 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
139 $form = new ilPropertyFormGUI();
140 $form->setFormAction($ilCtrl->getFormAction($this));
141 if ($a_insert) {
142 $form->setTitle($this->lng->txt("cont_insert_profile"));
143 } else {
144 $form->setTitle($this->lng->txt("cont_update_profile"));
145 }
146
147 $mode = new ilRadioGroupInputGUI($this->lng->txt("cont_profile_mode"), "mode");
148 $form->addItem($mode);
149
150 $mode_inherit = new ilRadioOption($this->lng->txt("cont_profile_mode_inherit"), "inherit");
151 $mode_inherit->setInfo($this->lng->txt("cont_profile_mode" . $lng_suffix . "_inherit_info"));
152 $mode->addOption($mode_inherit);
153
154 $mode_manual = new ilRadioOption($this->lng->txt("cont_profile_mode_manual"), "manual");
155 $mode_manual->setInfo($this->lng->txt("cont_profile_mode_manual_info"));
156 $mode->addOption($mode_manual);
157
158 $prefs = array();
159 if ($a_insert) {
160 $mode->setValue("inherit");
161 } else {
162 $mode_value = $this->content_obj->getMode();
163 $mode->setValue($mode_value);
164
165 $prefs = array();
166 if ($mode_value == "manual") {
167 foreach ($this->content_obj->getFields() as $name) {
168 $prefs["public_" . $name] = "y";
169 }
170 }
171 }
172
173 include_once "Services/User/classes/class.ilPersonalProfileGUI.php";
174 $profile = new ilPersonalProfileGUI();
175 $profile->showPublicProfileFields($form, $prefs, $mode_manual, $is_template);
176
177 if ($a_insert) {
178 $form->addCommandButton("create_profile", $this->lng->txt("save"));
179 $form->addCommandButton("cancelCreate", $this->lng->txt("cancel"));
180 } else {
181 $form->addCommandButton("update", $this->lng->txt("save"));
182 $form->addCommandButton("cancelUpdate", $this->lng->txt("cancel"));
183 }
184
185 return $form;
186 }
187
193 protected function getFieldsValues()
194 {
195 $fields = array();
196 foreach ($_POST as $name => $value) {
197 if (substr($name, 0, 4) == "chk_") {
198 if ($value) {
199 $fields[] = substr($name, 4);
200 }
201 }
202 }
203 return $fields;
204 }
205
209 public function create()
210 {
211 $form = $this->initForm(true);
212 if ($form->checkInput()) {
213 $this->content_obj = new ilPCProfile($this->getPage());
214 $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
215 $this->content_obj->setFields(
216 $form->getInput("mode"),
217 $this->getFieldsValues()
218 );
219 $this->updated = $this->pg_obj->update();
220 if ($this->updated === true) {
221 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
222 }
223 }
224
225 $this->insert($form);
226 }
227
231 public function update()
232 {
233 $form = $this->initForm(true);
234 if ($form->checkInput()) {
235 $this->content_obj->setFields(
236 $form->getInput("mode"),
237 $this->getFieldsValues()
238 );
239 $this->updated = $this->pg_obj->update();
240 if ($this->updated === true) {
241 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
242 }
243 }
244
245 $this->pg_obj->addHierIDs();
246 $this->edit($form);
247 }
248}
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
Class ilPCProfileGUI.
create()
Create new personal data.
edit(ilPropertyFormGUI $a_form=null)
Edit personal data form.
__construct(&$a_pg_obj, &$a_content_obj, $a_hier_id, $a_pc_id="")
Constructor @access public.
initForm($a_insert=false)
Init profile form.
getFieldsValues()
Gather field values.
executeCommand()
execute command
insert(ilPropertyFormGUI $a_form=null)
Insert new personal data form.
update()
Update personal data.
Class ilPCProfile.
User Interface for Editing of Page Content Objects (Paragraphs, Tables, ...)
getPageConfig()
Get Page Config.
displayValidationError()
display validation errors
GUI class for personal profile.
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.
global $ilCtrl
Definition: ilias.php:18
if($format !==null) $name
Definition: metadata.php:146
$ret
Definition: parser.php:6
if(isset($_POST['submit'])) $form
global $DIC
Definition: saml.php:7