LLMS_Admin_Analytics::save_search_fields( $analytics )

Save admin fields.


Description Description

Loops though the lifterlms options array and outputs each field.


Parameters Parameters

$settings

(array) (Required) Opens array to output


Top ↑

Return Return

(bool)


Top ↑

Source Source

File: includes/admin/class.llms.admin.analytics.php

	public static function save_search_fields( $analytics ) {
	    if ( empty( $_POST ) ) {
	    	return false; }

	    //sales analytics
	    if ( ! empty( $_POST['action'] ) && ( 'llms-analytics-sales' === $_POST['action'] ) && ! empty( $_POST['_wpnonce'] ) ) {

	 		$search = new stdClass;

	 		//validate fields
	 		if ( empty( $_POST['llms_product_select'] ) ) {
	 			self::set_error( __( 'You must choose a product option.' , 'lifterlms' ) );
	 		}
	 		if ( empty( $_POST['llms_date_filter'] ) ) {
	 			self::set_error( __( 'You must choose a date filter.' , 'lifterlms' ) );
	 		}
	 		if ( 'none' === $_POST['llms_date_filter'] && ( empty( $_POST['llms-start-date'] ) || empty( $_POST['llms-start-date'] ) ) ) {
	 			self::set_error( __( 'You must enter a start and end date.' , 'lifterlms' ) );
	 		}

	 		$search->product_id = llms_clean( $_POST['llms_product_select'] );
	 		$search->date_filter = llms_clean( $_POST['llms_date_filter'] );
	 		//$search->exclude_coupons = ( isset( $_POST[ 'llms_exclude_coupons' ] ) ? $_POST[ 'llms_exclude_coupons' ] : false );

	 		//get start and end date for date filter
	 		if ( 'none' !== $search->date_filter ) {

	 			$date_range = LLMS_Date::get_date_range_by_filter( $search->date_filter );
	 			$search->date_range = $date_range;
	 			$search->start_date = $date_range['start_date'];
	 			$search->end_date = $date_range['end_date'];
	 			$search->end_date_plus_one = LLMS_Date::db_date( $date_range['end_date'] . '+ 1 day' );

	 		} else {

	 			$search->start_date = LLMS_Date::db_date( llms_clean( $_POST['llms-start-date'] ) );
	 			$search->end_date = LLMS_Date::db_date( llms_clean( $_POST['llms-end-date'] ) );
	 			$search->end_date_plus_one = LLMS_Date::db_date( llms_clean( $_POST['llms-end-date'] ) . '+ 1 day' );
	 		}

	 		//set up search arguments
			$values = array(
				'0' => array(
				 	'key' => '_llms_order_date',
					'value' => $search->start_date,
					'compare' => '>=',
				),
				'1' => array(
				 	'key' => '_llms_order_date',
					'value' => $search->end_date_plus_one,
					'compare' => '<=',
				),
			);

			// if product id is not "all" then add product id to values
			if ( 'all_products' !== $search->product_id ) {

				$product_value = array(
				 	'key' => '_llms_order_product_id',
					'value' => $search->product_id,
					'compare' => '=',
				);
				array_push( $values, $product_value );

			}

			//get results and save to search object
	 		$search->results = LLMS_Analytics::get_orders( $values );

	 		//set search object as session object
		    LLMS()->session->set( 'llms_analytics_sales', $search );
	    }// End if().

	    //course analytics
	    if ( ! empty( $_POST['action'] ) && ( 'llms-analytics-course' === $_POST['action'] ) && ! empty( $_POST['_wpnonce'] ) ) {

	 		$search = new stdClass;

	 		//validate fields
	 		if ( empty( $_POST['llms_product_select'] ) ) {
	 			self::set_error( __( 'You must choose a product option.' , 'lifterlms' ) );
	 		}
	 		if ( empty( $_POST['llms_date_filter'] ) ) {
	 			self::set_error( __( 'You must choose a date filter.' , 'lifterlms' ) );
	 		}
	 		if ( 'none' === $_POST['llms_date_filter'] && ( empty( $_POST['llms-start-date'] ) || empty( $_POST['llms-start-date'] ) ) ) {
	 			self::set_error( __( 'You must enter a start and end date.' , 'lifterlms' ) );
	 		}

	 		$search->product_id = llms_clean( $_POST['llms_product_select'] );
	 		$search->date_filter = llms_clean( $_POST['llms_date_filter'] );
	 		//$search->exclude_coupons = ( isset( $_POST[ 'llms_exclude_coupons' ] ) ? $_POST[ 'llms_exclude_coupons' ] : false );

	 		//get start and end date for date filter
	 		if ( 'none' !== $search->date_filter ) {

	 			$date_range = LLMS_Date::get_date_range_by_filter( $search->date_filter );
	 			$search->date_range = $date_range;
	 			$search->start_date = $date_range['start_date'];
	 			$search->end_date = $date_range['end_date'];

	 		} else {

	 			$search->start_date = LLMS_Date::db_date( llms_clean( $_POST['llms-start-date'] ) );
	 			$search->end_date = LLMS_Date::db_date( llms_clean( $_POST['llms-end-date'] ) );

	 		}

			// if product id is not "all" then add product id to values
			if ( 'all_courses' === $search->product_id ) {

				$courses = LLMS_Analytics::get_posts( 'course' );

				//if any courses are returned loop through them and get the enrolled students
				if ( $courses ) {

					$search->courses = $courses;
					$students = array();

					foreach ( $courses as $course ) {
						$enrolled_users = LLMS_Analytics::get_total_users_all_time( $course->ID, $search->end_date );

						$students = array_merge( $students, $enrolled_users );
					}

					$search->students = $students;
				}
			} else {

				//get course data
				$course = array( get_post( $search->product_id ) );

				//get course enrollment data
				$enrolled_users = LLMS_Analytics::get_total_users_all_time( $search->product_id, $search->end_date );
				$search->students = $enrolled_users;
				$search->courses = $course;

				//create new course object
				$course_obj = new LLMS_Course( $search->product_id );
				$lesson_ids = $course_obj->get_lesson_ids();
				//$search->lesson_ids = $lesson_ids;

				//get all lessons in a course
				$search->lessons = array();
				foreach ( $lesson_ids as $id ) {

					array_push( $search->lessons, get_post( $id ) );

				}
			}// End if().

	 		//set search object as session object
		    LLMS()->session->set( 'llms_analytics_course', $search );
	    }// End if().

	    //membership analytics
	    if ( ! empty( $_POST['action'] ) && ( 'llms-analytics-membership' === $_POST['action'] ) && ! empty( $_POST['_wpnonce'] ) ) {

	 		$search = new stdClass;

	 		//validate fields
	 		if ( empty( $_POST['llms_product_select'] ) ) {
	 			self::set_error( __( 'You must choose a product option.' , 'lifterlms' ) );
	 		}
	 		if ( empty( $_POST['llms_date_filter'] ) ) {
	 			self::set_error( __( 'You must choose a date filter.' , 'lifterlms' ) );
	 		}
	 		if ( 'none' === $_POST['llms_date_filter'] && ( empty( $_POST['llms-start-date'] ) || empty( $_POST['llms-start-date'] ) ) ) {
	 			self::set_error( __( 'You must enter a start and end date.' , 'lifterlms' ) );
	 		}

	 		$search->product_id = llms_clean( $_POST['llms_product_select'] );
	 		$search->date_filter = llms_clean( $_POST['llms_date_filter'] );
	 		//$search->exclude_coupons = ( isset( $_POST[ 'llms_exclude_coupons' ] ) ? $_POST[ 'llms_exclude_coupons' ] : false );

	 		//get start and end date for date filter
	 		if ( 'none' !== $search->date_filter ) {

	 			$date_range = LLMS_Date::get_date_range_by_filter( $search->date_filter );
	 			$search->date_range = $date_range;
	 			$search->start_date = $date_range['start_date'];
	 			$search->end_date = $date_range['end_date'];

	 		} else {

	 			$search->start_date = LLMS_Date::db_date( llms_clean( $_POST['llms-start-date'] ) );
	 			$search->end_date = LLMS_Date::db_date( llms_clean( $_POST['llms-end-date'] ) );

	 		}

			// if product id is not "all" then add product id to values
			if ( 'all_memberships' === $search->product_id ) {

				$memberships = LLMS_Analytics::get_posts( 'llms_membership' );

				//if any courses are returned loop through them and get the enrolled students
				if ( $memberships ) {

					$search->memberships = $memberships;
					$members = array();

					foreach ( $memberships as $membership ) {
						$enrolled_users = LLMS_Analytics::get_total_users_all_time( $membership->ID, $search->end_date );

						$members = array_merge( $members, $enrolled_users );
					}

					$search->members = $members;
				}
			} else {

				//get course data
				$membership = array( get_post( $search->product_id ) );

				//get course enrollment data
				$enrolled_users = LLMS_Analytics::get_total_users_all_time( $search->product_id, $search->end_date );
				$search->members = $enrolled_users;
				$search->memberships = $membership;

				//$search->test_student_progress = $course_obj->get_student_progress( '147' );

			}

	 		//set search object as session object
		    LLMS()->session->set( 'llms_analytics_membership', $search );
	    }// End if().

	}


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.





Permalink: