Exemple #1
0
 static function my_certificates($in_shortcode = false)
 {
     global $wpdb, $user_ID;
     $_cert = new NamasteLMSCertificateModel();
     $certificates = $_cert->student_certificates($user_ID);
     $student_id = $user_ID;
     if (@file_exists(get_stylesheet_directory() . '/namaste/my-certificates.php')) {
         require get_stylesheet_directory() . '/namaste/my-certificates.php';
     } else {
         require NAMASTE_PATH . "/views/my-certificates.php";
     }
 }
Exemple #2
0
 function complete($course_id, $student_id)
 {
     global $wpdb;
     $student_course = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . NAMASTE_STUDENT_COURSES . "\n\t\t\tWHERE course_id=%d AND user_id=%d", $course_id, $student_id));
     if (empty($student_course->id)) {
         return false;
     }
     // if the course is already completed, don't mark it again
     if ($student_course->status == 'completed') {
         return false;
     }
     $course = get_post($course_id);
     $wpdb->query($wpdb->prepare("UPDATE " . NAMASTE_STUDENT_COURSES . " SET status = 'completed',\n\t\t\tcompletion_date = %s, completion_time=%s WHERE id=%d", date("Y-m-d", current_time('timestamp')), current_time('mysql'), $student_course->id));
     // should we assign certificates?
     $_cert = new NamasteLMSCertificateModel();
     $_cert->complete_course($course_id, $student_id);
     // award points?
     $use_points_system = get_option('namaste_use_points_system');
     if ($use_points_system) {
         $award_points = get_post_meta($course_id, 'namaste_award_points', true);
         if ($award_points === '') {
             $award_points = get_option('namaste_points_course');
         }
         if ($award_points) {
             NamastePoint::award($student_id, $award_points, sprintf(__('Received %d points for completing course "%s".', 'namaste'), $award_points, $course->post_title, 'course', $course_id));
         }
     }
     // add custom action
     do_action('namaste_completed_course', $student_id, $course_id);
     // insert in history
     $wpdb->query($wpdb->prepare("INSERT INTO " . NAMASTE_HISTORY . " SET\n\t\t\tuser_id=%d, date=CURDATE(), datetime=NOW(), action='completed_course', value=%s, num_value=%d", $student_id, sprintf(__('Completed course "%s"', 'namaste'), $course->post_title), $course_id));
 }