本文整理汇总了PHP中WooThemes_Sensei_Utils::user_started_lesson方法的典型用法代码示例。如果您正苦于以下问题:PHP WooThemes_Sensei_Utils::user_started_lesson方法的具体用法?PHP WooThemes_Sensei_Utils::user_started_lesson怎么用?PHP WooThemes_Sensei_Utils::user_started_lesson使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WooThemes_Sensei_Utils
的用法示例。
在下文中一共展示了WooThemes_Sensei_Utils::user_started_lesson方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sensei_start_lesson
/**
* Marked lesson as started for user
* @param integer $lesson_id ID of lesson
* @return mixed boolean or comment_ID
*/
public static function sensei_start_lesson($lesson_id = 0, $user_id = 0, $complete = false)
{
global $woothemes_sensei;
if (intval($user_id) == 0) {
$user_id = get_current_user_id();
}
$activity_logged = false;
if (intval($lesson_id) > 0) {
$course_id = get_post_meta($lesson_id, '_lesson_course', true);
if ($course_id) {
$is_user_taking_course = WooThemes_Sensei_Utils::user_started_course($course_id, $user_id);
if (!$is_user_taking_course) {
WooThemes_Sensei_Utils::user_start_course($user_id, $course_id);
}
}
$metadata = array();
$status = 'in-progress';
// Note: When this action runs the lesson status may not yet exist
do_action('sensei_user_lesson_start', $user_id, $lesson_id);
if ($complete) {
$has_questions = get_post_meta($lesson_id, '_quiz_has_questions', true);
if ($has_questions) {
$status = 'passed';
// Force a pass
$metadata['grade'] = 100;
} else {
$status = 'complete';
}
}
// Check if user is already taking the lesson
$activity_logged = WooThemes_Sensei_Utils::user_started_lesson($lesson_id, $user_id);
if (!$activity_logged) {
$metadata['start'] = current_time('mysql');
$activity_logged = WooThemes_Sensei_Utils::update_lesson_status($user_id, $lesson_id, $status, $metadata);
}
if ($complete) {
// Run this *after* the lesson status has been created/updated
do_action('sensei_user_lesson_end', $user_id, $lesson_id);
}
}
return $activity_logged;
}
示例2: save_user_answers_feedback
/**
* Save the user's answers feedback
*
* For this function you must supply all three parameters. If will return false one is left out.
* The data will be saved on the lesson ID supplied.
*
* @since 1.7.5
* @access public
*
* @param array $answers_feedback{
* $type int $question_id
* $type string $question_feedback
* }
* @param int $lesson_id
* @param int $user_id
*
* @return false or int $feedback_saved
*/
public function save_user_answers_feedback($answers_feedback, $lesson_id, $user_id = 0)
{
// 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($answers_feedback)) {
return false;
}
global $woothemes_sensei;
// check if the lesson is started before saving, if not start the lesson for the user
if (!(0 < intval(WooThemes_Sensei_Utils::user_started_lesson($lesson_id, $user_id)))) {
WooThemes_Sensei_Utils::sensei_start_lesson($lesson_id, $user_id);
}
// encode the feedback
$encoded_answers_feedback = array();
foreach ($answers_feedback as $question_id => $feedback) {
$encoded_answers_feedback[$question_id] = base64_encode($feedback);
}
// save the user data
$feedback_saved = WooThemes_Sensei_Utils::add_user_data('quiz_answers_feedback', $lesson_id, $encoded_answers_feedback, $user_id);
//Were the the question feedback save correctly?
if (intval($feedback_saved) > 0) {
// save transient to make retrieval faster in future
$transient_key = 'sensei_answers_feedback_' . $user_id . '_' . $lesson_id;
set_transient($transient_key, $encoded_answers_feedback, 10 * DAY_IN_SECONDS);
}
return $feedback_saved;
}