JAccess::getUsersByGroup, How to check is user act

2019-08-31 02:46发布

I have a problem which I can't solve. What I need is list all activated Joomla users. I found and modifed this code:

    jimport( 'joomla.access.access' );
    $coaches = JAccess::getUsersByGroup(2);
    jimport( 'joomla.user.user' );
    foreach($coaches as $coaches){
        $coach[$coaches] =& JFactory::getUser($coaches);
    }
    asort($coach);

But this solution has two bugs which I can't fix: - first: this showing unactive (not activated) users too, - secound: asort() don't sort users by name (probably it's sort users by login?).

with kind regards W.

标签: php joomla
1条回答
聊天终结者
2楼-- · 2019-08-31 03:13

Here you go, check comments to understand:

    jimport( 'joomla.access.access' );
    $coaches = JAccess::getUsersByGroup(2);
    jimport( 'joomla.user.user' );

    foreach($coaches as $coaches){

        $users =& JFactory::getUser($coaches);

        //check if user is NOT blocked or NOT activated yet
        if($users->block == '0' && empty($users->activation)){

        //create array not object for better sorting possibilities
        $coach[$coaches] = (array) $users;

       }

    }

    array_multisort($coach, SORT_ASC);
    var_dump($coach);
查看更多
登录 后发表回答