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

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

Discussion in 'Closed Suggestions' started by Jon W, Jul 15, 2013.

  1. Jon W

    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: Jul 15, 2013
    xf_phantom likes this.
  2. xf_phantom

    xf_phantom Well-Known Member

    The same problem exists with the genders:( ( http://xenforo.com/community/threads/user-age-gender-permissions.11363/ )

    PHP:
    if (count($criteria['gender']) == 3)
                {
                    unset(
    $criteria['gender']);
                }
    We've changed it by replacing the whole criteria class (and dozen other classes had to be changed too: / )


    And may i ask how you changed the states?( http://xenforo.com/community/threads/alternative-to-enum-db-fields.50736/#post-545338 )
     
  3. Jon W

    Jon W Well-Known Member

    xf_phantom likes this.

Share This Page