<?php

class Whizzie {

	public function __construct() {
		$this->init();
	}

	public function init()
	{
	
	}
	public static function personal_tutor_setup_widgets(){


			/* Create Menu */
            $personal_tutor_menuname  = 'Main menu';
            $personal_tutor_location  = 'main-menu';

            $personal_tutor_menu = wp_get_nav_menu_object( $personal_tutor_menuname );

            if ( ! $personal_tutor_menu ) {
            $personal_tutor_menu_id = wp_create_nav_menu( $personal_tutor_menuname );

           // Home Page 
			wp_update_nav_menu_item( $personal_tutor_menu_id, 0, array(
				'menu-item-title'     => __( 'Home', 'personal-tutor' ),
				'menu-item-url'       => home_url( '/' ),
				'menu-item-type'      => 'custom',
				'menu-item-status'    => 'publish',
			) );

			// About Us Page 
			$personal_tutor_about_id = wp_insert_post( array(
			'post_type'   => 'page',
			'post_content' => 'We are committed to providing reliable, professional, and result-oriented solutions tailored to meet individual needs. Our goal is to empower people with the right guidance, knowledge, and support to help them make informed decisions for a better future. <br><br> Our mission is to deliver high-quality services with honesty, transparency, and dedication. We focus on understanding client requirements and offering practical solutions that create long-term value. <br><br> With a client-centric approach, experienced professionals, and a commitment to excellence, we ensure every individual receives the attention and guidance they deserve. We believe in building trust through quality service and consistent results.',
			'post_title'  => 'About Us',
			'post_status' => 'publish',
			) );

			if ( $personal_tutor_about_id ) {
			wp_update_nav_menu_item( $personal_tutor_menu_id, 0, array(
			'menu-item-title'     => 'About Us',
			'menu-item-object'    => 'page',
			'menu-item-object-id' => $personal_tutor_about_id,
			'menu-item-type'      => 'post_type',
			'menu-item-status'    => 'publish',
			) );
			}

			// Subjects Page 
			$personal_tutor_about_id = wp_insert_post( array(
			'post_type'   => 'page',
			'post_content' => 'We are committed to providing reliable, professional, and result-oriented solutions tailored to meet individual needs. Our goal is to empower people with the right guidance, knowledge, and support to help them make informed decisions for a better future. <br><br> Our mission is to deliver high-quality services with honesty, transparency, and dedication. We focus on understanding client requirements and offering practical solutions that create long-term value. <br><br> With a client-centric approach, experienced professionals, and a commitment to excellence, we ensure every individual receives the attention and guidance they deserve. We believe in building trust through quality service and consistent results.',
			'post_title'  => 'Subjects',
			'post_status' => 'publish',
			) );

			if ( $personal_tutor_about_id ) {
			wp_update_nav_menu_item( $personal_tutor_menu_id, 0, array(
			'menu-item-title'     => 'Subjects',
			'menu-item-object'    => 'page',
			'menu-item-object-id' => $personal_tutor_about_id,
			'menu-item-type'      => 'post_type',
			'menu-item-status'    => 'publish',
			) );
			}

			// Testimonials Page 
			$personal_tutor_about_id = wp_insert_post( array(
			'post_type'   => 'page',
			'post_content' => 'We are committed to providing reliable, professional, and result-oriented solutions tailored to meet individual needs. Our goal is to empower people with the right guidance, knowledge, and support to help them make informed decisions for a better future. <br><br> Our mission is to deliver high-quality services with honesty, transparency, and dedication. We focus on understanding client requirements and offering practical solutions that create long-term value. <br><br> With a client-centric approach, experienced professionals, and a commitment to excellence, we ensure every individual receives the attention and guidance they deserve. We believe in building trust through quality service and consistent results.',
			'post_title'  => 'Testimonials',
			'post_status' => 'publish',
			) );

			if ( $personal_tutor_about_id ) {
			wp_update_nav_menu_item( $personal_tutor_menu_id, 0, array(
			'menu-item-title'     => 'Testimonials',
			'menu-item-object'    => 'page',
			'menu-item-object-id' => $personal_tutor_about_id,
			'menu-item-type'      => 'post_type',
			'menu-item-status'    => 'publish',
			) );
			}

            // Create Blog Page
                $personal_tutor_blog_page_title = 'Blog';

                $personal_tutor_blog_page_query = new WP_Query(array(
                    'post_type'      => 'page',
                    'name'           => sanitize_title($personal_tutor_blog_page_title),
                    'post_status'    => 'publish',
                    'posts_per_page' => 1
                ));
                if (!$personal_tutor_blog_page_query->hae_posts()) {
                    $personal_tutor_blog_page = array(
                        'post_type'   => 'page',
                        'post_title'  => $personal_tutor_blog_page_title,
                        'post_status' => 'publish',
                        'post_author' => 1,
                    );
                    $personal_tutor_blog_page_id = wp_insert_post($personal_tutor_blog_page);
                    update_option('page_for_posts', $personal_tutor_blog_page_id);

                    wp_update_na_menu_item($personal_tutor_menu_id, 0, array(
                        'menu-item-title'      => __('Blog', 'personal-tutor'),
                        'menu-item-url'        => get_permalink($personal_tutor_blog_page_id),
                        'menu-item-status'     => 'publish',
                        'menu-item-object-id'  => $personal_tutor_blog_page_id,
                        'menu-item-object'     => 'page',
                        'menu-item-type'       => 'post_type',
                    ));
                }
            
			/* Assign Menu Location */
			$personal_tutor_locations = get_theme_mod( 'nav_menu_locations', array() );
			$personal_tutor_locations[ $personal_tutor_location ] = $personal_tutor_menu_id;
			set_theme_mod( 'nav_menu_locations', $personal_tutor_locations );
		}

		// LMS POST START
		$personal_tutor_course_category= array(
			'Demanding Subjects'    => array(
				'Math Mastery Program',
				'English Writing & Grammar Boost',
				'Science Concept Clarity Sessions',
			),
		);

		foreach ( $personal_tutor_course_category as $personal_tutor_course_cats => $personal_tutor_products_name ) {

			// Insert category
			wp_insert_term(
				$personal_tutor_course_cats,
				'course-category',
				array(
					'description'=> 'This is sample course category',
					'slug' => $personal_tutor_course_cats
				)
			);

			foreach ( $personal_tutor_products_name as $personal_tutor_course_title ) {

				// Create course
				$personal_tutor_my_post = array(
					'post_title'    => wp_strip_all_tags( $personal_tutor_course_title ),
					'post_content'  => 'Lorem Ipsum has been the industrys standard dummy text ever since the 1500...',
					'post_status'   => 'publish',
					'post_type'     => 'courses',
				);

				$personal_tutor_wpepost_id = wp_insert_post($personal_tutor_my_post);

				// Tutor LMS Meta
				update_post_meta( $personal_tutor_wpepost_id, '_tutor_course_price_type', 'paid' );

				$personal_tutor_qa_key = '_tutor_enable_qa';
				$personal_tutor_qa_value = 'yes';
				update_post_meta( $personal_tutor_wpepost_id, $personal_tutor_qa_key, $personal_tutor_qa_value );

				update_post_meta( $personal_tutor_wpepost_id, 'meta-course-student-enroll-num', '34 Students Enrolled' );

				// Assign category
				wp_set_object_terms( $personal_tutor_wpepost_id, $personal_tutor_course_cats, 'course-category', true );

				$personal_tutor_image_path = get_template_directory() . '/assets/images/Categories/'.$personal_tutor_course_cats.'/'.$personal_tutor_course_title.'.png';

				$personal_tutor_image_name = $personal_tutor_course_title.'.png';

				$personal_tutor_upload_dir = wp_upload_dir();

				if (file_exists($personal_tutor_image_path)) {
					$personal_tutor_image_data = file_get_contents($personal_tutor_image_path);
				} else {
					echo 'Image not found: ' . $personal_tutor_image_path;
					continue;
				}

				$personal_tutor_unique_file_name = wp_unique_filename($personal_tutor_upload_dir['path'], $personal_tutor_image_name);
				$personal_tutor_filename = basename($personal_tutor_unique_file_name);

				if (wp_mkdir_p($personal_tutor_upload_dir['path'])) {
					$personal_tutor_file = $personal_tutor_upload_dir['path'].'/'.$personal_tutor_filename;
				} else {
					$personal_tutor_file = $personal_tutor_upload_dir['basedir'].'/'.$personal_tutor_filename;
				}

				file_put_contents($personal_tutor_file, $personal_tutor_image_data);

				$personal_tutor_wp_filetype = wp_check_filetype($personal_tutor_filename, null);

				$personal_tutor_attachment = array(
					'post_mime_type' => $personal_tutor_wp_filetype['type'],
					'post_title'     => sanitize_file_name($personal_tutor_filename),
					'post_type'      => 'courses',
					'post_status'    => 'inherit',
				);

				$personal_tutor_attach_id = wp_insert_attachment($personal_tutor_attachment, $personal_tutor_file, $personal_tutor_wpepost_id);

				require_once (ABSPATH.'wp-admin/includes/image.php');

				$personal_tutor_attach_data = wp_generate_attachment_metadata($personal_tutor_attach_id, $personal_tutor_file);
				wp_update_attachment_metadata($personal_tutor_attach_id, $personal_tutor_attach_data);

				set_post_thumbnail($personal_tutor_wpepost_id, $personal_tutor_attach_id);
			}
		}
	}
}
 