Filtering Users in the Admin backend - FIXED IN V3.3

Post Reply
RWAP
Site Admin
Posts: 750
Joined: Fri Jan 08, 2010 2:23 am
Location: Stoke-on-Trent
Contact:

Filtering Users in the Admin backend - FIXED IN V3.3

Post by RWAP » Wed Oct 17, 2012 2:22 pm

When applying filters to the user management list (in the admin backend), the code loses pageination and other details.

The problem is in class\Action\Admin\User.php

Find:

Code: Select all

    public function filter()
    {
        $par = $this->context->parameters;
        $keyword = (isset($par['keyword']) ? $par['keyword'] : '');

        $data['keyword'] = $keyword;

        //Pagination
        $maxListed  = 20; //max listed items on the page
        $page       = ( intval($par['page']) ? intval($par['page']) : 1 ); //by default page=1
        $bottomCut  = ($page-1) * $maxListed;
        $totalPages = intval(ceil( count($users) / $maxListed ));
        if($users){
            $users     = array_slice($users, $bottomCut, $maxListed);
        }
        $data['page']       = $page;
        $data['totalPages'] = $totalPages;
        $data['extraParameters'] = ""; //usefull in search (example: "keyword=asd&country=AG"). Here it's not needed.

        $data['users'] = User::getFilteredListFromDB($this->db,$par['keyword'],$par['filter']);
        $data['currentFilter'] = (isset($par['filter'])? $par['filter']:'');
        $data['filters'] = User::getFiltersNames();

        $countries = Country::getListFromDB($this->db, 'where active=1 order by name');
        $data['exportUrl'] = $this->context->relativePath.'admin/user/filter?v=CSV';
        $data['countries'] = $countries;
        $data['totalUsers'] = count($data['users']);
        $data['template']  = "userList.php";
        $this->context->addData($data);
    }
Change this to:

Code: Select all

    public function filter()
    {
        $par = $this->context->parameters;
        $keyword = (isset($par['keyword']) ? $par['keyword'] : '');

        $data['keyword'] = $keyword;

        $users = User::getFilteredListFromDB($this->db,$par['keyword'],$par['filter']);
        $bannedEmails = BannedEmail::getListFromDB($this->db);
        foreach($users as $k=>$v){
            $user = User::getInstanceFromDB($this->db, $v['id']);
            $v['offers'] = $user->getOffersStatsFromDB($this->db);
            $v['emailBanned'] = in_array($v['email'],$bannedEmails);
            $users[$k]=$v;
        }

        //Pagination
        $maxListed  = 20; //max listed items on the page
        $page       = ( intval($par['page']) ? intval($par['page']) : 1 ); //by default page=1
        $bottomCut  = ($page-1) * $maxListed;
        $totalPages = intval(ceil( count($users) / $maxListed ));
        $data['totalUsers'] = count($users);
        if($users){
            $users     = array_slice($users, $bottomCut, $maxListed);
        }
        $data['page']       = $page;
        $data['totalPages'] = $totalPages;
        $data['extraParameters'] = ""; //usefull in search (example: "keyword=asd&country=AG"). Here it's not needed.
        $data['users']=$users;

        $data['currentFilter'] = (isset($par['filter'])? $par['filter']:'');
        $data['filters'] = User::getFiltersNames();

        $countries = Country::getListFromDB($this->db, 'where active=1 order by name');
        $data['exportUrl'] = $this->context->relativePath.'admin/user/filter?v=CSV';
        $data['countries'] = $countries;
        $data['template']  = "userList.php";
        $this->context->addData($data);
    }


Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest