Allow different tags in course catalog BT#16817

pull/3159/head
Julio Montoya 6 years ago
parent 4a029bb81b
commit 1c1e35e0fb
  1. 154
      main/auth/courses.php
  2. 14
      main/inc/lib/CoursesAndSessionsCatalog.class.php
  3. 12
      main/inc/lib/extra_field.lib.php
  4. 52
      main/template/default/catalog/course_item_catalog.tpl

@ -207,23 +207,6 @@ switch ($action) {
$countCoursesInCategory = count($courses);
} else {
$values = $_REQUEST;
if (!empty($values) && $form->hasElement('extra_tags')) {
$tagElement = $form->getElement('extra_tags');
if (isset($values['extra_tags']) && !empty($values['extra_tags'])) {
$tags = [];
foreach ($values['extra_tags'] as $tag) {
$tag = Security::remove_XSS($tag);
$tags[] = $tag;
$tagElement->addOption(
$tag,
$tag
);
}
$defaults['extra_tags'] = $tags;
}
}
if ($allowExtraFields) {
// Parse params.
foreach ($values as $key => $value) {
@ -235,12 +218,17 @@ switch ($action) {
}
}
$extraFields = $extraField->get_all(['visible_to_self = ? AND filter = ?' => [1, 1]], 'option_order');
$extraFields = array_column($extraFields, 'variable');
$extraFieldsAll = $extraField->get_all(
['visible_to_self = ? AND filter = ?' => [1, 1]],
'option_order'
);
$extraFieldsType = array_column($extraFieldsAll, 'field_type', 'variable');
$extraFields = array_column($extraFieldsAll, 'variable');
$filter = new stdClass();
foreach ($fields as $variable => $col) {
$variableNoExtra = str_replace('extra_', '', $variable);
if (isset($values[$variable]) && !empty($values[$variable]) &&
in_array(str_replace('extra_', '', $variable), $extraFields)
in_array($variableNoExtra, $extraFields)
) {
$rule = new stdClass();
$rule->field = $variable;
@ -252,6 +240,20 @@ switch ($action) {
$rule->data = $data;
$filter->rules[] = $rule;
$filter->groupOp = 'AND';
if ($extraFieldsType[$variableNoExtra] == ExtraField::FIELD_TYPE_TAG) {
$tagElement = $form->getElement($variable);
$tags = [];
foreach ($values[$variable] as $tag) {
$tag = Security::remove_XSS($tag);
$tags[] = $tag;
$tagElement->addOption(
$tag,
$tag
);
}
$defaults[$variable] = $tags;
}
}
}
$result = $extraField->getExtraFieldRules($filter);
@ -270,7 +272,12 @@ switch ($action) {
}
$courses = CoursesAndSessionsCatalog::searchCourses($categoryCode, $searchTerm, $limit, false, $conditions);
$countCoursesInCategory = CourseCategory::countCoursesInCategory($categoryCode, $searchTerm, true, $conditions);
$countCoursesInCategory = CourseCategory::countCoursesInCategory(
$categoryCode,
$searchTerm,
true,
$conditions
);
}
$showCourses = CoursesAndSessionsCatalog::showCourses();
$showSessions = CoursesAndSessionsCatalog::showSessions();
@ -279,6 +286,7 @@ switch ($action) {
$pageTotal = (int) ceil($countCoursesInCategory / $pageLength);
$url = CoursesAndSessionsCatalog::getCatalogUrl(1, $pageLength, 'ALL', 'search_course', $fields);
$urlNoExtraFields = CoursesAndSessionsCatalog::getCatalogUrl(1, $pageLength, 'ALL', 'search_course');
$urlNoCategory = CoursesAndSessionsCatalog::getCatalogUrl(1, $pageLength, '', 'search_course', $fields);
$urlNoCategory = str_replace('&category_code=ALL', '', $urlNoCategory);
@ -376,9 +384,9 @@ switch ($action) {
$content .= '</div></div></div></div>';
if ($showCourses) {
if (!empty($searchTerm)) {
/*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';
@ -397,13 +405,6 @@ switch ($action) {
$em = Database::getManager();
$fieldsRepo = $em->getRepository('ChamiloCoreBundle:ExtraField');
$fieldTagsRepo = $em->getRepository('ChamiloCoreBundle:ExtraFieldRelTag');
$tagField = $fieldsRepo->findOneBy(
[
'extraFieldType' => \Chamilo\CoreBundle\Entity\ExtraField::COURSE_FIELD_TYPE,
'variable' => 'tags',
]
);
}
$courseUrl = api_get_path(WEB_COURSE_PATH);
@ -415,13 +416,8 @@ switch ($action) {
if (COURSE_VISIBILITY_HIDDEN == $course['visibility']) {
continue;
}
$courseTags = [];
if ($allowExtraFields && !is_null($tagField)) {
$courseTags = $fieldTagsRepo->getTags($tagField, $courseId);
}
$aboutPage = api_get_path(WEB_PATH).'course/'.$course['real_id'].'/about';
$settingsUrl = [
'course_description_popup' => api_get_path(WEB_CODE_PATH).'inc/ajax/course_home.ajax.php?a=show_course_information&code='.$course['code'],
'course_about' => $aboutPage,
@ -482,7 +478,6 @@ switch ($action) {
);
}
}
// end buy course validation
$course['rating'] = '';
@ -502,41 +497,58 @@ 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'] = '';
$values = $extraFieldValues->getAllValuesForAnItem($courseId, true, true);
foreach ($values as $valueItem) {
/** @var \Chamilo\CoreBundle\Entity\ExtraFieldValues $value */
$value = $valueItem['value'];
if ($value) {
$data = $value->getValue();
if (!empty($data)) {
$course['extra_data'] .= $value->getField()->getDisplayText().': ';
switch ($value->getField()->getFieldType()) {
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_tags'] = [];
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'][] = $tagUrl;
}
}
$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;
// }
// }
// }
// }
}
// if user registered as student
@ -590,7 +602,9 @@ switch ($action) {
$template = new Template($toolTitle, true, true, false, false, false);
$template->assign('content', $content);
$template->assign('courses', $courses);
$template->assign('catalog_url_no_extra_fields', $urlNoExtraFields);
$template->assign('pagination', $catalogPagination);
$template->display($template->get_template('catalog/course_catalog.tpl'));
exit;
break;

@ -497,7 +497,6 @@ class CoursesAndSessionsCatalog
";
}
}
$result = Database::query($sql);
$courses = [];
while ($row = Database::fetch_array($result)) {
@ -765,7 +764,6 @@ class CoursesAndSessionsCatalog
{
$em = Database::getManager();
$qb = $em->createQueryBuilder();
$urlId = api_get_current_access_url_id();
$qb->select('s')
@ -852,7 +850,7 @@ class CoursesAndSessionsCatalog
$list = [];
$row = [];
if ($code !== 'ALL' and $code !== 'NONE') {
if ($code !== 'ALL' && $code !== 'NONE') {
foreach ($allCategories as $category) {
if ($category['code'] === $code) {
$list = self::buildCourseCategoryTree($allCategories, $category['code'], 0);
@ -1514,8 +1512,14 @@ class CoursesAndSessionsCatalog
*
* @return string
*/
public static function getCatalogPagination($pageCurrent, $pageLength, $pageTotal, $categoryCode = '', $action = '', $fields = [])
{
public static function getCatalogPagination(
$pageCurrent,
$pageLength,
$pageTotal,
$categoryCode = '',
$action = '',
$fields = []
) {
// Start empty html
$pageDiv = '';
$html = '';

@ -2553,10 +2553,11 @@ JAVASCRIPT;
* Get the extra fields and their formatted values.
*
* @param int|string $itemId The item ID (It could be a session_id, course_id or user_id)
* @param bool $filter
*
* @return array The extra fields data
*/
public function getDataAndFormattedValues($itemId)
public function getDataAndFormattedValues($itemId, $filter = false)
{
$valuesData = [];
$fields = $this->get_all();
@ -2569,6 +2570,11 @@ JAVASCRIPT;
continue;
}
if ($filter && $field['filter'] != 1) {
continue;
}
$valueAsArray = [];
$fieldValue = new ExtraFieldValue($this->type);
$valueData = $fieldValue->get_values_by_handler_and_field_id(
$itemId,
@ -2587,13 +2593,13 @@ JAVASCRIPT;
$data[] = $tag->getTag();
}
$valueData = implode(',', $data);
$valueAsArray = $data;
}
}
if (!$valueData) {
continue;
}
$displayedValue = get_lang('None');
switch ($field['field_type']) {
@ -2660,8 +2666,10 @@ JAVASCRIPT;
}
$valuesData[] = [
'variable' => $field['variable'],
'text' => $field['display_text'],
'value' => $displayedValue,
'value_as_array' => $valueAsArray,
];
}

@ -53,22 +53,44 @@
{% if course.extra_data %}
<div class="toolbar row">
<div class="col-sm-12">
{{ course.extra_data }}
{% for field in course.extra_data %}
{% if field.value_as_array %}
<div class="panel-tags">
<ul class="list-inline course-tags">
<li> {{ field.text }} :</li>
{% for tag in field.value_as_array %}
<li class="label label-info">
<span>
<a href="{{ catalog_url_no_extra_fields }}&extra_{{ field.variable }}%5B%5D={{ tag }}" >
{{ tag }}
</a>
</span>
</li>
{% endfor %}
</ul>
</div>
{% else %}
{{ field.text }} : {{ field.value }} <br />
{% endif %}
{% if course.extra_data_tags %}
<div class="panel-tags">
<ul class="list-inline course-tags">
<li> {{ 'Tags' | get_lang }}</li>
{% for tag in course.extra_data_tags %}
<li class="label label-info">
<span>
{{ tag }}
</span>
</li>
{% endfor %}
</ul>
</div>
{% endif %}
{% endfor %}
{# {% if course.extra_data_tags %}ss#}
{# {% for tags in course.extra_data_tags %}#}
{# <div class="panel-tags">#}
{# <ul class="list-inline course-tags">#}
{# <li> {{ 'Tags' | get_lang }}</li>#}
{# {% for tag in tags %}#}
{# <li class="label label-info">#}
{# <span>#}
{# {{ tag }}#}
{# </span>#}
{# </li>#}
{# {% endfor %}#}
{# </ul>#}
{# </div>#}
{# {% endfor %}#}
{# {% endif %}#}
</div>
</div>
{% endif %}

Loading…
Cancel
Save