ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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 
24 require_once("./Services/COPage/classes/class.ilPCProfile.php");
25 require_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  {
86  $tpl = $this->tpl;
87 
88  $this->displayValidationError();
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  {
103  $tpl = $this->tpl;
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("ildashboardgui", "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  $profile = new ilPersonalProfileGUI();
174  $profile->showPublicProfileFields($form, $prefs, $mode_manual, $is_template);
175 
176  if ($a_insert) {
177  $form->addCommandButton("create_profile", $this->lng->txt("save"));
178  $form->addCommandButton("cancelCreate", $this->lng->txt("cancel"));
179  } else {
180  $form->addCommandButton("update", $this->lng->txt("save"));
181  $form->addCommandButton("cancelUpdate", $this->lng->txt("cancel"));
182  }
183 
184  return $form;
185  }
186 
192  protected function getFieldsValues()
193  {
194  $fields = array();
195  foreach ($_POST as $name => $value) {
196  if (substr($name, 0, 4) == "chk_") {
197  if ($value) {
198  $fields[] = substr($name, 4);
199  }
200  }
201  }
202  return $fields;
203  }
204 
208  public function create()
209  {
210  $form = $this->initForm(true);
211  if ($form->checkInput()) {
212  $this->content_obj = new ilPCProfile($this->getPage());
213  $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
214  $this->content_obj->setFields(
215  $form->getInput("mode"),
216  $this->getFieldsValues()
217  );
218  $this->updated = $this->pg_obj->update();
219  if ($this->updated === true) {
220  $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
221  }
222  }
223 
224  $this->insert($form);
225  }
226 
230  public function update()
231  {
232  $form = $this->initForm(true);
233  if ($form->checkInput()) {
234  $this->content_obj->setFields(
235  $form->getInput("mode"),
236  $this->getFieldsValues()
237  );
238  $this->updated = $this->pg_obj->update();
239  if ($this->updated === true) {
240  $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
241  }
242  }
243 
244  $this->pg_obj->addHierIDs();
245  $this->edit($form);
246  }
247 }
This class represents an option in a radio group.
Class ilPCProfileGUI.
This class represents a property form user interface.
create()
Create new personal data.
getPageConfig()
Get Page Config.
setInfo($a_info)
Set Info.
initForm($a_insert=false)
Init profile form.
insert(ilPropertyFormGUI $a_form=null)
Insert new personal data form.
global $ilCtrl
Definition: ilias.php:18
executeCommand()
execute command
if($format !==null) $name
Definition: metadata.php:230
User Interface for Editing of Page Content Objects (Paragraphs, Tables, ...)
This class represents a property in a property form.
getFieldsValues()
Gather field values.
edit(ilPropertyFormGUI $a_form=null)
Edit personal data form.
Class ilPCProfile.
displayValidationError()
display validation errors
update()
Update personal data.
__construct(Container $dic, ilPlugin $plugin)
$ret
Definition: parser.php:6
$DIC
Definition: xapitoken.php:46
__construct(&$a_pg_obj, &$a_content_obj, $a_hier_id, $a_pc_id="")
Constructor public.
$_POST["username"]
GUI class for personal profile.