Adding "random pick" feature in course catalog

skala
Julio Montoya 14 years ago
parent 050769ed0c
commit 1bd9ae54b1
  1. 4
      main/auth/courses.php
  2. 14
      main/auth/courses_controller.php
  3. 7
      main/css/fix_chamilo.css
  4. 22
      main/inc/lib/auth.lib.php
  5. 10
      main/template/default/auth/courses_categories.php

@ -15,7 +15,6 @@ $cidReset = true; // Flag forcing the 'current course' reset
// including files
require_once '../inc/global.inc.php';
require_once api_get_path(LIBRARY_PATH).'auth.lib.php';
require_once api_get_path(LIBRARY_PATH).'app_view.php';
require_once 'courses_controller.php';
@ -50,7 +49,7 @@ if (!(api_is_platform_admin() || api_is_course_admin() || api_is_allowed_to_crea
}
// filter actions
$actions = array('sortmycourses', 'createcoursecategory', 'subscribe', 'deletecoursecategory', 'unsubscribe', 'display_courses');
$actions = array('sortmycourses', 'createcoursecategory', 'subscribe', 'deletecoursecategory', 'unsubscribe', 'display_courses','display_random_courses');
$action = 'subscribe';
$nameTools = get_lang('SortMyCourses');
@ -155,6 +154,7 @@ switch ($action) {
$courses_controller->courses_list($action);
break;
case 'subscribe':
case 'display_random_courses':
$courses_controller->courses_categories($action);
break;
case 'display_courses':

@ -65,11 +65,8 @@ class CoursesController { // extends Controller {
* @param string error message(optional)
*/
public function categories_list($action, $message='', $error='') {
$data = array();
$data['user_course_categories'] = $this->model->get_user_course_categories();
$data['action'] = $action;
$data['message'] = $message;
$data['error'] = $error;
@ -79,7 +76,6 @@ class CoursesController { // extends Controller {
$this->view->set_layout('layout');
$this->view->set_template('categories_list');
$this->view->render();
}
/**
@ -92,10 +88,14 @@ class CoursesController { // extends Controller {
$data = array();
$browse_course_categories = $this->model->browse_course_categories();
if ($action == 'display_random_courses') {
$data['browse_courses_in_category'] = $this->model->browse_courses_in_category(null, 20);
} else {
if (!isset($category_code)) {
$category_code = $browse_course_categories[0][1]['code']; // by default first category
}
$data['browse_courses_in_category'] = $this->model->browse_courses_in_category($category_code);
}
$data['browse_course_categories'] = $browse_course_categories;
$data['code'] = Security::remove_XSS($category_code);
@ -110,10 +110,7 @@ class CoursesController { // extends Controller {
$user_coursecodes[] = $value['code'];
}
}
$data['user_coursecodes'] = $user_coursecodes;
$data['action'] = $action;
$data['message'] = $message;
$data['error'] = $error;
@ -283,7 +280,4 @@ class CoursesController { // extends Controller {
$action = 'sortmycourses';
$this->courses_list($action, $message);
}
}
?>

@ -75,3 +75,10 @@ div.admin_section {
padding-right:10px;
}
body {
font-family: Arial, Helvetica, sans-serif;
}
a:link {
font-family: Arial, Helvetica, sans-serif;
}

@ -49,13 +49,10 @@ class Auth
// Secondly we select the courses that are in a category (user_course_cat<>0) and sort these according to the sort of the category
$user_id = intval($user_id);
$sql_select_courses = "SELECT course.code k, course.visual_code vc, course.subscribe subscr, course.unsubscribe unsubscr,
course.title i, course.tutor_name t, course.db_name db, course.directory dir, course_rel_user.status status,
course_rel_user.sort sort, course_rel_user.user_course_cat user_course_cat
FROM $TABLECOURS course,
$TABLECOURSUSER course_rel_user
FROM $TABLECOURS course, $TABLECOURSUSER course_rel_user
WHERE course.code = course_rel_user.course_code
AND course_rel_user.relation_type<>".COURSE_RELATION_TYPE_RRHH."
AND course_rel_user.user_id = '".$user_id."' $without_special_courses
@ -65,7 +62,6 @@ class Auth
//we only need the database name of the course
$courses[] = array('db' => $row['db'], 'code' => $row['k'], 'visual_code' => $row['vc'], 'title' => $row['i'], 'directory' => $row['dir'], 'status' => $row['status'], 'tutor' => $row['t'], 'subscribe' => $row['subscr'], 'unsubscribe' => $row['unsubscr'], 'sort' => $row['sort'], 'user_course_category' => $row['user_course_cat']);
}
return $courses;
}
@ -427,10 +423,8 @@ class Auth
* @param string Category code
* @return array Courses data
*/
public function browse_courses_in_category($category_code) {
public function browse_courses_in_category($category_code, $random_value = null) {
global $_configuration;
$tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
$TABLE_COURSE_FIELD = Database :: get_main_table(TABLE_MAIN_COURSE_FIELD);
$TABLE_COURSE_FIELD_VALUE = Database :: get_main_table(TABLE_MAIN_COURSE_FIELD_VALUES);
@ -451,11 +445,17 @@ class Auth
$without_special_courses = ' AND course.code NOT IN ('.implode(',',$special_course_list).')';
}
if (!empty($random_value)) {
$random_value = intval($random_value);
$sql = "SELECT * FROM $tbl_course WHERE 1 $without_special_courses ORDER BY RAND() LIMIT $random_value";
/*SELECT * FROM $tbl_course, (SELECT CEIL(MAX($tbl_course.id) * RAND()) AS randId FROM $tbl_course) AS someRandId
WHERE $tbl_course.id >= someRandId.randId LIMIT 10
*/
} else {
$category_code = Database::escape_string($category_code);
$my_category = (empty($category) ? " IS NULL" : "='".$category."'");
//$my_category = (empty($category) ? " IS NULL" : "='".$category."'");
$sql = "SELECT * FROM $tbl_course WHERE category_code='$category_code' $without_special_courses ORDER BY title, visual_code";
}
//showing only the courses of the current Dokeos access_url_id
if ($_configuration['multiple_access_urls']) {

@ -49,7 +49,12 @@ $stok = Security::get_token();
<div id="categories-list">
<?php if (!empty($browse_course_categories)) {
if ($_GET['action'] == 'display_random_courses') {
echo '<strong>'.get_lang('RandomPick').'</strong>';
$code = '';
} else {
echo '<a href="'.api_get_self().'?action=display_random_courses">'.get_lang('RandomPick').'</a>';
}
// level 1
foreach ($browse_course_categories[0] as $category) {
$category_name = $category['name'];
@ -62,10 +67,9 @@ $stok = Security::get_token();
if (!empty($count_courses_lv1)) {
$category_link = '<a href="'. api_get_self().'?action=display_courses&amp;category_code='.$category_code.'&amp;hidden_links='.$hidden_links.'">'.$category_name.'</a> ('.$count_courses_lv1.')';
} else {
$category_link = '<strong>'.$category_name.' ('.$count_courses_lv1.')</strong>';
$category_link = '<a href="#">'.$category_name.' ('.$count_courses_lv1.')</a>';
}
}
echo '<div>'.$category_link.'</div>';
// level 2
if (!empty($browse_course_categories[$category_code])) {

Loading…
Cancel
Save