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


PHP WooThemes_Sensei_Utils::delete_user_data方法代码示例

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


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

示例1: reset_user_lesson_data

 /**
  * Reset user submitted questions
  *
  * This function resets the quiz data for a user that has been submitted fro grading already. It is different to
  * the save_user_answers as currently the saved and submitted answers are stored differently.
  *
  * @since 1.7.4
  * @access public
  *
  * @return bool $reset_success
  * @param int $user_id
  * @param int $lesson_id
  */
 public function reset_user_lesson_data($lesson_id, $user_id = 0)
 {
     //make sure the parameters are valid
     if (empty($lesson_id) || empty($user_id) || 'lesson' != get_post_type($lesson_id) || !get_userdata($user_id)) {
         return false;
     }
     global $woothemes_sensei;
     //get the users lesson status to make
     $user_lesson_status = WooThemes_Sensei_Utils::user_lesson_status($lesson_id, $user_id);
     if (!isset($user_lesson_status->comment_ID)) {
         // this user is not taking this lesson so this process is not needed
         return false;
     }
     //get the lesson quiz and course
     $quiz_id = $woothemes_sensei->lesson->lesson_quizzes($lesson_id);
     $course_id = $woothemes_sensei->lesson->get_course_id($lesson_id);
     // reset the transients
     $answers_transient_key = 'sensei_answers_' . $user_id . '_' . $lesson_id;
     $grades_transient_key = 'quiz_grades_' . $user_id . '_' . $lesson_id;
     $answers_feedback_transient_key = 'sensei_answers_feedback_' . $user_id . '_' . $lesson_id;
     //delete_transient( $answers_transient_key );
     delete_transient($grades_transient_key);
     delete_transient($answers_feedback_transient_key);
     // reset the quiz answers and feedback notes
     //$deleted_answers = WooThemes_Sensei_Utils::delete_user_data( 'quiz_answers', $lesson_id, $user_id );
     $deleted_grades = WooThemes_Sensei_Utils::delete_user_data('quiz_grades', $lesson_id, $user_id);
     $deleted_user_feedback = WooThemes_Sensei_Utils::delete_user_data('quiz_answers_feedback', $lesson_id, $user_id);
     // Delete quiz answers, this auto deletes the corresponding meta data, such as the question/answer grade
     //WooThemes_Sensei_Utils::sensei_delete_quiz_answers( $quiz_id, $user_id );
     WooThemes_Sensei_Utils::update_lesson_status($user_id, $lesson_id, 'in-progress', array('questions_asked' => '', 'grade' => ''));
     // Update course completion
     WooThemes_Sensei_Utils::update_course_status($user_id, $course_id);
     // 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', $user_id, $lesson_id);
     $woothemes_sensei->frontend->messages = '<div class="sensei-message note">' . apply_filters('sensei_quiz_reset_text', __('Quiz Reset Successfully.', 'woothemes-sensei')) . '</div>';
     return $deleted_answers && $deleted_grades;
 }
开发者ID:mattytemple,项目名称:YTC-Sensei,代码行数:50,代码来源:class-woothemes-sensei-quiz.php

示例2: testGetUserQuestionFeedback

 /**
  * This test Sensei()->quiz->get_user_question_feedback
  */
 public function testGetUserQuestionFeedback()
 {
     global $woothemes_sensei;
     // does this function add_user_data exist?
     $this->assertTrue(method_exists($woothemes_sensei->quiz, 'get_user_question_feedback'), 'The utils class function `get_user_question_feedback` does not exist ');
     // does it return false for invalid data
     $invalid_data_message = 'This get_user_question_feedback function does not check false data correctly';
     $this->assertFalse($woothemes_sensei->quiz->get_user_question_feedback('', '', ''), $invalid_data_message);
     $this->assertFalse($woothemes_sensei->quiz->get_user_question_feedback(' ', ' ', ' '), $invalid_data_message);
     $this->assertFalse($woothemes_sensei->quiz->get_user_question_feedback(-2, -3, -1), $invalid_data_message);
     $this->assertFalse($woothemes_sensei->quiz->get_user_question_feedback(3000, 5000, 5000), $invalid_data_message);
     // setup the next assertion
     $test_user_id = wp_create_user('studentQuestionFeedback', 'studentQuestionFeedback', 'studQFeedback@test.com');
     $test_lesson_id = $this->factory->get_random_lesson_id();
     $test_quiz_id = $woothemes_sensei->lesson->lesson_quizzes($test_lesson_id);
     $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);
     $woothemes_sensei->quiz->save_user_answers_feedback($test_user_answers_feedback, $test_lesson_id, $test_user_id);
     $test_question_id = array_rand($test_user_answers_feedback);
     $retrieved_grade = $woothemes_sensei->quiz->get_user_question_feedback($test_lesson_id, $test_question_id, $test_user_id);
     //test if the the question grade can be retrieved
     $this->assertEquals($test_user_answers_feedback[$test_question_id], $retrieved_grade, 'The feedback retrieved is not equal to the one that was set for this question ID');
     //setup the next assertion for backwards compatibility.
     $transient_key = 'sensei_answers_feedback_' . $test_user_id . '_' . $test_lesson_id;
     delete_transient($transient_key);
     WooThemes_Sensei_Utils::delete_user_data('quiz_answers_feedback', $test_lesson_id, $test_user_id);
     $random_question_id = array_rand($test_user_answers_feedback);
     $old_data_args = array('post_id' => $random_question_id, 'user_id' => $test_user_id, 'type' => 'sensei_user_answer', 'data' => 'test answer feedback');
     $old_data_activity_id = WooThemes_Sensei_Utils::sensei_log_activity($old_data_args);
     update_comment_meta($old_data_activity_id, 'answer_note', base64_encode('Sensei sample feedback'));
     $retrieved_feedback = $woothemes_sensei->quiz->get_user_question_feedback($test_lesson_id, $random_question_id, $test_user_id);
     // Does the fall back to 1.7.3 data work?
     $this->assertEquals('Sensei sample feedback', $retrieved_feedback, 'The get user feedback does not fall back the old data');
 }
开发者ID:ragulka,项目名称:sensei,代码行数:37,代码来源:test-class-quiz.php

示例3: testDeleteUserData

 /**
  * This tests Woothemes_Sensei_Utils::delete_user_data
  */
 public function testDeleteUserData()
 {
     // does this function add_user_data exist?
     $this->assertTrue(method_exists('WooThemes_Sensei_Utils', 'delete_user_data'), 'The utils class function `delete_user_data` does not exist ');
     // does it return false for invalid the parameters?
     $invalid_data_message = 'This function does not check false data correctly';
     $this->assertFalse(WooThemes_Sensei_Utils::delete_user_data('', '', ''), $invalid_data_message . ": '','','' ");
     $this->assertFalse(WooThemes_Sensei_Utils::delete_user_data(' ', ' ', ' '), $invalid_data_message . ": ' ', ' ', ' ' ");
     $this->assertFalse(WooThemes_Sensei_Utils::delete_user_data(-1, -2, -3), $invalid_data_message . ": -1,-2, -3 ");
     $this->assertFalse(WooThemes_Sensei_Utils::delete_user_data('key', 500, 5000), $invalid_data_message . ": 500, 'key', 5000");
     // setup the data for the next assertions
     $test_user_id = wp_create_user('testDeleteUserData', 'testDeleteUserData', 'testDeleteUserData@test.com');
     $test_array = array(1, 2, 3, 4);
     $test_lesson_id = $this->factory->post->create(array('post_type' => "lesson"));
     $test_data_key = 'test_key';
     //does this function return false when there is no lesson status?
     $this->assertFalse(WooThemes_Sensei_Utils::get_user_data($test_data_key, $test_lesson_id, $test_user_id), 'This function should return false when the status has not be set for the given post type');
     //setup assertion data
     WooThemes_Sensei_Utils::update_user_data($test_data_key, $test_lesson_id, $test_array, $test_user_id);
     $deleted = WooThemes_Sensei_Utils::delete_user_data($test_data_key, $test_lesson_id, $test_user_id);
     $retrieved_value = WooThemes_Sensei_Utils::get_user_data($test_data_key, $test_lesson_id, $test_user_id);
     // doest the function successfully delete existing Sensei user data ?
     $this->assertTrue($deleted, 'The user data should have been deleted, but was not');
     $this->assertEmpty($retrieved_value, 'After deleting the user data should return false');
 }
开发者ID:pra85,项目名称:sensei,代码行数:28,代码来源:test-class-utils.php


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