Allow subscribe/unsubscribe from course catalog for open (not public) courses - refs #5240

skala
Yannick Warnier 13 years ago
parent 6f223278cd
commit bb6de80ad5
  1. 28
      main/auth/courses.php
  2. 8
      main/auth/courses_controller.php
  3. 2
      main/inc/lib/auth.lib.php
  4. 17
      main/template/default/auth/courses_categories.php

@ -73,7 +73,7 @@ if (api_is_platform_admin() || api_is_course_admin() || api_is_allowed_to_create
} }
// filter actions // filter actions
$actions = array('sortmycourses', 'createcoursecategory', 'subscribe', 'deletecoursecategory', 'unsubscribe', 'display_courses','display_random_courses'); $actions = array('sortmycourses', 'createcoursecategory', 'subscribe', 'deletecoursecategory', 'display_courses','display_random_courses');
$action = 'display_random_courses'; $action = 'display_random_courses';
$nameTools = get_lang('SortMyCourses'); $nameTools = get_lang('SortMyCourses');
@ -149,14 +149,6 @@ if ($action == 'deletecoursecategory' && isset($_GET['id'])) {
} }
} }
// We are unsubscribing from a course (=Unsubscribe from course).
if (isset($_POST['unsubscribe'])) {
if ($ctok == $_POST['sec_token']) {
$courses_controller->unsubscribe_user_from_course($_POST['unsubscribe']);
//$message = remove_user_from_course($_user['user_id'], $_POST['unsubscribe']);
}
}
// We are creating a new user defined course category (= Create Course Category). // We are creating a new user defined course category (= Create Course Category).
if (isset($_POST['create_course_category']) && isset($_POST['title_course_category']) && strlen(trim($_POST['title_course_category'])) > 0) { if (isset($_POST['create_course_category']) && isset($_POST['title_course_category']) && strlen(trim($_POST['title_course_category'])) > 0) {
if ($ctok == $_POST['sec_token']) { if ($ctok == $_POST['sec_token']) {
@ -174,9 +166,23 @@ if (isset($_REQUEST['search_course'])) {
// subscribe user to course // subscribe user to course
if (isset($_GET['subscribe_course'])) { if (isset($_GET['subscribe_course'])) {
//if ($ctok == $_GET['sec_token'] || $_POST['token'] == $_GET['sec_token']) { if ($ctok == $_GET['sec_token']) {
$courses_controller->subscribe_user($_GET['subscribe_course'], $_GET['search_term'], $_GET['category_code']); $courses_controller->subscribe_user($_GET['subscribe_course'], $_GET['search_term'], $_GET['category_code']);
//} }
}
// We are unsubscribing from a course (=Unsubscribe from course).
if (isset($_GET['unsubscribe'])) {
if ($ctok == $_GET['sec_token']) {
$courses_controller->unsubscribe_user_from_course($_GET['unsubscribe'], $_GET['search_term'], $_GET['category_code']);
//$message = remove_user_from_course($_user['user_id'], $_POST['unsubscribe']);
}
}
// We are unsubscribing from a course (=Unsubscribe from course).
if (isset($_POST['unsubscribe'])) {
if ($ctok == $_POST['sec_token']) {
$courses_controller->unsubscribe_user_from_course($_POST['unsubscribe']);
//$message = remove_user_from_course($_user['user_id'], $_POST['unsubscribe']);
}
} }
switch ($action) { switch ($action) {

@ -277,11 +277,15 @@ class CoursesController { // extends Controller {
* render to listing view * render to listing view
* @param string Course code * @param string Course code
*/ */
public function unsubscribe_user_from_course($course_code) { public function unsubscribe_user_from_course($course_code, $search_term = null, $category_code = null) {
$result = $this->model->remove_user_from_course($course_code); $result = $this->model->remove_user_from_course($course_code);
$message = ''; $message = '';
if ($result) { $message = get_lang('YouAreNowUnsubscribed'); } if ($result) { $message = get_lang('YouAreNowUnsubscribed'); }
$action = 'sortmycourses'; $action = 'sortmycourses';
$this->courses_list($action, $message); if (!empty($search_term)) {
$this->search_courses($search_term, $message, $error);
} else {
$this->courses_categories('subcribe', $category_code, $message, $error);
}
} }
} }

@ -642,4 +642,4 @@ class Auth
return $return; return $return;
} }
} }
} }

@ -170,14 +170,14 @@ $stok = Security::get_token();
} }
// Go To Course button (only if admin, if course public or if student already subscribed) // Go To Course button (only if admin, if course public or if student already subscribed)
if (api_is_platform_admin() || ( if (api_is_platform_admin()
$course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD || || $course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD
($course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM && api_user_is_login()) || || (api_user_is_login() && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM)
in_array($course['code'], $user_coursecodes && $course['visibility'] != COURSE_VISIBILITY_CLOSED ) || in_array($course['code'], $user_coursecodes && $course['visibility'] != COURSE_VISIBILITY_CLOSED )
) ) {
) {
echo ' <a class="btn btn-primary" href="'. api_get_course_url($course['code']).'">'.get_lang('GoToCourse').'</a>'; echo ' <a class="btn btn-primary" href="'. api_get_course_url($course['code']).'">'.get_lang('GoToCourse').'</a>';
} elseif (!api_is_anonymous() // Subscribe button }
if (!api_is_anonymous() // Subscribe button
&& ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD || $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM) && ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD || $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM)
&& $course['subscribe'] == SUBSCRIBE_ALLOWED && $course['subscribe'] == SUBSCRIBE_ALLOWED
&& (!in_array($course['code'], $user_coursecodes) || empty($user_coursecodes))) { && (!in_array($course['code'], $user_coursecodes) || empty($user_coursecodes))) {
@ -186,6 +186,9 @@ $stok = Security::get_token();
// If user is already subscribed to the course // If user is already subscribed to the course
if (!api_is_anonymous() && in_array($course['code'], $user_coursecodes)) { 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>';
}
echo '<br />'; echo '<br />';
echo '<br />'; echo '<br />';
echo Display::label(get_lang("AlreadyRegisteredToCourse"), "info"); echo Display::label(get_lang("AlreadyRegisteredToCourse"), "info");

Loading…
Cancel
Save