Install::create_databases()

Create databases required by DozentLMS


Description

This method fires during DozentLMS activation

See also


Source

File: classes/Install.php

	public function create_databases() {
		global $wpdb;

		$prefix          = $wpdb->prefix;
		$charset_collate = $wpdb->get_charset_collate();

		if ( ! function_exists( 'dbDelta' ) ) {
			require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
		}

		/**
		 * Database Table for Course Complete
		 *
		 * @since DozentLMS 1.0.0
		 */

		$completes_table = "CREATE TABLE IF NOT EXISTS {$prefix}dozent_completes (
            complete_id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
            user_id int(11) DEFAULT NULL,
            completed_course_id int(11) DEFAULT NULL,
            course_id int(11) DEFAULT NULL,
            content_id int(11) DEFAULT NULL,
            completed_at datetime DEFAULT NULL,
            KEY user_id (user_id),
            KEY completed_course_id (completed_course_id),
            KEY course_id (course_id),
            KEY content_id (content_id)
		) {$charset_collate};";

		dbDelta( $completes_table );

		/**
		 * Database Table for Ratings and Reviews
		 *
		 * @since DozentLMS 1.0.0
		 */

		$reviews_table = "CREATE TABLE IF NOT EXISTS {$prefix}dozent_reviews (
            ID bigint(20) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
            user_id int(11) DEFAULT NULL,
            course_id int(11) DEFAULT NULL,
            review_id int(11) DEFAULT '0',
            review text DEFAULT NULL,
            rating tinyint(4) DEFAULT NULL,
            status tinyint(1) DEFAULT '1',
            created_at datetime DEFAULT NULL,
            updated_at datetime DEFAULT NULL,
            KEY user_id (user_id),
			KEY course_id (course_id),
			KEY review_id (review_id),
			KEY rating (rating) 
        ) {$charset_collate};";

		dbDelta( $reviews_table );

		/**
		 * Database Table for Instructor courses permission
		 *
		 * @since DozentLMS 1.0.0
		 */

		$instructor_courses_table = "CREATE TABLE IF NOT EXISTS {$prefix}dozent_instructor_courses (
            ID bigint(20) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
			course_id int(11) DEFAULT NULL,
			instructor_id int(11) DEFAULT NULL,
			permissions text DEFAULT NULL,
			added_at datetime NULL DEFAULT NULL,
			KEY course_id (course_id),
			KEY instructor_id (instructor_id)
        ) {$charset_collate};";

		dbDelta( $instructor_courses_table );

		/**
		 * Create database for enrolments
		 */

		$enrols_table = "CREATE TABLE IF NOT EXISTS {$prefix}dozent_enrols (
            ID bigint(20) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
			course_id int(11) unsigned DEFAULT NULL,
			user_id int(11) unsigned DEFAULT NULL,
			order_id int(11) unsigned DEFAULT NULL,
			order_by_product_id int(11) unsigned DEFAULT NULL,
			status varchar(30) DEFAULT NULL,
			expired_at datetime NULL DEFAULT NULL,
			created_at datetime NULL DEFAULT NULL,
            KEY  course_id (course_id),
            KEY  user_id (user_id),
            KEY  order_id (order_id),
            KEY  order_by_product_id (order_by_product_id),
            KEY  status (status),
            KEY  expired_at (expired_at),
            KEY  created_at (created_at)
        ) {$charset_collate};";

		dbDelta( $enrols_table );

		/**
		 * Instructors Earnings table
		 */

		$earning_table = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}dozent_earnings (
			ID bigint(20) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
			user_id int(11) unsigned DEFAULT NULL,
			course_id int(11) unsigned DEFAULT NULL,
			order_id int(11) unsigned DEFAULT NULL,
			order_status varchar(50) DEFAULT NULL,
			total_courses_under_order int(11) DEFAULT NULL,
			course_price_total decimal(16,2) DEFAULT NULL,
			per_course_price decimal(16,2) DEFAULT NULL,
			instructor_amount decimal(16,2) DEFAULT NULL,
			instructor_rate decimal(16,2) DEFAULT NULL,
			admin_amount decimal(16,2) DEFAULT NULL,
			admin_rate decimal(16,2) DEFAULT NULL,
			commission_type varchar(20) DEFAULT NULL,
			deduct_fees_rate decimal(16,2) DEFAULT NULL,
			deduct_fees_amount decimal(16,2) DEFAULT NULL,
			deduct_fees_name varchar(250) DEFAULT NULL,
			deduct_fees_type varchar(20) DEFAULT NULL,
			process_by varchar(20) DEFAULT NULL,
			raw_data text DEFAULT NULL,
			created_at datetime DEFAULT NULL,
            KEY  user_id (user_id),
            KEY  course_id (course_id),
            KEY  order_id (order_id),
            KEY  order_status (order_status),
            KEY  created_at (created_at)
		) {$charset_collate};";

		dbDelta( $earning_table );

		/**
		 * Withdraw by Instructor
		 */

		$withdraws_table = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}dozent_withdrawal (
			withdraw_id bigint(20) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
			user_id int(11) DEFAULT NULL,
			amount decimal(16,2) DEFAULT NULL,
			method_data text DEFAULT NULL,
			status varchar(50) DEFAULT NULL,
			updated_at datetime DEFAULT NULL,
			created_at datetime DEFAULT NULL,
            KEY  user_id (user_id),
            KEY  amount (amount),
            KEY  status (status),
            KEY  created_at (created_at)
		) {$charset_collate};";

		dbDelta( $withdraws_table );


		/**
		 * Dozent Quiz Questions
		 */

		$quiz_questions_table = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}dozent_quiz_questions (
			question_id bigint(20) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
			user_id int(11) DEFAULT NULL,
			quiz_id int(11) DEFAULT NULL,
			title varchar(191) DEFAULT NULL,
			image_id int(11) DEFAULT NULL,  
			question_type varchar(20) DEFAULT NULL,
			mixed_value text DEFAULT NULL,
			score decimal(8,2) DEFAULT NULL,
			sort_order int(11) DEFAULT NULL,
            KEY  quiz_id (quiz_id)
		) {$charset_collate};";

		dbDelta( $quiz_questions_table );

		/**
		 * Dozent Quiz Question Options
		 */

		$quiz_options_table = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}dozent_quiz_question_options (
			option_id bigint(20) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
			question_id int(11) DEFAULT NULL,
			title varchar(191) DEFAULT NULL,
			image_id int(11) DEFAULT NULL,  
			display_preference varchar(20) DEFAULT NULL,
			is_correct int(11) DEFAULT NULL,
			sort_order int(11) DEFAULT NULL,
            KEY  question_id (question_id)
		) {$charset_collate};";

		dbDelta( $quiz_options_table );

		/**
		 * Dozent Quiz Attempt
		 */

		$quiz_options_table = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}dozent_quiz_attempts (
			id bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
			course_id int(11) DEFAULT NULL,
			quiz_id int(11) DEFAULT NULL,
			user_id int(11) DEFAULT NULL,
			reviewer_id int(11) DEFAULT NULL,
			questions_limit int(11) DEFAULT NULL,
			total_answered int(11) DEFAULT NULL,
			total_scores decimal(6,2) DEFAULT NULL,
			earned_scores decimal(6,2) DEFAULT NULL,
			passing_percent int(11) DEFAULT NULL,
			earned_percent int(11) DEFAULT NULL,
			status varchar(191) DEFAULT NULL,
			quiz_gradable tinyint(1) DEFAULT '0',
			is_reviewed tinyint(1) DEFAULT '0',
			ended_at timestamp NULL DEFAULT NULL,
			reviewed_at timestamp NULL DEFAULT NULL,
			passed tinyint(4) DEFAULT NULL,
			quiz_option text DEFAULT NULL,
			created_at datetime DEFAULT NULL,
			updated_at datetime DEFAULT NULL,
			KEY  course_id (course_id),
			KEY  quiz_id (quiz_id),
			KEY  user_id (user_id),
			KEY  total_scores (total_scores),
			KEY  earned_scores (earned_scores),
			KEY  status (status)
		) {$charset_collate};";

		dbDelta( $quiz_options_table );

		$quiz_options_table = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}dozent_quiz_answers (
		  	id bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
			quiz_id int(11) DEFAULT NULL,
			question_id int(11) DEFAULT NULL,
			user_id int(11) DEFAULT NULL,
			attempt_id int(11) DEFAULT NULL,
			answer text DEFAULT NULL,
			q_type varchar(20) DEFAULT NULL,
			q_score decimal(6,2) DEFAULT NULL,
			earned_scores decimal(6,2) DEFAULT NULL,
			is_correct tinyint(1) DEFAULT '0',
			KEY  quiz_id (quiz_id),
			KEY  question_id (question_id),
			KEY  user_id (user_id),
			KEY  attempt_id (attempt_id),
			KEY  q_score (q_score),
			KEY  earned_scores (earned_scores)
		) {$charset_collate};";

		dbDelta( $quiz_options_table );
	}

Changelog

Changelog
Version Description
DozentLMS 1.0.0 Introduced.