Admin: Add config 'course_catalog_settings.extra_fields_in_search_form'

And course_catalog_settings.extra_fields_in_course_block
In order to show extra fields in the course catalog BT#16815
pull/3167/head
Julio Montoya 6 years ago
parent 1b86854c33
commit a8bec39940
  1. 73
      main/auth/courses.php
  2. 9
      main/inc/lib/extra_field.lib.php
  3. 8
      main/install/configuration.dist.php

@ -72,6 +72,9 @@ $courseCatalogSettings = [
$redirectAfterSubscription = 'course_home';
$settings = api_get_configuration_value('course_catalog_settings');
// By default all extra fields are shown (visible and filterable)
$extraFieldsInSearchForm = [];
$extraFieldsInCourseBlock = [];
if (!empty($settings)) {
if (isset($settings['link_settings'])) {
$courseCatalogSettings = $settings['link_settings'];
@ -79,6 +82,14 @@ if (!empty($settings)) {
if (isset($settings['redirect_after_subscription'])) {
$redirectAfterSubscription = $settings['redirect_after_subscription'];
}
if (isset($settings['extra_fields_in_search_form'])) {
$extraFieldsInSearchForm = $settings['extra_fields_in_search_form'];
}
if (isset($settings['extra_fields_in_course_block'])) {
$extraFieldsInCourseBlock = $settings['extra_fields_in_course_block'];
}
}
switch ($action) {
@ -165,7 +176,6 @@ switch ($action) {
}
}
header('Location: '.$redirectionTarget);
exit;
}
@ -222,7 +232,8 @@ switch ($action) {
$jqueryReadyContent = '';
if ($allowExtraFields) {
$extraField = new ExtraField('course');
$returnParams = $extraField->addElements($form, null, [], true);
$onlyFields = [ ];
$returnParams = $extraField->addElements($form, null, [], true, false, $extraFieldsInSearchForm);
$jqueryReadyContent = $returnParams['jquery_ready_content'];
}
@ -412,10 +423,6 @@ switch ($action) {
$content .= '</div></div></div></div>';
if ($showCourses) {
/*if (!empty($searchTerm)) {
$content .= '<p><strong>'.get_lang('SearchResultsFor').' '.$searchTerm.'</strong><br />';
}*/
$showTeacher = 'true' === api_get_setting('display_teacher_in_courselist');
$ajax_url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=add_course_vote';
$user_id = api_get_user_id();
@ -471,7 +478,7 @@ switch ($action) {
// display the course bloc
$course['category_title'] = '';
if (isset($course['category_code'])) {
if (!empty($course['category_code'])) {
$course['category_title'] = isset($categoryList[$course['category_code']]) ? $categoryList[$course['category_code']] : '';
$course['category_code_link'] = $urlNoCategory.'&category_code='.$course['category_code'];
}
@ -506,7 +513,6 @@ switch ($action) {
);
}
}
// end buy course validation
$course['rating'] = '';
if ($hideRating === false) {
@ -526,57 +532,8 @@ switch ($action) {
// display button line
$course['buy_course'] = $separator;
$course['extra_data'] = '';
$course['extra_data_tags'] = [];
//$tagUrl = Display::url($tag->getTag(), $url.'&extra_tags%5B%5D='.$tag->getTag());
if ($allowExtraFields) {
$course['extra_data'] = $extraField->getDataAndFormattedValues($courseId, true);
// $values = $extraFieldValues->getAllValuesForAnItem($courseId, true, true);
// foreach ($values as $valueItem) {
// /** @var \Chamilo\CoreBundle\Entity\ExtraFieldValues $value */
// $value = $valueItem['value'];
// var_dump($value->getField()->getVariable());
// if ($value) {
// $data = $value->getValue();
// if (!empty($data) || $value->getField()->getFieldType() == ExtraField::FIELD_TYPE_TAG) {
// $course['extra_data'] .= $value->getField()->getDisplayText().': ';
// switch ($value->getField()->getFieldType()) {
// case ExtraField::FIELD_TYPE_TAG:
// $tagField = $fieldsRepo->findOneBy(
// [
// 'extraFieldType' => \Chamilo\CoreBundle\Entity\ExtraField::COURSE_FIELD_TYPE,
// 'variable' => $value->getField()->getVariable(),
// ]
// );
//
// $courseTags = [];
// if (!is_null($tagField)) {
// $courseTags = $fieldTagsRepo->getTags($tagField, $courseId);
// }
//
// if (!empty($courseTags)) {
// /** @var \Chamilo\CoreBundle\Entity\Tag $tag */
// foreach ($courseTags as $tag) {
// $tagUrl = Display::url($tag->getTag(), $url.'&extra_tags%5B%5D='.$tag->getTag());
// $course['extra_data_tags'][$value->getField()->getVariable()][] = $tagUrl;
// }
// }
//
// break;
// case ExtraField::FIELD_TYPE_CHECKBOX:
// if ($value->getValue() == 1) {
// $course['extra_data'] .= get_lang('Yes').'<br />';
// } else {
// $course['extra_data'] .= get_lang('No').'<br />';
// }
// break;
// default:
// $course['extra_data'] .= $value->getValue().'<br />';
// break;
// }
// }
// }
// }
$course['extra_data'] = $extraField->getDataAndFormattedValues($courseId, true, $extraFieldsInCourseBlock);
}
// if user registered as student

@ -2554,10 +2554,11 @@ JAVASCRIPT;
*
* @param int|string $itemId The item ID (It could be a session_id, course_id or user_id)
* @param bool $filter
* @param array $onlyShow (list of extra fields variables to show)
*
* @return array The extra fields data
*/
public function getDataAndFormattedValues($itemId, $filter = false)
public function getDataAndFormattedValues($itemId, $filter = false, $onlyShow = [])
{
$valuesData = [];
$fields = $this->get_all();
@ -2566,6 +2567,7 @@ JAVASCRIPT;
$repoTag = $em->getRepository('ChamiloCoreBundle:ExtraFieldRelTag');
foreach ($fields as $field) {
if ('1' != $field['visible_to_self']) {
continue;
}
@ -2574,6 +2576,10 @@ JAVASCRIPT;
continue;
}
if (!empty($onlyShow) && !in_array($field['variable'], $onlyShow)) {
continue;
}
$valueAsArray = [];
$fieldValue = new ExtraFieldValue($this->type);
$valueData = $fieldValue->get_values_by_handler_and_field_id(
@ -2581,7 +2587,6 @@ JAVASCRIPT;
$field['id'],
true
);
if (ExtraField::FIELD_TYPE_TAG == $field['field_type']) {
$tags = $repoTag->findBy(['fieldId' => $field['id'], 'itemId' => $itemId]);
if ($tags) {

@ -1429,14 +1429,18 @@ ALTER TABLE notification_event ADD COLUMN event_id INT NULL;
//$_configuration['allow_course_extra_field_in_catalog'] = false;
// Course catalog links behaviour.
/*$_configuration['course_catalog_settings'] = [
/*
$_configuration['course_catalog_settings'] = [
'link_settings' => [
'info_url' => 'course_description_popup', // course description popup page
'title_url' => 'course_home', // Course home URL
'image_url' => 'course_about', // Course about URL
],
'redirect_after_subscription' => 'course_home', // or 'course_catalog' to stay in the page
];*/
'extra_fields_in_search_form' => ['variable1', 'variable2'],
'extra_fields_in_course_block' => ['variable3', 'variable4'],
];
*/
// KEEP THIS AT THE END
// -------- Custom DB changes

Loading…
Cancel
Save