Lack of interest Number of user states is hard coded, making it difficult to extend

This suggestion has been closed automatically because it did not receive enough votes over an extended period of time. If you wish to see this, please search for an open suggestion and, if you don't find any, post a new one.

Jon W

Well-known member
In XenForo_ControllerHelper_UserCriteria, there is a filter that checks whether all user states are ticked and, if so, unsets the criteria. This is done by checking whether there are EXACTLY 4 that are ticked, as follows:
PHP:
        if (isset($criteria['user_state']) && is_array($criteria['user_state']) && count($criteria['user_state']) == 4)
        {
            // all types selected, no filtering
            unset($criteria['user_state']);
        }

This makes it difficult for a developer to add new user criteria, because it means that we have to add some sort of hack to any controller that calls that helper and add back the criteria (or something similar).

It would be much nicer if that number 4 was calculated by counting a static array of all the user states inside that helper (or something similar).

In other words, you would change to:
PHP:
        if (isset($criteria['user_state']) && is_array($criteria['user_state']) && count($criteria['user_state']) == count(self::$userStates))
        {
            // all types selected, no filtering
            unset($criteria['user_state']);
        }
and then add:
PHP:
public static $userStates = array('email_confirm','email_confirm_edit','moderated','valid');
to the top of the class.

The array of $userStates could then be easily added to by any add-on to get a correct count.
 
Last edited:
Upvote 1
This suggestion has been closed. Votes are no longer accepted.
Top Bottom