Adding api_format_course_array() in order to clean the course array

skala
Julio Montoya 14 years ago
parent bbcb4ccd60
commit 2cb5d6f05a
  1. 48
      main/inc/lib/course.lib.php
  2. 15
      main/inc/lib/document.lib.php
  3. 149
      main/inc/lib/main_api.lib.php
  4. 2
      main/inc/lib/sessionmanager.lib.php
  5. 4
      main/inc/local.inc.php

@ -3788,53 +3788,7 @@ class CourseManager {
$res = Database::query($sql);
$row = Database::fetch_row($res);
return $row[0];
}
/*
* This code was originaly in local.inc.php
*/
public static function get_course_info_with_category($course_code) {
global $_configuration;
$course_table = Database::get_main_table(TABLE_MAIN_COURSE);
$course_cat_table = Database::get_main_table(TABLE_MAIN_CATEGORY);
$course_code = Database::escape_string($course_code);
$sql = "SELECT course.*, course_category.code faCode, course_category.name faName FROM $course_table
LEFT JOIN $course_cat_table
ON course.category_code = course_category.code
WHERE course.code = '$course_code'";
$result = Database::query($sql);
$_course = array();
if (Database::num_rows($result) > 0) {
$course_data = Database::fetch_array($result);
//@TODO real_cid should be cid, for working with numeric course id
$_course['real_id'] = $course_data['id'];
$_course['id'] = $course_data['code']; //auto-assigned integer
$_course['code'] = $course_data['code'];
$_course['name'] = $course_data['title'];
$_course['title'] = $course_data['title'];
$_course['official_code'] = $course_data['visual_code']; // use in echo
$_course['sysCode'] = $course_data['code']; // use as key in db
$_course['path'] = $course_data['directory']; // use as key in path
$_course['dbName'] = $course_data['db_name']; // use as key in db list
$_course['db_name'] = $course_data['db_name']; // not needed in Chamilo 1.9
$_course['dbNameGlu'] = $_configuration['table_prefix'] . $course_data['db_name'] . $_configuration['db_glue']; // use in all queries //not needed in Chamilo 1.9
$_course['titular'] = $course_data['tutor_name'];// this should be deprecated and use the table course_rel_user
$_course['language'] = $course_data['course_language'];
$_course['extLink']['url' ] = $course_data['department_url'];
$_course['extLink']['name'] = $course_data['department_name'];
$_course['categoryCode'] = $course_data['faCode'];
$_course['categoryName'] = $course_data['faName'];
$_course['visibility'] = $course_data['visibility'];
$_course['subscribe_allowed'] = $course_data['subscribe'];
$_course['unsubscribe'] = $course_data['unsubscribe'];
$_course['activate_legal'] = $course_data['activate_legal'];
$_course['legal'] = $course_data['legal' ];
$_course['show_score'] = $course_data['show_score']; //used in the work tool
}
return $_course;
}
}
/**
* Return a link to go to the course, validating the visibility of the

@ -23,20 +23,13 @@ class DocumentManager {
*/
public static function get_course_quota() {
$course_info = api_get_course_info();
$course_quota = null;
if (empty($course_info)) {
return DEFAULT_DOCUMENT_QUOTA;
} else {
$course_quota = $course_info['disk_quota'];
}
$course_code = Database::escape_string($course_info['code']);
$course_table = Database::get_main_table(TABLE_MAIN_COURSE);
$sql_query = "SELECT disk_quota FROM $course_table WHERE code = '$course_code'";
$sql_result = Database::query($sql_query);
$course_quota = null;
if (Database::num_rows($sql_result)) {
$result = Database::fetch_array($sql_result);
$course_quota = $result['disk_quota'];
}
if (is_null($course_quota) || empty($course_quota)) {
// Course table entry for quota was null, then use default value
$course_quota = DEFAULT_DOCUMENT_QUOTA;

@ -1244,49 +1244,9 @@ function api_get_course_info($course_code = null) {
WHERE course.code = '$course_code'";
$result = Database::query($sql);
$_course = array();
if (Database::num_rows($result) > 0) {
global $_configuration;
if (Database::num_rows($result) > 0) {
$course_data = Database::fetch_array($result);
$_course['id' ] = $course_data['code' ];
$_course['code' ] = $course_data['code' ];
$_course['name' ] = $course_data['title' ];
$_course['title' ] = $course_data['title' ];
$_course['official_code'] = $course_data['visual_code' ]; // Use in echo statements.
$_course['sysCode' ] = $course_data['code' ]; // Use as key in db.
$_course['path' ] = $course_data['directory' ]; // Use as key in path.
$_course['directory' ] = $course_data['directory' ];
//@todo should be deprecated
$_course['dbName' ] = $course_data['db_name' ]; // Use as key in db list.
$_course['db_name' ] = $course_data['db_name']; //
$_course['dbNameGlu' ] = $_configuration['table_prefix'] . $course_data['db_name'] . $_configuration['db_glue']; // Use in all queries.
$_course['titular' ] = $course_data['tutor_name' ];
$_course['language' ] = $course_data['course_language'];
$_course['extLink' ]['url' ] = $course_data['department_url' ];
$_course['extLink' ]['name'] = $course_data['department_name'];
$_course['categoryCode' ] = $course_data['faCode' ];
$_course['categoryName' ] = $course_data['faName' ];
$_course['visibility' ] = $course_data['visibility' ];
$_course['subscribe_allowed'] = $course_data['subscribe' ];
$_course['unsubscribe'] = $course_data['unsubscribe' ];
$_course['department_name'] = $course_data['department_name'];
$_course['department_url'] = $course_data['department_url' ];
$_course['legal'] = $course_data['legal' ];
$_course['show_score'] = $course_data['show_score']; //used in the work tool
// The real_id is an integer. It is mandatory for future implementations.
$_course['real_id' ] = $course_data['id' ];
$_course['activate_legal'] = isset($course_data['activate_legal']) ? $course_data['activate_legal'] : false;
//I know this is bad, but this reflects that it was a bad decistion to not add a flag in the DB if an image exists
if (file_exists(api_get_path(SYS_COURSE_PATH).$course_data['directory'].'/course-pic85x85.png')) {
$url_image = api_get_path(WEB_COURSE_PATH).$course_data['directory'].'/course-pic85x85.png';
} else {
$url_image = api_get_path(WEB_IMG_PATH).'without_picture.png';
}
$_course['course_image'] = $url_image;
$_course = api_format_course_array($course_data);
}
return $_course;
}
@ -1295,7 +1255,6 @@ function api_get_course_info($course_code = null) {
return $_course;
}
/**
* Returns the current course info array.
@ -1314,51 +1273,9 @@ function api_get_course_info_by_id($id = null) {
WHERE course.id = $id";
$result = Database::query($sql);
$_course = array();
if (Database::num_rows($result) > 0) {
global $_configuration;
if (Database::num_rows($result) > 0) {
$course_data = Database::fetch_array($result);
$_course['id' ] = $course_data['code' ];
// Added
$_course['code' ] = $course_data['code' ];
$_course['name' ] = $course_data['title' ];
$_course['title' ] = $course_data['title' ];
$_course['official_code'] = $course_data['visual_code' ]; // Use in echo statements.
$_course['sysCode' ] = $course_data['code' ]; // Use as key in db.
$_course['path' ] = $course_data['directory' ]; // Use as key in path.
$_course['directory' ] = $course_data['directory' ];
//@todo should be deprecated
$_course['dbName' ] = $course_data['db_name' ]; // Use as key in db list.
$_course['db_name' ] = $course_data['db_name' ];
$_course['dbNameGlu' ] = $_configuration['table_prefix'] . $course_data['db_name'] . $_configuration['db_glue']; // Use in all queries.
$_course['titular' ] = $course_data['tutor_name' ];
$_course['language' ] = $course_data['course_language'];
$_course['extLink' ]['url' ] = $course_data['department_url' ];
$_course['extLink' ]['name'] = $course_data['department_name'];
$_course['categoryCode' ] = $course_data['faCode' ];
$_course['categoryName' ] = $course_data['faName' ];
$_course['visibility' ] = $course_data['visibility' ];
$_course['subscribe_allowed'] = $course_data['subscribe' ];
$_course['unsubscribe'] = $course_data['unsubscribe' ];
$_course['real_id' ] = $course_data['id' ];
$_course['title' ] = $course_data['title' ];
$_course['course_language'] = $course_data['course_language'];
$_course['activate_legal'] = $course_data['activate_legal'];
$_course['legal'] = $course_data['legal' ];
$_course['show_score'] = $course_data['show_score']; //used in the work tool
if (file_exists(api_get_path(SYS_COURSE_PATH).$course_data['directory'].'/course-pic85x85.png')) {
$url_image = api_get_path(WEB_COURSE_PATH).$course_data['directory'].'/course-pic85x85.png';
} else {
$url_image = api_get_path(WEB_IMG_PATH).'without_picture.png';
}
$_course['course_image'] = $url_image;
$_course = api_format_course_array($course_data);
}
return $_course;
}
@ -1368,6 +1285,64 @@ function api_get_course_info_by_id($id = null) {
return $_course;
}
function api_format_course_array($course_data) {
global $_configuration;
if (empty($course_data)) {
return array();
}
$_course = array();
$_course['id' ] = $course_data['code' ];
$_course['real_id' ] = $course_data['id' ];
// Added
$_course['code' ] = $course_data['code' ];
$_course['name' ] = $course_data['title' ];
$_course['title' ] = $course_data['title' ];
$_course['official_code'] = $course_data['visual_code' ]; // Use in echo statements.
$_course['sysCode' ] = $course_data['code' ]; // Use as key in db.
$_course['path' ] = $course_data['directory' ]; // Use as key in path.
$_course['directory' ] = $course_data['directory' ];
//@todo should be deprecated
$_course['dbName' ] = $course_data['db_name' ]; // Use as key in db list.
$_course['db_name' ] = $course_data['db_name' ];
$_course['dbNameGlu' ] = $_configuration['table_prefix'] . $course_data['db_name'] . $_configuration['db_glue']; // Use in all queries.
$_course['titular' ] = $course_data['tutor_name' ];
$_course['language' ] = $course_data['course_language'];
$_course['extLink' ]['url' ] = $course_data['department_url' ];
$_course['extLink' ]['name'] = $course_data['department_name'];
$_course['categoryCode' ] = $course_data['faCode' ];
$_course['categoryName' ] = $course_data['faName' ];
$_course['visibility' ] = $course_data['visibility' ];
$_course['subscribe_allowed'] = $course_data['subscribe' ];
$_course['unsubscribe'] = $course_data['unsubscribe' ];
$_course['course_language'] = $course_data['course_language'];
$_course['activate_legal'] = isset($course_data['activate_legal']) ? $course_data['activate_legal'] : false;;
$_course['legal'] = $course_data['legal' ];
$_course['show_score'] = $course_data['show_score']; //used in the work tool
$_course['department_name'] = $course_data['department_name'];
$_course['department_url'] = $course_data['department_url' ];
$_course['disk_quota'] = $course_data['disk_quota'];
if (file_exists(api_get_path(SYS_COURSE_PATH).$course_data['directory'].'/course-pic85x85.png')) {
$url_image = api_get_path(WEB_COURSE_PATH).$course_data['directory'].'/course-pic85x85.png';
} else {
$url_image = api_get_path(WEB_IMG_PATH).'without_picture.png';
}
$_course['course_image'] = $url_image;
return $_course;
}
/* SESSION MANAGEMENT */

@ -1575,7 +1575,7 @@ class SessionManager {
* @param $session_id
* @return unknown_type
*/
public function get_user_status_in_session($user_id, $course_code, $session_id) {
public static function get_user_status_in_session($user_id, $course_code, $session_id) {
$tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
$tbl_user = Database::get_main_table(TABLE_MAIN_USER);
$sql = "SELECT session_rcru.status

@ -661,7 +661,7 @@ if (isset($uidReset) && $uidReset) { // session data refresh requested
if (isset($cidReset) && $cidReset) {
// Course session data refresh requested or empty data
if ($cidReq) {
$_course = CourseManager::get_course_info_with_category($cidReq);
$_course = api_get_course_info($cidReq);
if (!empty($_course)) {
@ -729,7 +729,7 @@ if (isset($cidReset) && $cidReset) {
if (empty($_SESSION['_course']) && !empty($_SESSION['_cid'])) {
//Just in case $_course is empty we try to load if the c_id still exists
$_course = CourseManager::get_course_info_with_category($_SESSION['_cid']);
$_course = api_get_course_info($_SESSION['_cid']);
if (!empty($_course)) {
$_real_cid = $_course['real_id'];
$_cid = $_course['code'];

Loading…
Cancel
Save