/**
  * Get field HTML
  *
  * @param mixed $meta
  * @param array $field
  *
  * @return string
  */
 static function html($meta, $field)
 {
     global $post;
     $course = LP_Course::get_course($post);
     $view = learn_press_get_admin_view('meta-boxes/course/curriculum.php');
     ob_start();
     include $view;
     return ob_get_clean();
 }
/**
 * get current status of user's course
 *
 * @author  Tunn
 *
 * @param   int $user_id
 * @param   int $course_id
 *
 * @return  string
 */
function learn_press_get_user_course_status($user_id = null, $course_id = null)
{
    _deprecated_function(__FUNCTION__, '1.0', 'LP_User() -> get_course_status');
    if ($course = LP_Course::get_course($course_id) && ($user = learn_press_get_user($user_id))) {
        return $user->get_course_status($course_id);
    }
    return false;
    $status = null;
    // try to get current user if not passed
    if (!$user_id) {
        $user_id = get_current_user_id();
    }
    // try to get course id if not passed
    if (!$course_id) {
        global $course;
        $course_id = $course ? $course->id : get_the_ID();
    }
    if ($course_id && $user_id) {
        //add_user_meta(  $user_id, '_lpr_order_id', 40 );
        $orders = get_user_meta($user_id, '_lpr_order_id');
        $orders = array_unique($orders);
        if ($orders) {
            $order_id = 0;
            foreach ($orders as $order) {
                $order_items = get_post_meta($order, '_learn_press_order_items', true);
                if ($order_items && $order_items->products) {
                    if (!empty($order_items->products[$course_id])) {
                        $order_id = max($order_id, $order);
                    }
                }
            }
            if (($order = get_post($order_id)) && $order->post_status != 'lpr-draft') {
                $status = get_post_meta($order_id, '_learn_press_transaction_status', true);
            }
        }
    }
    return $status;
}
 function get_course()
 {
     if (empty($this->course)) {
         global $wpdb;
         $query = $wpdb->prepare("\n\t\t\t\tSELECT c.*\n\t\t\t\tFROM {$wpdb->posts} c\n\t\t\t\tINNER JOIN {$wpdb->learnpress_sections} ls on c.ID = ls.course_id\n\t\t\t\tINNER JOIN {$wpdb->learnpress_section_items} lsi on lsi.section_id = ls.ID AND lsi.item_id = %d\n\t\t\t\t", $this->id);
         if ($course_id = $wpdb->get_var($query)) {
             $this->course = LP_Course::get_course($course_id);
         }
     }
     return $this->course;
 }
Beispiel #4
0
 function __get($key)
 {
     if (empty($this->{$key})) {
         switch ($key) {
             case 'email':
                 $this->{$key} = LP_Email::instance();
                 break;
             case 'checkout':
                 $this->{$key} = LP_Checkout::instance();
                 break;
             case 'course':
                 if (is_course()) {
                     $this->{$key} = LP_Course::get_course(get_the_ID());
                 }
                 break;
             case 'quiz':
                 if (is_quiz()) {
                     $this->{$key} = LP_Quiz::get_quiz(get_the_ID());
                 }
                 break;
         }
     }
     return !empty($this->{$key}) ? $this->{$key} : false;
 }
 /**
  * Creates temp new order if needed
  *
  * @return mixed|WP_Error
  * @throws Exception
  */
 function create_order()
 {
     global $wpdb;
     // Third-party can be controls to create a order
     if ($order_id = apply_filters('learn_press_create_order', null, $this)) {
         return $order_id;
     }
     try {
         // Start transaction if available
         //$wpdb->query( 'START TRANSACTION' );
         $order_data = array('status' => apply_filters('learn_press_default_order_status', 'pending'), 'user_id' => get_current_user_id(), 'user_note' => isset($_REQUEST['order_comments']) ? $_REQUEST['order_comments'] : '', 'created_via' => 'checkout');
         // Insert or update the post data
         $order_id = absint(LP()->session->order_awaiting_payment);
         // Resume the unpaid order if its pending
         if ($order_id > 0 && ($order = learn_press_get_order($order_id)) && $order->has_status(array('pending', 'failed'))) {
             $order_data['ID'] = $order_id;
             $order = learn_press_update_order($order_data);
             if (is_wp_error($order)) {
                 throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'learn_press'), 401));
             } else {
                 $order->remove_order_items();
                 //do_action( 'learn_press_resume_order', $order_id );
             }
         } else {
             $order = learn_press_create_order($order_data);
             if (is_wp_error($order)) {
                 throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'learn_press'), 400));
             } else {
                 $order_id = $order->id;
                 do_action('learn_press_new_order', $order_id);
             }
         }
         // Store the line items to the new/resumed order
         foreach (LP()->cart->get_items() as $item) {
             if (empty($item['order_item_name']) && !empty($item['item_id']) && ($course = LP_Course::get_course($item['item_id']))) {
                 $item['order_item_name'] = $course->get_title();
             } else {
                 throw new Exception(sprintf(__('Item does not exists!', 'learn_press'), 402));
             }
             $item_id = $order->add_item($item);
             if (!$item_id) {
                 throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'learn_press'), 402));
             }
             // Allow plugins to add order item meta
             do_action('learn_press_add_order_item_meta', $item_id, $item);
         }
         $order->set_payment_method($this->payment_method);
         // Update user meta
         if (!empty($this->user_id)) {
             if (apply_filters('learn_press_checkout_update_user_data', true, $this)) {
                 // TODO: update user meta
             }
             do_action('learn_press_checkout_update_user_meta', $this->user_id, $_REQUEST);
         }
         // Third-party add meta data
         do_action('learn_press_checkout_update_order_meta', $order_id, $_REQUEST);
         //$wpdb->query( 'COMMIT' );
     } catch (Exception $e) {
         // There was an error adding order data!
         $wpdb->query('ROLLBACK');
         echo $e->getMessage();
         return false;
         //$e->getMessage();
     }
     return $order_id;
 }
Beispiel #6
0
 /**
  * Print content for custom column
  *
  * @param $column
  */
 function columns_content($column)
 {
     global $post;
     switch ($column) {
         case 'sections':
             $course = LP_Course::get_course($post->ID);
             $sections = $course->get_curriculum();
             if ($sections) {
                 $items = $course->get_curriculum_items(array('group' => true));
                 $count_sections = sizeof($sections);
                 $count_lessons = sizeof($items['lessons']);
                 $count_quizzes = sizeof($items['quizzes']);
                 $output = sprintf(_nx('%d section', '%d sections', $count_sections, 'learn_press'), $count_sections);
                 $output .= ' (';
                 if ($count_lessons) {
                     $output .= sprintf(_nx('%d lesson', '%d lessons', $count_lessons, 'learn_press'), $count_lessons);
                 } else {
                     $output .= __("0 lesson", 'learn_press');
                 }
                 $output .= ', ';
                 if ($count_quizzes) {
                     $output .= sprintf(_nx('%d quiz', '%d quizzes', $count_quizzes, 'learn_press'), $count_quizzes);
                 } else {
                     $output .= __("0 quiz", 'learn_press');
                 }
                 $output .= ')';
                 echo $output;
             } else {
                 _e('No content', 'learn_press');
             }
             break;
     }
 }
Beispiel #7
0
</th>
				<th class="course-total"><?php 
_e('Total', 'learn_press');
?>
</th>
			</tr>
		</thead>
		<tbody>
		<?php 
do_action('learn_press_before_cart_contents');
?>

		<?php 
foreach (LP()->cart->get_items() as $cart_item) {
    $_course_id = apply_filters('learn_press_cart_item_course_id', $cart_item['item_id'], $cart_item, $cart_item_key);
    $_course = apply_filters('learn_press_cart_item_course', LP_Course::get_course($_course_id), $cart_item);
    if ($_course && $_course->exists() && $cart_item['quantity'] > 0 && apply_filters('learn_press_cart_item_visible', true, $cart_item)) {
        ?>
				<tr class="<?php 
        echo esc_attr(apply_filters('learn_press_cart_item_class', 'cart_item', $cart_item));
        ?>
">

					<td class="course-thumbnail">
						<?php 
        $thumbnail = apply_filters('learn_press_cart_item_thumbnail', $_course->get_image(), $cart_item);
        if (!$_course->is_visible()) {
            echo $thumbnail;
        } else {
            printf('<a href="%s">%s</a>', esc_url($_course->get_permalink($cart_item)), $thumbnail);
        }
Beispiel #8
0
 function get_course()
 {
     if (empty($this->course)) {
         $course_id = $this->_lpr_course;
         $this->course = LP_Course::get_course($course_id);
     }
     return $this->course;
 }
/**
 * Get curriculum of a course
 *
 * @version 1.0
 *
 * @param $course_id
 *
 * @return mixed
 */
function learn_press_get_course_curriculum($course_id)
{
    $course = LP_Course::get_course($course_id);
    return $course->get_curriculum();
}
 /**
  * Get the owns order of all items in a course to check permission for view
  * This function is called when a function related with a course also is called
  * Make sure parse the order of any items before check permission of it
  *
  * @param $course_id
  *
  * @return bool
  */
 private function _parse_item_order_of_course($course_id)
 {
     static $courses_parsed = array();
     if (!empty($courses_parsed[$course_id])) {
         return true;
     }
     global $wpdb;
     $items = LP_Course::get_course($course_id)->get_curriculum_items(array('field' => 'ID'));
     // How to make this simpler, LOL?
     $query = $wpdb->prepare("\n\t\t\tSELECT order_id, si.item_id\n\t\t\tFROM {$wpdb->posts} o\n\t\t\tINNER JOIN {$wpdb->postmeta} om ON om.post_id = o.ID AND om.meta_key = %s AND om.meta_value = %d\n\t\t\tINNER JOIN {$wpdb->learnpress_order_items} oi ON o.ID = oi.order_ID\n\t\t\tINNER JOIN {$wpdb->learnpress_order_itemmeta} oim ON oim.learnpress_order_item_id= oi.order_item_id AND oim.meta_key = %s\n\t\t\tINNER JOIN {$wpdb->posts} c ON c.ID = oim.meta_value\n\t\t\tINNER JOIN {$wpdb->learnpress_sections} s ON s.course_id = c.ID\n\t\t\tINNER JOIN {$wpdb->learnpress_section_items} si ON si.section_id = s.id WHERE si.item_id IN (" . join(',', $items) . ")\n\t\t", '_user_id', $this->id, '_course_id');
     if ($results = $wpdb->get_results($query)) {
         foreach ($results as $row) {
             self::$_order_items[$row->item_id] = $row->order_id;
         }
     }
     $courses_parsed[$course_id] = true;
 }
/**
 * count the number of students has enrolled a course
 *
 * @author  TuNN
 *
 * @param   int $course_id
 *
 * @return  int
 */
function learn_press_count_students_enrolled($course_id = null)
{
    $course_id = learn_press_get_course_id($course_id);
    $course = LP_Course::get_course($course_id);
    $student = $course->course_student;
    // get_post_meta( $course_id, '_lpr_course_student', true );
    if ($student) {
        $count = $student;
    } else {
        $count = $course->count_users_enrolled();
        //( $users = get_post_meta( $course_id, '_lpr_course_user', true ) ) ? sizeof( $users ) : 0;
    }
    return apply_filters('learn_press_count_student_enrolled_course', $count, $course_id);
}
Beispiel #12
0
	<?php 
learn_press_admin_view('meta-boxes/course/loop-section.php', array('class' => 'lp-section-empty', 'toggle_class' => 'dashicons-minus', 'section_name' => '', 'content_items' => ''));
?>
</script>
<script type="text/html" id="tmpl-section-item">
	<?php 
$item = learn_press_post_object(array('post_type' => LP()->lesson_post_type));
$item->post_title = '{{data.text}}';
$item->item_id = '{{data.id}}';
$item->post_type = '{{data.type}}';
learn_press_admin_view('meta-boxes/course/loop-item.php', array('item' => $item));
?>
</script>

<?php 
$curriculum_items = LP_Course::get_course($post)->get_curriculum_items(array('group' => true, 'field' => 'ID'));
?>
<script type="text/html" id="tmpl-lp-modal-search-lesson">
	<div id="lp-modal-search-lesson" class="lp-modal-search">
		<?php 
$exclude_lessons = $curriculum_items['lessons'];
$lessons = learn_press_get_current_user()->get_lessons(array('orderby' => 'name', 'order' => 'ASC', 'posts_per_page' => -1));
?>
		<div class="lp-search-items">
			<input type="text" name="lp-item-name" placeholder="<?php 
_e('Type here to search the lesson', 'learn_press');
?>
" />
			<!--<button type="button" class="button lp-add-new-item"><?php 
_e('Add New', 'learn_press');
?>