当前位置: 首页>>代码示例>>PHP>>正文


PHP WooThemes_Sensei_Utils::user_lesson_status方法代码示例

本文整理汇总了PHP中WooThemes_Sensei_Utils::user_lesson_status方法的典型用法代码示例。如果您正苦于以下问题:PHP WooThemes_Sensei_Utils::user_lesson_status方法的具体用法?PHP WooThemes_Sensei_Utils::user_lesson_status怎么用?PHP WooThemes_Sensei_Utils::user_lesson_status使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WooThemes_Sensei_Utils的用法示例。


在下文中一共展示了WooThemes_Sensei_Utils::user_lesson_status方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: lesson_quiz_questions

 /**
  * Fetches all the questions for a quiz depending on certain conditions.
  *
  * Determine which questions should be shown depending on:
  * - admin/teacher selected questions to be shown
  * - questions shown to a user previously (saved as asked questions)
  * - limit number of questions lesson setting
  *
  * @since 1.0
  * @param int $quiz_id (default: 0)
  * @param string $post_status (default: 'publish')
  * @param string $orderby (default: 'meta_value_num title')
  * @param string $order (default: 'ASC')
  *
  * @return array $questions { $question type WP_Post }
  */
 public function lesson_quiz_questions($quiz_id = 0, $post_status = 'any', $orderby = 'meta_value_num title', $order = 'ASC')
 {
     $quiz_id = (string) $quiz_id;
     $quiz_lesson_id = get_post_meta($quiz_id, '_quiz_lesson', true);
     // setup the user id
     if (is_admin()) {
         $user_id = isset($_GET['user']) ? $_GET['user'] : '';
     } else {
         $user_id = get_current_user_id();
     }
     // Set the default quesiton order if it has not already been set for this quiz
     $this->set_default_question_order($quiz_id);
     // If viewing quiz on the frontend then show questions in random order if set
     if (!is_admin()) {
         $random_order = get_post_meta($quiz_id, '_random_question_order', true);
         if ($random_order && $random_order == 'yes') {
             $orderby = 'rand';
         }
     }
     // Get all questions and multiple questions
     $question_query_args = array('post_type' => array('question', 'multiple_question'), 'posts_per_page' => -1, 'meta_key' => '_quiz_question_order' . $quiz_id, 'orderby' => $orderby, 'order' => $order, 'meta_query' => array(array('key' => '_quiz_id', 'value' => $quiz_id)), 'post_status' => $post_status, 'suppress_filters' => 0);
     //query the questions
     $questions_query = new WP_Query($question_query_args);
     // Set return array to initially include all items
     $questions = $questions_query->posts;
     // set the questions array that will be manipulated within this function
     $questions_array = $questions_query->posts;
     // If viewing quiz on frontend or in grading then only single questions must be shown
     $selected_questions = false;
     if (!is_admin() || is_admin() && isset($_GET['page']) && 'sensei_grading' == $_GET['page'] && isset($_GET['user']) && isset($_GET['quiz_id'])) {
         // Fetch the questions that the user was asked in their quiz if they have already completed it
         $lesson_status = WooThemes_Sensei_Utils::user_lesson_status($quiz_lesson_id, $user_id);
         $questions_asked_string = !empty($lesson_status->comment_ID) ? get_comment_meta($lesson_status->comment_ID, 'questions_asked', true) : false;
         if (!empty($questions_asked_string)) {
             $selected_questions = explode(',', $questions_asked_string);
             // Fetch each question in the order in which they were asked
             $questions = array();
             foreach ($selected_questions as $question_id) {
                 if (!$question_id) {
                     continue;
                 }
                 $question = get_post($question_id);
                 if (!isset($question) || !isset($question->ID)) {
                     continue;
                 }
                 $questions[] = $question;
             }
         } else {
             // Otherwise, make sure that we convert all multiple questions into single questions
             $multiple_array = array();
             $existing_questions = array();
             // Set array of questions that already exist so we can prevent duplicates from appearing
             foreach ($questions_array as $question) {
                 if ('question' != $question->post_type) {
                     continue;
                 }
                 $existing_questions[] = $question->ID;
             }
             // Include only single questions in the return array
             $questions_loop = $questions_array;
             $questions_array = array();
             foreach ($questions_loop as $k => $question) {
                 // If this is a single question then include it
                 if ('question' == $question->post_type) {
                     $questions_array[] = $question;
                 } else {
                     // If this is a multiple question then get the specified amount of questions from the specified category
                     $question_cat = intval(get_post_meta($question->ID, 'category', true));
                     $question_number = intval(get_post_meta($question->ID, 'number', true));
                     $qargs = array('post_type' => 'question', 'posts_per_page' => $question_number, 'orderby' => $orderby, 'tax_query' => array(array('taxonomy' => 'question-category', 'field' => 'term_id', 'terms' => $question_cat)), 'post_status' => $post_status, 'suppress_filters' => 0, 'post__not_in' => $existing_questions);
                     $cat_questions = get_posts($qargs);
                     // Merge results into return array
                     $questions_array = array_merge($questions_array, $cat_questions);
                     // Add selected questions to existing questions array to prevent duplicates from being added
                     foreach ($questions_array as $cat_question) {
                         if (in_array($cat_question->ID, $existing_questions)) {
                             continue;
                         }
                         $existing_questions[] = $cat_question->ID;
                     }
                 }
             }
             // Set return data
             $questions = $questions_array;
//.........这里部分代码省略.........
开发者ID:grey-rsi,项目名称:sensei,代码行数:101,代码来源:class-woothemes-sensei-lesson.php

示例2: calculate_user_module_progress_custom

 public function calculate_user_module_progress_custom($user_id, $module_id, $course_id)
 {
     $lessons = Sensei_Core_Modules::get_lessons($course_id, $module_id);
     //if (is_wp_error($lessons) || 0 >= count($lessons)) return 0;
     $completed = false;
     $lesson_count = 0;
     $completed_count = 0;
     $strcom = '';
     foreach ($lessons as $lesson) {
         $lesson_id = $lesson->ID;
         $lesson_id = (int) $lesson_id;
         $quiz_id = WooThemes_Sensei_Lesson::lesson_quizzes($lesson_id, $post_status = 'any');
         $quiz_id = (int) $quiz_id;
         $lesson_quiz_questions = WooThemes_Sensei_Utils::sensei_get_quiz_questions($quiz_id);
         if (count($lesson_quiz_questions) > 0) {
             $lesson_status = WooThemes_Sensei_Utils::user_lesson_status($lesson_id, $user_id);
             $lesson_status = $lesson_status->comment_approved;
             ++$lesson_count;
             if ($lesson_status == 'passed') {
                 ++$completed_count;
             } else {
                 $question = $lesson_quiz_questions[0];
                 $question_title = $question->post_title;
                 if ($question_title == 'Offline Upload') {
                     ++$completed_count;
                 }
                 //$strcom = $strcom.' -- Lesson ID: '.$lesson_id.' '.print_r($lesson_quiz_questions, true);
             }
         }
         //$strcom = $strcom.' -- '.$user_id.' '.$lesson_id.' '.$lesson_status. ' '.print_r($lesson_quizzes, true);
     }
     $module_progress = $completed_count / $lesson_count * 100;
     return (double) $module_progress;
     //return $strcom;
 }
开发者ID:Ezyva2015,项目名称:opendooronline.com.au,代码行数:35,代码来源:class-woothemes-sensei-grading.php

示例3: sensei_quiz_action_buttons

    public function sensei_quiz_action_buttons()
    {
        global $post, $current_user, $woothemes_sensei;
        $lesson_id = (int) get_post_meta($post->ID, '_quiz_lesson', true);
        $lesson_course_id = (int) get_post_meta($lesson_id, '_lesson_course', true);
        $lesson_prerequisite = (int) get_post_meta($lesson_id, '_lesson_prerequisite', true);
        $show_actions = true;
        $user_lesson_status = WooThemes_Sensei_Utils::user_lesson_status($lesson_id, $current_user->ID);
        //setup quiz grade
        $user_quiz_grade = '';
        if (!empty($user_lesson_status)) {
            $user_quiz_grade = get_comment_meta($user_lesson_status->comment_ID, 'grade', true);
        }
        if (intval($lesson_prerequisite) > 0) {
            // If the user hasn't completed the prereq then hide the current actions
            $show_actions = WooThemes_Sensei_Utils::user_completed_lesson($lesson_prerequisite, $current_user->ID);
        }
        if ($show_actions && is_user_logged_in() && WooThemes_Sensei_Utils::user_started_course($lesson_course_id, $current_user->ID)) {
            // Get Reset Settings
            $reset_quiz_allowed = get_post_meta($post->ID, '_enable_quiz_reset', true);
            ?>

            <!-- Action Nonce's -->
            <input type="hidden" name="woothemes_sensei_complete_quiz_nonce" id="woothemes_sensei_complete_quiz_nonce"
                   value="<?php 
            echo esc_attr(wp_create_nonce('woothemes_sensei_complete_quiz_nonce'));
            ?>
" />
			<input type="hidden" name="woothemes_sensei_reset_quiz_nonce" id="woothemes_sensei_reset_quiz_nonce"
                   value="<?php 
            echo esc_attr(wp_create_nonce('woothemes_sensei_reset_quiz_nonce'));
            ?>
" />
            <input type="hidden" name="woothemes_sensei_save_quiz_nonce" id="woothemes_sensei_save_quiz_nonce"
                   value="<?php 
            echo esc_attr(wp_create_nonce('woothemes_sensei_save_quiz_nonce'));
            ?>
" />
            <!--#end Action Nonce's -->

            <?php 
            //if ( '' == $user_quiz_grade) {
            ?>
		 	<span><input type="submit" name="quiz_complete" class="quiz-submit complete" value="<?php 
            echo apply_filters('sensei_complete_quiz_text', __('Complete Quiz', 'woothemes-sensei'));
            ?>
"/></span>
		 	<span><input type="submit" name="quiz_save" class="quiz-submit save" value="<?php 
            echo apply_filters('sensei_save_quiz_text', __('Save Quiz', 'woothemes-sensei'));
            ?>
"/></span>
		     <?php 
            php;
            ?>
	          <?php 
            php;
            ?>
		 	   <span><input type="submit" name="quiz_reset" class="quiz-submit reset" value="<?php 
            echo apply_filters('sensei_reset_quiz_text', __('Reset Quiz', 'woothemes-sensei'));
            ?>
"/></span>
		     <?php 
            php;
            ?>
        <?php 
        }
    }
开发者ID:Ezyva2015,项目名称:opendooronline.com.au,代码行数:67,代码来源:class-woothemes-sensei-frontend.php

示例4: savedquest_options


//.........这里部分代码省略.........
        }
        ?>

		</table><br /><br />


	<?php 
    } elseif ($tab == "timequizecompleted") {
        global $woothemes_sensei, $post, $current_user, $wp_query, $learner_user;
        echo "<table class='wp-list-table widefat fixed striped pages'>";
        $allUsers = get_users();
        echo "<tr>\r\r\n\t\t\t\t<th>User</th>\r\r\n\t\t\t\t<th>Courses</th>\r\r\n\t\t\t\t<th>Percentage Incomplete</th>\r\r\n\t\t\t\t<th>Percentage Complete</th>\r\r\n\t\t\t\t<th>Percentage Competent</th>\r\r\n\t\t\t\t<th>Percentage Attempted</th>\r\r\n\t\t\t\t<th>Length of time Course Completed</th>\r\r\n\t\t\t  </tr>";
        foreach ($allUsers as $user) {
            $args = array('post_type' => 'course');
            $courses = get_posts($args);
            $i = 1;
            foreach ($courses as $course) {
                $course_user_grade = WooThemes_Sensei_Utils::sensei_course_user_grade($course->ID, $user->ID);
                $course_status = WooThemes_Sensei_Utils::user_course_status($course->ID, $user->ID);
                $course_status_update = get_comment_meta($course_status->comment_ID);
                if (!empty($course_status)) {
                    $displayed_lessons = array();
                    $modules = Sensei()->modules->get_course_modules(intval($course->ID));
                    foreach ($modules as $module) {
                        $args = array('post_type' => 'lesson', 'post_status' => 'publish', 'posts_per_page' => -1, 'meta_query' => array(array('key' => '_lesson_course', 'value' => intval($course->ID), 'compare' => '=')), 'tax_query' => array(array('taxonomy' => Sensei()->modules->taxonomy, 'field' => 'id', 'terms' => intval($module->term_id))), 'meta_key' => '_order_module_' . $module->term_id, 'orderby' => 'meta_value_num date', 'order' => 'ASC', 'suppress_filters' => 0);
                        $lessons = get_posts($args);
                        if (count($lessons) > 0) {
                            $html .= '<h3>' . $module->name . '</h3>' . "\n";
                            $count = 0;
                            foreach ($lessons as $lesson_item) {
                                $lesson_grade = ' n/a';
                                $has_questions = get_post_meta($lesson_item->ID, '_quiz_has_questions', true);
                                if ($has_questions) {
                                    $lesson_status = WooThemes_Sensei_Utils::user_lesson_status($lesson_item->ID, $user->ID);
                                    // Get user quiz grade
                                    $lesson_grade = get_comment_meta($lesson_status->comment_ID, 'grade', true);
                                    if ($lesson_grade) {
                                        $lesson_grade .= '%';
                                    }
                                    $modulequizdata = get_comment_meta($lesson_status->comment_ID);
                                    //echo "<a href='".get_post_permalink($lesson_item->ID)."'>".$lesson_item->post_title."</a><br />";
                                    $modulequestion_asked = count(explode(",", $modulequizdata['questions_asked'][0]));
                                    $moduleanswered_quiz = count(unserialize($modulequizdata['quiz_answers'][0]));
                                    //echo "number of questions:".$modulequestion_asked."<br />";
                                    //echo "number of Answered:".$moduleanswered_quiz."<br />";
                                    if ($course_status->comment_approved == "complete") {
                                        $attempted = "(100%)";
                                    } else {
                                        if ($modulequizdata['grade'][0] == "") {
                                            if ($lesson_status->comment_approved == "passed") {
                                                $attempted = 'P/Q';
                                            } else {
                                                if ($modulequestion_asked >= $moduleanswered_quiz) {
                                                    if ($modulequizdata['quiz_answers'][0] == "") {
                                                        $attempted = "";
                                                    } else {
                                                        $attempted = "( " . get_percentage($modulequestion_asked, $moduleanswered_quiz) . "% ) Saved";
                                                    }
                                                }
                                            }
                                        } else {
                                            $attempted = "( " . get_percentage($modulequestion_asked, $moduleanswered_quiz) . "% )";
                                        }
                                        //echo "<pre>";
                                        //echo "Attempted:".$attempted."<br />";
                                        //echo $user->user_email."<br />";
开发者ID:Ezyva2015,项目名称:opendooronline.com.au,代码行数:67,代码来源:fp-sensei-extended-function.php

示例5: user_passed_quiz

 public static function user_passed_quiz($quiz_id = 0, $user_id = 0)
 {
     if (!$quiz_id) {
         return false;
     }
     if (!$user_id) {
         $user_id = get_current_user_id();
     }
     $lesson_id = get_post_meta($quiz_id, '_quiz_lesson', true);
     // Quiz Grade
     $lesson_status = WooThemes_Sensei_Utils::user_lesson_status($lesson_id, $user_id);
     $quiz_grade = get_comment_meta($lesson_status->comment_ID, 'grade', true);
     // Check if Grade is greater than or equal to pass percentage
     $quiz_passmark = abs(round(doubleval(get_post_meta($quiz_id, '_quiz_passmark', true)), 2));
     if ($quiz_passmark <= intval($quiz_grade)) {
         return true;
     }
     return false;
 }
开发者ID:grey-rsi,项目名称:sensei,代码行数:19,代码来源:class-woothemes-sensei-utils.php

示例6: sensei_complete_quiz


//.........这里部分代码省略.........
                    // Grade quiz
                    // 3rd arg is count of total number of questions but it's not used by sensei_grade_quiz_auto()
                    $grade = WooThemes_Sensei_Utils::sensei_grade_quiz_auto($post->ID, $_POST['sensei_question'], count($lesson_quiz_questions), $quiz_grade_type);
                    $lesson_metadata = array();
                    // Get Lesson Grading Setting
                    if (is_wp_error($grade) || 'auto' != $quiz_grade_type) {
                        $lesson_status = 'ungraded';
                        // Quiz is manually graded and this was a user submission
                    } else {
                        // Quiz has been automatically Graded
                        if ($pass_required) {
                            // Student has reached the pass mark and lesson is complete
                            if ($quiz_passmark <= $grade) {
                                $lesson_status = 'passed';
                            } else {
                                $lesson_status = 'failed';
                            }
                            // End If Statement
                        } else {
                            $lesson_status = 'graded';
                        }
                        $lesson_metadata['grade'] = $grade;
                        // Technically already set as part of "WooThemes_Sensei_Utils::sensei_grade_quiz_auto()" above
                    }
                    WooThemes_Sensei_Utils::update_lesson_status($current_user->ID, $quiz_lesson_id, $lesson_status, $lesson_metadata);
                    switch ($lesson_status) {
                        case 'passed':
                        case 'graded':
                            do_action('sensei_user_lesson_end', $current_user->ID, $quiz_lesson_id);
                            break;
                    }
                    do_action('sensei_user_quiz_submitted', $current_user->ID, $post->ID, $grade, $quiz_passmark, $quiz_grade_type);
                    break;
                case apply_filters('sensei_save_quiz_text', __('Save Quiz', 'woothemes-sensei')):
                    $activity_logged = WooThemes_Sensei_Utils::sensei_start_lesson($quiz_lesson_id);
                    if ($activity_logged) {
                        // Save questions that were asked in this quiz
                        if (!empty($questions_asked_string)) {
                            update_comment_meta($activity_logged, 'questions_asked', $questions_asked_string);
                        }
                        if (isset($_POST['sensei_question'])) {
                            WooThemes_Sensei_Utils::sensei_save_quiz_answers($_POST['sensei_question']);
                        }
                    }
                    // Need message in case the data wasn't saved?
                    $this->messages = '<div class="sensei-message note">' . apply_filters('sensei_quiz_saved_text', __('Quiz Saved Successfully.', 'woothemes-sensei')) . '</div>';
                    break;
                case apply_filters('sensei_reset_quiz_text', __('Reset Quiz', 'woothemes-sensei')):
                    // Don't want to remove the lesson status (such as start meta data etc), just remove the answers, the questions asked meta and any grade meta
                    // Delete quiz answers, this auto deletes the corresponding meta data, such as the question/answer grade
                    WooThemes_Sensei_Utils::sensei_delete_quiz_answers($post->ID, $user_id);
                    WooThemes_Sensei_Utils::update_lesson_status($current_user->ID, $quiz_lesson_id, 'in-progress', array('questions_asked' => '', 'grade' => ''));
                    // Run any action on quiz/lesson reset (previously this didn't occur on resetting a quiz, see resetting a lesson in sensei_complete_lesson()
                    do_action('sensei_user_lesson_reset', $current_user->ID, $quiz_lesson_id);
                    $this->messages = '<div class="sensei-message note">' . apply_filters('sensei_quiz_reset_text', __('Quiz Reset Successfully.', 'woothemes-sensei')) . '</div>';
                    break;
                default:
                    // Nothing
                    break;
            }
            // End Switch Statement
            // Refresh page to avoid re-posting
            ?>
			<script type="text/javascript"> window.location = '<?php 
            echo get_permalink($post->ID);
            ?>
'; </script>
			<?php 
        }
        // End If Statement, submission of quiz
        $this->data = new stdClass();
        // Get latest quiz answers and grades
        $user_quizzes = $this->sensei_get_user_quiz_answers($post->ID);
        $user_lesson_status = WooThemes_Sensei_Utils::user_lesson_status($quiz_lesson_id, $current_user->ID);
        $user_quiz_grade = 0;
        if (isset($user_lesson_status->comment_ID)) {
            $user_quiz_grade = get_comment_meta($user_lesson_status->comment_ID, 'grade', true);
        }
        if (!is_array($user_quizzes)) {
            $user_quizzes = array();
        }
        // Check again that the lesson is complete
        $user_lesson_end = WooThemes_Sensei_Utils::user_completed_lesson($user_lesson_status);
        $user_lesson_complete = false;
        if ($user_lesson_end) {
            $user_lesson_complete = true;
        }
        // End If Statement
        $reset_allowed = get_post_meta($post->ID, '_enable_quiz_reset', true);
        // Build frontend data object
        $this->data->user_quizzes = $user_quizzes;
        $this->data->user_quiz_grade = $user_quiz_grade;
        $this->data->quiz_passmark = $quiz_passmark;
        $this->data->quiz_lesson = $quiz_lesson_id;
        $this->data->quiz_grade_type = $quiz_grade_type;
        $this->data->user_lesson_end = $user_lesson_end;
        $this->data->user_lesson_complete = $user_lesson_complete;
        $this->data->lesson_quiz_questions = $lesson_quiz_questions;
        $this->data->reset_quiz_allowed = $reset_allowed;
    }
开发者ID:AlecBeltrami,项目名称:sensei,代码行数:101,代码来源:class-woothemes-sensei-frontend.php

示例7: esc_url

             }
             $html .= '<h2><a href="' . esc_url(get_permalink($lesson_item->ID)) . '" title="' . esc_attr(sprintf(__('Start %s', 'woothemes-sensei'), $lesson_item->post_title)) . '">' . esc_html(sprintf(__('%s', 'woothemes-sensei'), $lesson_item->post_title)) . '</a> <span class="lesson-grade">' . $lesson_grade . '</span></h2>';
             $displayed_lessons[] = $lesson_item->ID;
         }
     }
 }
 $args = array('post_type' => 'lesson', 'posts_per_page' => -1, 'suppress_filters' => 0, 'meta_key' => '_order_' . $course->ID, 'orderby' => 'meta_value_num date', 'order' => 'ASC', 'meta_query' => array(array('key' => '_lesson_course', 'value' => intval($course->ID))), 'post__not_in' => $displayed_lessons);
 $lessons = get_posts($args);
 if (0 < count($displayed_lessons)) {
     $html .= '<h3>' . __('Other Lessons', 'woothemes-sensei') . '</h3>' . "\n";
 }
 foreach ($lessons as $lesson_item) {
     $lesson_grade = 'n/a';
     $has_questions = get_post_meta($lesson_item->ID, '_quiz_has_questions', true);
     if ($has_questions) {
         $lesson_status = WooThemes_Sensei_Utils::user_lesson_status($lesson_item->ID, $current_user->ID);
         // Get user quiz grade
         $lesson_grade = get_comment_meta($lesson_status->comment_ID, 'grade', true);
         if ($lesson_grade) {
             $lesson_grade .= '%';
         }
     }
     $html .= '<h2><a href="' . esc_url(get_permalink($lesson_item->ID)) . '" title="' . esc_attr(sprintf(__('Start %s', 'woothemes-sensei'), $lesson_item->post_title)) . '">' . esc_html(sprintf(__('%s', 'woothemes-sensei'), $lesson_item->post_title)) . '</a> <span class="lesson-grade">' . $lesson_grade . '</span></h2>';
 }
 // End For Loop
 $html .= '<h2 class="total-grade">' . apply_filters('sensei_total_grade_text', __('Total Grade', 'woothemes-sensei')) . '<span class="lesson-grade">' . $course_user_grade . '%</span></h2>';
 $html .= '</article>';
 $html .= '</section>';
 do_action('sensei_course_results_before_lessons', $course->ID);
 // Output the HTML
 echo $html;
开发者ID:ragulka,项目名称:sensei,代码行数:31,代码来源:course-lessons.php

示例8: testSaveUserAnswersFeedback

 /**
  * This tests Sensei()->quiz->save_user_answers_feedback
  */
 public function testSaveUserAnswersFeedback()
 {
     // setup the data and objects needed for this test
     global $woothemes_sensei;
     $test_user_id = wp_create_user('studentFeedbackSave', 'studentFeedbackSave', 'studentFeedbackSave@test.com');
     $test_lesson_id = $this->factory->get_random_lesson_id();
     $test_quiz_id = $woothemes_sensei->lesson->lesson_quizzes($test_lesson_id);
     // does the save_user_answers function exist?
     $this->assertTrue(method_exists($woothemes_sensei->quiz, 'save_user_answers_feedback'), 'The quiz class function `save_user_answers_feedback` does not exist ');
     // does this save_user_answers return false for bogus data
     $this->assertFalse($woothemes_sensei->quiz->save_user_answers_feedback(array(), array(), -1000, -200), 'save_user_answers_feedback does not return false for no existent users and lesson ');
     $this->assertFalse($woothemes_sensei->quiz->save_user_answers_feedback('', array(), '', ''), 'save_user_answers_feedback does not return false for empty parameters');
     // does the function return the correct information when a user doesn't exist?
     $this->assertFalse($woothemes_sensei->quiz->save_user_answers_feedback('', array(), '', $test_lesson_id), 'save_user_answers_feedback does not return false for empty user');
     $this->assertFalse($woothemes_sensei->quiz->save_user_answers_feedback('', array(), -500, $test_lesson_id), 'save_user_answers_feedback does not return false for a non existant user');
     // Test the answers_array parameter
     $this->assertFalse($woothemes_sensei->quiz->save_user_answers_feedback('Answers Text', array(), $test_lesson_id, $test_user_id), 'save_user_answers_feedback does not return false if answers is not passed in as an array');
     $this->assertFalse($woothemes_sensei->quiz->save_user_answers_feedback('', array(), $test_lesson_id, $test_user_id), 'save_user_answers_feedback does not return false for empty answer array');
     $this->assertFalse($woothemes_sensei->quiz->save_user_answers_feedback('', array(), '', ''), 'save_user_answers_feedback does not return false incorrectly formatted answers');
     // Test a case that is setup correctly which should return a positive result
     $test_user_answers_feedback = $this->factory->generate_user_answers_feedback($test_quiz_id);
     WooThemes_Sensei_Utils::sensei_start_lesson($test_lesson_id, $test_user_id);
     $lesson_data_saved = $woothemes_sensei->quiz->save_user_answers_feedback($test_user_answers_feedback, $test_lesson_id, $test_user_id);
     // did the correct data return a valid comment id on the lesson as a result?
     $this->assertTrue(intval($lesson_data_saved) > 0, 'The comment id returned after saving the quiz feedback does not represent a valid comment ');
     //setup for the next group of assertions
     $sensei_activity_logged = WooThemes_Sensei_Utils::sensei_check_for_activity(array('post_id' => $test_lesson_id, 'user_id' => $test_user_id));
     $status_comment = WooThemes_Sensei_Utils::user_lesson_status($test_lesson_id, $test_user_id);
     $saved_feedback = get_comment_meta($status_comment->comment_ID, 'quiz_answers_feedback', true);
     // was the data that was just stored stored correctly ? Check the comment meta on the lesson id
     $this->assertTrue((bool) $sensei_activity_logged, 'The saved answers feedback was not stored correctly on the Lesson');
     $this->assertFalse(empty($saved_feedback), 'The saved feedback was not stored correctly on the Quiz');
     $this->assertTrue(is_array(maybe_unserialize($saved_feedback)), 'The saved feedback was not stored correctly on the Lesson');
     // can you retrieve data and is it the same as what was stored?
     //compare every single answer
     $retrieved_feedback_array = maybe_unserialize($saved_feedback);
     foreach ($test_user_answers_feedback as $question_id => $feedback) {
         $saved_single_answer = $retrieved_feedback_array[$question_id];
         $assert_message = 'The saved feedback does not correspond to what was passed into the save_user_answers_feedback function ';
         $this->assertEquals($feedback, base64_decode($saved_single_answer), $assert_message);
     }
     // end for each
 }
开发者ID:ragulka,项目名称:sensei,代码行数:46,代码来源:test-class-quiz.php

示例9: submit_answers_for_grading

 /**
  * Submit the users quiz answers for grading
  *
  * This function accepts users answers and stores it but also initiates the grading
  * if a quiz can be graded automatically it will, if not the answers can be graded by the teacher.
  *
  * @since 1.7.4
  * @access public
  *
  * @param array $quiz_answers
  * @param array $files from $_FILES
  * @param int $user_id
  * @param int $lesson_id
  *
  * @return bool $answers_submitted
  */
 public static function submit_answers_for_grading($quiz_answers, $files = array(), $lesson_id, $user_id = 0)
 {
     $answers_submitted = false;
     // get the user_id if none was passed in use the current logged in user
     if (!intval($user_id) > 0) {
         $user_id = get_current_user_id();
     }
     // make sure the parameters are valid before continuing
     if (empty($lesson_id) || empty($user_id) || 'lesson' != get_post_type($lesson_id) || !get_userdata($user_id) || !is_array($quiz_answers)) {
         return false;
     }
     global $post, $woothemes_sensei;
     // Default grade
     $grade = 0;
     // Get Quiz ID
     $quiz_id = $woothemes_sensei->lesson->lesson_quizzes($lesson_id);
     // Get quiz grade type
     $quiz_grade_type = get_post_meta($quiz_id, '_quiz_grade_type', true);
     // Get quiz pass setting
     $pass_required = get_post_meta($quiz_id, '_pass_required', true);
     // Get the minimum percentage need to pass this quiz
     $quiz_pass_percentage = abs(round(doubleval(get_post_meta($quiz_id, '_quiz_passmark', true)), 2));
     // Handle Quiz Completion submit for grading
     if (isset($_POST['questions_asked']) && is_array($_POST['questions_asked'])) {
         $questions_asked = array_filter(array_map('absint', $_POST['questions_asked']));
     } else {
         $questions_asked = array_keys($quiz_answers);
     }
     $questions_asked_string = implode(',', $questions_asked);
     // Save Quiz Answers for grading, the save function also calls the sensei_start_lesson
     self::save_user_answers($quiz_answers, $files, $lesson_id, $user_id);
     // Save questions that were asked in this quiz
     $user_lesson_status = WooThemes_Sensei_Utils::user_lesson_status($lesson_id, $user_id);
     if (isset($user_lesson_status->comment_ID)) {
         update_comment_meta($user_lesson_status->comment_ID, 'questions_asked', $questions_asked_string);
     }
     // Grade quiz
     $grade = WooThemes_Sensei_Utils::sensei_grade_quiz_auto($quiz_id, $quiz_answers, 0, $quiz_grade_type);
     // Get Lesson Grading Setting
     $lesson_metadata = array();
     $lesson_status = 'ungraded';
     // Default when completing a quiz
     // At this point the answers have been submitted
     $answers_submitted = true;
     // if this condition is false the quiz should manually be graded by admin
     if ('auto' == $quiz_grade_type && !is_wp_error($grade)) {
         // Quiz has been automatically Graded
         if ('on' == $pass_required) {
             // Student has reached the pass mark and lesson is complete
             if ($quiz_pass_percentage <= $grade) {
                 $lesson_status = 'passed';
             } else {
                 $lesson_status = 'failed';
             }
             // End If Statement
         } else {
             // Student only has to partake the quiz
             $lesson_status = 'graded';
         }
         $lesson_metadata['grade'] = $grade;
         // Technically already set as part of "WooThemes_Sensei_Utils::sensei_grade_quiz_auto()" above
     }
     // end if ! is_wp_error( $grade ...
     WooThemes_Sensei_Utils::update_lesson_status($user_id, $lesson_id, $lesson_status, $lesson_metadata);
     if ('passed' == $lesson_status || 'graded' == $lesson_status) {
         /**
          * Lesson end action hook
          *
          * This hook is fired after a lesson quiz has been graded and the lesson status is 'passed' OR 'graded'
          *
          * @param int $user_id
          * @param int $lesson_id
          */
         do_action('sensei_user_lesson_end', $user_id, $lesson_id);
     }
     /**
      * User quiz has been submitted
      *
      * Fires the end of the submit_answers_for_grading function. It will fire irrespective of the submission
      * results.
      *
      * @param int $user_id
      * @param int $quiz_id
      * @param string $grade
//.........这里部分代码省略.........
开发者ID:mattytemple,项目名称:YTC-Sensei,代码行数:101,代码来源:class-woothemes-sensei-quiz.php

示例10: savedquest_options


//.........这里部分代码省略.........
		</table><br /><br />





	<?php 
    } elseif ($tab == "timequizecompleted") {
        global $woothemes_sensei, $post, $current_user, $wp_query, $learner_user;
        echo "<table class='wp-list-table widefat fixed striped pages'>";
        $allUsers = get_users();
        echo "<tr>\n\n\t\t\t\t<th>User</th>\n\n\t\t\t\t<th>Courses</th>\n\n\t\t\t\t<th>Percentage Incomplete</th>\n\n\t\t\t\t<th>Percentage Complete</th>\n\n\t\t\t\t<th>Percentage Competent</th>\n\n\t\t\t\t<th>Percentage Attempted</th>\n\n\t\t\t\t<th>Length of time Course Completed</th>\n\n\t\t\t  </tr>";
        foreach ($allUsers as $user) {
            $args = array('post_type' => 'course');
            $courses = get_posts($args);
            $i = 1;
            foreach ($courses as $course) {
                $course_user_grade = WooThemes_Sensei_Utils::sensei_course_user_grade($course->ID, $user->ID);
                $course_status = WooThemes_Sensei_Utils::user_course_status($course->ID, $user->ID);
                $course_status_update = get_comment_meta($course_status->comment_ID);
                if (!empty($course_status)) {
                    $displayed_lessons = array();
                    $modules = Sensei()->modules->get_course_modules(intval($course->ID));
                    foreach ($modules as $module) {
                        $args = array('post_type' => 'lesson', 'post_status' => 'publish', 'posts_per_page' => -1, 'meta_query' => array(array('key' => '_lesson_course', 'value' => intval($course->ID), 'compare' => '=')), 'tax_query' => array(array('taxonomy' => Sensei()->modules->taxonomy, 'field' => 'id', 'terms' => intval($module->term_id))), 'meta_key' => '_order_module_' . $module->term_id, 'orderby' => 'meta_value_num date', 'order' => 'ASC', 'suppress_filters' => 0);
                        $lessons = get_posts($args);
                        if (count($lessons) > 0) {
                            $html .= '<h3>' . $module->name . '</h3>' . "\n";
                            $count = 0;
                            foreach ($lessons as $lesson_item) {
                                $lesson_grade = ' n/a';
                                $has_questions = get_post_meta($lesson_item->ID, '_quiz_has_questions', true);
                                if ($has_questions) {
                                    $lesson_status = WooThemes_Sensei_Utils::user_lesson_status($lesson_item->ID, $user->ID);
                                    // Get user quiz grade
                                    $lesson_grade = get_comment_meta($lesson_status->comment_ID, 'grade', true);
                                    if ($lesson_grade) {
                                        $lesson_grade .= '%';
                                    }
                                    $modulequizdata = get_comment_meta($lesson_status->comment_ID);
                                    //echo "<a href='".get_post_permalink($lesson_item->ID)."'>".$lesson_item->post_title."</a><br />";
                                    $modulequestion_asked = count(explode(",", $modulequizdata['questions_asked'][0]));
                                    $moduleanswered_quiz = count(unserialize($modulequizdata['quiz_answers'][0]));
                                    //echo "number of questions:".$modulequestion_asked."<br />";
                                    //echo "number of Answered:".$moduleanswered_quiz."<br />";
                                    //echo "<pre>";
                                    //echo "<h1>".$user->user_email.$lesson_item->post_title."</h1>";
                                    //print_r($course_status );
                                    //echo $course_status->comment_approved;
                                    //echo $modulequestion_asked."------".$moduleanswered_quiz;
                                    //echo "</pre>";
                                    if ($course_status->comment_approved == "complete") {
                                        $attempted = '<span style="color:green;">(100%)</span>';
                                    } else {
                                        if ($lesson_status->comment_approved == "passed" || $lesson_status->comment_approved == "graded") {
                                            $attempted = '<span style="color:green;">(100%)</span>';
                                        } else {
                                            $attempted = "";
                                        }
                                    }
                                    //echo "<pre>";
                                    //echo "Attempted:".$attempted."<br />";
                                    //echo $user->user_email."<br />";
                                    //echo $modulequizdata['grade'][0]."<br />";
                                    //echo $modulequizdata['quiz_answers'][0]."<br />";
                                    //print_r($lesson_status);
开发者ID:Ezyva2015,项目名称:opendooronline.com.au,代码行数:67,代码来源:functions.php

示例11: do_action

    do_action('sensei_lesson_archive_header');
    ?>

        	    <?php 
    while (have_posts()) {
        the_post();
        // Meta data
        $post_id = get_the_ID();
        ?>

					<?php 
        $single_lesson_complete = false;
        $user_lesson_status = false;
        if (is_user_logged_in()) {
            // Check if Lesson is complete
            $user_lesson_status = WooThemes_Sensei_Utils::user_lesson_status($post_id, $current_user->ID);
            if (WooThemes_Sensei_Utils::user_completed_lesson($user_lesson_status)) {
                $single_lesson_complete = true;
            }
        }
        // End If Statement
        $complexity_array = $woothemes_sensei->post_types->lesson->lesson_complexities();
        $lesson_length = get_post_meta($post_id, '_lesson_length', true);
        $lesson_complexity = get_post_meta($post_id, '_lesson_complexity', true);
        if ('' != $lesson_complexity) {
            $lesson_complexity = $complexity_array[$lesson_complexity];
        }
        $user_info = get_userdata(absint(get_the_author_meta('ID')));
        $html = '<article class="' . esc_attr(join(' ', get_post_class(array('lesson', 'course', 'post'), $post_id))) . '">';
        $html .= '<header>';
        $html .= '<h2><a href="' . esc_url(get_permalink($post_id)) . '" title="' . esc_attr(sprintf(__('Start %s', 'woothemes-sensei'), get_the_title())) . '">';
开发者ID:TravisSperry,项目名称:mpa_website,代码行数:31,代码来源:loop-lesson.php


注:本文中的WooThemes_Sensei_Utils::user_lesson_status方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。