| 1 |
<?php |
| 2 |
/** |
| 3 |
* WP Ultimate Exporter plugin file. |
| 4 |
* |
| 5 |
* Copyright (C) 2010-2020, Smackcoders Inc - info@smackcoders.com |
| 6 |
*/ |
| 7 |
namespace Smackcoders\SMEXP; |
| 8 |
|
| 9 |
if ( ! defined( 'ABSPATH' ) ) |
| 10 |
exit; // Exit if accessed directly |
| 11 |
|
| 12 |
/** |
| 13 |
* Class LearnPressExport |
| 14 |
* @package Smackcoders\SMEXP |
| 15 |
*/ |
| 16 |
|
| 17 |
class LearnPressExport extends ExportExtension{ |
| 18 |
|
| 19 |
protected static $instance = null,$export_instance; |
| 20 |
public static function getInstance() { |
| 21 |
if ( null == self::$instance ) { |
| 22 |
self::$instance = new self; |
| 23 |
LearnPressExport::$export_instance = ExportExtension::getInstance(); |
| 24 |
} |
| 25 |
return self::$instance; |
| 26 |
} |
| 27 |
|
| 28 |
/** |
| 29 |
* CustomerReviewExport constructor. |
| 30 |
*/ |
| 31 |
public function __construct() { |
| 32 |
$this->plugin = Plugin::getInstance(); |
| 33 |
} |
| 34 |
|
| 35 |
public function getCourseData($id) |
| 36 |
{ |
| 37 |
global $wpdb; |
| 38 |
$get_section_details = $wpdb->get_results("SELECT section_id, section_name, section_description FROM {$wpdb->prefix}learnpress_sections WHERE section_course_id = $id ", ARRAY_A); |
| 39 |
$section_names = ''; |
| 40 |
$section_descriptions = ''; |
| 41 |
$get_lesson_name = ''; |
| 42 |
$get_lesson_description = ''; |
| 43 |
$get_lesson_duration = ''; |
| 44 |
$get_lesson_preview = ''; |
| 45 |
$get_quiz_name = ''; |
| 46 |
$get_quiz_description = ''; |
| 47 |
$get_quiz_meta = []; |
| 48 |
|
| 49 |
foreach($get_section_details as $section_details){ |
| 50 |
$section_names .= $section_details['section_name'] . '|'; |
| 51 |
$section_descriptions .= $section_details['section_description'] . '|'; |
| 52 |
|
| 53 |
$section_id = $section_details['section_id']; |
| 54 |
$get_section_item_details = $wpdb->get_results("SELECT item_id, item_type FROM {$wpdb->prefix}learnpress_section_items WHERE section_id = $section_id ", ARRAY_A); |
| 55 |
|
| 56 |
$lesson_name = ''; |
| 57 |
$lesson_description = ''; |
| 58 |
$quiz_name = ''; |
| 59 |
$quiz_description = ''; |
| 60 |
$lesson_duration = ''; |
| 61 |
$lesson_preview = ''; |
| 62 |
$quiz_metas = []; |
| 63 |
|
| 64 |
foreach($get_section_item_details as $section_item_details){ |
| 65 |
$section_item_id = $section_item_details['item_id']; |
| 66 |
if($section_item_details['item_type'] == 'lp_lesson'){ |
| 67 |
$lesson_name .= $wpdb->get_var("SELECT post_title FROM {$wpdb->prefix}posts WHERE ID = $section_item_id ") . ', '; |
| 68 |
$lesson_description .= $wpdb->get_var("SELECT post_content FROM {$wpdb->prefix}posts WHERE ID = $section_item_id "). ', '; |
| 69 |
$lesson_duration .= $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $section_item_id AND meta_key = '_lp_duration' ") . ', '; |
| 70 |
$lesson_preview .= $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $section_item_id AND meta_key = '_lp_preview' ") . ', '; |
| 71 |
} |
| 72 |
elseif($section_item_details['item_type'] == 'lp_quiz'){ |
| 73 |
$quiz_name .= $wpdb->get_var("SELECT post_title FROM {$wpdb->prefix}posts WHERE ID = $section_item_id ") . ', '; |
| 74 |
$quiz_description .= $wpdb->get_var("SELECT post_content FROM {$wpdb->prefix}posts WHERE ID = $section_item_id "). ', '; |
| 75 |
|
| 76 |
$quiz_meta = $wpdb->get_results("SELECT meta_key, meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $section_item_id AND meta_key LIKE '_lp_%' ", ARRAY_A); |
| 77 |
foreach($quiz_meta as $quiz_meta_values){ |
| 78 |
$quiz_key = $quiz_meta_values['meta_key']; |
| 79 |
$quiz_value = $quiz_meta_values['meta_value'] . ', '; |
| 80 |
|
| 81 |
if($quiz_key != '_lp_hidden_questions'){ |
| 82 |
if($quiz_key == '_lp_retake_count'){ |
| 83 |
$quiz_key = '_lp_quiz_retake_count'; |
| 84 |
} |
| 85 |
$quiz_metas[$quiz_key] = $quiz_value; |
| 86 |
} |
| 87 |
} |
| 88 |
} |
| 89 |
} |
| 90 |
|
| 91 |
$get_lesson_name .= rtrim($lesson_name, ', ') . '|'; |
| 92 |
$get_lesson_description .= rtrim($lesson_description, ', ') . '|'; |
| 93 |
$get_quiz_name .= rtrim($quiz_name, ', ') . '|'; |
| 94 |
$get_quiz_description .= rtrim($quiz_description, ', ') . '|'; |
| 95 |
$get_lesson_duration .= rtrim($lesson_duration, ', ') . '|'; |
| 96 |
$get_lesson_preview .= rtrim($lesson_preview, ', ') . '|'; |
| 97 |
|
| 98 |
foreach($quiz_metas as $quiz_meta_keys => $quiz_meta_values){ |
| 99 |
$get_quiz_meta[$quiz_meta_keys] = rtrim($quiz_meta_values, ', ') . '|'; |
| 100 |
} |
| 101 |
} |
| 102 |
|
| 103 |
LearnPressExport::$export_instance->data[$id]['curriculum_name'] = rtrim($section_names, '|'); |
| 104 |
LearnPressExport::$export_instance->data[$id]['curriculum_description'] = rtrim($section_descriptions, '|'); |
| 105 |
LearnPressExport::$export_instance->data[$id]['lesson_name'] = rtrim($get_lesson_name, '|'); |
| 106 |
LearnPressExport::$export_instance->data[$id]['lesson_description'] = rtrim($get_lesson_description, '|'); |
| 107 |
LearnPressExport::$export_instance->data[$id]['quiz_name'] = rtrim($get_quiz_name, '|'); |
| 108 |
LearnPressExport::$export_instance->data[$id]['quiz_description'] = rtrim($get_quiz_description, '|'); |
| 109 |
LearnPressExport::$export_instance->data[$id]['_lp_lesson_duration'] = rtrim($get_lesson_duration, '|'); |
| 110 |
LearnPressExport::$export_instance->data[$id]['_lp_preview'] = rtrim($get_lesson_preview, '|'); |
| 111 |
|
| 112 |
foreach($get_quiz_meta as $get_quiz_meta_keys => $get_quiz_meta_values){ |
| 113 |
LearnPressExport::$export_instance->data[$id][$get_quiz_meta_keys] = rtrim($get_quiz_meta_values, '|'); |
| 114 |
} |
| 115 |
} |
| 116 |
|
| 117 |
public function getLessonData($id){ |
| 118 |
global $wpdb; |
| 119 |
$lesson_duration = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id AND meta_key = '_lp_duration' "); |
| 120 |
LearnPressExport::$export_instance->data[$id]['_lp_lesson_duration'] = $lesson_duration; |
| 121 |
|
| 122 |
$get_section_id = $wpdb->get_var("SELECT section_id FROM {$wpdb->prefix}learnpress_section_items WHERE item_id = $id AND item_type = 'lp_lesson' "); |
| 123 |
if(!empty($get_section_id)){ |
| 124 |
$get_section_name = $wpdb->get_var("SELECT section_name FROM {$wpdb->prefix}learnpress_sections WHERE section_id = $get_section_id "); |
| 125 |
$get_section_course_id = $wpdb->get_var("SELECT section_course_id FROM {$wpdb->prefix}learnpress_sections WHERE section_id = $get_section_id "); |
| 126 |
|
| 127 |
LearnPressExport::$export_instance->data[$id]['curriculum_name'] = $get_section_name; |
| 128 |
LearnPressExport::$export_instance->data[$id]['course_id'] = $get_section_course_id; |
| 129 |
} |
| 130 |
} |
| 131 |
|
| 132 |
|
| 133 |
public function getQuizData($id){ |
| 134 |
global $wpdb; |
| 135 |
$quiz_retake_count = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id AND meta_key = '_lp_retake_count' "); |
| 136 |
LearnPressExport::$export_instance->data[$id]['_lp_quiz_retake_count'] = $quiz_retake_count; |
| 137 |
|
| 138 |
$get_section_id = $wpdb->get_var("SELECT section_id FROM {$wpdb->prefix}learnpress_section_items WHERE item_id = $id AND item_type = 'lp_quiz' "); |
| 139 |
if(!empty($get_section_id)){ |
| 140 |
$get_section_name = $wpdb->get_var("SELECT section_name FROM {$wpdb->prefix}learnpress_sections WHERE section_id = $get_section_id "); |
| 141 |
$get_section_course_id = $wpdb->get_var("SELECT section_course_id FROM {$wpdb->prefix}learnpress_sections WHERE section_id = $get_section_id "); |
| 142 |
|
| 143 |
LearnPressExport::$export_instance->data[$id]['curriculum_name'] = $get_section_name; |
| 144 |
LearnPressExport::$export_instance->data[$id]['course_id'] = $get_section_course_id; |
| 145 |
} |
| 146 |
|
| 147 |
$get_question_title = ''; |
| 148 |
$get_question_content = ''; |
| 149 |
$get_question_mark = ''; |
| 150 |
$get_question_explanation = ''; |
| 151 |
$get_question_hint = ''; |
| 152 |
$get_question_type = ''; |
| 153 |
$get_option_value = ''; |
| 154 |
|
| 155 |
$get_question_ids = $wpdb->get_results("SELECT question_id FROM {$wpdb->prefix}learnpress_quiz_questions WHERE quiz_id = $id ", ARRAY_A); |
| 156 |
foreach($get_question_ids as $question_ids){ |
| 157 |
$question_id = $question_ids['question_id']; |
| 158 |
$get_question_title .= $wpdb->get_var("SELECT post_title FROM {$wpdb->prefix}posts WHERE ID = $question_id ") . ','; |
| 159 |
$get_question_content .= $wpdb->get_var("SELECT post_content FROM {$wpdb->prefix}posts WHERE ID = $question_id ") . ','; |
| 160 |
|
| 161 |
$get_question_mark .= $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $question_id AND meta_key = '_lp_mark' ") . ', '; |
| 162 |
$get_question_explanation .= $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $question_id AND meta_key = '_lp_explanation' ") . ','; |
| 163 |
$get_question_hint .= $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $question_id AND meta_key = '_lp_hint' ") . ','; |
| 164 |
$get_question_type .= $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $question_id AND meta_key = '_lp_type' ") . ','; |
| 165 |
|
| 166 |
$get_question_options = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}learnpress_question_answers WHERE question_id = $question_id ", ARRAY_A); |
| 167 |
$option_value = ''; |
| 168 |
foreach($get_question_options as $question_option){ |
| 169 |
if(empty($question_option['is_true'])){ |
| 170 |
$question_option['is_true'] = 'no'; |
| 171 |
} |
| 172 |
|
| 173 |
$option_value .= $question_option['title'] .'|'. $question_option['is_true'] . '->'; |
| 174 |
} |
| 175 |
$get_option_value .= rtrim($option_value, '->') . ','; |
| 176 |
} |
| 177 |
|
| 178 |
LearnPressExport::$export_instance->data[$id]['question_title'] = rtrim($get_question_title, ','); |
| 179 |
LearnPressExport::$export_instance->data[$id]['question_description'] = rtrim($get_question_content, ','); |
| 180 |
LearnPressExport::$export_instance->data[$id]['_lp_mark'] = rtrim($get_question_mark, ', '); |
| 181 |
LearnPressExport::$export_instance->data[$id]['_lp_explanation'] = rtrim($get_question_explanation, ','); |
| 182 |
LearnPressExport::$export_instance->data[$id]['_lp_hint'] = rtrim($get_question_hint, ','); |
| 183 |
LearnPressExport::$export_instance->data[$id]['_lp_type'] = rtrim($get_question_type, ','); |
| 184 |
LearnPressExport::$export_instance->data[$id]['question_options'] = rtrim($get_option_value, ','); |
| 185 |
|
| 186 |
} |
| 187 |
|
| 188 |
public function getQuestionData($id){ |
| 189 |
global $wpdb; |
| 190 |
$get_quiz_id = $wpdb->get_var("SELECT quiz_id FROM {$wpdb->prefix}learnpress_quiz_questions WHERE question_id = $id "); |
| 191 |
|
| 192 |
$get_question_options = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}learnpress_question_answers WHERE question_id = $id ", ARRAY_A); |
| 193 |
$option_value = ''; |
| 194 |
foreach($get_question_options as $question_options){ |
| 195 |
if(empty($question_options['is_true'])){ |
| 196 |
$question_options['is_true'] = 'no'; |
| 197 |
} |
| 198 |
$option_value .= $question_options['title'] .'|'. $question_options['is_true'] . '->'; |
| 199 |
} |
| 200 |
|
| 201 |
if(!empty($get_quiz_id)){ |
| 202 |
$get_section_id = $wpdb->get_var("SELECT section_id FROM {$wpdb->prefix}learnpress_section_items WHERE item_id = $get_quiz_id AND item_type = 'lp_quiz' "); |
| 203 |
if(!empty($get_section_id)){ |
| 204 |
$get_section_name = $wpdb->get_var("SELECT section_name FROM {$wpdb->prefix}learnpress_sections WHERE section_id = $get_section_id "); |
| 205 |
$get_section_course_id = $wpdb->get_var("SELECT section_course_id FROM {$wpdb->prefix}learnpress_sections WHERE section_id = $get_section_id "); |
| 206 |
|
| 207 |
LearnPressExport::$export_instance->data[$id]['curriculum_name'] = $get_section_name; |
| 208 |
LearnPressExport::$export_instance->data[$id]['course_id'] = $get_section_course_id; |
| 209 |
} |
| 210 |
LearnPressExport::$export_instance->data[$id]['quiz_id'] = $get_quiz_id; |
| 211 |
} |
| 212 |
|
| 213 |
LearnPressExport::$export_instance->data[$id]['question_options'] = rtrim($option_value, '->'); |
| 214 |
} |
| 215 |
public function getOrderData($id){ |
| 216 |
global $wpdb; |
| 217 |
|
| 218 |
$order_status = $wpdb->get_var("SELECT post_status FROM {$wpdb->prefix}posts WHERE ID = $id "); |
| 219 |
$order_date = $wpdb->get_var("SELECT post_date FROM {$wpdb->prefix}posts WHERE ID = $id "); |
| 220 |
$order_total = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id AND meta_key = '_order_total' "); |
| 221 |
$order_subtotal = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id AND meta_key = '_order_subtotal' "); |
| 222 |
$user_id = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id AND meta_key = '_user_id' "); |
| 223 |
|
| 224 |
$get_order_items = $wpdb->get_results("SELECT order_item_id FROM {$wpdb->prefix}learnpress_order_items WHERE order_id = $id ",ARRAY_A); |
| 225 |
$course_id = ''; |
| 226 |
$item_quantity = ''; |
| 227 |
$item_total = ''; |
| 228 |
$item_subtotal = ''; |
| 229 |
foreach($get_order_items as $get_order_values){ |
| 230 |
$order_item_id = $get_order_values['order_item_id']; |
| 231 |
|
| 232 |
$course_id .= $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}learnpress_order_itemmeta WHERE learnpress_order_item_id = $order_item_id AND meta_key = '_course_id' ") . ', '; |
| 233 |
$item_quantity .= $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}learnpress_order_itemmeta WHERE learnpress_order_item_id = $order_item_id AND meta_key = '_quantity' ") . ', '; |
| 234 |
$item_total .= $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}learnpress_order_itemmeta WHERE learnpress_order_item_id = $order_item_id AND meta_key = '_subtotal' ") . ', '; |
| 235 |
$item_subtotal .= $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}learnpress_order_itemmeta WHERE learnpress_order_item_id = $order_item_id AND meta_key = '_total' ") . ', '; |
| 236 |
} |
| 237 |
|
| 238 |
LearnPressExport::$export_instance->data[$id]['order_status'] = $order_status; |
| 239 |
LearnPressExport::$export_instance->data[$id]['order_date'] = $order_date; |
| 240 |
LearnPressExport::$export_instance->data[$id]['_order_total'] = $order_total; |
| 241 |
LearnPressExport::$export_instance->data[$id]['_order_subtotal'] = $order_subtotal; |
| 242 |
LearnPressExport::$export_instance->data[$id]['user_id'] = $user_id; |
| 243 |
LearnPressExport::$export_instance->data[$id]['item_id'] = rtrim($course_id, ', '); |
| 244 |
LearnPressExport::$export_instance->data[$id]['item_quantity'] = rtrim($item_quantity, ', '); |
| 245 |
LearnPressExport::$export_instance->data[$id]['_item_total'] = rtrim($item_total, ', '); |
| 246 |
LearnPressExport::$export_instance->data[$id]['_item_subtotal'] = rtrim($item_subtotal, ', '); |
| 247 |
} |
| 248 |
|
| 249 |
} |
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
global $learnpress_exp_class; |
| 256 |
$learnpress_exp_class = new LearnPressExport(); |
| 257 |
|