/**
  * Init form
  */
 protected function initForm()
 {
     $this->setFormAction($this->ctrl->getFormAction($this->parent_gui));
     $title = $this->isNew ? $this->pl->txt('add_new_type') : $this->pl->txt('edit_type');
     $this->setTitle($title);
     $item = new ilTextInputGUI($this->lng->txt('title'), 'title');
     $item->setRequired(true);
     $item->setValue($this->type->getTitle());
     $this->addItem($item);
     $item = new ilTextAreaInputGUI($this->lng->txt('description'), 'description');
     $item->setValue($this->type->getDescription());
     $this->addItem($item);
     $item = new ilMultiSelectInputGUI($this->lng->txt('languages'), 'languages');
     $item->setWidth(self::WIDTH_MULTISELECT_INPUT);
     $langs = $this->lng->getInstalledLanguages();
     $options = array();
     foreach ($langs as $lang_code) {
         $options[$lang_code] = $this->lng->txt("meta_l_{$lang_code}");
     }
     $item->setOptions($options);
     $item->setValue($this->type->getLanguages());
     $item->setRequired(true);
     $this->addItem($item);
     $item = new ilMultiSelectInputGUI($this->lng->txt('roles'), 'roles');
     $item->setWidth(self::WIDTH_MULTISELECT_INPUT);
     $roles = $this->rbac->getRolesByFilter(ilRbacReview::FILTER_ALL, 0, '');
     $options = array();
     $hide_roles = array(14, 5);
     foreach ($roles as $role) {
         if (strpos($role['title'], 'il_') === 0 || in_array($role['obj_id'], $hide_roles)) {
             // Don't show auto-generated roles. If this takes to much performance, write query...
             continue;
         }
         $options[$role['obj_id']] = $role['title'];
     }
     $item->setOptions($options);
     $item->setValue($this->type->getRoles());
     $item->setInfo($this->pl->txt('roles_info'));
     $this->addItem($item);
     $item = new ilMultiSelectInputGUI($this->pl->txt('available_objects'), 'available_objects');
     $item->setWidth(self::WIDTH_MULTISELECT_INPUT);
     $options = array();
     foreach (srCertificateType::getAllAvailableObjectTypes() as $type) {
         $options[$type] = $type;
     }
     $item->setOptions($options);
     $item->setValue($this->type->getAvailableObjects());
     $item->setRequired(true);
     $item->setInfo($this->pl->txt('available_objects_info'));
     $this->addItem($item);
     $this->addCommandButton('saveType', $this->lng->txt('save'));
 }
 /**
  * Get settings
  */
 protected function buildData()
 {
     $data = array();
     /** @var $placeholder srCertificatePlaceholder */
     foreach ($this->type->getPlaceholders() as $placeholder) {
         $row = array();
         $row['id'] = $placeholder->getId();
         $row['identifier'] = $placeholder->getIdentifier();
         $row['max_characters'] = $placeholder->getMaxCharactersValue();
         $row['mandatory'] = (int) $placeholder->getIsMandatory();
         $row['editable_in'] = implode(',', $placeholder->getEditableIn());
         foreach ($this->type->getLanguages() as $lang_code) {
             $row["default_value_{$lang_code}"] = $placeholder->getDefaultValue($lang_code);
             $row["label_{$lang_code}"] = $placeholder->getLabel($lang_code);
         }
         $data[] = $row;
     }
     $this->setData($data);
 }
 /**
  * Get input GUI depending on identifier
  *
  * @return ilFormPropertyGUI|null
  */
 protected function getInputByIdentifier()
 {
     $name = 'default_value';
     $title = $this->pl->txt('default_value');
     switch ($this->identifier) {
         case srCertificateTypeSetting::IDENTIFIER_DEFAULT_LANG:
             $input = new ilSelectInputGUI($title, $name);
             $options = array();
             foreach ($this->type->getLanguages() as $lang) {
                 $options[$lang] = $this->lng->txt("meta_l_{$lang}");
             }
             $input->setOptions($options);
             $input->setValue($this->setting->getValue());
             break;
         case srCertificateTypeSetting::IDENTIFIER_GENERATION:
             $input = new ilRadioGroupInputGUI($title, $name);
             $option = new ilRadioOption($this->pl->txt('setting_generation_auto'), srCertificateTypeSetting::GENERATION_AUTO);
             $input->addOption($option);
             $option = new ilRadioOption($this->pl->txt('setting_generation_manually'), srCertificateTypeSetting::GENERATION_MANUAL);
             $input->addOption($option);
             $input->setValue($this->setting->getValue());
             break;
         case srCertificateTypeSetting::IDENTIFIER_VALIDITY_TYPE:
             $input = new ilRadioGroupInputGUI($title, $name);
             $option = new ilRadioOption($this->pl->txt('always'), srCertificateTypeSetting::VALIDITY_TYPE_ALWAYS);
             $input->addOption($option);
             $option = new ilRadioOption($this->pl->txt('setting_validity_range'), srCertificateTypeSetting::VALIDITY_TYPE_DATE_RANGE);
             $input->addOption($option);
             $option = new ilRadioOption($this->pl->txt('setting_validity_date'), srCertificateTypeSetting::VALIDITY_TYPE_DATE);
             $input->addOption($option);
             $input->setValue($this->setting->getValue());
             break;
         case srCertificateTypeSetting::IDENTIFIER_VALIDITY:
             $validity_value = $this->setting->getValue();
             switch ($this->type->getSettingByIdentifier(srCertificateTypeSetting::IDENTIFIER_VALIDITY_TYPE)->getValue()) {
                 case srCertificateTypeSetting::VALIDITY_TYPE_DATE_RANGE:
                     $input = new ilDurationInputGUI($title, $name);
                     $input->setShowMinutes(false);
                     $input->setShowHours(false);
                     $input->setShowDays(true);
                     $input->setShowMonths(true);
                     if ($validity_value) {
                         $range_array = json_decode($validity_value, true);
                         $data = array();
                         $data[$input->getPostVar()]['MM'] = $range_array['m'];
                         $data[$input->getPostVar()]['dd'] = $range_array['d'];
                         $input->setValueByArray($data);
                     }
                     break;
                 case srCertificateTypeSetting::VALIDITY_TYPE_DATE:
                     $input = new ilDateTimeInputGUI($title, $name);
                     $input->setMode(ilDateTimeInputGUI::MODE_INPUT);
                     if ($validity_value) {
                         $input->setDate(new ilDateTime($validity_value, IL_CAL_DATE));
                     }
                     break;
                 case srCertificateTypeSetting::VALIDITY_TYPE_ALWAYS:
                     // Makes no sence to configure this further
                     $input = null;
                     break;
                 default:
                     $input = new ilTextInputGUI($title, $name);
             }
             break;
         case srCertificateTypeSetting::IDENTIFIER_DOWNLOADABLE:
         case srCertificateTypeSetting::IDENTIFIER_SCORM_TIMING:
         case srCertificateTypeSetting::IDENTIFIER_NOTIFICATION_USER:
             $input = new ilCheckboxInputGUI($title, $name);
             if ($this->setting->getValue()) {
                 $input->setChecked(true);
             }
             break;
         default:
             $input = new ilTextInputGUI($title, $name);
             $input->setValue($this->setting->getValue());
     }
     return $input;
 }