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

Admin Pages

Discussion in 'XenForo Development Discussions' started by silence, Jul 30, 2013.

  1. silence

    silence Well-Known Member

    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>
     
  2. Chris D

    Chris D XenForo Developer Staff Member

    It's more likely going to be that you're not passing the, $perPage, $totalUsers, or $page parameters to the template.
     
  3. silence

    silence Well-Known Member

    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.
     
  4. Chris D

    Chris D XenForo Developer Staff Member

    I'd need to see the rest of your code to work out the issue.
     
  5. silence

    silence Well-Known Member

    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);
        }
     
  6. silence

    silence Well-Known Member

    Do you need anymore info, fine sir?
     
  7. Chris D

    Chris D XenForo Developer Staff Member

    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...
     
  8. silence

    silence Well-Known Member

    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
            '
    );
        }
     
  9. Marcus

    Marcus Well-Known Member

    For debugging try ZEND_DEBUG::dump($variable); in the code.

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

    silence Well-Known Member

    int(0) which I'm guessing is bad?
     
    Marcus likes this.
  11. Chris D

    Chris D XenForo Developer Staff Member

    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?
     
    Marcus likes this.
  12. silence

    silence Well-Known Member

    Total Users: int(25) Per Page: int(10) Page: int(0)
     
  13. Chris D

    Chris D XenForo Developer Staff Member

    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.
     
  14. silence

    silence Well-Known Member

    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
     
  15. Chris D

    Chris D XenForo Developer Staff Member

    I know. That's currently still unexplained.

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

    silence Well-Known Member

    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>
     
  17. Chris D

    Chris D XenForo Developer Staff Member

    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'}
     
  18. silence

    silence Well-Known Member

  19. Chris D

    Chris D XenForo Developer Staff Member

    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.
     
  20. silence

    silence Well-Known Member

    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($routePathZend_Controller_Request_Http $requestXenForo_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($components02)) : $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.
     

Share This Page