/** * Check to see if the unit has been completed or not. * @return Boolean True if the unit has been completed, false otherwise. */ function check_unit_isCompleted() { return $this->userProgress && $this->userProgress->isUnitCompleted($this->unitPost->ID); }
/** * Shows a detailed summary of the user progress. */ function WPCW_showPage_UserProgess_load() { global $wpcwdb, $wpdb; $wpdb->show_errors(); $page = new PageBuilder(false); $page->showPageHeader(__('Detailed User Progress Report', 'wp_courseware'), '75%', WPCW_icon_getPageIconURL()); // Check passed user ID is valid $userID = WPCW_arrays_getValue($_GET, 'user_id'); $userDetails = get_userdata($userID); if (!$userDetails) { $page->showMessage(__('Sorry, but that user could not be found.', 'wp_courseware'), true); $page->showPageFooter(); return false; } printf(__('<p>Here you can see how well <b>%s</b> (Username: <b>%s</b>) is doing with your training courses.</p>', 'wp_courseware'), $userDetails->data->display_name, $userDetails->data->user_login); // #### 1 - Show a list of all training courses, and then list the units associated with that course. $SQL = "SELECT * \n\t\t\tFROM {$wpcwdb->courses}\n\t\t\tORDER BY course_title ASC \n\t\t\t"; $courseCount = 0; $courses = $wpdb->get_results($SQL); if ($courses) { foreach ($courses as $course) { $up = new UserProgress($course->course_id, $userID); // Skip if user is not allowed to access the training course. if (!WPCW_courses_canUserAccessCourse($course->course_id, $userID)) { continue; } printf('<h3 class="wpcw_tbl_progress_course">%s</h3>', $course->course_title); printf('<table class="widefat wpcw_tbl wpcw_tbl_progress">'); printf('<thead>'); printf('<th>%s</th>', __('Unit', 'wp_courseware')); printf('<th class="wpcw_center">%s</th>', __('Completed', 'wp_courseware')); printf('<th class="wpcw_center wpcw_tbl_progress_quiz_name">%s</th>', __('Quiz Name', 'wp_courseware')); printf('<th class="wpcw_center">%s</th>', __('Quiz Status', 'wp_courseware')); printf('<th class="wpcw_center">%s</th>', __('Actions', 'wp_courseware')); printf('</thead><tbody>'); // #### 2 - Fetch all associated modules $modules = WPCW_courses_getModuleDetailsList($course->course_id); if ($modules) { foreach ($modules as $module) { // #### 3 - Render Modules as a heading. printf('<tr class="wpcw_tbl_progress_module">'); printf('<td colspan="3">%s %d - %s</td>', __('Module', 'wp_courseware'), $module->module_number, $module->module_title); // Blanks for Quiz Name and Actions. printf('<td> </td>'); printf('<td> </td>'); printf('</tr>'); // #### 4. - Render the units for this module $units = WPCW_units_getListOfUnits($module->module_id); if ($units) { foreach ($units as $unit) { $showDetailLink = false; printf('<tr class="wpcw_tbl_progress_unit">'); printf('<td class="wpcw_tbl_progress_unit_name">%s %d - %s</td>', __('Unit', 'wp_courseware'), $unit->unit_meta->unit_number, $unit->post_title); // Has the unit been completed yet? printf('<td class="wpcw_tbl_progress_completed">%s</td>', $up->isUnitCompleted($unit->ID) ? __('Completed', 'wp_courseware') : ''); // See if there's a quiz for this unit? $quizDetails = WPCW_quizzes_getAssociatedQuizForUnit($unit->ID, false, $userID); // Render the quiz details. if ($quizDetails) { // Title of quiz printf('<td class="wpcw_tbl_progress_quiz_name">%s</td>', $quizDetails->quiz_title); // No correct answers, so mark as complete. if ('survey' == $quizDetails->quiz_type) { $quizResults = WPCW_quizzes_getUserResultsForQuiz($userID, $unit->ID, $quizDetails->quiz_id); if ($quizResults) { printf('<td class="wpcw_tbl_progress_completed">%s</td>', __('Completed', 'wp_courseware')); // Showing a link to view details $showDetailLink = true; printf('<td><a href="%s&user_id=%d&quiz_id=%d&unit_id=%d" class="button-secondary">%s</a></td>', admin_url('users.php?page=WPCW_showPage_UserProgess_quizAnswers'), $userID, $quizDetails->quiz_id, $unit->ID, __('View Survey Details', 'wp_courseware')); } else { printf('<td class="wpcw_center">%s</td>', __('Pending', 'wp_courseware')); } } else { $quizResults = WPCW_quizzes_getUserResultsForQuiz($userID, $unit->ID, $quizDetails->quiz_id); // Show the admin how many questions were right. if ($quizResults) { // -1% means that the quiz is needing grading. if ($quizResults->quiz_grade < 0) { printf('<td class="wpcw_center">%s</td>', __('Awaiting Final Grading', 'wp_courseware')); } else { printf('<td class="wpcw_tbl_progress_completed">%d%%</td>', number_format($quizResults->quiz_grade, 1)); } // Showing a link to view details $showDetailLink = true; printf('<td><a href="%s&user_id=%d&quiz_id=%d&unit_id=%d" class="button-secondary">%s</a></td>', admin_url('users.php?page=WPCW_showPage_UserProgess_quizAnswers'), $userID, $quizDetails->quiz_id, $unit->ID, __('View Quiz Details', 'wp_courseware')); } else { printf('<td class="wpcw_center">%s</td>', __('Pending', 'wp_courseware')); } } // end of if survey } else { printf('<td class="wpcw_center">-</td>'); printf('<td class="wpcw_center">-</td>'); } // Quiz detail link if (!$showDetailLink) { printf('<td> </td>'); } printf('</tr>'); } } } } printf('</tbody></table>'); // Track number of courses user can actually access $courseCount++; } // Course is not allowed to access any courses. So show a meaningful message. if ($courseCount == 0) { $page->showMessage(sprintf(__('User <b>%s</b> is not currently allowed to access any training courses.', 'wp_courseware'), $userDetails->data->display_name), true); } } else { printf('<p>%s</p>', __('There are currently no courses to show. Why not create one?', 'wp_courseware')); } $page->showPageFooter(); }
/** * Function that creates a list of units. * * @param Integer $courseID The ID of the course to show. * @param Array $options The list of options to show. */ function WPCW_courses_renderCourseList($courseID, $options) { extract(shortcode_atts(array('module' => 0, 'module_desc' => false, 'show_title' => false, 'show_desc' => false, 'widget_mode' => false, 'show_toggle_col' => false, 'show_modules_previous' => 'all', 'show_modules_next' => 'all', 'toggle_modules' => 'expand_all'), $options)); // Check settings to to see if they are true $module_desc = $module_desc == 'true'; $show_title = $show_title == 'true'; $show_desc = $show_desc == 'true'; $courseDetails = false; $parentData = false; global $post; // Show course based on current location for user. Use the currently shown post // to work out which course to show using the associated parent data. if ('current' == $courseID) { $parentData = WPCW_units_getAssociatedParentData($post->ID); if ($parentData) { $courseDetails = WPCW_courses_getCourseDetails($parentData->parent_course_id); $courseID = $parentData->parent_course_id; } else { return false; } } else { // Check course ID is valid $courseDetails = WPCW_courses_getCourseDetails($courseID); if (!$courseDetails) { return __('Unrecognised course ID.', 'wp_courseware'); } // Course ID is fine, get associated parent data for // hiding aspects of the widget $parentData = WPCW_units_getAssociatedParentData($post->ID); } $moduleList = false; // Do we just want a single module? if ($module > 0) { // Get module by module number within course (not the module ID) $moduleDetailsSingle = WPCW_modules_getModuleDetails_byModuleNumber($courseDetails->course_id, $module); if (!$moduleDetailsSingle) { return __('Could not find module.', 'wp_courseware'); } // Create module list of 1 using single module $moduleList[$moduleDetailsSingle->module_id] = $moduleDetailsSingle; } else { // Check there are modules $moduleList = WPCW_courses_getModuleDetailsList($courseID); if (!$moduleList) { return __('There are no modules in this training course.', 'wp_courseware'); } } $html = false; // #### Show course title/description if ($show_title) { $html .= sprintf('<div class="wpcw_fe_course_title">%s</div>', $courseDetails->course_title); } if ($show_desc) { $html .= sprintf('<div class="wpcw_fe_course_desc">%s</div>', $courseDetails->course_desc); } $html .= '<table id="wpcw_fe_course" cellspacing="0" cellborder="0">'; $showUnitLinks = false; // If true, show links to the units $colCount = 2; // Number of columns in the table // UP Object to determine what to show to the user. $userProgress = false; // Check user is logged in, and if they can access this course $user_id = get_current_user_id(); if ($user_id != 0) { $userProgress = new UserProgress($courseID, $user_id); // Show links for user if they are allowed to access this course. if ($userProgress->canUserAccessCourse()) { // User is logged in and can do course, so show the stuff they can do. $showUnitLinks = true; // Got an extra column to show progress $colCount = 3; } } // If we're showing a widget, and we have the parent data based on the // currently viewed unit, then change what's in the widget in terms // of previous/next units. $hideList = array(); if ($widget_mode && $module == 0 && $parentData) { // Build a list of the modules before and after the current // module, so that we can more easily control what's visible, // and what's not. $modulesBefore = array(); $modulesAfter = array(); $currentList =& $modulesBefore; foreach ($moduleList as $moduleID => $moduleObj) { // Switch lists, we've found the current module if ($moduleID == $parentData->parent_module_id) { $currentList =& $modulesAfter; } else { $currentList[] = $moduleID; } } // Handle showing previous modules switch ($show_modules_previous) { // All all items in the before list to be hidden case 'none': $hideList = array_merge($hideList, $modulesBefore); break; case 'all': break; // Keep a specific number of modules to show. // Keep a specific number of modules to show. default: $show_modules_previous += 0; $modulesToPickFrom = count($modulesBefore); // Remove the modules at the start of the list, leaving the right number of // $show_modules_previous modules in the list. if ($show_modules_previous > 0 && $modulesToPickFrom > $show_modules_previous) { $hideList = array_merge($hideList, array_slice($modulesBefore, 0, $modulesToPickFrom - $show_modules_previous)); } break; } // end switch // Handle showing the next modules. switch ($show_modules_next) { // All all items in the after list to be hidden case 'none': $hideList = array_merge($hideList, $modulesAfter); break; case 'all': break; // Keep a specific number of modules to show. // Keep a specific number of modules to show. default: $show_modules_next += 0; $modulesToPickFrom = count($modulesAfter); // Remove the modules at the start of the list, leaving the right number of // $show_modules_previous modules in the list. if ($show_modules_next > 0 && $modulesToPickFrom > $show_modules_next) { $hideList = array_merge($hideList, array_slice($modulesAfter, $show_modules_next)); } break; } // end switch } // Columns for marking item as being pending or complete. $progress_Complete = '<td class="wpcw_fe_unit_progress wpcw_fe_unit_progress_complete"><span> </span></td>'; $progress_Pending = '<td class="wpcw_fe_unit_progress wpcw_fe_unit_progress_incomplete"><span> </span></td>'; $progress_Blank = '<td class="wpcw_fe_unit_progress"><span> </span></td>'; // Show modules foreach ($moduleList as $moduleID => $moduleObj) { // See if we're skipping this module if (in_array($moduleID, $hideList)) { continue; } // If $collapseTitleArea is set to true, then the module will be collapsed. So just check what to hide // based on the contents of $toggle_modules $collapseTitleArea = false; if ($widget_mode && $parentData) { switch ($toggle_modules) { case 'contract_all': $collapseTitleArea = true; break; // See if the currently visible unit module is the one being rendered. // See if the currently visible unit module is the one being rendered. case 'contract_all_but_current': $collapseTitleArea = $moduleID != $parentData->parent_module_id; break; // Default is not to collapse. } } // We're showing the toggle section, so add it. if ($show_toggle_col) { $moduleTitleArea = false; $moduleTitleArea = sprintf('<td>%s</td><td class="wpcw_fe_toggle">%s</td>', $moduleObj->module_title, $collapseTitleArea ? '+' : '-'); } else { $moduleTitleArea = sprintf('<td colspan="%d">%s</td>', $colCount - 1, $moduleObj->module_title); } // Render final title bit $html .= sprintf('<tr class="wpcw_fe_module %s" id="wpcw_fe_module_group_%d"> <td>%s %d</td> ' . $moduleTitleArea . ' </tr>', $collapseTitleArea ? 'wpcw_fe_module_toggle_hide' : '', $moduleObj->module_number, __('Module', 'wp_courseware'), $moduleObj->module_number, $moduleTitleArea); // ### Showing the module descriptions? if ($module_desc) { $html .= sprintf('<tr class="wpcw_fe_module_des"><td colspan="%d">%s</td></tr>', $colCount, $moduleObj->module_desc); } // Add the class for the row that matches the parent module ID. $moduleRowClass = ' wpcw_fe_module_group_' . $moduleObj->module_number; // ### No Units Line $units = WPCW_units_getListOfUnits($moduleID); if (!$units) { $extraColSpan = 0; if ($show_toggle_col) { $extraColSpan = 1; } $html .= sprintf('<tr class="wpcw_fe_unit wpcw_fe_unit_none %s"> <td colspan="%d">%s</td> </tr>', $moduleRowClass, $colCount + $extraColSpan, __('There are no units in this module.', 'wp_courseware')); } else { // Render each unit foreach ($units as $unit) { $progressRow = false; $progressCol = false; // Show links for units if ($showUnitLinks) { // Yes we are showing progress data... see what state we're at. if ($userProgress) { if ($userProgress->isUnitCompleted($unit->ID)) { $progressCol = $progress_Complete; $progressRow = 'wpcw_fe_unit_complete'; } else { $progressCol = $progress_Pending; $progressRow = 'wpcw_fe_unit_pending'; } //$progressCol = ($userProgress->isUnitCompleted($unit->ID) ? $progress_Complete : $progress_Pending); } // See if the user is allowed to access this unit or not. if ($userProgress->canUserAccessUnit($unit->ID)) { // Main unit title, link and unit number $html .= sprintf(' <tr class="wpcw_fe_unit ' . $progressRow . $moduleRowClass . '"> <td>%s %d</td> <td class="wpcw_fe_unit"><a href="%s">%s</a></td> ' . $progressCol . ' </tr>', __('Unit', 'wp_courseware'), $unit->unit_meta->unit_number, get_permalink($unit->ID), $unit->post_title); } else { // If we're not allowed to access the unit, then it's always marked as pending. $html .= sprintf(' <tr class="wpcw_fe_unit ' . $progressRow . $moduleRowClass . '"> <td>%s %d</td> <td class="wpcw_fe_unit">%s</td> ' . $progress_Pending . ' </tr>', __('Unit', 'wp_courseware'), $unit->unit_meta->unit_number, $unit->post_title); } } else { $colspan = 1; if ($show_toggle_col) { $colspan = 2; } $html .= sprintf(' <tr class="wpcw_fe_unit ' . $progressRow . $moduleRowClass . '"> <td>%s %d</td> <td colspan="%d" class="wpcw_fe_unit">%s</td> </tr>', __('Unit', 'wp_courseware'), $unit->unit_meta->unit_number, $colspan, $unit->post_title); } } } // end show units } $html .= '</table>'; // Add powered by link $settings = TidySettings_getSettings(WPCW_DATABASE_SETTINGS_KEY); $html .= WPCW_generatedPoweredByLink($settings); return $html; }