/** * Creates the column columns of data. * * @param String $colContent The content of the column. * @param String $column_name The name of the column we're changing. * @param Integer $user_id The ID of the user we're rendering. * * @return String The formatted HTML code for the table. */ function WPCW_users_addCustomColumnContent($colContent, $column_name, $user_id) { switch ($column_name) { // #### Basically condense user details. case 'wpcw_col_user_details': // Format nice details of name, email and role to save space. $userDetails = get_userdata($user_id); // Ensure role is valid and it exists. $roleName = false; if (!empty($userDetails->roles)) { $roleName = $userDetails->roles[0]; } $colContent = sprintf('<span class="wpcw_col_cell_name">%s</span>', $userDetails->data->display_name); $colContent .= sprintf('<span class="wpcw_col_cell_email"><a href="mailto:%s" target="_blank">%s</a></span>', $userDetails->data->user_email, $userDetails->data->user_email); $colContent .= sprintf('<span class="wpcw_col_cell_role">%s</span>', ucwords($roleName)); break; // ####ÊThe training course statuses. // ####ÊThe training course statuses. case 'wpcw_col_training_courses': // Got some associated courses, so render progress. $courseData = WPCW_users_getUserCourseList($user_id); if ($courseData) { foreach ($courseData as $courseDataItem) { $colContent .= WPCW_stats_convertPercentageToBar($courseDataItem->course_progress, $courseDataItem->course_title); } } else { $colContent = __('No associated courses', 'wp_courseware'); } break; // #### Links to change user access for courses. // #### Links to change user access for courses. case 'wpcw_col_training_courses_access': $colContent = sprintf('<span><a href="%s&user_id=%d" class="button-primary">%s</a></span>', admin_url('users.php?page=WPCW_showPage_UserProgess'), $user_id, __('View Detailed Progress', 'wp_courseware')); // View the full progress of the user. $colContent .= sprintf('<span><a href="%s&user_id=%d" class="button-secondary">%s</a></span>', admin_url('users.php?page=WPCW_showPage_UserCourseAccess'), $user_id, __('Update Course Access Permissions', 'wp_courseware')); break; } // return $colContent; }
/** * 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; }
/** * Creates the column columns of data. * * @param String $colContent The content of the column. * @param String $column_name The name of the column we're changing. * @param Integer $user_id The ID of the user we're rendering. * * @return String The formatted HTML code for the table. */ function WPCW_users_addCustomColumnContent($colContent, $column_name, $user_id) { switch ($column_name) { // #### Basically condense user details. case 'wpcw_col_user_details': // Format nice details of name, email and role to save space. $userDetails = get_userdata($user_id); // Ensure role is valid and it exists. $roleName = false; if (!empty($userDetails->roles)) { $roleName = $userDetails->roles[0]; } $colContent = sprintf('<span class="wpcw_col_cell_name">%s</span>', $userDetails->data->display_name); $colContent .= sprintf('<span class="wpcw_col_cell_email"><a href="mailto:%s" target="_blank">%s</a></span>', $userDetails->data->user_email, $userDetails->data->user_email); $colContent .= sprintf('<span class="wpcw_col_cell_role">%s</span>', ucwords($roleName)); break; // ####ÊThe training course statuses. // ####ÊThe training course statuses. case 'wpcw_col_training_courses': // Got some associated courses, so render progress. $courseData = WPCW_users_getUserCourseList($user_id); if ($courseData) { foreach ($courseData as $courseDataItem) { $colContent .= WPCW_stats_convertPercentageToBar($courseDataItem->course_progress, $courseDataItem->course_title); } } else { $colContent = __('No associated courses', 'wp_courseware'); } break; // #### Links to change user access for courses. // #### Links to change user access for courses. case 'wpcw_col_training_courses_access': $colContent = sprintf('<span><a href="%s&user_id=%d" class="button-primary">%s</a></span>', admin_url('users.php?page=WPCW_showPage_UserProgess'), $user_id, __('View Detailed Progress', 'wp_courseware')); // View the full progress of the user. $colContent .= sprintf('<span><a href="%s&user_id=%d" class="button-secondary">%s</a></span>', admin_url('users.php?page=WPCW_showPage_UserCourseAccess'), $user_id, __('Update Course Access Permissions', 'wp_courseware')); // Allow the user progress to be reset $courseData = WPCW_users_getUserCourseList($user_id); $courseIDList = array(); if (!empty($courseData)) { // Construct a simple list of IDs that we can use for filtering. foreach ($courseData as $courseDetails) { $courseIDList[] = $courseDetails->course_id; } } // Construct the mini form for resetting the user progress. $colContent .= '<span>'; $colContent .= '<form method="get">'; // Using this method of the user ID automaticallyed added the first user to any bulk action, which is clearly a bug. // So the field had to be renamed. //$colContent .= sprintf('<input type="hidden" name="users[]" value="%d" >', $user_id); $colContent .= sprintf('<input type="hidden" name="wpcw_users_single" value="%d" >', $user_id); // The dropdown for this. $colContent .= WPCW_courses_getCourseResetDropdown('wpcw_user_progress_reset_point_single', $courseIDList, __('No associated courses.', 'wp_courseware'), __('Reset this user to beginning of...', 'wp_courseware'), '', 'wpcw_user_progress_reset_select wpcw_user_progress_reset_point_single'); $colContent .= '</form>'; $colContent .= '</span>'; break; } return $colContent; }