News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Need help regarding Online time on Profile summary

Started by Rumpa, November 30, 2024, 02:06:19 AM

Previous topic - Next topic

Rumpa

Need help regarding Online time on Profile summary


here are the code i am trying
// Add the online time display in the profile areas
function add_online_time_to_profile(&$profile_areas)
{
    global $txt;

    // Load the custom language file for the current language
    loadLanguage('OnlineTime');

    // Add the custom callback to the summary area
    if (isset($profile_areas['info']['areas']['summary']['enabled']))
    {
        $profile_areas['info']['areas']['summary']['custom_callback'] = 'display_online_time_in_summary';
    }
}


// Custom callback to fetch and display online time
function display_online_time_in_summary($memID)
{
    global $context, $smcFunc, $txt;

    // Query to fetch total online time from the `members` table
    $request = $smcFunc['db_query']('', '
        SELECT total_time_logged_in
        FROM {db_prefix}members
        WHERE id_member = {int:id_member}',
        [
            'id_member' => $memID,
        ]
    );

    // Fetch the result
    list($total_time_logged_in) = $smcFunc['db_fetch_row']($request);
    $smcFunc['db_free_result']($request);

    // Convert total time (in seconds) to hours and minutes
    $hours = floor($total_time_logged_in / 3600);
    $minutes = floor(($total_time_logged_in % 3600) / 60);

    // Add the formatted time to the profile context
    $context['member']['online_time'] = sprintf($txt['online_time'], $hours, $minutes);
}


tried to triggered hook with this
<hook hook="integrate_pre_include" function="integrate_pre_include" file="$sourcedir/OnlineTimeProfile.php" />
<hook hook="integrate_load_theme" function="integrate_load_theme" file="$sourcedir/OnlineTimeProfile.php" />


but not working

Diego Andrés

Quote from: Rumpa on November 30, 2024, 02:06:19 AM<hook hook="integrate_pre_include" function="integrate_pre_include" file="$sourcedir/OnlineTimeProfile.php" />
<hook hook="integrate_load_theme" function="integrate_load_theme" file="$sourcedir/OnlineTimeProfile.php" />


???
You have an obvious issue here, it will probably even show up in the error log.

SMF Tricks - Free & Premium Responsive Themes for SMF.

Rumpa

Quote from: Diego Andrés on November 30, 2024, 11:39:11 AM
Quote from: Rumpa on November 30, 2024, 02:06:19 AM<hook hook="integrate_pre_include" function="integrate_pre_include" file="$sourcedir/OnlineTimeProfile.php" />
<hook hook="integrate_load_theme" function="integrate_load_theme" file="$sourcedir/OnlineTimeProfile.php" />


???
You have an obvious issue here, it will probably even show up in the error log.
How to resolved it can you tell me please

Advertisement: