MySQL Callback in Xenforo 2

Madhouse

Active member
I have a mysql query that displays on a page node in xf1, what do I need to change to make it work in xf2?

PHP:
<?php

class Callback_PageNode
{
    public static function myfunction(XenForo_ControllerPublic_Abstract $controller, XenForo_ControllerResponse_Abstract &$response)
    {
        $mydb = XenForo_Application::get('db');
        
                $myrows = $mydb->fetchAll("
            SELECT
                    xf_user_external_auth.provider_key,
                    xf_user_external_auth.user_id,
                    xf_user.user_id,
                    xf_user.username,
                    xf_user.secondary_group_ids   
            FROM xf_user_external_auth
            LEFT JOIN xf_user ON
                    (xf_user_external_auth.user_id = xf_user.user_id)
            WHERE
                    xf_user_external_auth.provider = 'steam'
            ORDER BY xf_user_external_auth.user_id ASC           
        ");   

        $response->params['myrows'] = $myrows;
    }
}

1523194053702.webp
 
In src/addons/Site/Pages/Providers.php:
PHP:
<?php

/*
 * This file is part of a XenForo add-on.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Site\Pages;

/**
 * Static methods for the Providers page.
 */
class Providers
{
    /**
     * @param \XF\Pub\Controller\AbstractController $controller
     * @param \XF\Mvc\Reply\AbstractReply           $reply
     */
    public static function getData(
        \XF\Pub\Controller\AbstractController $controller,
        \XF\Mvc\Reply\AbstractReply &$reply
    ) {
        if ($reply instanceof \XF\Mvc\Reply\View) {
            $providers = \XF::db()->fetchAll(
                "SELECT
                        xf_user_external_auth.provider_key,
                        xf_user_external_auth.user_id,
                        xf_user.user_id,
                        xf_user.username,
                        xf_user.secondary_group_ids
                    FROM xf_user_external_auth
                    LEFT JOIN xf_user ON
                        (xf_user_external_auth.user_id = xf_user.user_id)
                    WHERE xf_user_external_auth.provider = 'steam'
                    ORDER BY xf_user_external_auth.user_id ASC"
            );

            $reply->setParam('providers', $providers);
        }
    }
}

Template HTML:
HTML:
<xf:foreach loop="$providers" value="$provider">
     Admin={$provider.provider_key}:WhiteList // {$provider.user_id} {$provider.username}<br>
</xf:foreach>

PHP callback: Site\Pages\Providers::getData()

Untested, adjust to suit your needs.
 
In src/addons/Site/Pages/Providers.php:
PHP:
<?php

/*
* This file is part of a XenForo add-on.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Site\Pages;

/**
* Static methods for the Providers page.
*/
class Providers
{
    /**
     * @param \XF\Pub\Controller\AbstractController $controller
     * @param \XF\Mvc\Reply\AbstractReply           $reply
     */
    public static function getData(
        \XF\Pub\Controller\AbstractController $controller,
        \XF\Mvc\Reply\AbstractReply &$reply
    ) {
        if ($reply instanceof \XF\Mvc\Reply\View) {
            $providers = \XF::db()->fetchAll(
                "SELECT
                        xf_user_external_auth.provider_key,
                        xf_user_external_auth.user_id,
                        xf_user.user_id,
                        xf_user.username,
                        xf_user.secondary_group_ids
                    FROM xf_user_external_auth
                    LEFT JOIN xf_user ON
                        (xf_user_external_auth.user_id = xf_user.user_id)
                    WHERE xf_user_external_auth.provider = 'steam'
                    ORDER BY xf_user_external_auth.user_id ASC"
            );

            $reply->setParam('providers', $providers);
        }
    }
}

Template HTML:
HTML:
<xf:foreach loop="$providers" value="$provider">
     Admin={$provider.provider_key}:WhiteList // {$provider.user_id} {$provider.username}<br>
</xf:foreach>

PHP callback: Site\Pages\Providers::getData()

Untested, adjust to suit your needs.


That worked! Thank you.
 
Top Bottom