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.
Return Return
(mixed)
Source Source
File: includes/admin/reporting/tables/llms.table.quizzes.php
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 | */ 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 = '—' ; $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 = '—' ; $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 ); |
Expand full source code Collapse full source code View on GitHub
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. |