LLMS_Table_Quizzes::get_data( string $key, mixed $data )
Retrieve data for a cell
Description Description
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
Return Return
(mixed)
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 '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->found_results . '</a>'; break; case 'average': $grade = 0; $query = new LLMS_Query_Quiz_Attempt( array( 'quiz_id' => $quiz->get( 'id' ), 'per_page' => 1000, ) ); $attempts = count( $query->results ); if ( ! $attempts ) { $value = 0; } else { foreach ( $query->get_attempts() as $attempt ) { $grade += $attempt->get( 'grade' ); } $value = round( $grade / $attempts, 3 ) . '%'; } break; case 'course': $value = '—'; $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': $value = $this->get_post_link( $quiz->get( 'id' ) ); break; case 'lesson': $value = '—'; $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; }// End switch(). return $this->filter_get_data( $value, $key, $data ); }
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
3.16.0 | Introduced. |
User Contributed Notes User Contributed Notes
Permalink: