當前位置: 首頁>>代碼示例>>PHP>>正文


PHP WooThemes_Sensei_Utils::get_user_data方法代碼示例

本文整理匯總了PHP中WooThemes_Sensei_Utils::get_user_data方法的典型用法代碼示例。如果您正苦於以下問題:PHP WooThemes_Sensei_Utils::get_user_data方法的具體用法?PHP WooThemes_Sensei_Utils::get_user_data怎麽用?PHP WooThemes_Sensei_Utils::get_user_data使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在WooThemes_Sensei_Utils的用法示例。


在下文中一共展示了WooThemes_Sensei_Utils::get_user_data方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: get_user_answers_feedback

 /**
  * Get the user's answers feedback.
  *
  * This function returns the feedback submitted by the teacher/admin
  * during grading. Grading occurs manually or automatically.
  *
  * @since 1.7.5
  * @access public
  *
  * @param int $lesson_id
  * @param int $user_id
  *
  * @return false | array $answers_feedback{
  *  $type int $question_id
  *  $type string $question_feedback
  * }
  */
 public function get_user_answers_feedback($lesson_id, $user_id = 0)
 {
     $answers_feedback = array();
     // 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();
     }
     if (!intval($lesson_id) > 0 || 'lesson' != get_post_type($lesson_id) || !intval($user_id) > 0 || !get_userdata($user_id)) {
         return false;
     }
     // first check the transient to save a few split seconds
     $transient_key = 'sensei_answers_feedback_' . $user_id . '_' . $lesson_id;
     $encoded_feedback = get_transient($transient_key);
     // get the data if nothing was stored in the transient
     if (empty($encoded_feedback) || !$encoded_feedback) {
         $encoded_feedback = WooThemes_Sensei_Utils::get_user_data('quiz_answers_feedback', $lesson_id, $user_id);
         //set the transient with the new valid data for faster retrieval in future
         set_transient($transient_key, $encoded_feedback, 10 * DAY_IN_SECONDS);
     }
     // end if transient check
     // if there is no data for this user
     if (!is_array($encoded_feedback)) {
         return false;
     }
     foreach ($encoded_feedback as $question_id => $feedback) {
         $answers_feedback[$question_id] = base64_decode($feedback);
     }
     return $answers_feedback;
 }
開發者ID:mattytemple,項目名稱:YTC-Sensei,代碼行數:46,代碼來源:class-woothemes-sensei-quiz.php

示例2: 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::get_user_data方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。