Extra fields: Refactor type setter + fix breadcrumb

pull/4020/head^2
Julio 3 years ago
parent c8b87f2afd
commit 30f75c59af
  1. 26
      public/main/extrafield/translate.php
  2. 32
      public/main/extrafield/translate_option.php
  3. 101
      public/main/inc/lib/extra_field.lib.php
  4. 1
      tests/CoreBundle/Repository/ExtraFieldOptionsRepositoryTest.php

@ -55,26 +55,12 @@ $form->addButtonSave(get_lang('Save'));
$interbreadcrumb[] = ['url' => api_get_path(WEB_CODE_PATH).'admin', 'name' => get_lang('Administration')];
switch ($extraField->getExtraFieldType()) {
case ExtraField::USER_FIELD_TYPE:
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'admin/extra_fields.php?type=user',
'name' => get_lang('Profile attributes'),
];
break;
case ExtraField::COURSE_FIELD_TYPE:
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'admin/extra_fields.php?type=course',
'name' => get_lang('Course fields'),
];
break;
case ExtraField::SESSION_FIELD_TYPE:
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'admin/extra_fields.php?type=session',
'name' => get_lang('Session fields'),
];
break;
}
$type = \ExtraField::getExtraFieldTypeFromInt($extraField->getExtraFieldType());
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'admin/extra_fields.php?type='.$type,
'name' => get_lang('Fields'),
];
if ($form->validate()) {
$values = $form->getSubmitValues();

@ -57,26 +57,18 @@ $form->addButtonSave(get_lang('Save'));
$interbreadcrumb[] = ['url' => api_get_path(WEB_CODE_PATH).'admin', 'name' => get_lang('Administration')];
switch ($extraField->getExtraFieldType()) {
case ExtraField::USER_FIELD_TYPE:
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'admin/extra_fields.php?type=user',
'name' => get_lang('Profile attributes'),
];
break;
case ExtraField::COURSE_FIELD_TYPE:
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'admin/extra_fields.php?type=course',
'name' => get_lang('Course fields'),
];
break;
case ExtraField::SESSION_FIELD_TYPE:
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'admin/extra_fields.php?type=session',
'name' => get_lang('Session fields'),
];
break;
}
$type = \ExtraField::getExtraFieldTypeFromInt($extraField->getExtraFieldType());
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'admin/extra_fields.php?type='.$type,
'name' => get_lang('Fields'),
];
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).
'admin/extra_field_options.php?action=edit&field_id='.$extraField->getId().'&type='.$type.'&id='.$fieldId,
'name' => $extraField->getDisplayText(),
];
if ($form->validate()) {
$values = $form->getSubmitValues();

@ -98,70 +98,15 @@ class ExtraField extends Model
$this->table_field_tag = Database::get_main_table(TABLE_MAIN_TAG);
$this->table_field_rel_tag = Database::get_main_table(TABLE_MAIN_EXTRA_FIELD_REL_TAG);
$this->handler_id = 'item_id';
$this->extraFieldType = self::getExtraFieldTypeFromString($this->type);
switch ($this->type) {
case 'session':
case 'user':
case 'calendar_event':
$this->extraFieldType = EntityExtraField::CALENDAR_FIELD_TYPE;
break;
case 'course':
$this->extraFieldType = EntityExtraField::COURSE_FIELD_TYPE;
$this->primaryKey = 'id';
break;
case 'user':
$this->extraFieldType = EntityExtraField::USER_FIELD_TYPE;
$this->primaryKey = 'id';
break;
case 'session':
$this->extraFieldType = EntityExtraField::SESSION_FIELD_TYPE;
$this->primaryKey = 'id';
break;
case 'exercise':
$this->extraFieldType = EntityExtraField::EXERCISE_FIELD_TYPE;
break;
case 'question':
$this->extraFieldType = EntityExtraField::QUESTION_FIELD_TYPE;
break;
case 'lp':
$this->extraFieldType = EntityExtraField::LP_FIELD_TYPE;
break;
case 'lp_item':
$this->extraFieldType = EntityExtraField::LP_ITEM_FIELD_TYPE;
break;
case 'skill':
$this->extraFieldType = EntityExtraField::SKILL_FIELD_TYPE;
break;
case 'work':
$this->extraFieldType = EntityExtraField::WORK_FIELD_TYPE;
break;
case 'career':
$this->extraFieldType = EntityExtraField::CAREER_FIELD_TYPE;
break;
case 'user_certificate':
$this->extraFieldType = EntityExtraField::USER_CERTIFICATE;
break;
case 'survey':
$this->extraFieldType = EntityExtraField::SURVEY_FIELD_TYPE;
break;
case 'scheduled_announcement':
$this->extraFieldType = EntityExtraField::SCHEDULED_ANNOUNCEMENT;
break;
case 'terms_and_condition':
$this->extraFieldType = EntityExtraField::TERMS_AND_CONDITION_TYPE;
break;
case 'forum_category':
$this->extraFieldType = EntityExtraField::FORUM_CATEGORY_TYPE;
break;
case 'forum_post':
$this->extraFieldType = EntityExtraField::FORUM_POST_TYPE;
break;
case 'track_exercise':
$this->extraFieldType = EntityExtraField::TRACK_EXERCISE_FIELD_TYPE;
break;
case 'portfolio':
$this->extraFieldType = EntityExtraField::PORTFOLIO_TYPE;
break;
case 'lp_view':
$this->extraFieldType = EntityExtraField::LP_VIEW_TYPE;
}
$this->pageUrl = 'extra_fields.php?type='.$this->type;
@ -169,6 +114,44 @@ class ExtraField extends Model
$this->pageName = ucwords($this->type).'Fields';
}
public static function getTypeList(): array
{
return [
'calendar_event' => EntityExtraField::CALENDAR_FIELD_TYPE,
'course' => EntityExtraField::COURSE_FIELD_TYPE,
'user' => EntityExtraField::USER_FIELD_TYPE,
'session' => EntityExtraField::SESSION_FIELD_TYPE,
'exercise' => EntityExtraField::EXERCISE_FIELD_TYPE,
'question' => EntityExtraField::QUESTION_FIELD_TYPE,
'lp' => EntityExtraField::LP_FIELD_TYPE,
'lp_item' => EntityExtraField::LP_ITEM_FIELD_TYPE,
'skill' => EntityExtraField::SKILL_FIELD_TYPE,
'work' => EntityExtraField::WORK_FIELD_TYPE,
'career' => EntityExtraField::CAREER_FIELD_TYPE,
'user_certificate' => EntityExtraField::USER_CERTIFICATE,
'survey' => EntityExtraField::SURVEY_FIELD_TYPE,
'scheduled_announcement' => EntityExtraField::SCHEDULED_ANNOUNCEMENT,
'terms_and_condition' => EntityExtraField::TERMS_AND_CONDITION_TYPE,
'forum_category' => EntityExtraField::FORUM_CATEGORY_TYPE,
'forum_post' => EntityExtraField::FORUM_POST_TYPE,
'track_exercise' => EntityExtraField::TRACK_EXERCISE_FIELD_TYPE,
'portfolio' => EntityExtraField::PORTFOLIO_TYPE,
'lp_view' => EntityExtraField::LP_VIEW_TYPE,
];
}
public static function getExtraFieldTypeFromString($extraFieldTypeInString): string
{
return self::getTypeList()[$extraFieldTypeInString];
}
public static function getExtraFieldTypeFromInt($extraFieldTypeInt)
{
$reversed = array_flip(self::getTypeList());
return $reversed[$extraFieldTypeInt];
}
/**
* @return array
*/
@ -928,7 +911,7 @@ class ExtraField extends Model
if (!empty($extraFields)) {
foreach ($extraFields as &$extraField) {
$extraFieldId = $extraField['id'];
/** @var \Chamilo\CoreBundle\Entity\ExtraField $extraField */
/** @var \Chamilo\CoreBundle\Entity\ExtraField $field */
$field = $extraFieldRepo->find($extraFieldId);
$extraField['display_text'] = $field->getDisplayText();
$extraField['options'] = $option->get_field_options_by_field(

@ -8,7 +8,6 @@ namespace Chamilo\Tests\CoreBundle\Repository;
use Chamilo\CoreBundle\Entity\ExtraField;
use Chamilo\CoreBundle\Entity\ExtraFieldOptions;
use Chamilo\CoreBundle\Entity\ExtraFieldSavedSearch;
use Chamilo\CoreBundle\Repository\ExtraFieldOptionsRepository;
use Chamilo\CoreBundle\Repository\ExtraFieldRepository;
use Chamilo\Tests\AbstractApiTest;

Loading…
Cancel
Save