/**
  * Get settings
  */
 protected function buildData()
 {
     $data = array();
     /** @var $setting srCertificateTypeSetting */
     foreach ($this->type->getSettings() as $setting) {
         $row = array();
         $row['identifier'] = $setting->getIdentifier();
         $row['setting'] = $this->pl->txt("setting_id_" . $setting->getIdentifier());
         $row['editable_in'] = implode(',', $setting->getEditableIn());
         $default_value = $setting->getValue();
         switch ($setting->getIdentifier()) {
             case srCertificateTypeSetting::IDENTIFIER_VALIDITY_TYPE:
                 $default_value = $this->pl->txt("setting_validity_{$default_value}");
                 break;
             case srCertificateTypeSetting::IDENTIFIER_VALIDITY:
                 $validity_type = $this->type->getSettingByIdentifier(srCertificateTypeSetting::IDENTIFIER_VALIDITY_TYPE)->getValue();
                 if ($default_value && $validity_type == srCertificateTypeSetting::VALIDITY_TYPE_DATE_RANGE) {
                     $date_data = json_decode($default_value);
                     $default_value = sprintf($this->pl->txt('validity_date_range'), $date_data->m, $date_data->d);
                 }
                 break;
         }
         $row['default_value'] = $default_value;
         $data[] = $row;
     }
     $this->setData($data);
 }
 /**
  * Download template file
  */
 public function downloadTemplate()
 {
     if (is_file($this->type->getCertificateTemplatesPath(true))) {
         $filename = srCertificateTemplateTypeFactory::getById($this->type->getTemplateTypeId())->getTemplateFilename();
         ilUtil::deliverFile($this->type->getCertificateTemplatesPath(true), $filename);
     }
     $this->editTemplate();
 }
 /**
  * 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 $signature srCertificateSignature */
     foreach ($this->type->getSignatures() as $signature) {
         $row = array();
         $row['id'] = $signature->getId();
         $row['last_name'] = $signature->getLastName();
         $row['first_name'] = $signature->getFirstName();
         $data[] = $row;
     }
     $this->setData($data);
 }
 /**
  * Init form
  */
 protected function initForm()
 {
     $this->setFormAction($this->ctrl->getFormAction($this->parent_gui));
     $this->setTitle($this->pl->txt('edit_type_template'));
     $types_available = array();
     $types = array(srCertificateTemplateTypeFactory::getById(srCertificateTemplateType::TEMPLATE_TYPE_HTML), srCertificateTemplateTypeFactory::getById(srCertificateTemplateType::TEMPLATE_TYPE_JASPER));
     /** @var $type srCertificateTemplateType */
     foreach ($types as $type) {
         if ($type->isAvailable()) {
             $types_available[$type->getId()] = $type->getTitle();
         }
     }
     if (!count($types_available)) {
         ilUtil::sendInfo($this->pl->txt('msg_no_template_types'));
     }
     $item = new ilSelectInputGUI($this->pl->txt('template_type_id'), 'template_type_id');
     $item->setOptions($types_available);
     $item->setRequired(true);
     $item->setValue($this->type->getTemplateTypeId());
     $this->addItem($item);
     $item = new ilFileInputGUI($this->pl->txt('template_file'), 'template_file');
     $template_file = $this->type->getCertificateTemplatesPath(true);
     if (is_file($template_file)) {
         $item->setValue($template_file);
     }
     $item->setFilename($template_file);
     $item->setInfo($this->pl->txt('template_file_info'));
     $item->setRequired(!is_file($template_file));
     $this->addItem($item);
     $assets = $this->type->getAssets();
     if (count($assets)) {
         $item = new ilMultiSelectInputGUI($this->pl->txt('assets'), 'remove_assets');
         $options = array();
         foreach ($assets as $asset) {
             $options[$asset] = $asset;
         }
         $item->setOptions($options);
         $item->setInfo($this->pl->txt('assets_info'));
         $this->addItem($item);
     }
     $item = new ilFileWizardInputGUI($this->pl->txt('add_assets'), 'add_assets');
     $item->setFilenames(array(0 => ''));
     $this->addItem($item);
     $this->addCommandButton('downloadDefaultTemplate', $this->pl->txt('download_default_template'));
     if (is_file($this->type->getCertificateTemplatesPath(true))) {
         $this->addCommandButton('downloadTemplate', $this->pl->txt('download_template'));
     }
     $this->addCommandButton('updateTemplate', $this->lng->txt('save'));
 }
 /**
  * Get settings
  */
 protected function buildData()
 {
     $data = array();
     /** @var $setting srCertificateCustomTypeSetting */
     foreach ($this->type->getCustomSettings() as $setting) {
         $row = array();
         $row['id'] = $setting->getId();
         $row['identifier'] = $setting->getIdentifier();
         $row['editable_in'] = implode(',', $setting->getEditableIn());
         $row['setting_type'] = $this->pl->txt('custom_setting_type_' . $setting->getSettingTypeId());
         $row['default_value'] = $setting->getValue();
         $data[] = $row;
     }
     $this->setData($data);
 }
 public function __construct($a_parent_obj, $a_parent_cmd)
 {
     global $ilCtrl, $ilToolbar;
     $this->setId('cert_type_table');
     parent::__construct($a_parent_obj, $a_parent_cmd);
     $this->pl = ilCertificatePlugin::getInstance();
     $this->ctrl = $ilCtrl;
     $this->toolbar = $ilToolbar;
     $this->setRowTemplate('tpl.type_row.html', $this->pl->getDirectory());
     $this->initColumns();
     $this->addColumn($this->pl->txt('actions'));
     $this->setFormAction($this->ctrl->getFormAction($a_parent_obj));
     $this->toolbar->addButton($this->pl->txt('add_new_type'), $this->ctrl->getLinkTargetByClass('srcertificatetypegui', 'addType'));
     $data = srCertificateType::getArray();
     $this->setData($data);
 }
 /**
  * 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);
 }
 /**
  * @param mixed $value
  */
 public function setValue($value)
 {
     // This should be factored out, currently there is one exception where a value needs to be parsed before storing in DB
     if ($value && $this->getIdentifier() == srCertificateTypeSetting::IDENTIFIER_VALIDITY) {
         /** @var srCertificateType $type */
         $type = srCertificateType::find($this->getTypeId());
         $value = self::formatValidityBasedOnType($type->getSettingByIdentifier(self::IDENTIFIER_VALIDITY_TYPE)->getValue(), $value);
     }
     $this->value = $value;
 }
Ejemplo n.º 10
0
srCertificateCustomDefinitionSetting::installDB();
?>
<#10>
    <?php 
if (!$ilDB->tableColumnExists('uihkcertificate_c', 'value')) {
    $ilDB->renameTableColumn('uihkcertificate_c', 'config_value', 'value');
}
if (!$ilDB->tableColumnExists('uihkcertificate_c', 'name')) {
    $ilDB->renameTableColumn('uihkcertificate_c', 'config_key', 'name');
}
?>
<#11>
	<?php 
// We will add one default certificate definition for easier installation.
require_once './Customizing/global/plugins/Services/UIComponent/UserInterfaceHook/Certificate/classes/Definition/class.srCertificateDefinition.php';
$type = new srCertificateType();
$type->setTitle("Default Certificate");
$type->setLanguages(array('en'));
$type->setRoles(array(2));
//2 Is the default administration role.
$type->setAvailableObjects(array('crs'));
$type->setTemplateTypeId(1);
// JasperReport
$type->storeTemplateFileFromServer(ILIAS_ABSOLUTE_PATH . '/Customizing/global/plugins/Services/UIComponent/UserInterfaceHook/Certificate/resources/template.jrxml');
$type->create();
//	$placeholder = new srCertificatePlaceholder();
//	$placeholder->setCertificateType($type);
//	$placeholder->setIdentifier('crs_title');
//	$placeholder->setIsMandatory(true);
//	$placeholder->setEditableIn(array('crs'));
//	$placeholder->setLabel('Course Title', 'en');
 /**
  * Check if a given user is allowed to select a given certificate type to create a new definition for the given ref_id.
  * This method checks the following steps:
  *  1) Is the type restricted to certain object types, e.g. is the object type of the given ref_id valid?
  *  2) Is the type restricted to certain roles, e.g. check if the a user has at least one role
  *
  * @param srCertificateType $type
  * @param $ref_id
  * @param int $user_id If empty, the current user is used
  * @return bool
  */
 public static function isSelectable(srCertificateType $type, $ref_id, $user_id = 0)
 {
     global $ilUser, $rbacreview;
     $user_id = $user_id ? $user_id : $ilUser->getId();
     $pl = ilCertificatePlugin::getInstance();
     $object_type = $pl->isCourseTemplate($ref_id) ? 'crs-tpl' : ilObject::_lookupType($ref_id, true);
     if (!in_array($object_type, $type->getAvailableObjects())) {
         return false;
     }
     // Access restricted by roles. Check if current user has a role to choose the type
     if (count($type->getRoles()) && !$rbacreview->isAssignedToAtLeastOneGivenRole($user_id, $type->getRoles())) {
         return false;
     }
     return true;
 }
 /**
  * @return \srCertificateType
  */
 public function getType()
 {
     return srCertificateType::find($this->getTypeId());
 }
 /**
  * Add filter items
  *
  */
 public function initFilter()
 {
     if ($this->isColumnSelected('id')) {
         $this->addFilterItemWithValue(new ilTextInputGUI($this->pl->txt('cert_id'), 'id'));
     }
     if ($this->isColumnSelected('firstname')) {
         $this->addFilterItemWithValue(new ilTextInputGUI($this->pl->txt('firstname'), 'firstname'));
     }
     if ($this->isColumnSelected('lastname')) {
         $this->addFilterItemWithValue(new ilTextInputGUI($this->pl->txt('lastname'), 'lastname'));
     }
     if ($this->isColumnSelected('crs_title')) {
         $this->addFilterItemWithValue(new ilTextInputGUI($this->pl->txt('crs_title'), 'crs_title'));
     }
     if ($this->isColumnSelected('valid_from')) {
         $item = new ilDateTimeInputGUI($this->pl->txt('valid_from'), 'valid_from');
         $item->setMode(ilDateTimeInputGUI::MODE_INPUT);
         $this->addFilterItemWithValue($item);
     }
     if ($this->isColumnSelected('valid_to')) {
         $item = new ilDateTimeInputGUI($this->pl->txt('valid_to'), 'valid_to');
         $item->setMode(ilDateTimeInputGUI::MODE_INPUT);
         $this->addFilterItemWithValue($item);
     }
     if ($this->isColumnSelected('cert_type')) {
         $item = new ilSelectInputGUI($this->pl->txt('cert_type'), 'type_id');
         $options = array('' => '') + srCertificateType::getArray('id', 'title');
         $item->setOptions($options);
         $this->addFilterItemWithValue($item);
     }
     if (!$this->getOption('newest_version_only')) {
         $item = new ilCheckboxInputGUI($this->pl->txt('only_newest_version'), 'active');
         $this->addFilterItemWithValue($item);
     }
 }
 /**
  * Init your form
  *
  */
 protected function initForm()
 {
     $title = $this->setting->getId() ? sprintf($this->pl->txt('edit_setting'), $this->setting->getIdentifier()) : $this->pl->txt('add_new_custom_setting');
     $this->setTitle($title);
     $item = new ilHiddenInputGUI('custom_setting_id');
     $item->setValue($this->setting->getId());
     $this->addItem($item);
     $item = new ilTextInputGUI($this->pl->txt('identifier'), 'identifier');
     $item->setRequired(true);
     $item->setValue($this->setting->getIdentifier());
     $item->setInfo(sprintf($this->pl->txt('identifier_info'), srCertificatePlaceholder::REGEX_VALID_IDENTIFIER));
     $this->addItem($item);
     $item = new ilRadioGroupInputGUI($this->pl->txt('custom_setting_type'), 'setting_type_id');
     $item->setRequired(true);
     $option = new ilRadioOption($this->pl->txt('custom_setting_type_' . srCertificateCustomTypeSetting::SETTING_TYPE_BOOLEAN), srCertificateCustomTypeSetting::SETTING_TYPE_BOOLEAN);
     $item->addOption($option);
     $option = new ilRadioOption($this->pl->txt('custom_setting_type_' . srCertificateCustomTypeSetting::SETTING_TYPE_SELECT), srCertificateCustomTypeSetting::SETTING_TYPE_SELECT);
     $subitem = new ilTextAreaInputGUI($this->pl->txt('custom_setting_type_2_data'), 'data');
     $subitem->setValue($this->setting->getData());
     $subitem->setInfo($this->pl->txt('custom_setting_type_2_data_info'));
     $option->addSubItem($subitem);
     $item->setValue($this->setting->getSettingTypeId());
     $item->addOption($option);
     $this->addItem($item);
     $item = new ilTextInputGUI($this->pl->txt('default_value'), "value");
     $item->setInfo($this->pl->txt('custom_setting_default_value_info'));
     $item->setValue($this->setting->getValue());
     $this->addItem($item);
     $item = new ilMultiSelectInputGUI($this->pl->txt('editable_in'), 'editable_in');
     $options = array();
     foreach (srCertificateType::getAllAvailableObjectTypes() as $type) {
         $options[$type] = $type;
     }
     $item->setOptions($options);
     $item->setValue($this->setting->getEditableIn());
     $this->addItem($item);
     // Update definitions, add settings
     if (!$this->setting->getId()) {
         $item = new ilCheckboxInputGUI($this->pl->txt('update_cert_definitions'), 'update_definitions');
         $item->setInfo($this->pl->txt('custom_setting_update_cert_definitions_info'));
         $this->addItem($item);
     }
     // Label per language
     /** @var srCertificateType $type */
     $type = $this->setting->getId() ? srCertificateType::find($this->setting->getTypeId()) : srCertificateType::find((int) $_GET['type_id']);
     foreach ($type->getLanguages() as $lang_code) {
         $this->addLabelInput($lang_code);
     }
 }
 /**
  * Get dropdown for choosing the certificate type
  *
  * @return ilSelectInputGUI
  */
 protected function getTypeInput()
 {
     $types = srcertificateType::get();
     $options = array();
     $object_type = $this->pl->isCourseTemplate((int) $_GET['ref_id']) ? 'crs-tpl' : ilObject::_lookupType((int) $_GET['ref_id'], true);
     /** @var $type srCertificateType */
     $invalid = array();
     foreach ($types as $type) {
         if (!srCertificateType::isSelectable($type, (int) $_GET['ref_id'])) {
             continue;
         }
         // Skip the type if it contains no valid template file!
         if (!is_file($type->getCertificateTemplatesPath(true))) {
             $invalid[] = $type->getTitle();
             continue;
         }
         $options[$type->getId()] = $type->getTitle();
     }
     if (count($invalid) && $this->isNew) {
         ilUtil::sendInfo(sprintf($this->pl->txt('msg_info_invalid_cert_types'), implode(', ', $invalid)));
     }
     $item = new ilSelectInputGUI($this->pl->txt('setting_id_type'), 'type_id');
     asort($options);
     $item->setOptions($options);
     $info = $this->isNew ? $this->pl->txt('setting_id_type_info_new') : $this->pl->txt('setting_id_type_info_change');
     $item->setInfo($info);
     $item->setValue($this->definition->getTypeId());
     $item->setRequired(true);
     return $item;
 }
 /**
  * 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;
 }
 /**
  * @return \srCertificateType
  */
 public function getCertificateType()
 {
     if (is_null($this->type)) {
         $this->type = srCertificateType::find($this->getTypeId());
     }
     return $this->type;
 }