public function addEntry($data)
 {
     $entry = edr_get_entry();
     $entry->course_id = $data['course_id'];
     $entry->user_id = $data['user_id'];
     $entry->entry_status = $data['entry_status'];
     $entry->grade = isset($data['grade']) ? $data['grade'] : 0.0;
     $entry->complete_date = isset($data['complete_date']) ? $data['complete_date'] : '';
     return $entry->save() ? $entry : null;
 }
Example #2
0
 /**
  * Process payment.
  *
  * @return array
  */
 public function process_payment($object_id, $user_id = 0, $payment_type = 'course', $atts = array())
 {
     if (!$user_id) {
         $user_id = get_current_user_id();
     }
     if (!$user_id) {
         return array('status' => '', 'redirect' => home_url('/'));
     }
     // Add payment.
     $payment = edr_get_payment();
     $payment->user_id = $user_id;
     $payment->payment_type = $payment_type;
     $payment->payment_status = 'complete';
     $payment->payment_gateway = $this->get_id();
     $payment->amount = 0.0;
     $payment->currency = ib_edu_get_currency();
     if ('course' == $payment_type) {
         $payment->course_id = $object_id;
         $payment->amount = ib_edu_get_course_price($object_id);
     } elseif ('membership' == $payment_type) {
         $payment->object_id = $object_id;
         $ms = Edr_Memberships::get_instance();
         $payment->amount = $ms->get_price($object_id);
     }
     if (!empty($atts['ip'])) {
         $payment->ip = $atts['ip'];
     }
     if (0.0 == $payment->amount) {
         $payment->save();
         if ($payment->ID) {
             if ('course' == $payment->payment_type) {
                 // Setup course entry.
                 $entry = edr_get_entry();
                 $entry->course_id = $object_id;
                 $entry->user_id = $user_id;
                 $entry->payment_id = $payment->ID;
                 $entry->entry_status = 'inprogress';
                 $entry->entry_date = date('Y-m-d H:i:s');
                 $entry->save();
             } elseif ('membership' == $payment->payment_type) {
                 // Setup membership.
                 $ms->setup_membership($user_id, $object_id);
             }
         }
     }
     return array('status' => 'complete', 'redirect' => get_permalink($object_id), 'payment' => $payment);
 }
 /**
  * View certificates.
  * Listens to the "template_redirect" action hook.
  */
 public function view_certificate()
 {
     global $post;
     $post_type = get_post_type();
     if ('edr_certificate' == $post_type) {
         $edr_crt = Edr_Manager::get('edr_crt');
         // Check permission.
         if (!$edr_crt->can_view_certificate($post)) {
             wp_die(__('You are not allowed to view this page.', 'edr-crt'));
         }
         $custom = get_post_custom($post->ID);
         // Get entry.
         $entry = edr_get_entry($custom['entry_id'][0]);
         if ($entry->ID) {
             // Get course.
             $course = get_post($entry->course_id);
             if ($course) {
                 // Get template ID.
                 $crt_template = get_post_meta($course->ID, '_edr_crt_template', true);
                 // Get student.
                 $student = get_user_by('id', $entry->user_id);
                 if ($crt_template && $student) {
                     // Get page size.
                     $page_size = get_post_meta($crt_template, '_edr_crt_size', true);
                     $page_sizes = $edr_crt->get_page_sizes();
                     if (array_key_exists($page_size, $page_sizes)) {
                         $page_size = array($page_sizes[$page_size]['width'], $page_sizes[$page_size]['height']);
                     } else {
                         $page_size = 'a4';
                     }
                     $data = array('orientation' => get_post_meta($crt_template, '_edr_crt_orientation', true), 'image' => get_attached_file(get_post_thumbnail_id($crt_template)), 'student_name' => $edr_crt->get_student_name($student), 'course_title' => $course->post_title, 'date' => date_i18n(get_option('date_format'), time()), 'blocks' => get_post_meta($crt_template, '_edr_crt_blocks', true), 'file_name' => 'certificate-' . sanitize_title($post->post_name) . '.pdf', 'page_size' => $page_size);
                     $edr_crt->output_pdf($data);
                 }
             }
         }
         exit;
     } elseif ('edr_certificate_tpl' == $post_type) {
         $user = wp_get_current_user();
         if (!$user->ID || !current_user_can('edit_edr_certificate_tpl', $post->ID)) {
             wp_die(__('You are not allowed to view this page.', 'edr-crt'));
         }
         $post_id = get_the_ID();
         $edr_crt = Edr_Manager::get('edr_crt');
         // Get page size.
         $page_size = get_post_meta($post_id, '_edr_crt_size', true);
         $page_sizes = $edr_crt->get_page_sizes();
         if (array_key_exists($page_size, $page_sizes)) {
             $page_size = array($page_sizes[$page_size]['width'], $page_sizes[$page_size]['height']);
         } else {
             $page_size = 'a4';
         }
         $data = array('orientation' => get_post_meta($post_id, '_edr_crt_orientation', true), 'image' => get_attached_file(get_post_thumbnail_id($post_id)), 'course_title' => __('Course Title', 'edr-crt'), 'student_name' => $edr_crt->get_student_name($user), 'date' => date_i18n(get_option('date_format'), time()), 'blocks' => get_post_meta($post_id, '_edr_crt_blocks', true), 'file_name' => 'preview-certificate-' . $post_id . '.pdf', 'page_size' => $page_size);
         $edr_crt->output_pdf($data);
         exit;
     }
 }
Example #4
0
 /**
  * Delete an entry.
  */
 public static function delete_entry()
 {
     // Verify nonce.
     if (!isset($_GET['_wpnonce']) || !wp_verify_nonce($_GET['_wpnonce'], 'edr_delete_entry')) {
         return;
     }
     // Check permissions.
     if (!current_user_can('manage_educator')) {
         return;
     }
     // Get entry.
     $entry_id = isset($_GET['entry_id']) ? intval($_GET['entry_id']) : null;
     if (!$entry_id) {
         return;
     }
     $entry = edr_get_entry($entry_id);
     // Delete entry if it was found.
     if ($entry->ID && $entry->delete()) {
         wp_redirect(admin_url('admin.php?page=ib_educator_entries&edr-message=entry_deleted'));
         exit;
     }
 }
Example #5
0
 /**
  * Process bulk actions.
  */
 public function process_bulk_action()
 {
     $ids = isset($_POST['entry']) ? $_POST['entry'] : null;
     if (!is_array($ids) || empty($ids)) {
         return;
     }
     $action = $this->current_action();
     foreach ($ids as $id) {
         if ('delete' === $action) {
             $entry = edr_get_entry($id);
             if ($entry->ID) {
                 $entry->delete();
             }
         }
     }
 }
Example #6
0
<?php

if (!defined('ABSPATH')) {
    exit;
}
$entry_id = isset($_GET['entry_id']) ? absint($_GET['entry_id']) : 0;
$entry = edr_get_entry($entry_id);
$who = '';
if (current_user_can('manage_educator')) {
    $who = 'admin';
} elseif ($entry->course_id && current_user_can('edit_ib_educator_course', $entry->course_id)) {
    $who = 'lecturer';
}
// Check capabilities.
if (empty($who)) {
    // Current user cannot create entries.
    echo '<p>' . __('Access denied', 'ibeducator') . '</p>';
    return;
}
$statuses = edr_get_entry_statuses();
$origins = edr_get_entry_origins();
$student = null;
$course = null;
$input = array('payment_id' => isset($_POST['payment_id']) ? $_POST['payment_id'] : $entry->payment_id, 'membership_id' => isset($_POST['membership_id']) ? $_POST['membership_id'] : $entry->object_id, 'entry_origin' => isset($_POST['entry_origin']) ? $_POST['entry_origin'] : $entry->entry_origin, 'entry_status' => isset($_POST['entry_status']) ? $_POST['entry_status'] : $entry->entry_status, 'grade' => isset($_POST['grade']) ? $_POST['grade'] : $entry->grade, 'entry_date' => isset($_POST['entry_date']) ? $_POST['entry_date'] : (!empty($entry->entry_date) ? $entry->entry_date : date('Y-m-d H:i:s')));
if ('admin' == $who && isset($_POST['student_id'])) {
    $student = get_user_by('id', $_POST['student_id']);
} elseif ($entry->ID) {
    $student = get_user_by('id', $entry->user_id);
}
if ('admin' == $who && isset($_POST['course_id'])) {
    $course = get_post($_POST['course_id']);
Example #7
0
 /**
  * Pause user's entries with origin of "membership".
  */
 public function testPauseMembershipEntries()
 {
     $entry = edr_get_entry();
     $entry->course_id = $this->courses[0];
     $entry->user_id = $this->users['student1'];
     $entry->payment_id = 0;
     $entry->entry_status = 'inprogress';
     $entry->entry_origin = 'membership';
     $entry->entry_date = date('Y-m-d H:i:s');
     $entry->save();
     $ms = Edr_Memberships::get_instance();
     $ms->pause_membership_entries($this->users['student1']);
     $entry = edr_get_entry($entry->ID);
     $this->assertEquals('paused', $entry->entry_status);
 }
Example #8
0
 /**
  * Resume entry.
  */
 public static function resume_entry()
 {
     if (!isset($_POST['_wpnonce']) || !wp_verify_nonce($_POST['_wpnonce'], 'ib_educator_resume_entry')) {
         return;
     }
     // Get the current user id.
     $user_id = get_current_user_id();
     if (!$user_id) {
         return;
     }
     // Get entry id.
     if (!isset($_POST['entry_id'])) {
         return;
     }
     $entry_id = $_POST['entry_id'];
     // Get entry.
     $entry = edr_get_entry($entry_id);
     if (!$entry) {
         return;
     }
     $ms = Edr_Memberships::get_instance();
     // Check if there is an "inprogress" entry for this course.
     $api = IB_Educator::get_instance();
     $inprogress_entry = $api->get_entry(array('entry_status' => 'inprogress', 'course_id' => $entry->course_id, 'user_id' => $user_id));
     // Make sure that this entry belongs to the current user.
     // Make sure that the current membership gives access to this entry's course.
     if ($inprogress_entry || $entry->user_id != $user_id || !$ms->membership_can_access($entry->course_id, $user_id)) {
         return;
     }
     $entry->entry_status = 'inprogress';
     $entry->save();
     wp_safe_redirect(get_permalink());
 }
Example #9
0
 /**
  * Add course entry.
  */
 public function addEntry($data)
 {
     $payment = edr_get_payment($data['payment_id']);
     $entry = edr_get_entry();
     $entry->course_id = $data['course_id'];
     $entry->user_id = $payment->user_id;
     $entry->payment_id = $payment->ID;
     $entry->entry_status = $data['entry_status'];
     $entry->entry_date = date('Y-m-d H:i:s');
     $entry->save();
     return $entry->ID;
 }
Example #10
0
 /**
  * Setup payment item (e.g. course, membership).
  *
  * @param IB_Educator_Payment $payment
  */
 public function setup_payment_item($payment)
 {
     if ('course' == $payment->payment_type) {
         // Setup course entry.
         $entry = $this->get_entry(array('payment_id' => $payment->ID));
         if (!$entry) {
             $entry = edr_get_entry();
             $entry->course_id = $payment->course_id;
             $entry->user_id = $payment->user_id;
             $entry->payment_id = $payment->ID;
             $entry->entry_status = 'inprogress';
             $entry->entry_date = date('Y-m-d H:i:s');
             $entry->save();
             // Send notification email to the student.
             $student = get_user_by('id', $payment->user_id);
             $course = get_post($payment->course_id, OBJECT, 'display');
             if ($student && $course) {
                 ib_edu_send_notification($student->user_email, 'student_registered', array('course_title' => $course->post_title), array('student_name' => $student->display_name, 'course_title' => $course->post_title, 'course_excerpt' => $course->post_excerpt));
             }
         }
     } elseif ('membership' == $payment->payment_type) {
         // Setup membership.
         $ms = Edr_Memberships::get_instance();
         $ms->setup_membership($payment->user_id, $payment->object_id);
         $student = get_user_by('id', $payment->user_id);
         $membership = $ms->get_membership($payment->object_id);
         if ($student && $membership) {
             $user_membership = $ms->get_user_membership($student->ID);
             $membership_meta = $ms->get_membership_meta($membership->ID);
             $expiration = $user_membership ? $user_membership['expiration'] : 0;
             ib_edu_send_notification($student->user_email, 'membership_register', array(), array('student_name' => $student->display_name, 'membership' => $membership->post_title, 'expiration' => $expiration ? date_i18n(get_option('date_format'), $expiration) : __('None', 'ibeducator'), 'price' => $ms->format_price($membership_meta['price'], $membership_meta['duration'], $membership_meta['period'], false)));
         }
     }
 }
Example #11
0
 /**
  * AJAX: add grade for a quiz.
  */
 public static function quiz_grade()
 {
     global $wpdb;
     $entry_id = isset($_POST['entry_id']) ? absint($_POST['entry_id']) : 0;
     $lesson_id = isset($_POST['lesson_id']) ? absint($_POST['lesson_id']) : 0;
     // Verify nonce.
     if (!isset($_POST['_wpnonce']) || !wp_verify_nonce($_POST['_wpnonce'], 'edr_edit_progress_' . $entry_id)) {
         exit;
     }
     // Verify capabilities.
     if (!current_user_can('edit_ib_educator_lesson', $lesson_id)) {
         exit;
     }
     $quizzes = Edr_Manager::get('edr_quizzes');
     $quiz_grade = $quizzes->get_grade($lesson_id, $entry_id);
     if (!$quiz_grade) {
         exit;
     }
     $grade = isset($_POST['grade']) ? floatval($_POST['grade']) : 0;
     $quizzes->update_grade($quiz_grade->ID, array('grade' => $grade, 'status' => 'approved'));
     // Send notification email to the student.
     $entry = edr_get_entry($entry_id);
     $student = get_user_by('id', $entry->user_id);
     if ($student) {
         $lesson_title = get_the_title($lesson_id);
         ib_edu_send_notification($student->user_email, 'quiz_grade', array('lesson_title' => $lesson_title), array('student_name' => $student->display_name, 'lesson_title' => $lesson_title, 'grade' => ib_edu_format_grade($grade)));
     }
     echo json_encode(array('status' => 'success'));
     exit;
 }