• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Admin Pages

silence

Well-known member
#1
Ok so I'm listing users based on criteria (like user list)
It all is working fine but the adminpagenav at the bottom doesn't show &page=X but if I manually put it in the URL it goes to the next page without issue.

I don't think it's a routing issue but I can't find what adds it to the link :C
Here is the template I'm using:

HTML:
<xen:title>Teamspeak Users</xen:title>

<xen:topctrl>
    <a href="{xen:adminlink 'teamspeak/users/add'}" class="button">{xen:phrase teamspeak_add_user}</a>
</xen:topctrl>

<xen:require css="filter_list.css" />
<xen:require js="js/xenforo/filter_list.js" />

<xen:form action="{xen:adminlink teamspeak}" class="section">   
    <xen:if is="{$teamspeakUsers}">
       
        <h2 class="subHeading">
            Teamspeak Users
            <xen:include template="filter_list_controls" />
        </h2>
       
        <ol class="FilterList">
            <xen:foreach loop="$teamspeakUsers" value="$teamspeakUser">
                <xen:listitem
                    id="{$teamspeakUser.user_id}"
                    label="{$teamspeakUser.username}"
                    href="{xen:adminlink 'teamspeak/users/edit', $teamspeakUser}">
                    <xen:snippet>
                        {xen:if {$teamspeakUser.auth_id}, 'Identities: <span class="muted">{$teamspeakUser.auth_id}</span>'}
                    </xen:snippet>
                    <xen:beforelabel>
                        <img src="{xen:helper avatar, $teamspeakUser, s}" alt="" class="listAvatar" />
                    </xen:beforelabel>

                    <xen:popup title="{xen:phrase controls}" ctrlClass="toolsCtrl">
                        <xen:link href="{xen:adminlink 'teamspeak/users/edit', $teamspeakUser}">Edit Identities</xen:link>
                        <xen:link class="OverlayTrigger" href="{xen:adminlink 'teamspeak/users/delete', $teamspeakUser}">Delete Identities</xen:link>
                    </xen:popup>
                </xen:listitem>
            </xen:foreach>
        </ol>
       
        <p class="sectionFooter">{xen:phrase showing_x_of_y_items, 'count={xen:count $teamspeakUsers}', 'total={xen:number $totalUsers}'}</p>

        {xen:adminpagenav $perPage, $totalUsers, $page, 'teamspeak/users'}

    <xen:else />
        <div class="noResults">{xen:phrase teamspeak_no_users_to_display}</div>
    </xen:if>
</xen:form>
 

Chris D

XenForo developer
Staff member
#2
It's more likely going to be that you're not passing the, $perPage, $totalUsers, or $page parameters to the template.
 

silence

Well-known member
#3
It's more likely going to be that you're not passing the, $perPage, $totalUsers, or $page parameters to the template.
That can't be since the query print's out whatever I define the number to be (it's 10 in this case) and $totalUsers is printing out the correct integer.
 

silence

Well-known member
#5
I'd need to see the rest of your code to work out the issue.
ControllerAdmin:
PHP:
    public function actionIndex()
    {
        $accountModel = $this->_getAccountModel();

        $page = $this->_input->filterSingle('page', XenForo_Input::UINT);
        $perPage = 10;

        $conditions = array();

        $fetchOptions = array(
            'page' => $page,
            'perPage' => $perPage
        );

        $totalUsers = $accountModel->countUsers();

        $viewParams = array(
            'teamspeakUsers' => $accountModel->getAllUsers($fetchOptions),

            'totalUsers' => $totalUsers,
            'perPage' => $perPage,
            'page' => $page
        );

        return $this->responseView('Teamspeak_ViewAdmin_Teamspeak_Users_List', 'teamspeak_users_list', $viewParams);
    }
AccountModel:
PHP:
    public function getAllUsers(array $fetchOptions = array())
    {
        $limitOptions = $this->prepareLimitFetchOptions($fetchOptions);

        return $this->fetchAllKeyed($this->limitQueryResults(
            'SELECT teamspeak.*,
                    user.username, user.avatar_date, user.gravatar
                FROM xf_teamspeak AS teamspeak
                LEFT JOIN xf_user AS user ON (user.user_id = teamspeak.user_id)
                ORDER BY teamspeak.user_id DESC, user.username
            ', $limitOptions['limit'], $limitOptions['offset']
        ), 'user_id');
    }

    public function getUserID($user_id)
    {
        return $this->_getDb()->fetchRow('
            SELECT teamspeak.*,
                user.username
            FROM xf_teamspeak AS teamspeak
            LEFT JOIN xf_user AS user ON (user.user_id = teamspeak.user_id)
            WHERE teamspeak.user_id = ?
        ', $user_id);
    }
 

Chris D

XenForo developer
Staff member
#7
I have looked a few times now and I can't see anything obviously wrong :cautious:

The only thing I can't see in your code is the method that counts the users, but you said that checks out ok...
 

silence

Well-known member
#8
I have looked a few times now and I can't see anything obviously wrong :cautious:

The only thing I can't see in your code is the method that counts the users, but you said that checks out ok...
Yeah it does, I BELIEVE! I mean the footer shows the correct count so I think it does :C
PHP:
    public function countUsers()
    {
        return $this->_getDb()->fetchOne('
            SELECT COUNT(*)
            FROM xf_teamspeak AS teamspeak
        ');
    }
 

Marcus

Well-known member
#9
For debugging try ZEND_DEBUG::dump($variable); in the code.

And {xen:helper dump, $variable} in the template.
 

Chris D

XenForo developer
Staff member
#11
You said that your variables had been printing out the correct information.....

Let's start again with that, then.

In your Controller, add these lines after $viewParams but before return:
PHP:
Zend_Debug::dump($totalUsers, 'Total Users: ');
Zend_Debug::dump($perPage, 'Per Page: ');
Zend_Debug::dump($page, 'Page: ');
In your template, add these lines somewhere:
Code:
Total Users: {xen:helper dump, $totalUsers}
Per Page: {xen:helper dump, $perPage}
Page: {xen:helper dump, $page}
What do they output?
 

silence

Well-known member
#12
You said that your variables had been printing out the correct information.....

Let's start again with that, then.

In your Controller, add these lines after $viewParams but before return:
PHP:
Zend_Debug::dump($totalUsers, 'Total Users: ');
Zend_Debug::dump($perPage, 'Per Page: ');
Zend_Debug::dump($page, 'Page: ');
In your template, add these lines somewhere:
Code:
Total Users: {xen:helper dump, $totalUsers}
Per Page: {xen:helper dump, $perPage}
Page: {xen:helper dump, $page}
What do they output?
Total Users: int(25) Per Page: int(10) Page: int(0)
 

silence

Well-known member
#14
Does it show the same, then, at the top of the page and in the template?


And what returned int(0) here?

The page returning int(0) is fine if you're looking at page 1.
Yes it's the same at the top.
Page: int(0) so $page returned that. Uhhh it still doesn't tell me why it's not adding the &page=x to the page numbers at the bottom :C
 

Chris D

XenForo developer
Staff member
#15
I know. That's currently still unexplained.

Elsewhere in the Admin CP, e.g. the actual Users list... does the pagenav work there?
 

silence

Well-known member
#16
I know. That's currently still unexplained.

Elsewhere in the Admin CP, e.g. the actual Users list... does the pagenav work there?
Yes in banlist, and in Robbo's Donation Manager it work's just fine.
I'll post the template as well since it may be something in there but I'm at a loss of words :/
HTML:
<xen:title>Teamspeak Users</xen:title>

<xen:topctrl>
    <a href="{xen:adminlink 'teamspeak/users/add'}" class="button">{xen:phrase teamspeak_add_user}</a>
</xen:topctrl>

<xen:require css="filter_list.css" />
<xen:require js="js/xenforo/filter_list.js" />

<xen:form action="{xen:adminlink teamspeak}" class="section">   
    <xen:if is="{$teamspeakUsers}">
       
        <h2 class="subHeading">
            Teamspeak Users
            <xen:include template="filter_list_controls" />
        </h2>
       
        <ol class="FilterList">
            <xen:foreach loop="$teamspeakUsers" value="$teamspeakUser">
                <xen:listitem
                    id="{$teamspeakUser.user_id}"
                    label="{$teamspeakUser.username}"
                    href="{xen:adminlink 'teamspeak/users/edit', $teamspeakUser}">
                    <xen:snippet>
                        {xen:if {$teamspeakUser.auth_id}, 'Identities: <span class="muted">{$teamspeakUser.auth_id}</span>'}
                    </xen:snippet>
                    <xen:beforelabel>
                        <img src="{xen:helper avatar, $teamspeakUser, s}" alt="" class="listAvatar" />
                    </xen:beforelabel>

                    <xen:popup title="{xen:phrase controls}" ctrlClass="toolsCtrl">
                        <xen:link href="{xen:adminlink 'teamspeak/users/edit', $teamspeakUser}">Edit Identities</xen:link>
                        <xen:link class="OverlayTrigger" href="{xen:adminlink 'teamspeak/users/delete', $teamspeakUser}">Delete Identities</xen:link>
                    </xen:popup>
                </xen:listitem>
            </xen:foreach>
        </ol>
       
        <p class="sectionFooter">{xen:phrase showing_x_of_y_items, 'count={xen:count $teamspeakUsers}', 'total={xen:number $totalUsers}'}</p>

        {xen:adminpagenav $perPage, $totalUsers, $page, 'teamspeak/users'}
Total Users: {xen:helper dump, $totalUsers}
Per Page: {xen:helper dump, $perPage}
Page: {xen:helper dump, $page}
    <xen:else />
        <div class="noResults">{xen:phrase teamspeak_no_users_to_display}</div>
    </xen:if>
</xen:form>
 

Chris D

XenForo developer
Staff member
#17
All of your controller code is in the actionIndex() method.

What URL do you access the user list, on?

Does changing the pagenav code in the template to this, make any difference?

Code:
{xen:adminpagenav $perPage, $totalUsers, $page, 'teamspeak'}
 

Chris D

XenForo developer
Staff member
#19
teamspeak/ is your route prefix, users is the action.

Yet the action in your Controller is actionIndex().

I presume you can access the user list by going to:
https://site.org/admin.php?teamspeak (without /users -- or does that give you an error?)

It might be good to see what's happening in your Route prefix controller too.
 

silence

Well-known member
#20
teamspeak/ is your route prefix, users is the action.

Yet the action in your Controller is actionIndex().

I presume you can access the user list by going to:
https://site.org/admin.php?teamspeak (without /users -- or does that give you an error?)

It might be good to see what's happening in your Route prefix controller too.
No that's for the index of the admin functions. It's a mess :C
I'm using a route snippit from another addon so I can't vouch for it:
PHP:
<?php

class Teamspeak_Route_PrefixAdmin_Teamspeak implements XenForo_Route_Interface
{
    public function match($routePath, Zend_Controller_Request_Http $request, XenForo_Router $router)
    {
        $components = explode('/', $routePath);
        $subPrefix = strtolower(array_shift($components));

        $strParams = '';
        $slice = false;

        switch ($subPrefix)
        {
            case 'information':        $controllerName = '_Information';        $strParams = '';            $slice = true;    break;
            case 'users':            $controllerName = '_Users';                $strParams = 'user_id';        $slice = true;    break;
            default:                $controllerName = '_Index';
        }

        $routePathAction = ($slice ? implode('/', array_slice($components, 0, 2)) : $routePath);

        $action = $router->resolveActionWithStringParam($routePathAction, $request, $strParams);
        return $router->getRouteMatch('Teamspeak_ControllerAdmin' . $controllerName, $action, 'teamspeak', $routePath);
    }

    public function buildLink($originalPrefix, $outputPrefix, $action, $extension, $data, array &$extraParams)
    {
        $components = explode('/', $action);
        $subPrefix = strtolower(array_shift($components));

        $strParams = '';
        $title = '';
        $slice = false;

        switch ($subPrefix)
        {
            case 'information':        $strParams = '';            $slice = true;    break;
            case 'users':            $strParams = 'user_id';        $slice = true;    break;
        }

        if ($slice)
        {
            $outputPrefix .= '/'.$subPrefix;
            $action = implode('/', $components);
        }

        $action = XenForo_Link::getPageNumberAsAction($action, $extraParams);
        return XenForo_Link::buildBasicLinkWithStringParam($outputPrefix, $action, $extension, $data, $strParams);
    }
}
Basically each major part of the admin control panel for my addon is split into a separate class.