LLMS_Table_Student_Quiz_Attempts::get_data( string $key, LLMS_Quiz_Attempt $attempt )
Retrieve data for a cell.
Parameters Parameters
- $key
-
(string) (Required) The column id / key.
- $attempt
-
(LLMS_Quiz_Attempt) (Required) LLMS_Quiz_Attempt obj.
Return Return
(mixed)
Source Source
File: includes/admin/reporting/tables/llms.table.student.quiz.attempts.php
protected function get_data( $key, $attempt ) {
switch ( $key ) {
case 'quiz':
$quiz = $attempt->get_quiz();
if ( $quiz ) {
$value = $quiz->get( 'title' );
// Add link to quiz attempts if user has permission
if ( current_user_can( 'edit_post', $quiz->get( 'id' ) ) ) {
$url = LLMS_Admin_Reporting::get_current_tab_url(
array(
'tab' => 'quizzes',
'stab' => 'attempts',
'quiz_id' => $quiz->get( 'id' ),
)
);
$value = '<a href="' . esc_url( $url ) . '">' . esc_html( $value ) . '</a>';
}
} else {
$value = __( '[Deleted Quiz]', 'lifterlms' );
}
break;
case 'course':
$value = '—';
$quiz = $attempt->get_quiz();
if ( $quiz ) {
$course = $quiz->get_course();
if ( $course ) {
$url = LLMS_Admin_Reporting::get_current_tab_url(
array(
'tab' => 'courses',
'stab' => 'overview',
'course_id' => $course->get( 'id' ),
)
);
$value = '<a href="' . esc_url( $url ) . '">' . esc_html( $course->get( 'title' ) ) . '</a>';
}
}
break;
case 'lesson':
$quiz = $attempt->get_quiz();
if ( $quiz ) {
$lesson = $quiz->get_lesson();
if ( $lesson ) {
$value = $lesson->get( 'title' );
} else {
$value = __( '[Deleted Lesson]', 'lifterlms' );
}
} else {
$value = '–';
}
break;
case 'attempt':
$value = '#' . $attempt->get( $key );
break;
case 'grade':
$value = $attempt->get( $key ) ? $attempt->get( $key ) . '%' : '0%';
$additional = $attempt->l10n( 'status' );
if ( $attempt->can_be_resumed() && $attempt->is_last_attempt() ) {
$additional .= ' - ' . esc_html__( 'Can be resumed', 'lifterlms' );
}
$value .= ' (' . $additional . ')';
break;
case 'start_date':
case 'end_date':
$value = '–';
$date = $attempt->get( $key );
if ( $date ) {
$value = date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), strtotime( $date ) );
}
break;
case 'id':
$value = sprintf( '%2$d (%1$s)', $attempt->get_key(), $attempt->get( 'id' ) );
$url = LLMS_Admin_Reporting::get_current_tab_url(
array(
'tab' => 'quizzes',
'stab' => 'attempts',
'quiz_id' => $attempt->get( 'quiz_id' ),
'attempt_id' => $attempt->get( 'id' ),
)
);
$value = '<a href="' . esc_url( $url ) . '">' . $value . '</a>';
break;
default:
$value = $key;
}// End switch().
return $value;
}
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
| Version | Description |
|---|---|
| 9.1.0 | Introduced. |