Exemplo n.º 1
0
 static function complete($lesson_id, $student_id)
 {
     global $wpdb;
     $_course = new NamasteLMSCourseModel();
     // find the lesson
     $lesson = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->posts} WHERE ID=%d", $lesson_id));
     $course_id = get_post_meta($lesson->ID, 'namaste_course', true);
     // get course
     $course = $_course->select($course_id);
     // mark lesson as completed - at this point we must have student-lesson record
     $student_lesson = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . NAMASTE_STUDENT_LESSONS . "\n\t\t\tWHERE lesson_id=%d AND student_id=%d", $lesson->ID, $student_id));
     if (empty($student_lesson->id)) {
         return false;
     }
     // if the lesson is already completed, don't mark it again
     if ($student_lesson->status == 1) {
         return false;
     }
     $wpdb->query($wpdb->prepare("UPDATE " . NAMASTE_STUDENT_LESSONS . " \n\t\tSET status = '1', completion_date = %s, completion_time=%s\n\t\tWHERE id=%d", date("Y-m-d", current_time('timestamp')), current_time('mysql'), $student_lesson->id));
     // award points?
     $use_points_system = get_option('namaste_use_points_system');
     if ($use_points_system) {
         $award_points = get_post_meta($lesson_id, 'namaste_award_points', true);
         if ($award_points === '') {
             $award_points = get_option('namaste_points_lesson');
         }
         if ($award_points) {
             NamastePoint::award($student_id, $award_points, sprintf(__('Received %d points for completing lesson "%s".', 'namaste'), $award_points, $lesson->post_title), 'lesson', $lesson_id);
         }
     }
     do_action('namaste_completed_lesson', $student_id, $lesson_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_lesson', value=%s, num_value=%d", $student_id, sprintf(__('Completed lesson "%s"', 'namaste'), $lesson->post_title), $lesson_id));
     // now see if course should be completed
     if ($_course->is_ready($course_id, $student_id)) {
         $_course->complete($course_id, $student_id);
     }
     return true;
 }
Exemplo n.º 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));
 }
Exemplo n.º 3
0
 static function change_solution_status($lesson, $student_id = NULL)
 {
     global $wpdb, $user_ID;
     if (!current_user_can('namaste_manage')) {
         wp_die(__('You are not allowed to do this', 'namaste'));
     }
     $solution = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . NAMASTE_STUDENT_HOMEWORKS . " WHERE id=%d", $_POST['solution_id']));
     if (!$student_id) {
         $student_id = $solution->student_id;
     }
     $homework = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . NAMASTE_HOMEWORKS . " WHERE id=%d", $solution->homework_id));
     $multiuser_access = 'all';
     $multiuser_access = NamasteLMSMultiUser::check_access('homework_access');
     if ($multiuser_access == 'own' and $homework->editor_id != $user_ID) {
         wp_die(__('You are not allowed to see these solutions', 'namaste'));
     }
     $wpdb->query($wpdb->prepare("UPDATE " . NAMASTE_STUDENT_HOMEWORKS . " SET\n\t\t\tstatus=%s WHERE id=%d", $_POST['status'], $_POST['solution_id']));
     do_action('namaste_change_solution_status', $student_id, $_POST['solution_id'], $_POST['status']);
     // insert in history
     $wpdb->query($wpdb->prepare("INSERT INTO " . NAMASTE_HISTORY . " SET\n\t\t\tuser_id=%d, date=CURDATE(), datetime=NOW(), action='solution_processed', value=%s, num_value=%d", $student_id, sprintf(__('Solution to assignment %s was %s', 'namaste'), $homework->title, $_POST['status']), $_POST['solution_id']));
     // award points?
     if ($_POST['status'] == 'approved' and get_option('namaste_use_points_system')) {
         if ($homework->award_points) {
             NamastePoint::award($student_id, $homework->award_points, sprintf(__('Received %d points for completing assignment "%s".', 'namaste'), $homework->award_points, $homework->title, 'homework', $homework->id));
         }
     }
     // maybe complete the lesson if the status is approved
     if ($_POST['status'] == 'approved' and NamasteLMSLessonModel::is_ready($lesson->ID, $student_id)) {
         NamasteLMSLessonModel::complete($lesson->ID, $student_id);
     }
 }