Skip to content

Commit

Permalink
Fix create course link
Browse files Browse the repository at this point in the history
  • Loading branch information
jmontoyaa committed Oct 12, 2016
1 parent 3d50662 commit c7624b2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 36 deletions.
7 changes: 6 additions & 1 deletion main/inc/lib/api.lib.php
Expand Up @@ -2443,7 +2443,12 @@ function api_get_user_status($user_id = null)
* @return boolean True if the user has course creation rights,
* false otherwise.
*/
function api_is_allowed_to_create_course() {
function api_is_allowed_to_create_course()
{
if (api_is_platform_admin()) {
return true;
}

return Session::read('is_allowedCreateCourse');
}

Expand Down
67 changes: 32 additions & 35 deletions main/inc/lib/userportal.lib.php
Expand Up @@ -174,6 +174,9 @@ public function category_has_open_courses($category)
return false;
}

/**
* @return null|string
*/
public function return_teacher_link()
{
$html = '';
Expand All @@ -185,22 +188,19 @@ public function return_teacher_link()
$show_create_link = false;
$show_course_link = false;

if (api_is_platform_admin() || api_is_course_admin() || api_is_allowed_to_create_course()) {
if (api_is_allowed_to_create_course()) {
$show_menu = true;
$show_course_link = true;
$show_create_link = true;
} else {
if (api_get_setting('allow_students_to_browse_courses') == 'true') {
$show_menu = true;
$show_course_link = true;
}
}

if (api_get_setting('allow_users_to_create_courses') !== 'false' && !api_is_platform_admin()) {
$show_create_link = true;
}

if (api_is_student_boss() || api_is_session_admin()) {
$show_create_link = false;
if (api_get_setting('allow_users_to_create_courses')) {
$show_create_link = true;
}
}

if ($show_menu && ($show_create_link || $show_course_link)) {
Expand All @@ -211,7 +211,6 @@ public function return_teacher_link()
}

// My Account section

if ($show_menu) {
$html .= '<ul class="nav nav-pills nav-stacked">';
if ($show_create_link) {
Expand All @@ -229,7 +228,14 @@ public function return_teacher_link()
}

if (!empty($html)) {
$html = self::show_right_block(get_lang('Courses'), $html, 'teacher_block', null, 'teachers', 'teachersCollapse');
$html = self::show_right_block(
get_lang('Courses'),
$html,
'teacher_block',
null,
'teachers',
'teachersCollapse'
);
}

return $html;
Expand Down Expand Up @@ -446,20 +452,20 @@ public function return_courses_in_categories()
$setting_show_also_closed_courses = api_get_setting('show_closed_courses') == 'true';

// Database table definitions.
$main_course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
$main_category_table = Database :: get_main_table(TABLE_MAIN_CATEGORY);
$main_course_table = Database:: get_main_table(TABLE_MAIN_COURSE);
$main_category_table = Database:: get_main_table(TABLE_MAIN_CATEGORY);

// Get list of courses in category $category.
$sql_get_course_list = "SELECT * FROM $main_course_table cours
WHERE category_code = '" . $category . "'
ORDER BY title, UPPER(visual_code)";
$sql = "SELECT * FROM $main_course_table cours
WHERE category_code = '" . $category . "'
ORDER BY title, UPPER(visual_code)";

// Showing only the courses of the current access_url_id.
if (api_is_multiple_url_enabled()) {
$url_access_id = api_get_current_access_url_id();
if ($url_access_id != -1) {
$tbl_url_rel_course = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
$sql_get_course_list = "SELECT * FROM $main_course_table as course
$sql = "SELECT * FROM $main_course_table as course
INNER JOIN $tbl_url_rel_course as url_rel_course
ON (url_rel_course.c_id = course.id)
WHERE
Expand All @@ -470,8 +476,7 @@ public function return_courses_in_categories()
}

// Removed: AND cours.visibility='".COURSE_VISIBILITY_OPEN_WORLD."'
$sql_result_courses = Database::query($sql_get_course_list);

$sql_result_courses = Database::query($sql);
while ($course_result = Database::fetch_array($sql_result_courses)) {
$course_list[] = $course_result;
}
Expand Down Expand Up @@ -1002,34 +1007,27 @@ public function return_navigation_links()
public function return_course_block()
{
$html = '';

$show_create_link = false;
$show_course_link = false;

if ((api_get_setting('allow_users_to_create_courses') == 'false' &&
!api_is_platform_admin()) || api_is_student()
) {
$display_add_course_link = false;
} else {
$display_add_course_link = true;
}

if ($display_add_course_link) {
$show_create_link = true;
if (!api_is_anonymous()) {
if (api_get_setting('allow_users_to_create_courses') === 'true') {
$show_create_link = true;
} else {
if (api_is_allowed_to_create_course()) {
$show_create_link = true;
}
}
}

if (api_is_platform_admin() || api_is_course_admin() || api_is_allowed_to_create_course()) {
if (api_is_course_admin() || api_is_allowed_to_create_course()) {
$show_course_link = true;
} else {
if (api_get_setting('allow_students_to_browse_courses') == 'true') {
$show_course_link = true;
}
}

if (api_is_student_boss() || api_is_session_admin()) {
$show_create_link = false;
}

// My account section
$my_account_content = '<ul class="nav nav-pills nav-stacked">';

Expand Down Expand Up @@ -1065,7 +1063,6 @@ public function return_course_block()
}

// Course catalog

if ($show_course_link) {
if (!api_is_drh()) {
$my_account_content .= '<li class="list-course"><a href="main/auth/courses.php" >'.Display::return_icon('catalog-course.png',get_lang('CourseCatalog'),null,ICON_SIZE_SMALL).get_lang('CourseCatalog').'</a></li>';
Expand Down

0 comments on commit c7624b2

Please sign in to comment.