LLMS_Table_Quizzes::get_data( string $key, mixed $data )

Retrieve data for a cell


Parameters Parameters

$key

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

$data

(mixed) (Required) Object / array of data that the function can use to extract the data.


Top ↑

Return Return

(mixed)


Top ↑

Source Source

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

	 */
	protected function get_data( $key, $data ) {

		$quiz = llms_get_post( $data );

		switch ( $key ) {

			case 'actions':
				$value = $this->get_actions_html( $quiz );
				break;

			case 'attempts':
				$query = new LLMS_Query_Quiz_Attempt(
					array(
						'quiz_id'  => $quiz->get( 'id' ),
						'per_page' => 1,
					)
				);

				$url   = LLMS_Admin_Reporting::get_current_tab_url(
					array(
						'tab'     => 'quizzes',
						'stab'    => 'attempts',
						'quiz_id' => $quiz->get( 'id' ),
					)
				);
				$value = '<a href="' . $url . '">' . $query->get_found_results() . '</a>';

				break;

			case 'average':
				$grade = 0;
				$query = new LLMS_Query_Quiz_Attempt(
					array(
						'quiz_id'  => $quiz->get( 'id' ),
						'per_page' => 1000,
					)
				);

				$attempts = $query->get_number_results();

				if ( ! $attempts ) {
					$value = 0;
				} else {

					foreach ( $query->get_attempts() as $attempt ) {
						$grade += $attempt->get( 'grade' );
					}

					$value = round( $grade / $attempts, llms_get_floats_rounding_precision() ) . '%';

				}

				break;

			case 'course':
				$value  = '&mdash;';
				$course = $quiz->get_course();
				if ( $course ) {
					$url   = LLMS_Admin_Reporting::get_current_tab_url(
						array(
							'tab'       => 'courses',
							'course_id' => $course->get( 'id' ),
						)
					);
					$value = '<a href="' . esc_url( $url ) . '">' . $course->get( 'title' ) . '</a>';
				}
				break;

			case 'id':
				$id    = $quiz->get( 'id' );
				$value = $id;

				$course = $quiz->get_course();
				if ( ! $quiz->is_orphan( true ) && $course ) {

					$url = add_query_arg(
						array(
							'page'      => 'llms-course-builder',
							'course_id' => $course->get( 'id' ),
						),
						admin_url( 'admin.php' )
					);

					$url  .= sprintf( '#lesson:%d:quiz', $quiz->get( 'lesson_id' ) );
					$value = '<a href="' . esc_url( $url ) . '">' . $id . '</a>';
				}
				break;

			case 'lesson':
				$value  = '&mdash;';
				$lesson = $quiz->get_lesson();
				if ( $lesson ) {
					$value = $lesson->get( 'title' );
				}
				break;

			case 'title':
				$value = $quiz->get( 'title' );
				$url   = LLMS_Admin_Reporting::get_current_tab_url(
					array(
						'tab'     => 'quizzes',
						'quiz_id' => $quiz->get( 'id' ),
					)
				);
				$value = '<a href="' . esc_url( $url ) . '">' . $quiz->get( 'title' ) . '</a>';
				break;

			default:
				$value = $key;

		}

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



Top ↑

Changelog Changelog

Changelog
Version Description
6.0.0 Don't access LLMS_Query_Quiz_Attempt properties directly.
4.2.0 Added a deep check on whether the quiz is associated to a lesson.
3.37.8 Add actions column that allows deletion of orphaned quizzes. ID column displays as plain text if the quiz is not editable and directs to the quiz within the course builder when it is.
3.24.0 Unknown.
3.16.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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