Skip to content

Commit

Permalink
Reviews completed
Browse files Browse the repository at this point in the history
  • Loading branch information
pimteam committed Dec 3, 2021
1 parent 8f66bab commit 0c4042c
Show file tree
Hide file tree
Showing 9 changed files with 329 additions and 99 deletions.
65 changes: 50 additions & 15 deletions controllers/reviews.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,29 @@ public static function manage() {
}

// list reviews
$course_filter = $status_filter = '';
$course_filter = $status_filter = $other_filter_sql = '';
$other_filter_sql = apply_filters('namaste-filter-reviews', $other_filter_sql);

if(!empty($_GET['course_id'])) $course_filter = $wpdb->prepare(" AND course_id=%d ", intval($_GET['course_id']));
if(isset($_GET['status']) and $_GET['status'] !== '') $status_filter = $wpdb->prepare(" AND is_approved=%d ", intval($_GET['status']));

$offset = empty($_GET['offset']) ? 0 : intval($_GET['offset']);
$limit = 20;
$page_limit = 20;

$reviews = $wpdb->get_results($wpdb->prepare("SELECT tR.*, tP.post_title as course_name, tU.display_name as user_name
$reviews = $wpdb->get_results($wpdb->prepare("SELECT SQL_CALC_FOUND_ROWS tR.*, tP.post_title as course_name, tU.display_name as user_name
FROM ".NAMASTE_COURSE_REVIEWS." tR JOIN {$wpdb->posts} tP ON tP.ID = tR.course_id AND tP.post_type = 'namaste_course'
JOIN {$wpdb->users} tU ON tU.ID = tR.student_id
WHERE 1 $course_filter $status_filter ORDER BY tR.id DESC LIMIT %d, %d", $offset, $limit));

// add filter to allow Pro to reduce by class
$reviews = apply_filters('namaste-filter-reviews', $reviews);
WHERE 1 $course_filter $status_filter $other_filter_sql ORDER BY tR.id DESC LIMIT %d, %d", $offset, $page_limit));

$count = $wpdb->get_var("SELECT FOUND_ROWS()");

// select courses for the drop-down
$_course = new NamasteLMSCourseModel();
$courses = $_course->select();

$date_format = get_option('date_format');
$time_format = get_option('date_format');

if(@file_exists(get_stylesheet_directory().'/namaste/reviews.html.php')) include get_stylesheet_directory().'/namaste/reviews.html.php';
else include(NAMASTE_PATH."/views/reviews.html.php");
} // end manage
Expand All @@ -64,13 +67,7 @@ public static function submit($vars) {
public static function display_form($course_id) {
$course_id = intval($course_id);

$rating_options = [
1 => __('Poor', 'namaste'),
2 => __('Accedptable', 'namaste'),
3 => __('Average', 'namaste'),
4 => __('Good', 'namaste'),
5 => __('Great', 'namaste'),
];
$rating_options = self :: get_rating_options();

$content = '';
$editor_id = 'namaste_review_course_'.$course_id;
Expand All @@ -93,13 +90,51 @@ public static function display_form($course_id) {
} // end display_form

// shows the reviews on a course
public static function list_reviews() {
public static function list_reviews($course_id, $number = 0, $show = 'user_login') {
global $wpdb;

$limit_sql = $number ? " LIMIT ".intval($number) : '';

$reviews = $wpdb->get_results($wpdb->prepare("SELECT SQL_CALC_FOUND_ROWS tR.*, tP.post_title as course_name, tU.$show as user_name
FROM ".NAMASTE_COURSE_REVIEWS." tR JOIN {$wpdb->posts} tP ON tP.ID = tR.course_id AND tP.post_type = 'namaste_course'
JOIN {$wpdb->users} tU ON tU.ID = tR.student_id
WHERE tR.course_id=%d AND is_approved=1 ORDER BY tR.id DESC $limit_sql", intval($course_id)));

$date_format = get_option('date_format');
$time_format = get_option('date_format');

if(@file_exists(get_stylesheet_directory().'/namaste/list-reviews.html.php')) include get_stylesheet_directory().'/namaste/list-reviews.html.php';
else include(NAMASTE_PATH."/views/list-reviews.html.php");
} // end list_reviews

// a helper to display the stars for a review
public static function stars($rating) {
$rating_options = self :: get_rating_options();

$output = '';

foreach($rating_options as $r => $option) {
$class = $r <= $rating ? 'filled' : 'empty';
$output .= '<span class="dashicons dashicons-star-'.$class.'" style="color:#ffb900 !important;""></span>';
}

return $output;
} // end stars()

// safety
private static function prepare_vars(&$vars) {
$vars['course_id'] = intval($vars['course_id']);
$vars['rating'] = intval($vars['namaste_rating']);
$vars['review'] = wp_kses_post($vars['review']);
}

private static function get_rating_options() {
return [
1 => __('Poor', 'namaste'),
2 => __('Accedptable', 'namaste'),
3 => __('Average', 'namaste'),
4 => __('Good', 'namaste'),
5 => __('Great', 'namaste'),
];
}
}
15 changes: 13 additions & 2 deletions controllers/shortcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -888,8 +888,19 @@ public static function review_course($atts, $contents = '') {
return $content;
} // end review_course

// list reviews
// list reviews - for now just list them all without navigation.
// $atts[number] - show last number of reviews
public static function course_reviews($atts) {
return "NYI";
$course_id = empty($atts['course_id']) ? 0 : intval($atts['course_id']);
if(empty($course_id)) return "";

$number = empty($atts['number']) ? 0 : intval($atts['number']);
$show = empty($atts['show']) ? 'user_login' : sanitize_text_field($atts['show']);
if(!in_array($show, ['user_login', 'display_name'])) $show = 'user_login';

ob_start();
NamasteLMSReviews :: list_reviews($course_id, $number, $show);
$content = ob_get_clean();
return $content;
}
}
8 changes: 8 additions & 0 deletions css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@
cursor: pointer;
}

div.namaste-review {
border: 1pt solid #888888;
padding: 1em;
margin: 0.5em;
margin-bottom: 0.7em;
box-shadow: 0.5em 0.5em 0.5em #888888;
}

[role="region"][aria-labelledby][tabindex] {
width: 100%;
height: 100%;
Expand Down
2 changes: 1 addition & 1 deletion namaste.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Plugin URI: http://namaste-lms.org
Description: Learning Management System for WordPress. Courses, modules, lessons, gradebook, and everything you need.
Author: Kiboko Labs
Version: 2.5.4.2
Version: 2.5.5
Author URI: http://calendarscripts.info/
License: GPLv2 or later
Text Domain: namaste
Expand Down
Loading

0 comments on commit 0c4042c

Please sign in to comment.