tincanny_reporting_xtin_quiz_after_begin
Fires after the start of a Tin Can quiz, allowing for custom actions during the quiz initiation.
add_action( 'tincanny_reporting_xtin_quiz_after_begin', $callback, 10, 1 );
Description
Fires after the Tin Can reporting section begins. Developers can use this hook to add custom content or modify the default Tin Can reporting output before the main content is rendered.
Usage
add_action( 'tincanny_reporting_xtin_quiz_after_begin', 'your_function_name', 10, 1 );
Examples
<?php
/**
* Example of hooking into 'tincanny_reporting_xtin_quiz_after_begin'.
* This action is fired after the begining of the Xtin Quiz reporting section.
*
* @param string $quiz_id The ID of the quiz being reported on.
*/
function my_tincanny_xtin_quiz_reporting_logic( $quiz_id ) {
// Retrieve some data related to the quiz, for example, question attempts.
// In a real scenario, this might involve database queries or API calls.
$quiz_attempts = get_post_meta( $quiz_id, '_tincanny_quiz_attempts', true );
if ( ! empty( $quiz_attempts ) && is_array( $quiz_attempts ) ) {
// Calculate some statistics, e.g., average score for this quiz.
$total_score = 0;
$num_attempts = count( $quiz_attempts );
foreach ( $quiz_attempts as $attempt ) {
if ( isset( $attempt['score'] ) ) {
$total_score += (int) $attempt['score'];
}
}
$average_score = ( $num_attempts > 0 ) ? round( $total_score / $num_attempts, 2 ) : 0;
// Output some custom reporting information.
echo '<div class="my-custom-reporting-info">';
echo '<h3>Custom Xtin Quiz Reporting for Quiz ID: ' . esc_html( $quiz_id ) . '</h3>';
echo '<p>Number of attempts: ' . esc_html( $num_attempts ) . '</p>';
echo '<p>Average Score: ' . esc_html( $average_score ) . '%</p>';
echo '</div>';
} else {
echo '<p>No attempt data found for this Xtin Quiz.</p>';
}
}
add_action( 'tincanny_reporting_xtin_quiz_after_begin', 'my_tincanny_xtin_quiz_reporting_logic', 10, 1 ); // 10 is the priority, 1 is the number of accepted arguments.
?>
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/shortcode-tincanny/shortcode-tincanny.php:840
src/shortcode-tincanny/shortcode-tincanny.php:911
public static function admin_reporting_content() {
?>
<div class="uo-admin-reporting-tab-single" id="tin-can"
style="display: <?php echo self::$is_tincan_report ? 'block' : 'none'; ?>">
<?php
// Add Tin Can tab content.
if ( self::$is_tincan_report ) {
do_action( 'tincanny_reporting_tin_can_after_begin' );
include dirname( UO_REPORTING_FILE ) . '/src/reporting/tin-can/templates/tc-tincan-filter.php';
do_action( 'tincanny_reporting_tin_can_before_end' );
}
?>
</div>
<div class="uo-admin-reporting-tab-single" id="xapi-tincan"
style="display: <?php echo self::$is_xapi_report ? 'block' : 'none'; ?>">
<?php
// Add xAPI tab content.
if ( self::$is_xapi_report ) {
do_action( 'tincanny_reporting_xtin_quiz_after_begin' );
self::show_tincan_list_table( 'xapi-tincan' );
do_action( 'tincanny_reporting_xtin_quiz_before_end' );
}
?>
</div>
<?php
}