class-ld-import-quiz.php000066600000004473152133100170011262 0ustar00fetchAll( $ld_pro_quiz_id ); if ( !empty( $ld_quiz_questions ) ) { foreach( $ld_quiz_questions as $q_idx => $ld_quiz_question ) { $ld_quiz_questions[$q_idx] = $ld_quiz_question->get_object_as_array(); if ( ( isset( $ld_quiz_questions[$q_idx]['_answerData'] ) ) && ( !empty( $ld_quiz_questions[$q_idx]['_answerData'] ) ) ) { foreach( $ld_quiz_questions[$q_idx]['_answerData'] as $a_idx => $answer_item ) { $ld_quiz_questions[$q_idx]['_answerData'][$a_idx] = $answer_item->get_object_as_array(); } } } return $ld_quiz_questions; } } } } function startQuizSet() { $pro_quiz_import = new WpProQuiz_Model_Quiz(); return $pro_quiz_import->get_object_as_array(); } function saveQuizSet( $quiz_data = array() ) { if ( !empty( $quiz_data ) ) { $quiz_import = new WpProQuiz_Model_Quiz(); $quiz_import->set_array_to_object( $quiz_data ); $quizMapper = new WpProQuiz_Model_QuizMapper(); $quizMapper->save( $quiz_import ); $quiz_id = $quiz_import->getId(); return $quiz_id; } } // End of functions } }class-ld-import-user-progress.php000066600000004325152133100170013106 0ustar00set_course_prerequisite_enabled( $dest_post_id, true ); $prerequisite_posts = learndash_get_course_prerequisite( $dest_post_id ); $prerequisite_posts[] = $prereq_post_id; $this->set_course_prerequisite( $dest_post_id, $prerequisite_posts ); } } function set_course_prerequisite_enabled( $course_id, $enabled = true ) { if ( $enabled === true ) $enabled = 'on'; if ( $enabled != 'on' ) $enabled = ''; return learndash_update_setting( $course_id, 'course_prerequisite_enabled', $enabled ); } function set_course_prerequisite( $course_id = 0, $course_prerequisites = array() ) { if ( !empty( $course_id ) ) { if ( ( !empty( $course_prerequisites ) ) && ( is_array( $course_prerequisites ) ) ) { $course_prerequisites = array_unique( $course_prerequisites ); } return learndash_update_setting( $course_id, 'course_prerequisite', (array)$course_prerequisites ); } } // End of functions } }class-ld-import-post.php000066600000012754152133100170011260 0ustar00 $action, 'post' => $post->ID, 'ld_nonce' => wp_create_nonce( $action .'_'. $post->ID .'_'. $post->post_type .'_'. get_current_user_id() ) ); $url_params = apply_filters( 'ld_sensei_url_params', $url_params ); if ( !empty( $url_params ) ) { $url = add_query_arg( $url_params, admin_url( 'admin.php' ) ); return apply_filters( 'ld_sensei_url_link', $url, $url_params, $post_id, $action ); } } } public function duplicate_post( $source_post_id = 0, $force_copy = false ) { if ( !empty( $source_post_id ) ) { $source_post = get_post( $source_post_id ); if ( ( $source_post ) && ( $source_post->post_type == $this->source_post_type ) && ( is_a( $source_post, 'WP_Post' ) ) ) { $previous_imported_post_id = $this->get_imported( $source_post_id ); // For now set this to true so we don't have to clear all posts after each run. $force_copy = true; if ( ( empty( $previous_imported_post_id ) ) || ( $force_copy == true ) ) { $dest_post = array(); foreach( $source_post as $k => $v ) { if( ! in_array( $k, array( 'ID', 'post_type', 'guid', 'post_parent', 'comment_count', 'to_ping' ) ) ) { $dest_post[ $k ] = $v; } } $dest_post['post_type'] = $this->dest_post_type; // As per wp_update_post() we need to escape the data from the db. $dest_post = wp_slash( $dest_post ); $dest_post = apply_filters( 'learndash_duplicate_post_array', $dest_post, $source_post ); $dest_post_id = wp_insert_post( $dest_post ); if ( !is_wp_error( $dest_post_id ) ) { $dest_post = get_post( $dest_post_id ); add_post_meta( $dest_post->ID, '_ld_import_org', $source_post->ID ); $dest_post_meta = SFWD_CPT_Instance::$instances[ $dest_post->post_type ]->get_settings_values( $dest_post->post_type ); if ( !empty( $dest_post_meta ) ) { $dest_post_meta = wp_list_pluck( $dest_post_meta, 'value' ); } $dest_post_meta = apply_filters( 'learndash_sensei_import_meta', $dest_post_meta, $source_post, $dest_post ); add_post_meta( $dest_post->ID, '_' . $dest_post->post_type, $dest_post_meta ); return $dest_post; } } } } return false; } function duplicate_post_tax_term( $source_term, $create_parents = false ) { if ( ( $source_term ) && ( is_a( $source_term, 'WP_Term' ) ) ) { $terms_to_add = array( ); $ld_parent_term_id = 0; // First we build the parent tree if needed if ( ( !empty( $source_term->parent ) ) && ( is_taxonomy_hierarchical( $source_term->taxonomy ) ) && ( $create_parents == true ) ) { $term_parents = get_ancestors( $source_term->term_id, $source_term->taxonomy ); if ( !empty( $term_parents ) ) { //$terms_to_add = array_merge( array( $source_term->term_id ), $term_parents ); $terms_to_add = $term_parents; if ( !empty( $terms_to_add ) ) { krsort( $terms_to_add ); foreach( $terms_to_add as $s_term_idx => $s_term_id ) { $s_term = get_term_by( 'id', $s_term_id, $source_term->taxonomy ); if ( $s_term ) { $n_term = get_term_by( 'slug', $s_term->slug, $this->dest_taxonomy ); if ( !$n_term ) { $n_term = wp_insert_term( $s_term->name, $this->dest_taxonomy, array( 'slug' => $s_term->slug, 'parent' => $ld_parent_term_id ) ); if ( isset( $n_term['term_id'] ) ) { $ld_parent_term_id = $n_term['term_id']; } } else { $ld_parent_term_id = $n_term->term_id; } } } } } } $new_term = get_term_by( 'slug', $source_term->slug, $this->dest_taxonomy ); if ( !$new_term ) { $n_term = wp_insert_term( $source_term->name, $this->dest_taxonomy, array( 'slug' => $source_term->name, 'parent' => $ld_parent_term_id ) ); if ( !is_wp_error( $n_term ) ) { if ( isset( $n_term['term_id'] ) ) { $new_term = get_term_by( 'id', $n_term['term_id'], $this->dest_taxonomy ); } } } return $new_term; } } function set_post_tax_terms( $dest_post_id, $term_ids, $replace = false ) { if ( ( !empty( $dest_post_id )) && ( !empty( $term_ids ) ) ) { wp_set_object_terms( $dest_post_id, $term_ids, $this->dest_taxonomy, true ); } } function get_imported( $source_post_id = 0 ) { if ( !empty( $source_post_id ) ) { $dest_posts = get_posts( array( 'post_type' => $this->dest_post_type, 'meta_key' => '_ld_import_org', 'meta_value' => intval( $source_post_id ), ) ); if ( ( !empty( $dest_posts ) ) && ( is_array( $dest_posts ) ) ) { $dest_post = $dest_posts[0]; if ( is_a( $dest_post, 'WP_Post' ) ) { return $dest_post->ID; } } } return false; } // End of functions } }class-ld-import-topic.php000066600000001763152133100170011407 0ustar00get_object_as_array( ); } function startQuizStatisticsQuestion() { $pro_quiz_statistic_import = new WpProQuiz_Model_Statistic(); return $pro_quiz_statistic_import->get_object_as_array(); } // $quiz_statistic_data should be an array of arrays. Each array item represents a single user question response function saveQuizStatisticSet( $quiz_statistic_header = array(), $quiz_statistic_details = array() ) { if ( ( !empty( $quiz_statistic_header ) ) && ( !empty( $quiz_statistic_details ) ) ) { $statisticRefModel = new WpProQuiz_Model_StatisticRefModel(); $statisticRefModel->set_array_to_object( $quiz_statistic_header ); $statistic_values = array(); foreach( $quiz_statistic_details as $quiz_statistic_details ) { // Called to ensure we have a working Question Set ( WpProQuiz_Model_Question ) $pro_quiz_statistic_import = new WpProQuiz_Model_Statistic(); $pro_quiz_statistic_import->set_array_to_object( $quiz_statistic_details ); $statistic_values[] = $pro_quiz_statistic_import; } $statisticRefMapper = new WpProQuiz_Model_StatisticRefMapper(); $statisticRefMapper_id = $statisticRefMapper->statisticSave( $statisticRefModel, $statistic_values ); return $statisticRefMapper_id; } } // $file_upload_full is the full path to the existin file. // $question_id is needed when building the essay filename function migrate_file_upload_to_essay( $file_upload_full = '', $question_id = 0 ) { if ( !empty( $file_upload_full ) ) { // This logic was copied from LD core includes/quiz/ld-quiz-essay.php learndash_essay_fileupload_process() $filename = learndash_clean_filename( basename( $file_upload_full ) ); //$question_id = $ld_quiz_question['_id']; // get file info // @fixme: wp checks the file extension.... $filetype = wp_check_filetype( basename( $filename ), null ); $filetitle = preg_replace( '/\.[^.]+$/', '', basename( $filename ) ); $filename = sprintf( 'question_%d_%s.%s', $question_id, $filetitle, $filetype['ext'] ); $filename = apply_filters( 'learndash_essay_upload_filename', $filename, $question_id, $filetitle, $filetype['ext'] ); $upload_dir = wp_upload_dir(); $upload_dir_base = $upload_dir['basedir']; $upload_url_base = $upload_dir['baseurl']; $upload_dir_path = $upload_dir_base . apply_filters( 'learndash_essay_upload_dirbase', '/essays', $filename, $upload_dir ); $upload_url_path = $upload_url_base . apply_filters( 'learndash_essay_upload_urlbase', '/essays/', $filename, $upload_dir ); if ( ! file_exists( $upload_dir_path ) ) { mkdir( $upload_dir_path ); } /** * Check if the filename already exist in the directory and rename the * file if necessary */ $i = 0; while ( file_exists( $upload_dir_path . '/' . $filename ) ) { $i++; $filename = sprintf( 'question_%d_%s_%d.%s', $question_id, $filetitle, $i, $filetype['ext'] ); $filename = apply_filters( 'learndash_essay_upload_filename_dup', $filename, $question_id, $filetitle, $i, $filetype['ext'] ); } $filedest = $upload_dir_path . '/' . $filename; $copy_ret = copy( $file_upload_full, $filedest ); if ( $copy_ret === true ) { return $upload_url_path . $filename; //update_post_meta( $essay_post_id, 'upload', $upload_url_path . $filename ); //update_post_meta( $essay_post_id, '_ld_import_org', intval( $sensei_user_question_answers ) ); } } } /* [20-May-2017 16:53:07 UTC] user_quizzes
Array
		(
		    [0] => Array
		        (
		            [quiz] => 927
		            [score] => 5
		            [count] => 6
		            [question_show_count] => 6
		            [pass] => 0
		            [rank] => -
		            [time] => 1495293659
		            [pro_quizid] => 1
		            [points] => 25
		            [total_points] => 55
		            [percentage] => 45.45
		            [timespent] => 29.681
		            [has_graded] => 1
		            [statistic_ref_id] => 1
		            [started] => 1495293628
		            [completed] => 1495293658
		            [graded] => Array
		                (
		                    [1] => Array
		                        (
		                            [post_id] => 960
		                            [status] => graded
		                            [points_awarded] => 12
		                        )

		                    [2] => Array
		                        (
		                            [post_id] => 961
		                            [status] => not_graded
		                            [points_awarded] => 0
		                        )

		                )

		        )

		)
		
*/ function add_user_quiz_attempt( $user_id = 0, $quiz_attempt = array() ) { if ( ( !empty( $user_id ) ) && ( !empty( $quiz_attempt ) ) ) { $user_quiz_meta = get_user_meta( $user_id, '_sfwd-quizzes', true ); if ( ! is_array( $user_quiz_meta ) ) { $user_quiz_meta = array(); } $user_quiz_meta[] = $quiz_attempt; update_user_meta( $user_id, '_sfwd-quizzes', $user_quiz_meta ); } } // End of functions } }import-loader.php000066600000001340152133100170010026 0ustar00get_object_as_array(); } function saveQuizQuestionSet( $quiz_question_data = array() ) { if ( !empty( $quiz_question_data ) ) { // Called to ensure we have a working Question Set ( WpProQuiz_Model_Question ) $pro_quiz_question_import = new WpProQuiz_Model_Question(); $pro_quiz_question_import->set_array_to_object( $quiz_question_data ); $quizQuestionMapper = new WpProQuiz_Model_QuestionMapper(); $new_question = $quizQuestionMapper->save( $pro_quiz_question_import ); if ( is_a( $new_question, 'WpProQuiz_Model_Question' ) ) { return $new_question->getId(); } } } function startQuizQuestionAnswerTypesSet() { $pro_quiz_question_answer_types_import = new WpProQuiz_Model_AnswerTypes(); return $pro_quiz_question_answer_types_import->get_object_as_array(); } // End of functions } }class-ld-import-course.php000066600000007411152133100170011565 0ustar00set_course_prerequisite_enabled( $dest_post_id, true ); $prerequisite_posts = learndash_get_course_prerequisite( $dest_post_id ); $prerequisite_posts[] = $prereq_post_id; $this->set_course_prerequisite( $dest_post_id, $prerequisite_posts ); } } function set_course_prerequisite_enabled( $course_id, $enabled = true ) { if ( $enabled === true ) $enabled = 'on'; if ( $enabled != 'on' ) $enabled = ''; return learndash_update_setting( $course_id, 'course_prerequisite_enabled', $enabled ); } function set_course_prerequisite( $course_id = 0, $course_prerequisites = array() ) { if ( !empty( $course_id ) ) { if ( ( !empty( $course_prerequisites ) ) && ( is_array( $course_prerequisites ) ) ) { $course_prerequisites = array_unique( $course_prerequisites ); } return learndash_update_setting( $course_id, 'course_prerequisite', (array)$course_prerequisites ); } } function enroll_user( $user_id = 0, $course_id = 0, $enroll_timestamp_gmt = 0 ) { if ( ( !empty( $user_id ) ) && ( !empty( $course_id ) ) ) { if ( empty( $enroll_timestamp_gmt ) ) $enroll_timestamp_gmt = time(); $user_course_access_time = get_user_meta( $user_id, "course_". $course_id ."_access_from", true ); if ( empty( $user_course_access_time ) ) { update_user_meta( $user_id, "course_".$course_id."_access_from", $enroll_timestamp_gmt ); } } } function add_user_progress( $user_id = 0, $course_id = 0, $args = array(), $force = false ) { if ( ( !empty( $user_id ) ) && ( !empty( $course_id ) ) ) { $user_id = intval( $user_id ); $course_id = intval( $course_id ); $user = get_user_by('ID', $user_id ); if ( is_a( $user, 'WP_User' ) ) { $user_course_meta = get_user_meta( $user_id, '_sfwd-course_progress', true ); if ( ( $user_course_meta === false ) || ( !is_array($user_course_meta) ) ) $user_course_meta = array(); $_CHANGED = false; if ( !isset( $user_course_meta[$course_id] ) ) { $user_course_meta[$course_id] = array(); $_CHANGED = true; } if ( !empty( $args ) ) { foreach( $args as $key => $val ) { if ( ( !isset( $user_course_meta[$course_id][$key] ) ) || ( $force === true ) ) { $user_course_meta[$course_id][$key] = $val; $_CHANGED = true; } } } if ( $_CHANGED === true ) { update_user_meta( $user_id, '_sfwd-course_progress', $user_course_meta ); } } } } // End of functions } }class-ld-import-lesson.php000066600000001776152133100170011600 0ustar00