コード例 #1
0
ファイル: admin_only.inc.php プロジェクト: JalpMi/v2contact
/**
 * Function that show a summary of the training courses.
 */
function WPCW_showPage_QuizSummary()
{
    global $wpcwdb, $wpdb;
    $wpdb->show_errors();
    // Get the requested page number
    $paging_pageWanted = WPCW_arrays_getValue($_GET, 'pagenum') + 0;
    if ($paging_pageWanted == 0) {
        $paging_pageWanted = 1;
    }
    // Title for page with page number
    $titlePage = false;
    if ($paging_pageWanted > 1) {
        $titlePage = sprintf(' - %s %s', __('Page', 'wp_courseware'), $paging_pageWanted);
    }
    $page = new PageBuilder(false);
    $page->showPageHeader(__('Quiz & Survey Summary', 'wp_courseware') . $titlePage, '75%', WPCW_icon_getPageIconURL());
    // Handle the quiz deletion before showing remaining quizzes...
    WPCW_quizzes_handleQuizDeletion($page);
    // Was a search string specified? Or a specific item?
    $searchString = WPCW_arrays_getValue($_GET, 's');
    // Create WHERE string based search - Title or Description of Quiz
    $stringWHERE = false;
    if ($searchString) {
        $stringWHERE = sprintf(" WHERE quiz_title LIKE '%%%s%%' OR quiz_desc LIKE '%%%s%%' ", $wpdb->escape($searchString), $wpdb->escape($searchString));
    }
    $summaryPageURL = admin_url('admin.php?page=WPCW_showPage_QuizSummary');
    // Show the form for searching
    ?>
			
	<form id="wpcw_quizzes_search_box" method="get" action="<?php 
    echo $summaryPageURL;
    ?>
">
	<p class="search-box">
		<label class="screen-reader-text" for="wpcw_quizzes_search_input"><?php 
    _e('Search Quizzes', 'wp_courseware');
    ?>
</label>
		<input id="wpcw_quizzes_search_input" type="text" value="<?php 
    echo $searchString;
    ?>
" name="s"/>
		<input class="button" type="submit" value="<?php 
    _e('Search Quizzes', 'wp_courseware');
    ?>
"/>
		
		<input type="hidden" name="page" value="WPCW_showPage_QuizSummary" />
	</p>
	</form>
	<br/><br/>
	<?php 
    $SQL_PAGING = "\n\t\t\tSELECT COUNT(*) as quiz_count \n\t\t\tFROM {$wpcwdb->quiz}\t\t\t\n\t\t\t{$stringWHERE}\n\t\t\tORDER BY quiz_title ASC \n\t\t";
    $paging_resultsPerPage = 50;
    $paging_totalCount = $wpdb->get_var($SQL_PAGING);
    $paging_recordStart = ($paging_pageWanted - 1) * $paging_resultsPerPage + 1;
    $paging_recordEnd = $paging_pageWanted * $paging_resultsPerPage;
    $paging_pageCount = ceil($paging_totalCount / $paging_resultsPerPage);
    $paging_sqlStart = $paging_recordStart - 1;
    // Show search message - that a search has been tried.
    if ($searchString) {
        printf('<div class="wpcw_search_count">%s "%s" (%s %s) (<a href="%s">%s</a>)</div>', __('Search results for', 'wp_courseware'), htmlentities($searchString), $paging_totalCount, _n('result', 'results', $paging_totalCount, 'wp_courseware'), $summaryPageURL, __('reset', 'wp_courseware'));
    }
    // Do main query
    $SQL = "SELECT * \n\t\t\tFROM {$wpcwdb->quiz}\t\t\t\n\t\t\t{$stringWHERE}\n\t\t\tORDER BY quiz_title ASC\n\t\t\tLIMIT {$paging_sqlStart}, {$paging_resultsPerPage}\n\t\t\t";
    // Generate paging code
    $baseURL = WPCW_urls_getURLWithParams($summaryPageURL, 'pagenum') . "&pagenum=";
    $paging = WPCW_tables_showPagination($baseURL, $paging_pageWanted, $paging_pageCount, $paging_totalCount, $paging_recordStart, $paging_recordEnd);
    $quizzes = $wpdb->get_results($SQL);
    if ($quizzes) {
        $tbl = new TableBuilder();
        $tbl->attributes = array('id' => 'wpcw_tbl_quiz_summary', 'class' => 'widefat wpcw_tbl');
        $tblCol = new TableColumn(__('ID', 'wp_courseware'), 'quiz_id');
        $tblCol->cellClass = "quiz_id";
        $tbl->addColumn($tblCol);
        $tblCol = new TableColumn(__('Quiz Title', 'wp_courseware'), 'quiz_title');
        $tblCol->cellClass = "quiz_title";
        $tbl->addColumn($tblCol);
        $tblCol = new TableColumn(__('Description', 'wp_courseware'), 'quiz_desc');
        $tblCol->cellClass = "quiz_desc";
        $tbl->addColumn($tblCol);
        $tblCol = new TableColumn(__('Associated Unit', 'wp_courseware'), 'associated_unit');
        $tblCol->cellClass = "associated_unit";
        $tbl->addColumn($tblCol);
        $tblCol = new TableColumn(__('Quiz Type', 'wp_courseware'), 'quiz_type');
        $tblCol->cellClass = "quiz_type";
        $tbl->addColumn($tblCol);
        $tblCol = new TableColumn(__('Show Answers', 'wp_courseware'), 'quiz_show_answers');
        $tblCol->cellClass = "quiz_type wpcw_center";
        $tbl->addColumn($tblCol);
        $tblCol = new TableColumn(__('Total Questions', 'wp_courseware'), 'total_questions');
        $tblCol->cellClass = "total_questions wpcw_center";
        $tbl->addColumn($tblCol);
        $tblCol = new TableColumn(__('Actions', 'wp_courseware'), 'actions');
        $tblCol->cellClass = "actions";
        $tbl->addColumn($tblCol);
        // Stores course details in a mini cache to save lots of MySQL lookups.
        $miniCourseDetailCache = array();
        // Format row data and show it.
        $odd = false;
        foreach ($quizzes as $quiz) {
            $data = array();
            // URLs
            $editURL = admin_url('admin.php?page=WPCW_showPage_ModifyQuiz&quiz_id=' . $quiz->quiz_id);
            // Maintain paging where possible.
            $deleteURL = $baseURL . '&action=delete&quiz_id=' . $quiz->quiz_id;
            // Basic Details
            $data['quiz_id'] = $quiz->quiz_id;
            $data['quiz_desc'] = $quiz->quiz_desc;
            $data['quiz_title'] = sprintf('<a href="%s">%s</a>', $editURL, $quiz->quiz_title);
            // Associated Unit
            if ($quiz->parent_unit_id > 0 && ($unitDetails = get_post($quiz->parent_unit_id))) {
                $data['associated_unit'] = sprintf('<b>%s</b>: <a href="%s" target="_blank" title="%s \'%s\'...">%s</a>', __('Unit', 'wp_courseware'), get_permalink($unitDetails->ID), __('View ', 'wp_courseware'), $unitDetails->post_title, $unitDetails->post_title);
                // Also add associated course
                if (isset($miniCourseDetailCache[$quiz->parent_course_id])) {
                    $courseDetails = $miniCourseDetailCache[$quiz->parent_course_id];
                } else {
                    // Save course details to cache (as likely to use it again).
                    $courseDetails = $miniCourseDetailCache[$quiz->parent_course_id] = WPCW_courses_getCourseDetails($quiz->parent_course_id);
                }
                $data['associated_unit'] .= sprintf('<br/><b>%s:</b> <a href="admin.php?page=WPCW_showPage_ModifyCourse&course_id=%d" title="%s \'%s\'...">%s</a>', __('Course', 'wp_courseware'), $courseDetails->course_id, __('Edit ', 'wp_courseware'), $courseDetails->course_title, $courseDetails->course_title);
            } else {
                $data['associated_unit'] = 'n/a';
            }
            // Showing Answers?
            $data['quiz_show_answers'] = 'show_answers' == $quiz->quiz_show_answers ? __('Yes', 'wp_courseware') : '-';
            // Type of quiz
            $data['quiz_type'] = WPCW_quizzes_getQuizTypeName($quiz->quiz_type);
            if ('quiz_block' == $quiz->quiz_type) {
                $data['quiz_type'] .= '<span class="wpcw_quiz_pass_info">' . sprintf(__('Min. Pass Mark of %d%%', 'wp_courseware'), $quiz->quiz_pass_mark) . '</span>';
            }
            // Total number of questions
            $totalQuestions = $wpdb->get_var($wpdb->prepare("\n\t\t\t\t\tSELECT COUNT(*) as total_questions \n\t\t\t\t\tFROM {$wpcwdb->quiz_qs}\n\t\t\t\t\tWHERE parent_quiz_id = %d\n\t\t\t", $quiz->quiz_id));
            $data['total_questions'] = $totalQuestions + 0;
            // Actions
            $data['actions'] = '<ul class="wpcw_action_link_list">';
            $data['actions'] .= sprintf('<li><a href="%s" class="button-primary">%s</a></li>', $editURL, __('Edit', 'wp_courseware'));
            $data['actions'] .= sprintf('<li><a href="%s" class="button-secondary wpcw_action_link_delete_quiz wpcw_action_link_delete" rel="%s">%s</a></li>', $deleteURL, __('Are you sure you wish to delete this quiz?', 'wp_courseware'), __('Delete', 'wp_courseware'));
            $data['actions'] .= '</ul>';
            // Odd/Even row colouring.
            $odd = !$odd;
            $tbl->addRow($data, $odd ? 'alternate' : '');
        }
        // Finally show table
        echo $paging;
        echo $tbl->toString();
        echo $paging;
    } else {
        printf('<p>%s</p>', __('There are currently no quizzes to show. Why not create one?', 'wp_courseware'));
    }
    $page->showPageFooter();
}
コード例 #2
0
ファイル: page_gradebook.inc.php プロジェクト: NClaus/Ambrose
/**
 * Gradebook View - show the grade details for the users of the system. 
 */
function WPCW_showPage_GradeBook_load()
{
    $page = new PageBuilder(false);
    $courseDetails = false;
    $courseID = false;
    // Trying to view a specific course
    $courseDetails = false;
    if (isset($_GET['course_id'])) {
        $courseID = $_GET['course_id'] + 0;
        $courseDetails = WPCW_courses_getCourseDetails($courseID);
    }
    // Abort if course not found.
    if (!$courseDetails) {
        $page->showPageHeader(__('GradeBook', 'wp_courseware'), '75%', WPCW_icon_getPageIconURL());
        $page->showMessage(__('Sorry, but that course could not be found.', 'wp_courseware'), true);
        $page->showPageFooter();
        return;
    }
    // Show title of this course
    $page->showPageHeader(__('GradeBook', 'wp_courseware') . ': ' . $courseDetails->course_title, '75%', WPCW_icon_getPageIconURL());
    global $wpcwdb, $wpdb;
    $wpdb->show_errors();
    // Need a list of all quizzes for this course, excluding surveys.
    $quizzesForCourse = WPCW_quizzes_getAllQuizzesForCourse($courseDetails->course_id);
    // Handle situation when there are no quizzes.
    if (!$quizzesForCourse) {
        $page->showMessage(__('There are no quizzes for this course, therefore no grade information to show.', 'wp_courseware'), true);
        $page->showPageFooter();
        return;
    }
    // Create a simple list of IDs to use in SQL queries
    $quizIDList = array();
    foreach ($quizzesForCourse as $singleQuiz) {
        $quizIDList[] = $singleQuiz->quiz_id;
    }
    // Convert list of IDs into an SQL list
    $quizIDListForSQL = '(' . implode(',', $quizIDList) . ')';
    // Do we want certificates?
    $usingCertificates = 'use_certs' == $courseDetails->course_opt_use_certificate;
    // #### Handle checking if we're sending out any emails to users with their final grades
    // Called here so that any changes are reflected in the table using the code below.
    if ('email_grades' == WPCW_arrays_getValue($_GET, 'action')) {
        WPCW_showPage_GradeBook_handleFinalGradesEmail($courseDetails, $page);
    }
    // Get the requested page number
    $paging_pageWanted = WPCW_arrays_getValue($_GET, 'pagenum') + 0;
    if ($paging_pageWanted == 0) {
        $paging_pageWanted = 1;
    }
    // Need a count of how many there are to mark anyway, hence doing calculation.
    // Using COUNT DISTINCT so that we get a total of the different user IDs.
    // If we use GROUP BY, we end up with several rows of results.
    $userCount_toMark = $wpdb->get_var("\n\t\tSELECT COUNT(DISTINCT upq.user_id) AS user_count \n\t\tFROM {$wpcwdb->user_progress_quiz} upq\t\t\n\t\t\tLEFT JOIN {$wpdb->users} u ON u.ID = upq.user_id\t\t\t\t\t\t\t\t\t\t\t\n\t\tWHERE upq.quiz_id IN {$quizIDListForSQL}\n\t\t  AND upq.quiz_needs_marking > 0\n\t\t  AND u.ID IS NOT NULL\n\t\t  AND quiz_is_latest = 'latest'\n\t\t");
    // Count - all users for this course
    $userCount_all = $wpdb->get_var($wpdb->prepare("\n\t\tSELECT COUNT(*) AS user_count \n\t\tFROM {$wpcwdb->user_courses} uc\t\t\t\t\t\t\t\t\t\n\t\tLEFT JOIN {$wpdb->users} u ON u.ID = uc.user_id\n\t\tWHERE uc.course_id = %d\n\t\t  AND u.ID IS NOT NULL\n\t\t", $courseDetails->course_id));
    // Count - users who have completed the course.
    $userCount_completed = $wpdb->get_var($wpdb->prepare("\n\t\tSELECT COUNT(*) AS user_count \n\t\tFROM {$wpcwdb->user_courses} uc\t\t\t\t\t\t\t\t\t\n\t\tLEFT JOIN {$wpdb->users} u ON u.ID = uc.user_id\n\t\tWHERE uc.course_id = %d\n\t\t  AND u.ID IS NOT NULL\n\t\t  AND uc.course_progress = 100\n\t\t", $courseDetails->course_id));
    // Count - all users that need their final grade.
    $userCount_needGrade = $wpdb->get_var($wpdb->prepare("\n\t\tSELECT COUNT(*) AS user_count \n\t\tFROM {$wpcwdb->user_courses} uc\t\t\t\t\t\t\t\t\t\n\t\tLEFT JOIN {$wpdb->users} u ON u.ID = uc.user_id\n\t\tWHERE uc.course_id = %d\n\t\t  AND u.ID IS NOT NULL\n\t\t  AND uc.course_progress = 100\n\t\t  AND uc.course_final_grade_sent != 'sent'\n\t\t", $courseDetails->course_id));
    // SQL Code used by filters below
    $coreSQL_allUsers = $wpdb->prepare("\n\t\t\tSELECT * \n\t\t\tFROM {$wpcwdb->user_courses} uc\t\t\t\t\t\t\t\t\t\n\t\t\t\tLEFT JOIN {$wpdb->users} u ON u.ID = uc.user_id\n\t\t\tWHERE uc.course_id = %d\n\t\t\t  AND u.ID IS NOT NULL\t\t\t\n\t\t\t", $courseDetails->course_id);
    // The currently selected filter to determine what quizzes to show.
    $currentFilter = WPCW_arrays_getValue($_GET, 'filter');
    switch ($currentFilter) {
        case 'to_mark':
            // Chooses all progress where there are questions that need grading.
            // Then group by user, so that we don't show the same user twice.
            // Not added join for certificates, since they can't be complete
            // if they've got stuff to be marked.
            $coreSQL = "\n\t\t\t\tSELECT * \n\t\t\t\tFROM {$wpcwdb->user_progress_quiz} upq\t\t\t\t\t\t\t\t\t\n\t\t\t\t\tLEFT JOIN {$wpdb->users} u ON u.ID = upq.user_id\t\t\t\t\t\n\t\t\t\t\tLEFT JOIN {$wpcwdb->user_courses} uc ON uc.user_id = upq.user_id\n\t\t\t\tWHERE upq.quiz_id IN {$quizIDListForSQL}\n\t\t\t\t  AND upq.quiz_needs_marking > 0\n\t\t\t\t  AND u.ID IS NOT NULL\n\t\t\t\t  AND quiz_is_latest = 'latest'\n\t\t\t\tGROUP BY u.ID\t\t\t\t\t\t\t\t  \n\t\t\t\t";
            // No need to re-calculate, just re-use the number.
            $paging_totalCount = $userCount_toMark;
            break;
            // Completed the course
        // Completed the course
        case 'completed':
            // Same SQL as all users, but just filtering those with a progress of 100.
            $coreSQL = $coreSQL_allUsers . " \n\t\t\t\t\tAND uc.course_progress = 100\n\t\t\t\t";
            // The total number of results to show - used for paging
            $paging_totalCount = $userCount_completed;
            break;
            // Completed the course
        // Completed the course
        case 'eligible_for_final_grade':
            // Same SQL as all users, but just filtering those with a progress of 100 AND
            // needing a final grade due to flag in course_progress.
            $coreSQL = $coreSQL_allUsers . " \n\t\t\t\t\tAND uc.course_progress = 100 \n\t\t\t\t\tAND course_final_grade_sent != 'sent'\n\t\t\t\t";
            // The total number of results to show - used for paging
            $paging_totalCount = $userCount_needGrade;
            break;
            // Default to all users, regardless of what progress they've made
        // Default to all users, regardless of what progress they've made
        default:
            $currentFilter = 'all';
            // Allow the query to be modified by other plugins
            $coreSQL_filteredUsers = apply_filters("wpcw_back_query_filter_gradebook_users", $coreSQL_allUsers, $courseDetails->course_id);
            // Select all users that exist for this course
            $coreSQL = $coreSQL_filteredUsers;
            // The total number of results to show - used for paging
            $paging_totalCount = $userCount_all;
            break;
    }
    // Generate page URL
    $summaryPageURL = admin_url('admin.php?page=WPCW_showPage_GradeBook&course_id=' . $courseDetails->course_id);
    $paging_resultsPerPage = 50;
    $paging_recordStart = ($paging_pageWanted - 1) * $paging_resultsPerPage + 1;
    $paging_recordEnd = $paging_pageWanted * $paging_resultsPerPage;
    $paging_pageCount = ceil($paging_totalCount / $paging_resultsPerPage);
    $paging_sqlStart = $paging_recordStart - 1;
    // Use the main SQL from above, but limit it and order by user's name.
    $SQL = "{$coreSQL}\n\t\t\tORDER BY display_name ASC\n\t\t\tLIMIT {$paging_sqlStart}, {$paging_resultsPerPage}";
    // Generate paging code
    $baseURL = WPCW_urls_getURLWithParams($summaryPageURL, 'pagenum') . "&pagenum=";
    $paging = WPCW_tables_showPagination($baseURL, $paging_pageWanted, $paging_pageCount, $paging_totalCount, $paging_recordStart, $paging_recordEnd);
    $tbl = new TableBuilder();
    $tbl->attributes = array('id' => 'wpcw_tbl_quiz_gradebook', 'class' => 'widefat wpcw_tbl');
    $tblCol = new TableColumn(__('Learner Details', 'wp_courseware'), 'learner_details');
    $tblCol->cellClass = "wpcw_learner_details";
    $tbl->addColumn($tblCol);
    // ### Add the quiz data
    if ($quizzesForCourse) {
        // Show the overall progress for the course.
        $tblCol = new TableColumn(__('Overall Progress', 'wp_courseware'), 'course_progress');
        //$tblCol->headerClass = "wpcw_center";
        $tblCol->cellClass = "wpcw_grade_course_progress";
        $tbl->addColumn($tblCol);
        // ### Create heading for cumulative data.
        $tblCol = new TableColumn(__('Cumulative Grade', 'wp_courseware'), 'quiz_cumulative');
        $tblCol->headerClass = "wpcw_center";
        $tblCol->cellClass = "wpcw_grade_summary wpcw_center";
        $tbl->addColumn($tblCol);
        // ### Create heading for cumulative data.
        $tblCol = new TableColumn(__('Grade Sent?', 'wp_courseware'), 'grade_sent');
        $tblCol->headerClass = "wpcw_center";
        $tblCol->cellClass = "wpcw_grade_summary wpcw_center";
        $tbl->addColumn($tblCol);
        // ### Create heading for cumulative data.
        if ($usingCertificates) {
            $tblCol = new TableColumn(__('Certificate Available?', 'wp_courseware'), 'certificate_available');
            $tblCol->headerClass = "wpcw_center";
            $tblCol->cellClass = "wpcw_grade_summary wpcw_center";
            $tbl->addColumn($tblCol);
        }
        // ### Add main quiz scores
        foreach ($quizzesForCourse as $singleQuiz) {
            $tblCol = new TableColumn($singleQuiz->quiz_title, 'quiz_' . $singleQuiz->quiz_id);
            $tblCol->cellClass = "wpcw_center wpcw_quiz_grade";
            $tblCol->headerClass = "wpcw_center wpcw_quiz_grade";
            $tbl->addColumn($tblCol);
        }
    }
    $urlForQuizResultDetails = admin_url('users.php?page=WPCW_showPage_UserProgess_quizAnswers');
    $userList = $wpdb->get_results($SQL);
    if (!$userList) {
        switch ($currentFilter) {
            case 'to_mark':
                $msg = __('There are currently no quizzes that need a manual grade.', 'wp_courseware');
                break;
            case 'eligible_for_final_grade':
                $msg = __('There are currently no users that are eligible to receive their final grade.', 'wp_courseware');
                break;
            case 'completed':
                $msg = __('There are currently no users that have completed the course.', 'wp_courseware');
                break;
            default:
                $msg = __('There are currently no learners allocated to this course.', 'wp_courseware');
                break;
        }
        // Create spanning item with message - number of quizzes + fixed columns.
        $rowDataObj = new RowDataSimple('wpcw_no_users wpcw_center', $msg, count($quizIDList) + 5);
        $tbl->addRowObj($rowDataObj);
    } else {
        // ### Format main row data and show it.
        $odd = false;
        foreach ($userList as $singleUser) {
            $data = array();
            // Basic Details with avatar
            $data['learner_details'] = sprintf('
				%s
				<span class="wpcw_col_cell_name">%s</span>
				<span class="wpcw_col_cell_username">%s</span>
				<span class="wpcw_col_cell_email"><a href="mailto:%s" target="_blank">%s</a></span></span>
			', get_avatar($singleUser->ID, 48), $singleUser->display_name, $singleUser->user_login, $singleUser->user_email, $singleUser->user_email);
            // Get the user's progress for the quizzes.
            if ($quizzesForCourse) {
                $quizResults = WPCW_quizzes_getQuizResultsForUser($singleUser->ID, $quizIDListForSQL);
                // Track cumulative data
                $quizScoresSoFar = 0;
                $quizScoresSoFar_count = 0;
                // ### Now render results for each quiz
                foreach ($quizIDList as $aQuizID) {
                    // Got progress data, process the result
                    if (isset($quizResults[$aQuizID])) {
                        // Extract results and unserialise the data array.
                        $theResults = $quizResults[$aQuizID];
                        $theResults->quiz_data = maybe_unserialize($theResults->quiz_data);
                        $quizDetailURL = sprintf('%s&user_id=%d&quiz_id=%d&unit_id=%d', $urlForQuizResultDetails, $singleUser->ID, $theResults->quiz_id, $theResults->unit_id);
                        // We've got something that needs grading. So render link to where the quiz can be graded.
                        if ($theResults->quiz_needs_marking > 0) {
                            $data['quiz_' . $aQuizID] = sprintf('<span class="wpcw_grade_needs_grading"><a href="%s">%s</span>', $quizDetailURL, __('Manual Grade Required', 'wp_courseware'));
                        } else {
                            if ('quiz_fail_no_retakes' == $theResults->quiz_next_step_type) {
                                $data['quiz_' . $aQuizID] = sprintf('<span class="wpcw_grade_needs_grading"><a href="%s">%s</span>', $quizDetailURL, __('Quiz Retakes Exhausted', 'wp_courseware'));
                            } else {
                                if ('incomplete' == $theResults->quiz_paging_status) {
                                    $data['quiz_' . $aQuizID] = '<span class="wpcw_grade_not_taken">' . __('In Progress', 'wp_courseware') . '</span>';
                                } else {
                                    // Use grade for cumulative grade
                                    $score = number_format($quizResults[$aQuizID]->quiz_grade, 1);
                                    $quizScoresSoFar += $score;
                                    $quizScoresSoFar_count++;
                                    // Render score and link to the full test data.
                                    $data['quiz_' . $aQuizID] = sprintf('<span class="wpcw_grade_valid"><a href="%s">%s%%</span>', $quizDetailURL, $score);
                                }
                            }
                        }
                    } else {
                        $data['quiz_' . $aQuizID] = '<span class="wpcw_grade_not_taken">' . __('Not Taken', 'wp_courseware') . '</span>';
                    }
                }
                // #### Show the cumulative quiz results.
                $data['quiz_cumulative'] = '-';
                if ($quizScoresSoFar_count > 0) {
                    $data['quiz_cumulative'] = '<span class="wpcw_grade_valid">' . number_format($quizScoresSoFar / $quizScoresSoFar_count, 1) . '%</span>';
                }
            }
            // ####ÊUser Progress
            $data['course_progress'] = WPCW_stats_convertPercentageToBar($singleUser->course_progress);
            // #### Grade Sent?
            $data['grade_sent'] = 'sent' == $singleUser->course_final_grade_sent ? __('Yes', 'wp_courseware') : '-';
            // #### Certificate - Show if there's a certificate that can be downloaded.
            if ($usingCertificates && ($certDetails = WPCW_certificate_getCertificateDetails($singleUser->ID, $courseDetails->course_id, false))) {
                $data['certificate_available'] = sprintf('<a href="%s" title="%s">%s</a>', WPCW_certificate_generateLink($certDetails->cert_access_key), __('Download the certificate for this user.', 'wp_courseware'), __('Yes', 'wp_courseware'));
            } else {
                $data['certificate_available'] = '-';
            }
            // Odd/Even row colouring.
            $odd = !$odd;
            $tbl->addRow($data, $odd ? 'alternate' : '');
        }
        // single user
    }
    // Check we have some users.
    // Here are the action buttons for Gradebook.
    printf('<div class="wpcw_button_group">');
    // Button to generate a CSV of the gradebook.
    printf('<a href="%s" class="button-primary">%s</a>&nbsp;&nbsp;', admin_url('?wpcw_export=gradebook_csv&course_id=' . $courseDetails->course_id), __('Export Gradebook (CSV)', 'wp_courseware'));
    printf('<a href="%s" class="button-primary">%s</a>&nbsp;&nbsp;', admin_url('admin.php?page=WPCW_showPage_GradeBook&action=email_grades&filter=all&course_id=' . $courseDetails->course_id), __('Email Final Grades', 'wp_courseware'));
    // URL that shows the eligible users who are next to get the email for the final grade.
    $eligibleURL = sprintf(admin_url('admin.php?page=WPCW_showPage_GradeBook&course_id=%d&filter=eligible_for_final_grade'), $courseDetails->course_id);
    // Create information about how people are chosen to send grades to.
    printf('<div id="wpcw_button_group_info_gradebook" class="wpcw_button_group_info">%s</div>', sprintf(__('Grades will only be emailed to students who have <b>completed the course</b> and who have <b>not yet received</b> their final grade. 
			   You can see the students who are <a href="%s">eligible to receive the final grade email</a> here.', 'wp_courseware'), $eligibleURL));
    printf('</div>');
    echo $paging;
    // Show the filtering to selectively show different quizzes
    // Filter list can be modified to indicate Group's name instead of 'all'
    $filters_list = array('all' => sprintf(__('All (%d)', 'wp_courseware'), $userCount_all), 'completed' => sprintf(__('Completed (%d)', 'wp_courseware'), $userCount_completed), 'eligible_for_final_grade' => sprintf(__('Eligible for Final Grade Email (%d)', 'wp_courseware'), $userCount_needGrade), 'to_mark' => sprintf(__('Just Quizzes that Need Marking (%d)', 'wp_courseware'), $userCount_toMark));
    // Allow the filters to be customised
    $filters_list = apply_filters("wpcw_back_filters_gradebook_filters", $filters_list, $courseDetails->course_id);
    echo WPCW_table_showFilters($filters_list, WPCW_urls_getURLWithParams($summaryPageURL, 'filter') . "&filter=", $currentFilter);
    // Finally show table
    echo $tbl->toString();
    echo $paging;
    $page->showPageFooter();
}
コード例 #3
0
/**
 * Function to show a list of questions in the question pool for use by a standard page or the AJAX thickbox.
 * 
 * @param Integer $itemsPerPage The number of items to show on each table page.
 * @param Array $paramSrc The array of parameters to use for filtering/searching the question pool.
 * @param String $actionMode The type of mode we're in (ajax or std). 
 * @param PageBuilder $page The current page object (optional).
 */
function WPCW_questionPool_showPoolTable($itemsPerPage, $paramSrc, $actionMode = 'std', $page = false)
{
    global $wpcwdb, $wpdb;
    $wpdb->show_errors();
    // AJAX loader
    if ('ajax' == $actionMode) {
        printf('<img src="%simg/ajax_loader.gif" class="wpcw_loader" style="display: none;" />', WPCW_plugin_getPluginPath());
    }
    // Check to see if we've got questions to process
    if ('std' == $actionMode) {
        WPCW_showPage_QuestionPool_processActionForm($page);
    }
    $paging_pageWanted = WPCW_arrays_getValue($paramSrc, 'pagenum') + 0;
    if ($paging_pageWanted == 0) {
        $paging_pageWanted = 1;
    }
    // Handle the sorting and filtering
    $orderBy = WPCW_arrays_getValue($paramSrc, 'orderby');
    $ordering = WPCW_arrays_getValue($paramSrc, 'order');
    // Validate ordering
    switch ($orderBy) {
        case 'question_question':
        case 'question_type':
            break;
            // Default and question_id
            //case 'question_id':
        // Default and question_id
        //case 'question_id':
        default:
            $orderBy = 'qs.question_id';
            break;
    }
    // Create opposite ordering for reversing it.
    $ordering_opposite = false;
    switch ($ordering) {
        case 'desc':
            $ordering_opposite = 'asc';
            break;
        case 'asc':
            $ordering_opposite = 'desc';
            break;
        default:
            $ordering = 'desc';
            $ordering_opposite = 'asc';
            break;
    }
    // Was a search string specified? Or a specific item?
    $searchString = WPCW_arrays_getValue($paramSrc, 's');
    // Create WHERE string based search - Title or Description of Quiz
    $SQL_WHERE = false;
    if ($searchString) {
        $SQL_WHERE = $wpdb->prepare(" AND question_question LIKE %s", '%' . $searchString . '%');
    }
    $summaryPageURL = admin_url('admin.php?page=WPCW_showPage_QuestionPool');
    // Show the form for searching
    ?>
			
	<form id="wpcw_questions_search_box" method="get" action="<?php 
    echo $summaryPageURL;
    ?>
">
	<p class="search-box">
		<label class="screen-reader-text" for="wpcw_questions_search_input"><?php 
    _e('Search Questions', 'wp_courseware');
    ?>
</label>
		<input id="wpcw_questions_search_input" type="text" value="<?php 
    echo $searchString;
    ?>
" name="s"/>
		<input class="button" type="submit" value="<?php 
    _e('Search Questions', 'wp_courseware');
    ?>
"/>
		
		<input type="hidden" name="page" value="WPCW_showPage_QuestionPool" />
	</p>
	</form>
	<?php 
    $SQL_TAG_FILTER = false;
    $tagFilter = intval(WPCW_arrays_getValue($paramSrc, 'filter', false));
    // See if we have any tag filtering to do.
    if ($tagFilter > 0) {
        // Ensure we add the tag mapping table to the query
        $SQL_TAG_FILTER = "\n\t\t\tLEFT JOIN {$wpcwdb->question_tag_mapping} qtm ON qtm.question_id = qs.question_id\t\n\t\t";
        $SQL_WHERE .= $wpdb->prepare("\n\t\t\tAND qtm.tag_id = %d\n\t\t\tAND qs.question_question IS NOT NULL  \n\t\t", $tagFilter);
        //
    }
    $SQL_PAGING = "\n\t\t\tSELECT COUNT(*) as question_count \n\t\t\tFROM {$wpcwdb->quiz_qs} qs\n\t\t\t{$SQL_TAG_FILTER}\n\t\t\tWHERE question_type <> 'random_selection'\n\t\t\t{$SQL_WHERE} \n\t\t";
    $paging_resultsPerPage = $itemsPerPage;
    $paging_totalCount = $wpdb->get_var($SQL_PAGING);
    $paging_recordStart = ($paging_pageWanted - 1) * $paging_resultsPerPage + 1;
    $paging_recordEnd = $paging_pageWanted * $paging_resultsPerPage;
    $paging_pageCount = ceil($paging_totalCount / $paging_resultsPerPage);
    $paging_sqlStart = $paging_recordStart - 1;
    // Show search message - that a search has been tried.
    if ($searchString) {
        printf('<div class="wpcw_search_count">%s "%s" (%s %s) (<a href="%s">%s</a>)</div>', __('Search results for', 'wp_courseware'), htmlentities($searchString), $paging_totalCount, _n('result', 'results', $paging_totalCount, 'wp_courseware'), $summaryPageURL, __('reset', 'wp_courseware'));
    }
    // Do main query
    $SQL = "SELECT * \n\t\t\tFROM {$wpcwdb->quiz_qs} qs\t\t\t\n\t\t\t{$SQL_TAG_FILTER}\t\t\t\n\t\t\tWHERE question_type <> 'random_selection'\n\t\t\t{$SQL_WHERE}\n\t\t\tORDER BY {$orderBy} {$ordering}\n\t\t\tLIMIT {$paging_sqlStart}, {$paging_resultsPerPage}\t\t\t \n\t\t\t";
    // These are already checked, so they are safe, hence no prepare()
    // Generate paging code
    $baseURL = WPCW_urls_getURLWithParams($summaryPageURL, 'pagenum') . "&pagenum=";
    $questions = $wpdb->get_results($SQL);
    $tbl = new TableBuilder();
    $tbl->attributes = array('id' => 'wpcw_tbl_question_pool', 'class' => 'widefat wpcw_tbl');
    // Checkbox Col
    //$tblCol = new TableColumn(false, 'question_selection');
    //$tblCol->cellClass = "question_selection wpcw_center";
    //$tbl->addColumn($tblCol);
    // Wanting sorting links... in standard mode
    if ('std' == $actionMode) {
        // Checkbox field (no name, as we'll use jQuery to do a check all)
        $tblCol = new TableColumn('<input type="checkbox" />', 'question_id_cb');
        $tblCol->cellClass = "wpcw_center wpcw_select_cb";
        $tblCol->headerClass = "wpcw_center wpcw_select_cb";
        $tbl->addColumn($tblCol);
        // ID - sortable
        $sortableLink = sprintf('<a href="%s&order=%s&orderby=question_id"><span>%s</span><span class="sorting-indicator"></span></a>', $baseURL, 'question_id' == $orderBy ? $ordering_opposite : 'asc', __('ID', 'wp_courseware'));
        // ID - render
        $tblCol = new TableColumn($sortableLink, 'question_id');
        $tblCol->headerClass = 'question_id' == $orderBy ? 'sorted ' . $ordering : 'sortable';
        $tblCol->cellClass = "question_id";
        $tbl->addColumn($tblCol);
        // Question - sortable
        $sortableLink = sprintf('<a href="%s&order=%s&orderby=question_question"><span>%s</span><span class="sorting-indicator"></span></a>', $baseURL, 'question_question' == $orderBy ? $ordering_opposite : 'asc', __('Question', 'wp_courseware'));
        // Question - render
        $tblCol = new TableColumn($sortableLink, 'question_question');
        $tblCol->headerClass = 'question_question' == $orderBy ? 'sorted ' . $ordering : 'sortable';
        $tblCol->cellClass = "question_question";
        $tbl->addColumn($tblCol);
        // Question Type - sortable
        $sortableLink = sprintf('<a href="%s&order=%s&orderby=question_type"><span>%s</span><span class="sorting-indicator"></span></a>', $baseURL, 'question_type' == $orderBy ? $ordering_opposite : 'asc', __('Question Type', 'wp_courseware'));
        // Question Type - render
        $tblCol = new TableColumn($sortableLink, 'question_type');
        $tblCol->headerClass = ('question_type' == $orderBy ? 'sorted ' . $ordering : 'sortable') . ' wpcw_center';
        $tblCol->cellClass = "question_type";
        $tbl->addColumn($tblCol);
    } else {
        $tblCol = new TableColumn(__('ID', 'wp_courseware'), 'question_id');
        $tblCol->cellClass = "question_id";
        $tbl->addColumn($tblCol);
        $tblCol = new TableColumn(__('Question', 'wp_courseware'), 'question_question');
        $tblCol->cellClass = "question_question";
        $tbl->addColumn($tblCol);
        $tblCol = new TableColumn(__('Question Type', 'wp_courseware'), 'question_type');
        $tblCol->cellClass = "question_type";
        $tbl->addColumn($tblCol);
    }
    $tblCol = new TableColumn(__('Associated Quizzes', 'wp_courseware'), 'associated_quizzes');
    $tblCol->headerClass = "wpcw_center";
    $tblCol->cellClass = "associated_quizzes wpcw_center";
    $tbl->addColumn($tblCol);
    $tblCol = new TableColumn(__('Tags', 'wp_courseware'), 'question_tags');
    $tblCol->cellClass = "question_tags wpcw_center";
    $tbl->addColumn($tblCol);
    // Actions
    $tblCol = new TableColumn(__('Actions', 'wp_courseware'), 'actions');
    $tblCol->cellClass = "actions actions_right";
    $tblCol->headerClass = "actions_right";
    $tbl->addColumn($tblCol);
    // Stores course details in a mini cache to save lots of MySQL lookups.
    $miniCourseDetailCache = array();
    // Format row data and show it.
    if ($questions) {
        $odd = false;
        foreach ($questions as $singleQuestion) {
            $data = array();
            // URLs
            $editURL = admin_url('admin.php?page=WPCW_showPage_ModifyQuestion&question_id=' . $singleQuestion->question_id);
            // Maintain paging where possible.
            $deleteURL = $baseURL . '&action=delete&question_id=' . $singleQuestion->question_id;
            // Basic Details
            $data['question_id'] = $singleQuestion->question_id;
            $data['question_type'] = WPCW_quizzes_getQuestionTypeName($singleQuestion->question_type);
            $data['question_id_cb'] = sprintf('<input type="checkbox" name="question_%d" />', $singleQuestion->question_id);
            // Association Count
            $data['associated_quizzes'] = $singleQuestion->question_usage_count;
            // Actions - Std mode
            if ('std' == $actionMode) {
                // Edit by clicking
                $data['question_question'] = sprintf('<a href="%s">%s</a>', $editURL, $singleQuestion->question_question);
                $data['actions'] = '<ul class="wpcw_action_link_list">';
                $data['actions'] .= sprintf('<li><a href="%s" class="button-primary">%s</a></li>', $editURL, __('Edit', 'wp_courseware'));
                $data['actions'] .= sprintf('<li><a href="%s" class="button-secondary wpcw_action_link_delete_question wpcw_action_link_delete" rel="%s">%s</a></li>', $deleteURL, __('Are you sure you wish to delete this question? This cannot be undone.', 'wp_courseware'), __('Delete', 'wp_courseware'));
                $data['actions'] .= '</ul>';
            } else {
                if ('ajax' == $actionMode) {
                    // No Edit by clicking
                    $data['question_question'] = $singleQuestion->question_question . sprintf('<span class="wpcw_action_status wpcw_action_status_added">%s</span>', __('Added', 'wp_courseware'));
                    $data['actions'] = '<ul class="wpcw_action_link_list">';
                    $data['actions'] .= sprintf('<li><a href="#" class="button-primary wpcw_tb_action_add" data-questionnum="%d">%s</a></li>', $singleQuestion->question_id, __('Add To Quiz', 'wp_courseware'));
                    $data['actions'] .= '</ul>';
                }
            }
            // Tags
            $data['question_tags'] = sprintf('<span class="wpcw_quiz_details_question_tags" data-questionid="%d" id="wpcw_quiz_details_question_tags_%d">', $singleQuestion->question_id, $singleQuestion->question_id);
            $data['question_tags'] .= WPCW_questions_tags_render($singleQuestion->question_id, WPCW_questions_tags_getTagsForQuestion($singleQuestion->question_id));
            $data['question_tags'] .= '</span>';
            // Odd/Even row colouring.
            $odd = !$odd;
            $tbl->addRow($data, $odd ? 'alternate' : '');
        }
    } else {
        // No questions - show error in table.
        $tbl->addRowObj(new RowDataSimple('wpcw_center wpcw_none_found', __('There are currently no questions to show.', 'wp_courseware'), 7));
    }
    // Add the form for the start of the multiple-add
    $formWrapper_start = false;
    if ('std' == $actionMode) {
        // Set the action URL to preserve parameters that we have.
        $formWrapper_start = sprintf('<form method="POST" action="%s">', WPCW_urls_getURLWithParams($summaryPageURL, 'pagenum'));
    }
    // Create tag filter (uses a form)
    $tagFilter = WPCW_questions_tags_createTagFilter($tagFilter, 'WPCW_showPage_QuestionPool');
    // Work out paging and filtering
    $paging = WPCW_tables_showPagination($baseURL, $paging_pageWanted, $paging_pageCount, $paging_totalCount, $paging_recordStart, $paging_recordEnd, $tagFilter);
    // Show the actions
    $formWrapper_end = false;
    if ('std' == $actionMode) {
        $formWrapper_end = WPCW_showPage_QuestionPool_actionForm();
        // Form tag - needed for processing
        $formWrapper_end .= '</form>';
    }
    // Finally show table
    return $paging . $formWrapper_start . $tbl->toString() . $formWrapper_end . $paging;
}