19declare(strict_types=1);
51 $this->
http = $DIC->http();
54 $this->ref_id = $a_ref_id;
57 $this->
ctrl = $DIC->ctrl();
58 $this->tpl =
$DIC->ui()->mainTemplate();
59 $this->
lng = $DIC->language();
60 $this->
lng->loadLanguageModule(
'ps');
61 $this->
user = $DIC->user();
70 $next_class = $this->
ctrl->getNextClass($this);
71 $cmd = $this->
ctrl->getCmd();
73 switch ($next_class) {
75 if (!$cmd || $cmd ===
'view') {
76 $cmd =
'showAgreement';
102 $this->tpl->setContent($form->getHTML());
108 $form->setTitle($this->
lng->txt($this->type .
'_agreement_header'));
109 $form->setFormAction($this->
ctrl->getFormAction($this));
110 $form->addCommandButton(
'save', $this->
lng->txt(
'save'));
115 if ($this->
getPrivacy()->confirmationRequired($this->type)) {
129 $profile =
$DIC[
'user']->getProfile();
135 $tpl =
new ilTemplate(
'tpl.agreement_form.html',
true,
true,
'components/ILIAS/Membership');
137 foreach ($fields_info->getExportableFields() as $field) {
145 foreach ($profile->getVisibleUserDefinedFields(Context::buildFromObjectType(
$type)) as $field) {
162 $agreement->setRequired(
true);
163 $agreement->setOptionTitle(
$lng->txt($a_type .
'_info_agree'));
164 $agreement->setValue(
'1');
174 string $a_mode =
'user'
184 if ($a_mode ===
'user') {
186 $cdf->setValue(
$lng->txt($a_type .
'_ps_cdf_info'));
187 $cdf->setRequired(
true);
190 foreach ($cdf_fields as $field_obj) {
191 switch ($field_obj->getType()) {
194 if ($field_obj->getValueOptions()) {
197 if ($field_obj->isRequired()) {
198 $option_radios->setRequired(
true);
201 $open_answer_indexes = $field_obj->getValueOptions();
202 foreach ($field_obj->getValues() as $key => $val) {
203 $option_radio =
new ilRadioOption($val, $field_obj->getId() .
'_' . $key);
206 if (in_array($key, $open_answer_indexes)) {
208 $lng->txt(
"form_open_answer"),
209 'cdf_oa_' . $field_obj->getId() .
'_' . $key
211 $open_answer->setRequired(
true);
212 $option_radio->addSubItem($open_answer);
215 $option_radios->addOption($option_radio);
217 if ($a_mode ===
'user') {
218 $cdf->addSubItem($option_radios);
220 $form->
addItem($option_radios);
223 $select =
new ilSelectInputGUI($field_obj->getName(),
'cdf_' . $field_obj->getId());
224 $select->setOptions($field_obj->prepareSelectBox());
225 if ($field_obj->isRequired()) {
226 $select->setRequired(
true);
228 if ($a_mode ===
'user') {
229 $cdf->addSubItem($select);
237 $text =
new ilTextInputGUI($field_obj->getName(),
'cdf_' . $field_obj->getId());
239 $text->setMaxLength(255);
240 if ($field_obj->isRequired()) {
241 $text->setRequired(
true);
243 if ($a_mode ===
'user') {
244 $cdf->addSubItem($text);
251 if ($a_mode ===
'user') {
259 $form = $this->initFormAgreement();
262 if ($this->checkAgreement() && $form->
checkInput()) {
263 self::saveCourseDefinedFields($form, $this->obj_id);
265 $this->getAgreement()->setAccepted(
true);
266 $this->getAgreement()->setAcceptanceTime(time());
267 $this->getAgreement()->save();
270 $history->setUpdateUser($this->
user->getId());
274 $this->
ctrl->returnToParent($this);
275 } elseif (!$this->checkAgreement()) {
276 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt($this->type .
'_agreement_required'));
278 $this->showAgreement($form);
281 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'fill_out_all_required_fields'));
283 $this->showAgreement($form);
296 $ilUser =
$DIC[
'ilUser'];
299 $a_usr_id = $ilUser->getId();
305 $current_value = (string) ($ud[$a_usr_id][$field_obj->getId()] ??
'');
306 if (!$current_value) {
310 switch ($field_obj->getType()) {
313 $id = $field_obj->getIdByValue($current_value);
317 $item->setValue($field_obj->getId() .
'_' .
$id);
320 $open_answer_indexes = $field_obj->getValueOptions();
321 $open_answer_index = end($open_answer_indexes);
323 $item->setValue($field_obj->getId() .
'_' . $open_answer_index);
324 $item_txt = $form->
getItemByPostVar(
'cdf_oa_' . $field_obj->getId() .
'_' . $open_answer_index);
326 $item_txt->setValue($current_value);
333 $item->setValue($current_value);
343 $ilUser =
$DIC[
'ilUser'];
345 $a_usr_id = $ilUser->getId();
349 switch ($field_obj->getType()) {
352 $exp = explode(
'_', $form->
getInput(
'cdf_' . $field_obj->getId()));
354 $option_id = $exp[1] ??
null;
355 $open_answer_indexes = $field_obj->getValueOptions();
356 if (in_array($option_id, $open_answer_indexes)) {
357 $value = $form->
getInput(
'cdf_oa_' . $field_obj->getId() .
'_' . $option_id);
359 $value = $field_obj->getValueById((
int) $option_id);
364 $value = $form->
getInput(
'cdf_' . $field_obj->getId());
369 $course_user_data->setValue($value);
370 $course_user_data->update();
377 if ($this->
http->wrapper()->post()->has(
'agreement')) {
378 $agreement = $this->
http->wrapper()->post()->retrieve(
386 if ($this->privacy->confirmationRequired($this->type)) {
395 $this->agreement_required = $this->getAgreement()->agreementRequired();
401 if ($this->agreement_required) {
402 $message = $this->
lng->txt($this->type .
'_ps_agreement_req_info');
404 if (!$this->required_fullfilled) {
408 $message .= $this->
lng->txt($this->type .
'_ps_required_info');
411 $this->tpl->setOnScreenMessage(
'failure',
$message);
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
static _getFields(int $a_container_id, $a_sort=self::IL_CDF_SORT_NAME)
Get all fields of a container.
static _getValuesByObjId(int $a_obj_id)
static _checkRequired(int $a_usr_id, int $a_obj_id)
@classDescription Date and time handling
static _getInstanceByType(string $a_type)
Get Singleton Instance.
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...
static addCustomFields(ilPropertyFormGUI $form, int $a_obj_id, string $a_type, string $a_mode='user')
static setCourseDefinedFieldValues(ilPropertyFormGUI $form, int $a_obj_id, int $a_usr_id=0)
bool $required_fullfilled
static addAgreement(ilPropertyFormGUI $form, int $a_obj_id, string $a_type)
__construct(int $a_ref_id)
ilMemberAgreement $agreement
ilGlobalTemplateInterface $tpl
static addExportFieldInfo(ilPropertyFormGUI $form, int $a_obj_id, string $a_type)
showAgreement(?ilPropertyFormGUI $form=null)
Show agreement form.
static saveCourseDefinedFields(ilPropertyFormGUI $form, int $a_obj_id, int $a_usr_id=0)
ilPrivacySettings $privacy
This class represents a non editable value in a property form.
Editing history for object custom user fields.
static _lookupType(int $id, bool $reference=false)
static _lookupObjId(int $ref_id)
Singleton class that stores all privacy settings.
This class represents an option in a radio group.
special template class to simplify handling of ITX/PEAR
This class represents a text property in a property form.
Interface GlobalHttpState.
setVariable(string $variable, $value='')
Sets the given variable to the given value.
parseCurrentBlock(string $block_name=self::DEFAULT_BLOCK)
Parses the given block.
setCurrentBlock(string $part=self::DEFAULT_BLOCK)
Sets the template to the given block.
get(string $part=self::DEFAULT_BLOCK)
Renders the given block and returns the html string.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static http()
Fetches the global http state from ILIAS.