static function assignments($atts) { global $user_ID; if (!empty($atts['lesson_id'])) { $_GET['lesson_id'] = intval($atts['lesson_id']); } // prepare arguments $_GET['student_id'] = $user_ID; ob_start(); // returning the view solutions page if (!empty($_GET['view_solutions'])) { NamasteLMSHomeworkController::view(true); $content = ob_get_clean(); return $content; } // returning submit solution page if (!empty($_GET['submit_solution'])) { NamasteLMSHomeworkController::submit_solution(true); $content = ob_get_clean(); return $content; } // normally we return the homeworks NamasteLMSHomeworkModel::lesson_homeworks(true); $content = ob_get_clean(); return $content; }
static function student_lessons($simplified = false, $ob = null, $dir = null, $in_shortcode = false) { global $wpdb, $user_ID; // student_id $student_id = (empty($_GET['student_id']) or !current_user_can('namaste_manage')) ? $user_ID : $_GET['student_id']; // select this student $student = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->users} WHERE ID=%d", $student_id)); // select this course $course = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->posts} WHERE id=%d", $_GET['course_id'])); // am I enrolled? if (!current_user_can('namaste_manage') and !$in_shortcode) { $enrolled = $wpdb->get_var($wpdb->prepare("SELECT id FROM " . NAMASTE_STUDENT_COURSES . " WHERE user_id = %d AND course_id = %d AND (status = 'enrolled' OR status = 'completed')", $student_id, $course->ID)); if (!$enrolled) { _e("You must enroll in the course first before you can see the lessons", 'namaste'); return false; } } // end enrolled check // change student-lesson status? if (!empty($_POST['change_status'])) { $multiuser_access = 'all'; $multiuser_access = NamasteLMSMultiUser::check_access('students_access'); if ($multiuser_access == 'view') { wp_die(__('You are not allowed to do this.', 'namaste')); } $result = NamasteLMSStudentModel::lesson_status($student->ID, $_POST['lesson_id'], $_POST['status']); if (!$result) { $error = __('The lesson cannot be completed because there are unsatisfied requirements', 'namaste'); } } // select lessons $_lesson = new NamasteLMSLessonModel(); $select_ob = empty($ob) ? 'post_title' : $ob; $lessons = $_lesson->select($course->ID, 'array', null, $ob, $dir); $ids = array(0); foreach ($lessons as $lesson) { $ids[] = $lesson->ID; } $id_sql = implode(",", $ids); // select homeworks and match to lessons $homeworks = NamasteLMSHomeworkModel::select("WHERE lesson_id IN ({$id_sql})"); // using exams? select them too $use_exams = get_option('namaste_use_exams'); $exams_table = $use_exams == 'watu' ? $wpdb->prefix . 'watu_master' : $wpdb->prefix . 'watupro_master'; $shortcode = $use_exams == 'watu' ? 'WATU' : 'WATUPRO'; // select student-lesson relation so we can match status $student_lessons = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . NAMASTE_STUDENT_LESSONS . "\r\n\t\t\tWHERE student_id = %d", $student_id)); foreach ($lessons as $cnt => $lesson) { $lesson_homeworks = array(); foreach ($homeworks as $homework) { if ($homework->lesson_id == $lesson->ID) { $lesson_homeworks[] = $homework; } } $lessons[$cnt]->homeworks = $lesson_homeworks; if ($use_exams) { $required_exam = get_post_meta($lesson->ID, 'namaste_required_exam', true); if ($required_exam) { $exam = $wpdb->get_row("SELECT tE.*, tP.id as post_id FROM {$exams_table} tE, {$wpdb->posts} tP\r\n\t\t\t\t\t\tWHERE tE.ID = {$required_exam} AND tP.post_content LIKE CONCAT('%[{$shortcode} ', tE.ID, ']%')\r\n\t\t\t\t\t\tAND tP.post_status='publish' AND post_title!=''"); $lessons[$cnt]->exam = $exam; } } // status $status = null; foreach ($student_lessons as $l) { if ($l->lesson_id == $lesson->ID) { $status = $l; } } if (empty($status->id)) { $lessons[$cnt]->status = __('Not started', 'namaste'); $lessons[$cnt]->statuscode = -1; } else { if ($status->status == 1) { $lessons[$cnt]->status = __('Completed on', 'namaste') . ' ' . date(get_option('date_format'), strtotime($status->completion_date)); $lessons[$cnt]->statuscode = 1; } else { // in progress $lessons[$cnt]->status = "<a href='#' onclick='namasteInProgress(" . $lesson->ID . ", " . $student_id . ");return false;'>" . __('In progress', 'namaste') . "</a>"; $lessons[$cnt]->statuscode = 0; } } // end defining status } // external reorder? if (empty($ob)) { $lessons = apply_filters('namaste-reorder-lessons', $lessons); } // enqueue thickbox wp_enqueue_script('thickbox', null, array('jquery')); wp_enqueue_style('thickbox.css', '/' . WPINC . '/js/thickbox/thickbox.css', null, '1.0'); if (@file_exists(get_stylesheet_directory() . '/namaste/student-lessons.php')) { require get_stylesheet_directory() . '/namaste/student-lessons.php'; } else { require NAMASTE_PATH . "/views/student-lessons.php"; } }
static function view_all() { global $wpdb, $user_ID; list($homework, $course, $lesson) = NamasteLMSHomeworkModel::full_select($_GET['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')); } $use_grading_system = get_option('namaste_use_grading_system'); // approve or reject solution if (!empty($_POST['change_status'])) { self::change_solution_status($lesson); } // select submitted solutions $solutions = $wpdb->get_results($wpdb->prepare("SELECT tH.*, tU.user_login as user_login \n\t\t\tFROM " . NAMASTE_STUDENT_HOMEWORKS . " tH JOIN {$wpdb->users} tU ON tH.student_id = tU.ID\n\t\t\tWHERE homework_id=%d ORDER BY id DESC", $homework->id)); // select & match notes for each homework $notes = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . NAMASTE_HOMEWORK_NOTES . " \n\t\t \tWHERE homework_id=%d ORDER BY id", $homework->id)); // match notes to solutions. Currently all notes go to all solutions of a given homework, as long as it's from the same student foreach ($solutions as $cnt => $solution) { $s_notes = array(); foreach ($notes as $note) { if ($note->homework_id == $solution->homework_id and $note->student_id == $solution->student_id) { $s_notes[] = $note; } } $solutions[$cnt]->notes = $s_notes; } $manager_mode = true; $show_everyone = true; wp_enqueue_script('thickbox', null, array('jquery')); wp_enqueue_style('thickbox.css', '/' . WPINC . '/js/thickbox/thickbox.css', null, '1.0'); if (@file_exists(get_stylesheet_directory() . '/namaste/view-solutions.php')) { require get_stylesheet_directory() . '/namaste/view-solutions.php'; } else { require NAMASTE_PATH . "/views/view-solutions.php"; } }