本文整理汇总了PHP中WooThemes_Sensei_Utils::user_course_status方法的典型用法代码示例。如果您正苦于以下问题:PHP WooThemes_Sensei_Utils::user_course_status方法的具体用法?PHP WooThemes_Sensei_Utils::user_course_status怎么用?PHP WooThemes_Sensei_Utils::user_course_status使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WooThemes_Sensei_Utils
的用法示例。
在下文中一共展示了WooThemes_Sensei_Utils::user_course_status方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testUpdateUserData
/**
* This tests Woothemes_Sensei_Utils::update_user_data
*/
public function testUpdateUserData()
{
//setup data needed for this test
$test_user_id = wp_create_user('testUpdateUserData', 'testUpdateUserData', 'testUpdateUserData@test.com');
// does this function add_user_data exist?
$this->assertTrue(method_exists('WooThemes_Sensei_Utils', 'update_user_data'), 'The utils class function `update_user_data` does not exist ');
// does it return false for invalid data
$invalid_data_message = 'This function does not check false data correctly';
$this->assertFalse(WooThemes_Sensei_Utils::update_user_data('', '', '', ''), $invalid_data_message . ": '','','','' ");
$this->assertFalse(WooThemes_Sensei_Utils::update_user_data(' ', ' ', ' ', ' '), $invalid_data_message . ": ' ', ' ', ' ', ' ' ");
$this->assertFalse(WooThemes_Sensei_Utils::update_user_data(-1, -2, -3, -1), $invalid_data_message . ": -1,-2, -3, -1 ");
$this->assertFalse(WooThemes_Sensei_Utils::update_user_data('key', 500, 'val', 5000), $invalid_data_message . ": 'key', 500, 'val', 5000 ");
//does this function return false when attempting to add user data on non sensei post types
$test_post = $this->factory->post->create();
$this->assertFalse(WooThemes_Sensei_Utils::update_user_data('key', $test_post, 'val', $test_user_id), 'This function does not reject unsupported post types');
//does this function return false when attempting to add user data on non sensei post types
$test_array = array(1, 2, 3, 4);
$test_course_id = $this->factory->post->create(array('post_type' => "course"));
$test_data_key = 'test_key';
WooThemes_Sensei_Utils::update_user_data($test_data_key, $test_course_id, $test_array, $test_user_id);
$course_status = WooThemes_Sensei_Utils::user_course_status($test_course_id, $test_user_id);
// is the status updated on the passed in sensei post type ?
$this->assertTrue(isset($course_status->comment_ID), 'This function did not create the status on the passed in sensei post type');
// setup the next group of assertions
$retrieved_array = get_comment_meta($course_status->comment_ID, $test_data_key, true);
// is the data saved still intact
$this->assertEquals($test_array, $retrieved_array, 'The saved and retrieved data does not match');
}
示例2: savedquest_options
//.........这里部分代码省略.........
<th><?php
echo $diftime;
?>
</th>
<td><?php
echo implode(', ', $user_info->roles);
?>
</td>
</tr>
<?php
}
?>
<?php
}
?>
</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';
示例3: 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;
}
}
}
}
}
}
示例4: user_completed_course
/**
* Check if a user has completed a course or not
*
* @param mixed $course course_id or sensei_course_status entry
* @param int $user_id
* @return boolean
*/
public static function user_completed_course($course = 0, $user_id = 0)
{
if ($course) {
if (is_object($course)) {
$user_course_status = $course->comment_approved;
} elseif (is_string($course)) {
$user_course_status = $course;
} else {
if (!$user_id) {
$user_id = get_current_user_id();
}
$user_course_status = WooThemes_Sensei_Utils::user_course_status($course, $user_id);
if (isset($user_course_status->comment_approved)) {
$user_course_status = $user_course_status->comment_approved;
}
}
if ($user_course_status && 'complete' == $user_course_status) {
return true;
}
}
return false;
}
示例5: savedquest_options
//.........这里部分代码省略.........
?>
</td>
</tr>
<?php
}
?>
<?php
}
?>
</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>";