/**
  * Adding page title for course results page
  * @param  string $title Original title
  * @param  string $sep   Seeparator string
  * @return string        Modified title
  */
 public function page_title($title, $sep = null)
 {
     global $wp_query;
     if (isset($wp_query->query_vars['learner_profile'])) {
         $learner_user = get_user_by('login', $wp_query->query_vars['learner_profile']);
         $name = Sensei_Learner::get_full_name($learner_user->ID);
         $title = apply_filters('sensei_learner_profile_courses_heading', sprintf(__('Courses %s is taking', 'woothemes-sensei'), $name)) . ' ' . $sep . ' ';
     }
     return $title;
 }
Example #2
0
 /**
  * Testing the get_learner_full_name function to see if it returns what is expected.
  */
 public function testGetLearnerFullName()
 {
     //setup assertion
     $test_user_id = wp_create_user('getlearnertestuser', 'password', '*****@*****.**');
     $this->assertEquals('getlearnertestuser', Sensei_Learner::get_full_name($test_user_id), 'The user name should be equal to the display name when no first name and last name is specified');
     //setup the next assertion
     $first_name = 'Test';
     $last_name = 'User';
     $updated_user_data = array('ID' => $test_user_id, 'first_name' => $first_name, 'last_name' => $last_name);
     wp_update_user($updated_user_data);
     // does the function return 'first-name last-name' string?
     $this->assertEquals('Test User', Sensei_Learner::get_full_name($test_user_id), 'This function should return the users first name and last name.');
 }
    /**
     * Nav area for Grading specific users' quiz answers
     * @since  1.3.0
     * @return void
     */
    public function grading_user_quiz_nav()
    {
        global $wp_version;
        $title = sprintf('<a href="%s">%s</a>', add_query_arg(array('page' => $this->page_slug), admin_url('admin.php')), esc_html($this->name));
        if (isset($_GET['quiz_id'])) {
            $quiz_id = intval($_GET['quiz_id']);
            $lesson_id = get_post_meta($quiz_id, '_quiz_lesson', true);
            $course_id = get_post_meta($lesson_id, '_lesson_course', true);
            if (version_compare($wp_version, '4.1', '>=')) {
                $url = add_query_arg(array('page' => $this->page_slug, 'course_id' => $course_id), admin_url('admin.php'));
                $title .= sprintf('&nbsp;&nbsp;<span class="course-title">&gt;&nbsp;&nbsp;<a href="%s">%s</a></span>', esc_url($url), get_the_title($course_id));
            } else {
                $title .= sprintf('&nbsp;&nbsp;<span class="course-title">&gt;&nbsp;&nbsp;%s</span>', get_the_title($course_id));
            }
            $url = add_query_arg(array('page' => $this->page_slug, 'lesson_id' => $lesson_id), admin_url('admin.php'));
            $title .= sprintf('&nbsp;&nbsp;<span class="lesson-title">&gt;&nbsp;&nbsp;<a href="%s">%s</a></span>', esc_url($url), get_the_title($lesson_id));
        }
        if (isset($_GET['user']) && 0 < intval($_GET['user'])) {
            $user_name = Sensei_Learner::get_full_name($_GET['user']);
            $title .= '&nbsp;&nbsp;<span class="user-title">&gt;&nbsp;&nbsp;' . $user_name . '</span>';
        }
        // End If Statement
        ?>
			<h2><?php 
        echo apply_filters('sensei_grading_nav_title', $title);
        ?>
</h2>
		<?php 
    }
 /**
  * Generates content for a single row of the table, overriding parent
  * @since  1.7.0
  * @param object $item The current item
  */
 protected function get_row_data($item)
 {
     global $wp_version;
     $grade = '';
     if ('complete' == $item->comment_approved) {
         $status_html = '<span class="graded">' . __('Completed', 'woothemes-sensei') . '</span>';
         $grade = __('No Grade', 'woothemes-sensei');
     } elseif ('graded' == $item->comment_approved) {
         $status_html = '<span class="graded">' . __('Graded', 'woothemes-sensei') . '</span>';
         $grade = get_comment_meta($item->comment_ID, 'grade', true) . '%';
     } elseif ('passed' == $item->comment_approved) {
         $status_html = '<span class="passed">' . __('Passed', 'woothemes-sensei') . '</span>';
         $grade = get_comment_meta($item->comment_ID, 'grade', true) . '%';
     } elseif ('failed' == $item->comment_approved) {
         $status_html = '<span class="failed">' . __('Failed', 'woothemes-sensei') . '</span>';
         $grade = get_comment_meta($item->comment_ID, 'grade', true) . '%';
     } elseif ('ungraded' == $item->comment_approved) {
         $status_html = '<span class="ungraded">' . __('Ungraded', 'woothemes-sensei') . '</span>';
         $grade = __('N/A', 'woothemes-sensei');
     } else {
         $status_html = '<span class="in-progress">' . __('In Progress', 'woothemes-sensei') . '</span>';
         $grade = __('N/A', 'woothemes-sensei');
     }
     $title = Sensei_Learner::get_full_name($item->user_id);
     // QuizID to be deprecated
     $quiz_id = get_post_meta($item->comment_post_ID, '_lesson_quiz', true);
     $quiz_link = esc_url(add_query_arg(array('page' => $this->page_slug, 'user' => $item->user_id, 'quiz_id' => $quiz_id), admin_url('admin.php')));
     $grade_link = '';
     switch ($item->comment_approved) {
         case 'ungraded':
             $grade_link = '<a class="button-primary button" href="' . $quiz_link . '">' . __('Grade quiz', 'woothemes-sensei') . '</a>';
             break;
         case 'graded':
         case 'passed':
         case 'failed':
             $grade_link = '<a class="button-secondary button" href="' . $quiz_link . '">' . __('Review grade', 'woothemes-sensei') . '</a>';
             break;
     }
     $course_id = get_post_meta($item->comment_post_ID, '_lesson_course', true);
     $course_title = '';
     if (!empty($course_id) && version_compare($wp_version, '4.1', '>=')) {
         $course_title = '<a href="' . esc_url(add_query_arg(array('page' => $this->page_slug, 'course_id' => $course_id), admin_url('admin.php'))) . '">' . get_the_title($course_id) . '</a>';
     } else {
         if (!empty($course_id)) {
             $course_title = get_the_title($course_id);
         }
     }
     $lesson_title = '<a href="' . add_query_arg(array('page' => $this->page_slug, 'lesson_id' => $item->comment_post_ID), admin_url('admin.php')) . '">' . get_the_title($item->comment_post_ID) . '</a>';
     $column_data = apply_filters('sensei_grading_main_column_data', array('title' => '<strong><a class="row-title" href="' . esc_url(add_query_arg(array('page' => $this->page_slug, 'user_id' => $item->user_id), admin_url('admin.php'))) . '"">' . $title . '</a></strong>', 'course' => $course_title, 'lesson' => $lesson_title, 'updated' => $item->comment_date, 'user_status' => $status_html, 'user_grade' => $grade, 'action' => $grade_link), $item, $course_id);
     return $column_data;
 }
 /**
  * Generates the overall array for a single item in the display
  * @since  1.7.0
  * @param object $item The current item
  * @return array $column_data;
  */
 protected function get_row_data($item)
 {
     switch ($this->type) {
         case 'courses':
             // Get Learners (i.e. those who have started)
             $course_args = array('post_id' => $item->ID, 'type' => 'sensei_course_status', 'status' => 'any');
             $course_students = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_course_learners', $course_args, $item));
             // Get Course Completions
             $course_args = array('post_id' => $item->ID, 'type' => 'sensei_course_status', 'status' => 'complete');
             $course_completions = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_course_completions', $course_args, $item));
             // Course Lessons
             $course_lessons = Sensei()->lesson->lesson_count(array('publish', 'private'), $item->ID);
             // Get Percent Complete
             $grade_args = array('post_id' => $item->ID, 'type' => 'sensei_course_status', 'status' => 'any', 'meta_key' => 'percent');
             add_filter('comments_clauses', array('WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter'));
             $course_percentage = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_course_percentage', $grade_args, $item), true);
             remove_filter('comments_clauses', array('WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter'));
             $percent_count = !empty($course_percentage->total) ? $course_percentage->total : 1;
             $percent_total = !empty($course_percentage->meta_sum) ? doubleval($course_percentage->meta_sum) : 0;
             $course_average_percent = abs(round(doubleval($percent_total / $percent_count), 2));
             // Output course data
             if ($this->csv_output) {
                 $course_title = apply_filters('the_title', $item->post_title, $item->ID);
             } else {
                 $url = add_query_arg(array('page' => $this->page_slug, 'course_id' => $item->ID), admin_url('admin.php'));
                 $course_title = '<strong><a class="row-title" href="' . esc_url($url) . '">' . apply_filters('the_title', $item->post_title, $item->ID) . '</a></strong>';
                 $course_average_percent .= '%';
             }
             // End If Statement
             $column_data = apply_filters('sensei_analysis_overview_column_data', array('title' => $course_title, 'students' => $course_students, 'lessons' => $course_lessons, 'completions' => $course_completions, 'average_percent' => $course_average_percent), $item, $this);
             break;
         case 'lessons':
             // Get Learners (i.e. those who have started)
             $lesson_args = array('post_id' => $item->ID, 'type' => 'sensei_lesson_status', 'status' => 'any');
             $lesson_students = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_lesson_learners', $lesson_args, $item));
             // Get Course Completions
             $lesson_args = array('post_id' => $item->ID, 'type' => 'sensei_lesson_status', 'status' => array('complete', 'graded', 'passed', 'failed'), 'count' => true);
             $lesson_completions = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_lesson_completions', $lesson_args, $item));
             // Course
             $course_id = get_post_meta($item->ID, '_lesson_course', true);
             $course_title = $course_id ? get_the_title($course_id) : '';
             $lesson_average_grade = __('n/a', 'woothemes-sensei');
             if (false != get_post_meta($item->ID, '_quiz_has_questions', true)) {
                 // Get Percent Complete
                 $grade_args = array('post_id' => $item->ID, 'type' => 'sensei_lesson_status', 'status' => array('graded', 'passed', 'failed'), 'meta_key' => 'grade');
                 add_filter('comments_clauses', array('WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter'));
                 $lesson_grades = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_lesson_grades', $grade_args, $item), true);
                 remove_filter('comments_clauses', array('WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter'));
                 $grade_count = !empty($lesson_grades->total) ? $lesson_grades->total : 1;
                 $grade_total = !empty($lesson_grades->meta_sum) ? doubleval($lesson_grades->meta_sum) : 0;
                 $lesson_average_grade = abs(round(doubleval($grade_total / $grade_count), 2));
             }
             // Output lesson data
             if ($this->csv_output) {
                 $lesson_title = apply_filters('the_title', $item->post_title, $item->ID);
             } else {
                 $url = add_query_arg(array('page' => $this->page_slug, 'lesson_id' => $item->ID), admin_url('admin.php'));
                 $lesson_title = '<strong><a class="row-title" href="' . esc_url($url) . '">' . apply_filters('the_title', $item->post_title, $item->ID) . '</a></strong>';
                 if ($course_id) {
                     $url = add_query_arg(array('page' => $this->page_slug, 'course_id' => $course_id), admin_url('admin.php'));
                     $course_title = '<a href="' . esc_url($url) . '">' . $course_title . '</a>';
                 } else {
                     $course_title = __('n/a', 'woothemes-sensei');
                 }
                 if (is_numeric($lesson_average_grade)) {
                     $lesson_average_grade .= '%';
                 }
             }
             // End If Statement
             $column_data = apply_filters('sensei_analysis_overview_column_data', array('title' => $lesson_title, 'course' => $course_title, 'students' => $lesson_students, 'completions' => $lesson_completions, 'average_grade' => $lesson_average_grade), $item, $this);
             break;
         case 'users':
         default:
             // Get Started Courses
             $course_args = array('user_id' => $item->ID, 'type' => 'sensei_course_status', 'status' => 'any');
             $user_courses_started = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_user_courses_started', $course_args, $item));
             // Get Completed Courses
             $course_args = array('user_id' => $item->ID, 'type' => 'sensei_course_status', 'status' => 'complete');
             $user_courses_ended = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_user_courses_ended', $course_args, $item));
             // Get Quiz Grades
             $grade_args = array('user_id' => $item->ID, 'type' => 'sensei_lesson_status', 'status' => 'any', 'meta_key' => 'grade');
             add_filter('comments_clauses', array('WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter'));
             $user_quiz_grades = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_user_lesson_grades', $grade_args, $item), true);
             remove_filter('comments_clauses', array('WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter'));
             $grade_count = !empty($user_quiz_grades->total) ? $user_quiz_grades->total : 1;
             $grade_total = !empty($user_quiz_grades->meta_sum) ? doubleval($user_quiz_grades->meta_sum) : 0;
             $user_average_grade = abs(round(doubleval($grade_total / $grade_count), 2));
             // Output the users data
             if ($this->csv_output) {
                 $user_name = Sensei_Learner::get_full_name($item->ID);
             } else {
                 $url = add_query_arg(array('page' => $this->page_slug, 'user_id' => $item->ID), admin_url('admin.php'));
                 $user_name = '<strong><a class="row-title" href="' . esc_url($url) . '">' . $item->display_name . '</a></strong>';
                 $user_average_grade .= '%';
             }
             // End If Statement
             $column_data = apply_filters('sensei_analysis_overview_column_data', array('title' => $user_name, 'registered' => $item->user_registered, 'active_courses' => $user_courses_started - $user_courses_ended, 'completed_courses' => $user_courses_ended, 'average_grade' => $user_average_grade), $item, $this);
             break;
     }
     // end switch
     return $column_data;
 }
 /**
  * Generates the overall array for a single item in the display
  *
  * @since  1.7.0
  * @param object $item The current item
  */
 protected function get_row_data($item)
 {
     $user_start_date = get_comment_meta($item->comment_ID, 'start', true);
     $user_end_date = $item->comment_date;
     $status_class = $grade = '';
     if ('complete' == $item->comment_approved) {
         $status = __('Completed', 'woothemes-sensei');
         $status_class = 'graded';
         $grade = __('No Grade', 'woothemes-sensei');
     } elseif ('graded' == $item->comment_approved) {
         $status = __('Graded', 'woothemes-sensei');
         $status_class = 'graded';
         $grade = get_comment_meta($item->comment_ID, 'grade', true);
     } elseif ('passed' == $item->comment_approved) {
         $status = __('Passed', 'woothemes-sensei');
         $status_class = 'graded';
         $grade = get_comment_meta($item->comment_ID, 'grade', true);
     } elseif ('failed' == $item->comment_approved) {
         $status = __('Failed', 'woothemes-sensei');
         $status_class = 'failed';
         $grade = get_comment_meta($item->comment_ID, 'grade', true);
     } elseif ('ungraded' == $item->comment_approved) {
         $status = __('Ungraded', 'woothemes-sensei');
         $status_class = 'ungraded';
     } else {
         $status = __('In Progress', 'woothemes-sensei');
         $user_end_date = '';
     }
     // Output users data
     $user_name = Sensei_Learner::get_full_name($item->user_id);
     if (!$this->csv_output) {
         $url = add_query_arg(array('page' => $this->page_slug, 'user_id' => $item->user_id, 'course_id' => $this->course_id), admin_url('admin.php'));
         $user_name = '<strong><a class="row-title" href="' . esc_url($url) . '">' . $user_name . '</a></strong>';
         $status = sprintf('<span class="%s">%s</span>', $item->comment_approved, $status);
         if (is_numeric($grade)) {
             $grade .= '%';
         }
     }
     // End If Statement
     $column_data = apply_filters('sensei_analysis_lesson_column_data', array('title' => $user_name, 'started' => $user_start_date, 'completed' => $user_end_date, 'status' => $status, 'grade' => $grade), $item, $this);
     return $column_data;
 }
 /**
  * Output for table footer
  * @since  1.2.0
  * @return void
  */
 public function data_table_footer()
 {
     $course = get_post($this->course_id);
     $report = sanitize_title($course->post_title) . '-' . $this->view . 's-overview';
     if ($this->user_id) {
         $user_name = Sensei_Learner::get_full_name($this->user_id);
         $report = sanitize_title($user_name) . '-' . $report;
     }
     $url_args = array('page' => $this->page_slug, 'course_id' => $this->course_id, 'view' => $this->view, 'sensei_report_download' => $report);
     if ($this->user_id) {
         $url_args['user_id'] = $this->user_id;
     }
     $url = add_query_arg($url_args, admin_url('admin.php'));
     echo '<a class="button button-primary" href="' . esc_url(wp_nonce_url($url, 'sensei_csv_download-' . $report, '_sdl_nonce')) . '">' . __('Export all rows (CSV)', 'woothemes-sensei') . '</a>';
 }
Example #8
0
    /**
     * Nav area for Analysis of a specific Course and its Lessons, specific to a User
     * @since  1.2.0
     * @return void
     */
    public function analysis_user_course_nav()
    {
        $title = sprintf('<a href="%s">%s</a>', esc_url(add_query_arg(array('page' => $this->page_slug), admin_url('admin.php'))), esc_html($this->name));
        if (isset($_GET['user_id']) && 0 < intval($_GET['user_id'])) {
            $user_id = intval($_GET['user_id']);
            $user_data = get_userdata($user_id);
            $url = add_query_arg(array('page' => $this->page_slug, 'user_id' => $user_id), admin_url('admin.php'));
            $user_name = Sensei_Learner::get_full_name($user_id);
            $title .= sprintf('&nbsp;&nbsp;<span class="user-title">&gt;&nbsp;&nbsp;<a href="%s">%s</a></span>', $url, $user_name);
            $title .= sprintf('&nbsp;&nbsp;<span class="user-title">&gt;&nbsp;&nbsp;<a href="%s">%s</a></span>', esc_url($url), $user_data->display_name);
        }
        // End If Statement
        if (isset($_GET['course_id'])) {
            $course_id = intval($_GET['course_id']);
            $url = add_query_arg(array('page' => $this->page_slug, 'course_id' => $course_id), admin_url('admin.php'));
            $title .= sprintf('&nbsp;&nbsp;<span class="course-title">&gt;&nbsp;&nbsp;<a href="%s">%s</a></span>', esc_url($url), get_the_title($course_id));
        }
        ?>
			<h1><?php 
        echo apply_filters('sensei_analysis_nav_title', $title);
        ?>
</h1>
		<?php 
    }
 /**
  * Return the full name and surname or the display name of the user.
  *
  * The user must have both name and surname otherwise display name will be returned.
  *
  * @deprecated since 1.9.0 use Se
  * @since 1.8.0
  *
  * @param int $user_id | bool false for an invalid $user_id
  *
  * @return string $full_name
  */
 public function get_learner_full_name($user_id)
 {
     return Sensei_Learner::get_full_name($user_id);
 }
 /**
  * Generates content for a single row of the table in the user management
  * screen.
  *
  * @since  1.7.0
  *
  * @param object $item The current item
  *
  * @return void
  */
 protected function get_row_data($item)
 {
     global $wp_version;
     switch ($this->view) {
         case 'learners':
             // in this case the item passed in is actually the users activity on course of lesson
             $user_activity = $item;
             $post_id = false;
             if ($this->lesson_id) {
                 $post_id = intval($this->lesson_id);
                 $object_type = __('lesson', 'woothemes-sensei');
                 $post_type = 'lesson';
             } elseif ($this->course_id) {
                 $post_id = intval($this->course_id);
                 $object_type = __('course', 'woothemes-sensei');
                 $post_type = 'course';
             }
             if ('complete' == $user_activity->comment_approved || 'graded' == $user_activity->comment_approved || 'passed' == $user_activity->comment_approved) {
                 $status_html = '<span class="graded">' . __('Completed', 'woothemes-sensei') . '</span>';
             } else {
                 $status_html = '<span class="in-progress">' . __('In Progress', 'woothemes-sensei') . '</span>';
             }
             $title = Sensei_Learner::get_full_name($user_activity->user_id);
             $a_title = sprintf(__('Edit &#8220;%s&#8221;'), $title);
             /**
              * sensei_learners_main_column_data filter
              *
              * This filter runs on the learner management screen for a specific course.
              * It provides the learner row column details.
              *
              * @param array $columns{
              *   type string $title
              *   type string $date_started
              *   type string $course_status (completed, started etc)
              *   type html $action_buttons
              * }
              */
             $column_data = apply_filters('sensei_learners_main_column_data', array('title' => '<strong><a class="row-title" href="' . admin_url('user-edit.php?user_id=' . $user_activity->user_id) . '" title="' . esc_attr($a_title) . '">' . $title . '</a></strong>', 'date_started' => get_comment_meta($user_activity->comment_ID, 'start', true), 'user_status' => $status_html, 'actions' => '<a class="remove-learner button" data-user_id="' . $user_activity->user_id . '" data-post_id="' . $post_id . '" data-post_type="' . $post_type . '">' . sprintf(__('Remove from %1$s', 'woothemes-sensei'), $object_type) . '</a>'), $item, $post_id, $post_type);
             break;
         case 'lessons':
             $lesson_learners = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_learners_lesson_learners', array('post_id' => $item->ID, 'type' => 'sensei_lesson_status', 'status' => 'any')));
             $title = get_the_title($item);
             $a_title = sprintf(__('Edit &#8220;%s&#8221;'), $title);
             $grading_action = '';
             if (get_post_meta($item->ID, '_quiz_has_questions', true)) {
                 $grading_action = ' <a class="button" href="' . esc_url(add_query_arg(array('page' => 'sensei_grading', 'lesson_id' => $item->ID, 'course_id' => $this->course_id), admin_url('admin.php'))) . '">' . __('Grading', 'woothemes-sensei') . '</a>';
             }
             $column_data = apply_filters('sensei_learners_main_column_data', array('title' => '<strong><a class="row-title" href="' . admin_url('post.php?action=edit&post=' . $item->ID) . '" title="' . esc_attr($a_title) . '">' . $title . '</a></strong>', 'num_learners' => $lesson_learners, 'updated' => $item->post_modified, 'actions' => '<a class="button" href="' . esc_url(add_query_arg(array('page' => $this->page_slug, 'lesson_id' => $item->ID, 'course_id' => $this->course_id, 'view' => 'learners'), admin_url('admin.php'))) . '">' . __('Manage learners', 'woothemes-sensei') . '</a> ' . $grading_action), $item, $this->course_id);
             break;
         case 'courses':
         default:
             $course_learners = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_learners_course_learners', array('post_id' => $item->ID, 'type' => 'sensei_course_status', 'status' => 'any')));
             $title = get_the_title($item);
             $a_title = sprintf(__('Edit &#8220;%s&#8221;'), $title);
             $grading_action = '';
             if (version_compare($wp_version, '4.1', '>=')) {
                 $grading_action = ' <a class="button" href="' . esc_url(add_query_arg(array('page' => 'sensei_grading', 'course_id' => $item->ID), admin_url('admin.php'))) . '">' . __('Grading', 'woothemes-sensei') . '</a>';
             }
             $column_data = apply_filters('sensei_learners_main_column_data', array('title' => '<strong><a class="row-title" href="' . admin_url('post.php?action=edit&post=' . $item->ID) . '" title="' . esc_attr($a_title) . '">' . $title . '</a></strong>', 'num_learners' => $course_learners, 'updated' => $item->post_modified, 'actions' => '<a class="button" href="' . esc_url(add_query_arg(array('page' => $this->page_slug, 'course_id' => $item->ID, 'view' => 'learners'), admin_url('admin.php'))) . '">' . __('Manage learners', 'woothemes-sensei') . '</a> ' . $grading_action), $item);
             break;
     }
     // switch
     return $column_data;
 }