LLMS_Table_Students::get_data( string $key, LLMS_Student $student )

Retrieve data for the columns


Parameters Parameters

$key

(string) (Required) The column id / key.

$student

(LLMS_Student) (Required) Instance of the LLMS_Student.


Top ↑

Return Return

(mixed)


Top ↑

Source Source

File: includes/admin/reporting/tables/llms.table.students.php

	public function get_data( $key, $student ) {

		switch ( $key ) {

			case 'achievements':
				$url   = LLMS_Admin_Reporting::get_current_tab_url(
					array(
						'stab'       => 'achievements',
						'student_id' => $student->get_id(),
					)
				);
				$value = '<a href="' . esc_url( $url ) . '">' . $student->get_awards_count( 'achievement' ) . '</a>';
				break;

			case 'certificates':
				$url   = LLMS_Admin_Reporting::get_current_tab_url(
					array(
						'stab'       => 'certificates',
						'student_id' => $student->get_id(),
					)
				);
				$value = '<a href="' . esc_url( $url ) . '">' . $student->get_awards_count( 'certificate' ) . '</a>';
				break;

			case 'completions':
				$courses = $student->get_completed_courses();
				$value   = count( $courses['results'] );
				break;

			case 'enrollments':
				$url         = LLMS_Admin_Reporting::get_current_tab_url(
					array(
						'stab'       => 'courses',
						'student_id' => $student->get_id(),
					)
				);
				$enrollments = $student->get_courses(
					array(
						'limit' => 1,
					)
				);
				$value       = '<a href="' . esc_url( $url ) . '">' . $enrollments['found'] . '</a>';
				break;

			case 'id':
				$id = $student->get_id();
				if ( current_user_can( 'list_users' ) ) {
					$value = '<a href="' . esc_url( get_edit_user_link( $id ) ) . '">' . $id . '</a>';
				} else {
					$value = $id;
				}
				break;

			case 'last_seen':
				$query = new LLMS_Events_Query(
					array(
						'actor'         => $student->get_id(),
						'per_page'      => 1,
						'sort'          => array(
							'date' => 'DESC',
						),
						'no_found_rows' => true,
					)
				);

				if ( $query->has_results() ) {
					$events = $query->get_events();
					$last   = array_shift( $events );
					$value  = $last->get( 'date' );
				} else {
					$value = $student->get( 'last_login' );
				}

				$value = $value ? date_i18n( get_option( 'date_format' ), is_numeric( $value ) ? $value : strtotime( $value ) ) : '&ndash;';

				break;

			case 'memberships':
				$url   = LLMS_Admin_Reporting::get_current_tab_url(
					array(
						'stab'       => 'memberships',
						'student_id' => $student->get_id(),
					)
				);
				$value = '<a href="' . esc_url( $url ) . '">' . count( $student->get_membership_levels() ) . '</a>';
				break;

			case 'name':
				$first = $student->get( 'first_name' );
				$last  = $student->get( 'last_name' );

				if ( ! $first || ! $last ) {
					$value = $student->get( 'display_name' );
				} else {
					$value = $last . ', ' . $first;
				}

				$url   = LLMS_Admin_Reporting::get_current_tab_url(
					array(
						'student_id' => $student->get_id(),
					)
				);
				$value = '<a href="' . esc_url( $url ) . '">' . $value . '</a>';

				break;

			case 'overall_grade':
				$value = $student->get_overall_grade( true );
				if ( is_numeric( $value ) ) {
					$value .= '%';
				}
				break;

			case 'overall_progress':
				$value = $this->get_progress_bar_html( $student->get_overall_progress( true ) );
				break;

			case 'registered':
				$value = $student->get_registration_date();
				break;

			default:
				$value = $key;

		}

		return $this->filter_get_data( $value, $key, $student );

	}


Top ↑

Changelog Changelog

Changelog
Version Description
6.0.0 Don't access LLMS_Events_Query properties directly Use LLMS_Student::get_awards_count() for retrieving the number of earned achievements and certificates.
4.7.0 Speed up the query used to retrieve the last seen column by avoiding the found rows calculation.
3.36.1 Fixed "Last Seen" column displaying wrong date when the student last login date was saved as timestamp.
3.36.0 Added "Last Seen" column.
3.2.0
3.15.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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