Adding getParent see BT#7011

1.9.x
Julio Montoya 11 years ago
parent 0ce7c0e0f6
commit cefdd8d409
  1. 25
      main/inc/ajax/course.ajax.php
  2. 22
      main/inc/lib/course_category.lib.php

@ -63,8 +63,31 @@ switch ($action) {
$_REQUEST['q']
);
$results = array();
require_once api_get_path(LIBRARY_PATH).'course_category.lib.php';
$categories = browseCourseCategories();
foreach ($courseList as $courseInfo) {
$results[] = array('id' => $courseInfo['id'], 'text' => $courseInfo['title']);
$title = $courseInfo['title'];
if (!empty($courseInfo['category_code'])) {
$parents = getParents($courseInfo['category_code']);
if (!empty($parents)) {
$parents = array_reverse($parents);
$categories = array();
foreach ($parents as $category) {
$categories[] = $category['code'];
}
$categoriesInString = implode(' > ', $categories).' > ';
$title = $categoriesInString.$courseInfo['title'];
}
}
$results[] = array(
'id' => $courseInfo['id'],
'text' => $title
);
}
if (!empty($results)) {

@ -271,6 +271,26 @@ function getChildren($categoryCode)
return $children;
}
function getParents($categoryCode)
{
if (empty($categoryCode)) {
return array();
}
$tbl_category = Database::get_main_table(TABLE_MAIN_CATEGORY);
$categoryCode = Database::escape_string($categoryCode);
$sql = "SELECT code, parent_id FROM $tbl_category WHERE code = '$categoryCode'";
$result = Database::query($sql);
$children = array();
while ($row = Database::fetch_array($result, 'ASSOC')) {
$parent = getCategory($row['parent_id']);
$children[] = $row;
$subChildren = getParents($parent['code']);
$children = array_merge($children, $subChildren);
}
return $children;
}
/**
* @param string $categorySource
* @return string
@ -390,12 +410,12 @@ function browseCourseCategories()
$tbl_category = Database::get_main_table(TABLE_MAIN_CATEGORY);
$conditions = null;
$whereCondition = null;
if (isMultipleUrlSupport()) {
$table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE_CATEGORY);
$conditions = " INNER JOIN $table a ON (c.id = a.course_category_id)";
$whereCondition = " WHERE a.access_url_id = ".api_get_current_access_url_id();
}
$sql = "SELECT c.* FROM $tbl_category c
$conditions
$whereCondition

Loading…
Cancel
Save