/**
  * Method that renders the course progress.
  */
 function widget($args, $instance)
 {
     extract($args);
     // Turn options from widget into options for getting course details.
     $args = array('show_title' => $instance['option_show_course_title'] == 'on' ? 'true' : 'false', 'show_desc' => $instance['option_show_course_desc'] == 'on' ? 'true' : 'false', 'module_desc' => $instance['option_show_module_desc'] == 'on' ? 'true' : 'false', 'only_on_units' => $instance['option_show_only_on_units'] == 'on' ? 'true' : 'false', 'show_modules_next' => trim($instance['option_show_modules_next']), 'show_modules_previous' => trim($instance['option_show_modules_previous']), 'toggle_modules' => trim($instance['option_toggle_modules']), 'show_toggle_col' => true, 'widget_mode' => true);
     // Don't do anything if we're not on a unit page
     global $post;
     if ($args['only_on_units'] == 'true') {
         if ('course_unit' != get_post_type($post->ID)) {
             return;
         }
     }
     $title = apply_filters('widget_title', $instance['title']);
     echo $before_widget;
     if ($title) {
         echo $before_title . $title . $after_title;
     }
     $courseID = $instance['option_course'] + 0;
     echo '<div class="wpcw_widget_progress">';
     echo WPCW_courses_renderCourseList($courseID, $args);
     echo '</div>';
     echo $after_widget;
 }
Exemple #2
0
/**
 * Creates widget that shows off a training course, its modules, and its units.
 * 
 *  e.g. [wpcourse course="2" showunits="true" /]
 */
function WPCW_shortcodes_showTrainingCourse($atts, $content)
{
    extract(shortcode_atts(array('course' => 0), $atts));
    // Just pass arguments straight on
    return WPCW_courses_renderCourseList($course, $atts);
}
Exemple #3
0
/**
 * Creates widget that shows off the user's progress on their respective courses.
 * 
 *  e.g. [wpcourse_progress courses="2" user_progress="true" user_grade="true" /]
 */
function WPCW_shortcodes_showTrainingCourseProgress($atts, $content)
{
    extract(shortcode_atts(array('courses' => 'all', 'user_progress' => true, 'user_grade' => true), $atts));
    // Check flags to see what we're showing
    $showUserProgress = 'true' == strtolower($user_progress);
    $showUserGrade = 'true' == strtolower($user_grade);
    // Show a message to the user if they are not logged in.
    $user_id = get_current_user_id();
    if (!$user_id) {
        return sprintf('<div class="wpcw_fe_progress_box_wrap"><div class="wpcw_fe_progress_box wpcw_fe_progress_box_error">%s</div></div>', apply_filters('wpcw_front_shortcode_wpcourse_progress_notloggedin', __('You need to be logged in to see your course progress.', 'wp_courseware')));
    }
    // Get a list of all of the courses that the user is subscribed to.
    $courseList = WPCW_users_getUserCourseList($user_id);
    $selectedCourseList = array();
    // Filter the list of courses to remove the ones that the trainer doesn't
    // want the user to see. 'all' means show all courses with no filtering.
    // Only do this check if we have any courses to check, to save time.
    if (!empty($courseList) && 'all' != strtolower($courses)) {
        $selectedCourseList = explode(',', $courses);
        // This is the list of courses we'll actually use.
        $chosenListOfCourses = array();
        // We've got courses that have been specified, so we need to go through them now.
        if (!empty($selectedCourseList)) {
            foreach ($selectedCourseList as $potentialItem) {
                $potentialItem = trim($potentialItem);
                // Got a potential ID here.
                if (preg_match('/^([0-9]+)$/', $potentialItem)) {
                    // Check each course we still have to see if the ID matches.
                    // I know it's O(N), but it's simple at least.
                    foreach ($courseList as $idx => $aSingleCourse) {
                        // Got a match...
                        if ($potentialItem == $aSingleCourse->course_id) {
                            // Move the chosen course to the selected list. Doing
                            // so makes subsequent searches faster.
                            $chosenListOfCourses[] = $aSingleCourse;
                            unset($courseList[$idx]);
                            // Stop searching, we found it.
                            break;
                        }
                    }
                    // end foreach
                }
                // end ID check
            }
            // end foreach of potential IDs in list.
        }
        // Overwrite the list of courses to use.
        $courseList = $chosenListOfCourses;
    }
    // Handle when the list is empty
    if (empty($courseList)) {
        // Change message slightly based on how many courses are selected.
        $messageToShow = __('You are not currently enrolled on any courses.', 'wp_courseware');
        if (!empty($selectedCourseList)) {
            $messageToShow = __('You are not currently enrolled on any of these courses.', 'wp_courseware');
        }
        return sprintf('<div class="wpcw_fe_progress_box_wrap"><div class="wpcw_fe_progress_box wpcw_fe_progress_box_error">%s</div></div>', apply_filters('wpcw_front_shortcode_wpcourse_progress_no_courses', $messageToShow, count($courseList)));
    }
    // Used to determine how many columns we have in the table for showing the course details.
    $columnCount = 1;
    // Show the list of courses
    $html = '<table id="wpcw_fe_course_progress" class="wpcw_fe_table wpcw_fe_summary_course_progress">';
    // The title bar for the course.
    $html .= '<thead><tr>';
    // Course name
    $html .= sprintf('<th class="wpcw_fe_course_progress_course">%s</th>', __('Course', 'wp_courseware'));
    // Course progress
    if ($showUserProgress) {
        $columnCount++;
        $html .= sprintf('<th class="wpcw_fe_course_progress_pc">%s</th>', __('Your Progress', 'wp_courseware'));
    }
    // Overall grade so far
    if ($showUserGrade) {
        $columnCount++;
        $html .= sprintf('<th class="wpcw_fe_course_progress_grade">%s</th>', __('Your Overall Grade', 'wp_courseware'));
    }
    $html .= '</tr></thead><tbody>';
    // The main body of the course information.
    foreach ($courseList as $aSingleCourse) {
        $html .= '<tr class="wpcw_fe_course_progress_row">';
        // Course name
        $html .= sprintf('<td class="wpcw_fe_course_progress_course"><a href="#" data-toggle="wpcw_fe_course_progress_detail_%d">%s</a></td>', $aSingleCourse->course_id, $aSingleCourse->course_title);
        // Course progress
        if ($showUserProgress) {
            $html .= sprintf('<td class="wpcw_fe_course_progress_pc">%s</td>', WPCW_content_progressBar($aSingleCourse->course_progress));
        }
        // Show the Overall grade so far
        if ($showUserGrade) {
            $html .= sprintf('<td class="wpcw_fe_course_progress_grade">%s</td>', WPCW_courses_getCourseCumulativeGrade($aSingleCourse->course_id, $user_id));
        }
        $html .= '</tr>';
        // Show full course details. This might be a setting at some point.
        $html .= sprintf('<tr><td class="wpcw_fe_course_progress_detail" id="wpcw_fe_course_progress_detail_%d" colspan="%d">', $aSingleCourse->course_id, $columnCount);
        $html .= WPCW_courses_renderCourseList($aSingleCourse->course_id, array('hide_credit_link' => true));
        $html .= '</td></tr>';
    }
    $html .= '</tbody></table>';
    // end .wpcw_fe_summary_course_progress
    return $html;
}