LLMS_Analytics::get_total_enrolled_by_day( $search )


Description Description


Source Source

File: includes/class.llms.analytics.php

	public static function get_total_enrolled_by_day( $search ) {

		$total_by_day = array();
		$date = $search->start_date;
		// array key counter
		$i = 0;

		while ( $date <= $search->end_date ) {

			//create array for each date and add to $total_by_day
			$daily_results = array( $date );
			$total_by_day[] = $daily_results;

			if ( isset( $search->courses ) ) {

				foreach ( $search->courses as $course ) {

					$daily_total = 0;

					//loop through all students and count enrolled students
					if ( $search->students ) {
						foreach ( $search->students as $key => $value ) {

							if ( $value->post_id == $course->ID && LLMS_Date::db_date( $value->enrolled_date ) <= $date ) {

								if ( 'Enrolled' === $value->status ) {
									$daily_total++;
								}
							}
						}
					}
					array_push( $total_by_day[ $i ], $daily_total );
				}
			} elseif ( isset( $search->memberships ) ) {

				foreach ( $search->memberships as $membership ) {

					$daily_total = 0;

					//loop through all students and count enrolled students
					if ( $search->members ) {
						foreach ( $search->members as $key => $value ) {

							if ( $value->post_id == $membership->ID && LLMS_Date::db_date( $value->enrolled_date ) <= $date ) {

								if ( 'Enrolled' === $value->status ) {
									$daily_total++;
								}
							}
						}
					}
					array_push( $total_by_day[ $i ], $daily_total );
				}
			}// End if().

			//add 1 to array key counter
			$i++;
			//add one day to date
			$date = LLMS_Date::db_date( $date . '+ 1 day' );

		}// End while().

		return $total_by_day;

	}


Top ↑

User Contributed Notes User Contributed Notes

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