LLMS_Analytics_Sales::search_form()

Builds Search Form


Description Description


Source Source

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

	public function search_form() {

		//get session data if it exists
		$search = LLMS()->session->get( 'llms_analytics_sales' );

		$product_id = isset( $search->product_id ) ? $search->product_id : '';
		$date_filter = isset( $search->date_filter ) ? $search->date_filter : 'none';
		$start_date = isset( $search->start_date ) ? LLMS_Date::pretty_date( $search->start_date ) : '';
		$end_date = isset( $search->end_date ) ? LLMS_Date::pretty_date( $search->end_date ) : '';
		$inc_coupons = isset( $search->exclude_coupons ) ? $search->exclude_coupons : false;

		//get products
		$products = LLMS_Analytics::get_products();
		//get date filters
		$date_filters = LLMS_Date::date_filters();

		//var_dump( $search);

		//start building html
		$html = '<div class="llms-search-form-wrapper">';

		//Product Select ( Courses and Memberships )
		$html .= '<div class="llms-select">';
		$html .= '<label>' . __( 'Select a product', 'lifterlms' ) . '</label>';
		$html .= '<select id="llms-product-select" name="llms_product_select" class="chosen-select-width">';

		//all products option
		$html .= '<option value="all_products" ' . ( 'all_products' == $product_id ? 'selected' : '' ) . '>' . __( 'All Products', 'lifterlms' ) . '</option>';
		//$html .= '<option value="all_courses" ' . ( $product_id == 'all_courses' ? 'selected' : '' ) . '>' . __( 'All Courses', 'lifterlms' ) . '</option>';
		//$html .= '<option value="all_memberships" ' . ( $product_id == 'all_memberships' ? 'selected' : '' ) . '>' . __( 'All Memberships', 'lifterlms' ) . '</option>';

		//loop through posts
		if ( $products ) {
			$html .= '<optgroup label="' . __( 'Courses', 'lifterlms' ) . '">';
			foreach ( $products as $key => $product ) {
				if ( 'course' === $product->post_type ) {
						$html .= '<option value="' . $product->ID . '"
						' . ( $product_id == $product->ID  ? 'selected' : '' ) . '>
						' . $product->post_title . '</option>';
					//unset the objects so I don't loop over them again
					unset( $products[ $key ] );
				}
			}
			$html .= '</optgroup>';
			$html .= '<optgroup label="' . __( 'Memberships', 'lifterlms' ) . '">';
			foreach ( $products as $key => $product ) {
				if ( 'llms_membership' === $product->post_type ) {
					$html .= '<option value="' . $product->ID . '" 
						' . ( $product_id == $product->ID ? 'selected' : '' ) . '>
						' . $product->post_title . '</option>';
					//no real reason except the array means nothing anymore.
					unset( $products[ $key ] );
				}
			}
			$html .= '</optgroup>';
		}

		$html .= '</select>';
		$html .= '</div>';

		//Date filters ( Courses and Memberships )
		$html .= '<div class="llms-select">';
		$html .= '<label>' . __( 'Filter Date Range', 'lifterlms' ) . '</label>';
		$html .= '<select id="llms-date-filter-select" name="llms_date_filter" class="chosen-select-width">';

		foreach ( $date_filters as $key => $value ) {
			$html .= '<option value="' . $key . '" 
				' . ( $date_filter == $key ? 'selected' : '' ) . '>
				' . $value . '</option>';

		}

		$html .= '</select>';
		$html .= '</div>';

		//start date
		$html .= '<div class="llms-filter-options date-filter">';
		$html .= '<div class="llms-date-select">';
		$html .= '<label>' . __( 'Start date', 'lifterlms' ) . '</label>';
		$html .= '<input type="text" name="llms-start-date" class="llms-date-range-select-start" value="' . $start_date . '">';
		$html .= '</div>';

		//end date
		$html .= '<div class="llms-date-select">';
		$html .= '<label>' . __( 'End date', 'lifterlms' ) . '</label>';
		$html .= '<input type="text" name="llms-end-date" class="llms-date-range-select-end" value="' . $end_date . '">';
		$html .= '</div>';
		$html .= '</div>'; //end date filters

		// Removing this option as it isn't needed right now
		// // filter checkboxes
		// $html .= '<div class="llms-filter-options">';

		// // Exclude Coupons
		// $html .= '<div class="llms-checkbox">';
		// $html .= '<input type="checkbox" name="llms_exclude_coupons" ' .  ( $inc_coupons === 'on' ? 'checked' : '' ) . '>' . __( 'Exclude Coupons', 'lifterlms' );
		// $html .= '</div>';

		// $html .= '</div>'; //end filter options

		$html .= wp_nonce_field( 'search_analytics_sales', '_wpnonce', true, false );
		$html .= '<input type="hidden" name="action" value="llms-analytics-sales" />';

		//search button
		$html .= '<div class="llms-search-button">';
		//$html .= '<input type="submit" name="llms_search" class="button button-primary" id="llms_analytics_search" value="Filter Results" />';
		$html .= get_submit_button( 'Filter Results', 'primary', 'llms_search', true, array(
			'id' => 'llms_analytics_search',
		) );
		$html .= '</div>';

		$html .= '</div>';

		return $html;

	}


Top ↑

User Contributed Notes User Contributed Notes

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





Permalink: