Options


Source

File: classes/Options.php

class Options {

	public $option;
	public $sections;

	public function __construct() {
		$this->option   = (array) maybe_unserialize( get_option( 'dozent_options' ) );
		$this->sections = $this->set_sections();
	}

	/**
	 * @param null $key
	 * @param bool $default
	 * @return array|bool|mixed|void
	 *
	 * Get the option by dot notation, option->get('value.subvalue')
	 */
	private function get( $key = null, $default = false ) {
		return dozent_array_get( $key, $this->option, $default );
	}

	public function set_sections() {
		$pages = dozent_get_pages();
		array_walk( $pages, function ( &$page, $page_id ) {
			$page = $page . " (" . __( 'id', 'dozent' ) . ":{$page_id})";
		} );

		$sections = [];

		$sections[ 'general' ] = [
			'title'        => __( 'General', 'dozent' ),
			'icon'         => 'dicon-home',
			'field_groups' => [
				'general' => [
					'title'  => __( 'General', 'dozent' ),
					'desc'   => __( 'General Settings', 'dozent' ),
					'fields' => [
						'delete_on_uninstall'      => [
							'type'        => 'checkbox',
							'title'       => __( 'Erase upon uninstallation', 'dozent' ),
							'label_title' => __( 'Enable', 'dozent' ),
							'desc'        => __( 'Delete all data during uninstallation', 'dozent' ),
						],
						'redirect_back_after_logout'      => [
							'type'        => 'checkbox',
							'title'       => __( 'Redirect back after logout', 'dozent' ),
							'label_title' => __( 'Enable', 'dozent' ),
							'desc'        => __( 'This option enable redirect to previous page after logout', 'dozent' ),
						],
						'enable_focus_mode'        => [
							'type'  => 'switch',
							'title' => __( 'Focus mode', 'dozent' ),
							//'label_title' => __('Enable', 'dozent'),
							'desc'  => __( 'Distraction-free experience while study at the course.', 'dozent' ),
						],
						'enable_discussion'        => [
							'type'  => 'switch',
							'title' => __( 'Discussion', 'dozent' ),
							'desc'  => __( 'Discussion allows you to ask questions directly to the instructor.', 'dozent' ),
						],
						'auto_approve_instructor'  => [
							'type'  => 'switch',
							'title' => __( 'Auto Approve Instructor', 'dozent' ),
							'desc'  => __( 'Approve instructor automatically right after signup.', 'dozent' ),
						],
						'pagination_per_page'      => [
							'type'    => 'number',
							'title'   => __( 'Pagination', 'dozent' ),
							'default' => '20',
							'desc'    => __( 'How many results you would like to show per page', 'dozent' ),
						],
						'hide_admin_bar_for_users' => [
							'type'        => 'checkbox',
							'title'       => __( 'Frontend Admin Bar', 'dozent' ),
							'label_title' => __( 'Hide', 'dozent' ),
							'default'     => '0',
							'desc'        => __( 'Hide admin bar option allow you to hide WordPress admin bar entirely from the frontend. It will still show to administrator roles user', 'dozent' ),
						],
						'show_accept_terms_checkbox' => [
							'type'        => 'checkbox',
							'title'       => __( 'Show Checkbox to accept terms', 'dozent' ),
							'label_title' => __( 'Show', 'dozent' ),
							'default'     => '0',
							'desc'        => __( 'Show checkbox to accept terms at required forms', 'dozent' ),
						],
						'login_error_message'      => [
							'type'    => 'text',
							'title'   => __( 'Error message for wrong login credentials', 'dozent' ),
							'default' => 'Incorrect username or password.',
							'desc'    => __( 'Login error message displayed when the user puts wrong login credentials.', 'dozent' ),
						],

						'site_logo_id' => [
							'type'     => 'media',
							'title'    => __( 'Site Logo', 'dozent' ),
							'btn_text' => __( 'Upload Logo', 'dozent' ),
							'attr'     => [ 'media_type' => 'image' ], //image,file
							'desc'     => __( 'Upload your site brand logo.', 'dozent' ),
						],
					],
				],
			],
		];

		$sections[ 'permalinks' ] = [
			'title'        => __( 'Permalinks', 'dozent' ),
			'icon'         => 'dicon-link',
			'field_groups' => [
				'permalinks' => [
					'title'  => __( 'Dozent permalinks', 'dozent' ),
					'fields' => [
						'course_base_slug'          => [
							'type'    => 'text',
							'title'   => __( 'Course base slug', 'dozent' ),
							'default' => 'courses',
							'desc'    => __( 'Enter a course base base to use', 'dozent' ),
						],
						'course_category_base_slug' => [
							'type'    => 'text',
							'title'   => __( 'Course category base slug', 'dozent' ),
							'default' => 'course-category',
							'desc'    => __( 'Enter a course category base base to use', 'dozent' ),
						],
						'lecture_base_slug'         => [
							'type'    => 'text',
							'title'   => __( 'Lecture base slug', 'dozent' ),
							'default' => 'lecture',
							'desc'    => __( 'Enter a lecture base base to use', 'dozent' ),
						],
						'assignment_base_slug'      => [
							'type'    => 'text',
							'title'   => __( 'Assignments base slug', 'dozent' ),
							'default' => 'assignment',
							'desc'    => __( 'Enter an assignment base base to use', 'dozent' ),
						],
						'quiz_base_slug'            => [
							'type'    => 'text',
							'title'   => __( 'Quiz base slug', 'dozent' ),
							'default' => 'quiz',
							'desc'    => __( 'Enter a quiz base base to use', 'dozent' ),
						],
					],
				],
			],
		];


		$sections[ 'pages' ] = [
			'title'        => __( 'Pages', 'dozent' ),
			'icon'         => 'dicon-book',
			'field_groups' => array(
				'permalinks' => array(
					'title'  => __( 'Dozent Pages', 'dozent' ),
					'fields' => array(
						'dozent_dashboard_page_id'         => array(
							'type'    => 'select',
							'title'   => __( 'Dashboard Page', 'dozent' ),
							'default' => '0',
							'options' => $pages,
							'desc'    => __( 'This page will be used for student and instructor dashboard', 'dozent' ),
						),
						'dozent_user_signup_page_id' => array(
							'type'    => 'select',
							'title'   => __( 'User Signup Page', 'dozent' ),
							'default' => '0',
							'options' => $pages,
							'desc'    => __( 'Selected page contains a form to signup user', 'dozent' ),
						),
						'course_archive_page_id'           => array(
							'type'    => 'select',
							'title'   => __( 'Course Archive Page', 'dozent' ),
							'default' => '0',
							'options' => $pages,
							'desc'    => __( 'This page will be used as course archive', 'dozent' ),
						),
						'terms_and_condition_page_id'           => array(
							'type'    => 'select',
							'title'   => __( 'Terms and Condition Page', 'dozent' ),
							'default' => '0',
							'options' => $pages,
							'desc'    => __( 'Select a terms and condition page', 'dozent' ),
						),
						'privacy_policy_page_id'           => array(
							'type'    => 'select',
							'title'   => __( 'Privacy Policy Page', 'dozent' ),
							'default' => '0',
							'options' => $pages,
							'desc'    => __( 'Select a privacy policy page', 'dozent' ),
						),
					),
				)
			),
		];


		$sections[ 'course' ] = [
			'title'        => __( 'Course', 'dozent' ),
			'icon'         => 'dicon-graduation-cap',
			'field_groups' => array(
				'general' => array(
					'title'  => __( 'Course', 'dozent' ),
					'desc'   => __( 'Course Settings', 'dozent' ),
					'fields' => array(
						'enable_course_post_type_rest_api' => array(
							'type'        => 'checkbox',
							'title'       => __( 'Show in rest', 'dozent' ),
							'label_title' => __( 'Enable', 'dozent' ),
							'desc'        => __( 'Whether to expose this post type in the REST API. Must be true to enable the Gutenberg editor.', 'dozent' ),
						),
						'hide_course_from_shop_page'       => array(
							'type'        => 'checkbox',
							'title'       => __( 'Hide course products', 'dozent' ),
							'label_title' => __( 'Hide course products from shop page', 'dozent' ),
							'desc'        => __( 'Enabling this feature will be removed course products from the shop page.', 'dozent' ),
						),
						'instructor_can_publish_course'       => array(
							'type'        => 'checkbox',
							'title'       => __( 'Publish Course', 'dozent' ),
							'label_title' => __( 'Can instructor publish a course directly', 'dozent' ),
							'desc'        => __( 'Enabling this option allow instructor to publish their course directly, else they course require a review by the admin.', 'dozent' ),
						),

						/*
						'course_completion_process'        => array(
							'type'           => 'radio',
							'title'          => __( 'Course Completion Process', 'dozent' ),
							'default'        => 'flexible',
							'select_options' => false,
							'options'        => array(
								'flexible' => __( 'Flexible', 'dozent' ),
								'strict'   => __( 'Strict Mode', 'dozent' ),
							),
							'desc'           => __( 'Students can complete courses anytime in the Flexible mode. In the Strict mode, students have to complete, pass all the lectures and quizzes (if any) to mark a course as complete.', 'dozent' ),
						),
						*/

					),
				),
				'archive' => array(
					'title'  => __( 'Archive', 'dozent' ),
					'desc'   => __( 'Course Archive Settings', 'dozent' ),
					'fields' => array(
						'course_archive_page' => array(
							'type'    => 'select',
							'title'   => __( 'Course Archive Page', 'dozent' ),
							'default' => '0',
							'options' => $pages,
							'desc'    => __( 'The course archive page containing all courses.', 'dozent' ),
						),
						'courses_col_per_row' => array(
							'type'    => 'slider',
							'title'   => __( 'Column Per Row', 'dozent' ),
							'default' => '4',
							'options' => array( 'min' => 1, 'max' => 6, 'step' => 1 ),
							'desc'    => __( 'Total column per row.', 'dozent' ),
						),
						'courses_per_page'    => array(
							'type'    => 'slider',
							'title'   => __( 'Courses Per Page', 'dozent' ),
							'default' => '12',
							'options' => array( 'min' => 1, 'max' => 50 ),
							'desc'    => __( 'How many course you would like to see at the course per page.', 'dozent' ),
						),
					),
				),

			),
		];

		/*
		$sections[ 'selling_platform' ] = [
			'title'        => __( 'Selling Platform', 'dozent' ),
			'icon'         => 'dicon-cart',
			'field_groups' => array(
				'general' => [
					'title'  => __( 'Selling Platforms', 'dozent' ),
					'desc'   => __( 'You can sell the courses via any of the available platforms below.', 'dozent' ),
					'fields' => [
						'selling_platform' => [
							'type'           => 'radio',
							'title'          => __( 'Platforms', 'dozent' ),
							'default'        => 'none',
							'select_options' => false,
							'options'        => dozent_get_selling_platforms(),

							'desc' => sprintf( __( 'Select a platform to to start selling courses. Supports: %s', 'dozent' ), 'WooCommerce, Easy Digital Downloads, Paid Memberships Pro' ),
						],
					],
				],

			),
		];*/



		$sections[ 'dozent_earning' ] = [
			'title'        => __( 'Earning', 'dozent' ),
			'icon'         => 'dicon-money',
			'field_groups' => array(
				'general' => array(
					'title'  => __( 'Earning and commission allocation', 'dozent' ),
					'desc'   => __( 'Enable Disable Option to on/off notification on various event', 'dozent' ),
					'fields' => array(
						'enable_dozent_earning'         => array(
							'type'        => 'checkbox',
							'title'       => __( 'Earning', 'dozent' ),
							'label_title' => __( 'Enable', 'dozent' ),
							'default'     => '0',
							'desc'        => __( 'If disabled, the Admin will receive 100% of the earning', 'dozent' ),
						),
						'earning_admin_commission'      => array(
							'type'    => 'number',
							'title'   => __( 'Admin Commission Percentage', 'dozent' ),
							'default' => '0',
							'desc'    => __( 'Define the commission of the Admin from each sale.(after deducting fees)', 'dozent' ),
						),
						'earning_instructor_commission' => array(
							'type'    => 'number',
							'title'   => __( 'Instructor Commission Percentage', 'dozent' ),
							'default' => '0',
							'desc'    => __( 'Define the commission for instructors from each sale.(after deducting fees)', 'dozent' ),
						),
						'dozent_earning_fees'           => array(
							'type'         => 'group_fields',
							'title'        => __( 'Fee Deduction', 'dozent' ),
							'desc'         => __( 'Fees are charged from the entire sales amount. The remaining amount will be divided among admin and instructors.', 'dozent' ),
							'group_fields' => array(

								'enable_fees_deducting' => array(
									'type'    => 'checkbox',
									'title'   => __( 'Enable', 'dozent' ),
									'default' => '0',
								),
								'fees_name'             => array(
									'type'    => 'text',
									'title'   => __( 'Fees Name', 'dozent' ),
									'default' => '',
								),
								'fees_amount'           => array(
									'type'    => 'number',
									'title'   => __( 'Fees Amount', 'dozent' ),
									'default' => '',
								),
								'fees_type'             => array(
									'type'           => 'select',
									'default'        => 'minutes',
									'select_options' => false,
									'options'        => array(
										''        => __( 'Select Fees Type', 'dozent' ),
										'percent' => __( 'Percent', 'dozent' ),
										'fixed'   => __( 'Fixed', 'dozent' ),
									),
								),
							),
						),
						'statement_show_per_page'       => array(
							'type'    => 'number',
							'title'   => __( 'Show Statement Per Page', 'dozent' ),
							'default' => '20',
							'desc'    => __( 'Define the number of statements to show.', 'dozent' ),
						),
					),
				),
			),
		];

		$sections[ 'dozent_withdraw' ] = [
			'title'        => __( 'Withdrawal', 'dozent' ),
			'icon'         => 'dicon-wallet',
			'field_groups' => [
				'general' => [
					'title'  => __( 'Withdrawal Settings', 'dozent' ),
					'fields' => [
						'min_withdraw_amount' => [
							'type'    => 'number',
							'title'   => __( 'Minimum Withdraw Amount', 'dozent' ),
							'default' => '80',
							'desc'    => __( 'Instructors should earn equal or above this amount to make a withdraw request.', 'dozent' ),
						],
					],
				],

				'withdraw_methods' => [
					'title' => __( 'Withdraw Methods', 'dozent' ),
					'desc'  => __( 'Set withdraw settings', 'dozent' ),
				],
			],
		];

		$sections = apply_filters( 'dozent/options/attr', $sections );
		$extends  = apply_filters( 'dozent/options/extend/attr', [] );

		if ( dozent_count( $extends ) ) {
			foreach ( $extends as $extend_key => $extend_option ) {
				if ( isset( $sections[ $extend_key ] ) && dozent_count( $extend_option[ 'field_groups' ] ) ) {
					$sections                                  = $sections[ $extend_key ][ 'field_groups' ];
					$sections                                  = array_merge( $sections, $extend_option[ 'field_groups' ] );
					$sections[ $extend_key ][ 'field_groups' ] = $sections;
				}
			}
		}

		return $sections;
	}

	/**
	 * @param array $field
	 * @return false|string
	 *
	 * Generate Field Type Input for Dozent Option Panel
	 *
	 * @since DozentLMS 1.0.0
	 */

	public function field_type( $field = [] ) {
		ob_start();
		include DOZENT_ABSPATH . "views/options/fields/{$field['type']}.php";

		return ob_get_clean();
	}

	/**
	 * @return false|string
	 *
	 * Generate Option Field
	 *
	 * @since DozentLMS 1.0.0
	 */
	public function generate() {
		ob_start();
		include DOZENT_ABSPATH . 'views/options/generator.php';

		return ob_get_clean();
	}

	public function option_panel() {
		echo apply_filters( 'dozent/options_panel', $this->generate() );
	}

}

Methods