Course catalog display - ref #6654

1.9.x
Hubert Borderiou 11 years ago
parent 60dd525e51
commit 1a43df604b
  1. 234
      main/template/default/auth/courses_categories.php

@ -142,93 +142,197 @@ $stok = Security::get_token();
}
$ajax_url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=add_course_vote';
$user_id = api_get_user_id();
if (!empty($browse_courses_in_category)) {
foreach ($browse_courses_in_category as $course) {
// if course is closed, don't show it.
if ($course['visibility'] == COURSE_VISIBILITY_CLOSED || $course['visibility'] == COURSE_VISIBILITY_HIDDEN) {
$course_hidden = ($course['visibility'] == COURSE_VISIBILITY_HIDDEN);
if ($course_hidden) {
continue;
}
// course isn't closed
$title = cut($course['title'], 70);
$tutor_name = $course['tutor'];
$creation_date = substr($course['creation_date'],0,10);
$user_registerd_in_course = CourseManager::is_user_subscribed_in_course($user_id, $course['code']);
$user_registerd_in_course_as_teacher = CourseManager::is_course_teacher($user_id, $course['code']);
$user_registerd_in_course_as_student = ($user_registerd_in_course && !$user_registerd_in_course_as_teacher);
$course_public = ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD);
$course_open = ($course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM);
$course_private = ($course['visibility'] == COURSE_VISIBILITY_REGISTERED);
$course_closed = ($course['visibility'] == COURSE_VISIBILITY_CLOSED);
$course_subscribe_allowed = ($course['subscribe'] == 1);
$course_unsubscribe_allowed = ($course['unsubscribe'] == 1);
$count_connections = $course['count_connections'];
$creation_date = substr($course['creation_date'],0,10);
$course_path = api_get_path(SYS_COURSE_PATH).$course['directory']; // course path
if (file_exists($course_path.'/course-pic85x85.png')) {
$course_medium_image = api_get_path(WEB_COURSE_PATH).$course['directory'].'/course-pic85x85.png'; // redimensioned image 85x85
} else {
$course_medium_image = api_get_path(WEB_IMG_PATH).'without_picture.png'; // without picture
}
$rating = Display::return_rating_system('star_'.$course['real_id'], $ajax_url.'&course_id='.$course['real_id'], $course['point_info']);
// display the course bloc
echo '<div class="well_border"><div class="row">';
echo '<div class="span2">';
echo '<div class="thumbnail">';
if (api_get_setting('show_courses_descriptions_in_catalog') == 'true') {
echo '<a class="ajax" href="'.api_get_path(WEB_CODE_PATH).'inc/ajax/course_home.ajax.php?a=show_course_information&amp;code='.$course['code'].'" title="'.$icon_title.'" rel="gb_page_center[778]">';
echo '<img src="'.$course_medium_image.'" alt="" />';
echo '</a>';
} else {
echo '<img src="'.$course_medium_image.'" alt="'.$title.'"/>';
}
echo '</div>';//thumb
echo '</div>';
echo '<div class="span4">';
$teachers = CourseManager::get_teacher_list_from_course_code_to_string($course['code']);
$teachers = '<h5>'.$teachers.'</h5>';
echo '<div class="categories-course-description"><h3>'.cut($title, 60).'</h3>'.$teachers.$rating.'</div>';
echo '<p>';
// we display the icon to subscribe or the text already subscribed
echo '<div class="btn-toolbar">';
// display thumbnail
display_thumbnail($course, $icon_title);
if (api_get_setting('show_courses_descriptions_in_catalog') == 'true') {
echo '<a class="ajax btn" href="'.api_get_path(WEB_CODE_PATH).'inc/ajax/course_home.ajax.php?a=show_course_information&amp;code='.$course['code'].'" title="'.$icon_title.'" class="thickbox">'.get_lang('Description').'</a>';
}
// Get access type for course button ("enter" or/and "register")
$access_type = CourseManager::get_access_link_by_user(api_get_user_id(), $course);
// Go To Course button (only if admin, if course public or if student already subscribed)
if ($access_type && in_array('enter', $access_type)) {
echo ' <a class="btn btn-primary" href="'. api_get_course_url($course['code']).'">'.get_lang('GoToCourse').'</a>';
// display course title and button bloc
echo '<div class="span4">';
display_title($course);
// display button line
echo '<div class="btn-toolbar">';
// if user registered as student
if ($user_registerd_in_course_as_student) {
if (!$course_closed) {
display_description_button($course, $icon_title);
display_goto_button($course);
if ($course_unsubscribe_allowed) {
display_unregister_button($course, $stok, $search_term, $code);
}
display_already_registered_label('student');
}
// Register button
if ($access_type && in_array('register', $access_type)) {
echo ' <a class="btn btn-primary" href="'. api_get_self().'?action=subscribe_course&amp;sec_token='.$stok.'&amp;subscribe_course='.$course['code'].'&amp;search_term='.$search_term.'&amp;category_code='.$code.'">'.get_lang('Subscribe').'</a>';
} elseif ($user_registerd_in_course_as_teacher) {
// if user registered as teacher
display_description_button($course, $icon_title);
display_goto_button($course);
if ($course_unsubscribe_allowed) {
display_unregister_button($course, $stok, $search_term, $code);
}
// If user is already subscribed to the course
if (!api_is_anonymous() && in_array($course['code'], $user_coursecodes)) {
if ($course['unsubscribe'] == UNSUBSCRIBE_ALLOWED) {
echo ' <a class="btn btn-primary" href="'. api_get_self().'?action=unsubscribe&amp;sec_token='.$stok.'&amp;unsubscribe='.$course['code'].'&amp;search_term='.$search_term.'&amp;category_code='.$code.'">'.get_lang('Unsubscribe').'</a>';
display_already_registered_label('teacher');
} else {
// if user not registered in the course
if (!$course_closed) {
display_description_button($course, $icon_title);
if (!$course_private) {
display_goto_button($course);
if ($course_subscribe_allowed) {
display_register_button($course, $stok, $code, $search_term);
}
}
echo '<br />';
echo '<br />';
echo Display::label(get_lang("AlreadyRegisteredToCourse"), "info");
}
echo '</div>';
echo '</p>';
echo '</div>';
echo '<div class="span2">';
echo '<div class="course-block-popularity"><span>'.get_lang('ConnectionsLastMonth').'</span><div class="course-block-popularity-score">'.$count_connections.'</div></div>';
echo '</div>';
echo '</div></div>';
}
echo '</div>'; // btn-toolbar
echo '</div>'; // span4
// display counter
echo '<div class="span2">';
echo '<div class="course-block-popularity"><span>'.get_lang('ConnectionsLastMonth').'</span><div class="course-block-popularity-score">'.$count_connections.'</div></div>';
echo '</div>';
// end of course bloc
echo '</div></div>'; // well_border row
}
} else {
if (!isset($_REQUEST['subscribe_user_with_password']) && !isset($_REQUEST['subscribe_course'])) {
echo Display::display_warning_message(get_lang('ThereAreNoCoursesInThisCategory'));
Display::display_warning_message(get_lang('ThereAreNoCoursesInThisCategory'));
}
}
?>
</div>
</div>
<?php
/**
* Display the course catalog image of a course
* @param $course
* @param $icon_title
*/
function display_thumbnail($course, $icon_title)
{
$title = cut($course['title'], 70);
$course_path = api_get_path(SYS_COURSE_PATH).$course['directory']; // course path
if (file_exists($course_path.'/course-pic85x85.png')) {
$course_medium_image = api_get_path(WEB_COURSE_PATH).$course['directory'].'/course-pic85x85.png'; // redimensioned image 85x85
} else {
$course_medium_image = api_get_path(WEB_IMG_PATH).'without_picture.png'; // without picture
}
// course image
echo '<div class="span2">';
echo '<div class="thumbnail">';
if (api_get_setting('show_courses_descriptions_in_catalog') == 'true') {
echo '<a class="ajax" href="'.api_get_path(WEB_CODE_PATH).'inc/ajax/course_home.ajax.php?a=show_course_information&amp;code='.$course['code'].'" title="'.$icon_title.'" rel="gb_page_center[778]">';
echo '<img src="'.$course_medium_image.'" alt="" />';
echo '</a>';
} else {
echo '<img src="'.$course_medium_image.'" alt="'.$title.'"/>';
}
echo '</div>'; // thumbail
echo '</div>'; // span2
}
/**
* Display the title of a course in course catalog
* @param $course
*/
function display_title($course)
{
$title = cut($course['title'], 70);
$ajax_url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=add_course_vote';
$teachers = CourseManager::get_teacher_list_from_course_code_to_string($course['code']);
$rating = Display::return_rating_system('star_'.$course['real_id'], $ajax_url.'&amp;course_id='.$course['real_id'], $course['point_info']);
$teachers = '<h5>'.$teachers.'</h5>';
echo '<div class="categories-course-description">';
echo '<h3>'.cut($title, 60).'</h3>';
echo $teachers;
echo $rating;
echo '</div>'; // categories-course-description
}
/**
* Display the description button of a course in the course catalog
* @param $course
* @param $icon_title
*/
function display_description_button($course, $icon_title)
{
if (api_get_setting('show_courses_descriptions_in_catalog') == 'true') {
echo '<a class="ajax btn" href="'.api_get_path(WEB_CODE_PATH).'inc/ajax/course_home.ajax.php?a=show_course_information&amp;code='.$course['code'].'" title="'.$icon_title.'" class="thickbox">'.get_lang('Description').'</a>';
}
}
/**
* Display the goto course button of a course in the course catalog
* @param $course
*/
function display_goto_button($course)
{
echo ' <a class="btn btn-primary" href="'.api_get_course_url($course['code']).'">'.get_lang('GoToCourse').'</a>';
}
/**
* Display the already registerd text in a course in the course catalog
* @param $in_status
*/
function display_already_registered_label($in_status)
{
$icon = Display::return_icon('teachers.gif', get_lang('Teacher'));
if ($in_status == 'student') {
$icon = Display::return_icon('students.gif', get_lang('Student'));
}
echo Display::label($icon.' '.get_lang("AlreadyRegisteredToCourse"), "info");
}
/**
* Display the register button of a course in the course catalog
* @param $course
* @param $stok
* @param $code
* @param $search_term
*/
function display_register_button($course, $stok, $code, $search_term)
{
echo ' <a class="btn btn-primary" href="'.api_get_self().'?action=subscribe_course&amp;sec_token='.$stok.'&amp;subscribe_course='.$course['code'].'&amp;search_term='.$search_term.'&amp;category_code='.$code.'">'.get_lang('Subscribe').'</a>';
}
/**
* Display the unregister button of a course in the course catalog
* @param $course
* @param $stok
* @param $search_term
* @param $code
*/
function display_unregister_button($course, $stok, $search_term, $code)
{
echo ' <a class="btn btn-primary" href="'. api_get_self().'?action=unsubscribe&amp;sec_token='.$stok.'&amp;unsubscribe='.$course['code'].'&amp;search_term='.$search_term.'&amp;category_code='.$code.'">'.get_lang('Unsubscribe').'</a>';
}

Loading…
Cancel
Save