本文整理汇总了PHP中WooThemes_Sensei_Utils::user_start_course方法的典型用法代码示例。如果您正苦于以下问题:PHP WooThemes_Sensei_Utils::user_start_course方法的具体用法?PHP WooThemes_Sensei_Utils::user_start_course怎么用?PHP WooThemes_Sensei_Utils::user_start_course使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WooThemes_Sensei_Utils
的用法示例。
在下文中一共展示了WooThemes_Sensei_Utils::user_start_course方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: woocommerce_course_update
/**
* If WooCommerce is activated and the customer has purchased the course, update Sensei to indicate that they are taking the course.
* @access public
* @since 1.0.0
* @param int $course_id (default: 0)
* @param array/Object $order_user (default: array()) Specific user's data.
* @return void
*/
public function woocommerce_course_update($course_id = 0, $order_user = array())
{
global $current_user;
if (!isset($current_user)) {
return;
}
$data_update = false;
// Get the product ID
$wc_post_id = get_post_meta(intval($course_id), '_course_woocommerce_product', true);
// Check if in the admin
if (is_admin()) {
$user_login = $order_user['user_login'];
$user_email = $order_user['user_email'];
$user_url = $order_user['user_url'];
$user_id = $order_user['ID'];
} else {
$user_login = $current_user->user_login;
$user_email = $current_user->user_email;
$user_url = $current_user->user_url;
$user_id = $current_user->ID;
}
// End If Statement
// This doesn't appear to be purely WooCommerce related. Should it be in a separate function?
$course_prerequisite_id = (int) get_post_meta($course_id, '_course_prerequisite', true);
if (0 < absint($course_prerequisite_id)) {
$prereq_course_complete = WooThemes_Sensei_Utils::user_completed_course($course_prerequisite_id, intval($user_id));
if (!$prereq_course_complete) {
// Remove all course user meta
return WooThemes_Sensei_Utils::sensei_remove_user_from_course($course_id, $user_id);
}
}
$is_user_taking_course = WooThemes_Sensei_Utils::user_started_course(intval($course_id), intval($user_id));
if (!$is_user_taking_course) {
if (WooThemes_Sensei_Utils::sensei_is_woocommerce_activated() && WooThemes_Sensei_Utils::sensei_customer_bought_product($user_email, $user_id, $wc_post_id) && 0 < $wc_post_id) {
$activity_logged = WooThemes_Sensei_Utils::user_start_course(intval($user_id), intval($course_id));
$is_user_taking_course = false;
if (true == $activity_logged) {
$is_user_taking_course = true;
}
// End If Statement
}
// End If Statement
}
return $is_user_taking_course;
}
示例2: add_new_learners
public function add_new_learners()
{
$result = false;
if (!isset($_POST['add_learner_submit'])) {
return $result;
}
if (!isset($_POST['add_learner_nonce']) || !wp_verify_nonce($_POST['add_learner_nonce'], 'add_learner_to_sensei')) {
return $result;
}
if (!isset($_POST['add_user_id']) || '' == $_POST['add_user_id'] || !isset($_POST['add_post_type']) || !isset($_POST['add_course_id']) || !isset($_POST['add_lesson_id'])) {
return $result;
}
$post_type = $_POST['add_post_type'];
$user_id = absint($_POST['add_user_id']);
$course_id = absint($_POST['add_course_id']);
switch ($post_type) {
case 'course':
$result = WooThemes_Sensei_Utils::user_start_course($user_id, $course_id);
// Complete each lesson if course is set to be completed
if (isset($_POST['add_complete_course']) && 'yes' == $_POST['add_complete_course']) {
$lesson_ids = Sensei()->course->course_lessons($course_id, 'any', 'ids');
foreach ($lesson_ids as $id) {
WooThemes_Sensei_Utils::sensei_start_lesson($id, $user_id, true);
}
// Updates the Course status and it's meta data
WooThemes_Sensei_Utils::user_complete_course($course_id, $user_id);
do_action('sensei_user_course_end', $user_id, $course_id);
}
break;
case 'lesson':
$lesson_id = absint($_POST['add_lesson_id']);
$complete = false;
if (isset($_POST['add_complete_lesson']) && 'yes' == $_POST['add_complete_lesson']) {
$complete = true;
}
$result = WooThemes_Sensei_Utils::sensei_start_lesson($lesson_id, $user_id, $complete);
// Updates the Course status and it's meta data
WooThemes_Sensei_Utils::user_complete_course($course_id, $user_id);
break;
}
// Set redirect URL after adding user to course/lesson
$query_args = array('page' => $this->page_slug, 'view' => 'learners');
if ($result) {
if ($course_id) {
$query_args['course_id'] = $course_id;
}
if ($lesson_id) {
$query_args['lesson_id'] = $lesson_id;
}
$query_args['message'] = 'success';
} else {
$query_args['message'] = 'error';
}
$redirect_url = apply_filters('sensei_learners_add_learner_redirect_url', add_query_arg($query_args, admin_url('admin.php')));
wp_safe_redirect(esc_url_raw($redirect_url));
exit;
}
示例3: testGetCompletionPercentage
/**
* This tests Sensei_Courses::get_completion_percentage
* @since 1.8.0
*/
public function testGetCompletionPercentage()
{
//does the function exist?
$this->assertTrue(method_exists('WooThemes_Sensei_Course', 'get_completion_percentage'), 'The course class get_completion_percentage function does not exist.');
// setup the test
$test_user_id = wp_create_user('testGetCompletionPercentage', 'testGetCompletionPercentage', 'testGetCompletionPercentage@tes.co');
$test_lessons = $this->factory->get_lessons();
$test_course_id = $this->factory->get_random_course_id();
remove_all_actions('sensei_user_course_start');
WooThemes_Sensei_Utils::user_start_course($test_user_id, $test_course_id);
// add lessons to the course
foreach ($test_lessons as $lesson_id) {
add_post_meta($lesson_id, '_lesson_course', intval($test_course_id));
}
// complete 3 lessons and check if the correct percentage returns
$i = 0;
for ($i = 0; $i < 3; $i++) {
WooThemes_Sensei_Utils::update_lesson_status($test_user_id, $test_lessons[$i], 'complete');
}
$expected_percentage = 3 / count($test_lessons) * 100;
$this->assertEquals($expected_percentage, Sensei()->course->get_completion_percentage($test_course_id, $test_user_id), 'Course completed percentage is not accurate');
// complete all lessons
foreach ($test_lessons as $lesson_id) {
WooThemes_Sensei_Utils::update_lesson_status($test_user_id, $lesson_id, 'complete');
}
//all lessons should no be completed
$this->assertEquals(100, Sensei()->course->get_completion_percentage($test_course_id, $test_user_id), 'Course completed percentage is not accurate');
}
示例4: activate_purchased_single_course
/**
* Activate single course if already purchases
* @return void
*/
public function activate_purchased_single_course()
{
global $post, $current_user;
if (WooThemes_Sensei_Utils::sensei_is_woocommerce_activated()) {
if (!is_user_logged_in()) {
return;
}
if (!isset($post->ID)) {
return;
}
$user_id = $current_user->ID;
$course_id = $post->ID;
$course_product_id = (int) get_post_meta($course_id, '_course_woocommerce_product', true);
if (!$course_product_id) {
return;
}
$user_course_status = WooThemes_Sensei_Utils::user_course_status(intval($course_id), $user_id);
// Ignore course if already completed
if (WooThemes_Sensei_Utils::user_completed_course($user_course_status)) {
return;
}
// Ignore course if already started
if ($user_course_status) {
return;
}
// Get all user's orders
$order_args = array('post_type' => 'shop_order', 'posts_per_page' => -1, 'post_status' => array('wc-processing', 'wc-completed'), 'meta_query' => array(array('key' => '_customer_user', 'value' => $user_id)), 'fields' => 'ids');
$orders = get_posts($order_args);
foreach ($orders as $order_post_id) {
// Get course product IDs from order
$order = new WC_Order($order_post_id);
$items = $order->get_items();
foreach ($items as $item) {
$product = wc_get_product($item['product_id']);
// handle product bundles
if ($product->is_type('bundle')) {
$bundled_product = new WC_Product_Bundle($product->id);
$bundled_items = $bundled_product->get_bundled_items();
foreach ($bundled_items as $item) {
if ($item->product_id == $course_product_id) {
WooThemes_Sensei_Utils::user_start_course($user_id, $course_id);
return;
}
}
} else {
// handle regular products
if ($item['product_id'] == $course_product_id) {
WooThemes_Sensei_Utils::user_start_course($user_id, $course_id);
return;
}
}
}
}
}
}
示例5: 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;
}