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

Use style by gender or usergroup

Discussion in 'XenForo Development Discussions' started by PoLiZe, Jan 11, 2011.

  1. PoLiZe

    PoLiZe Well-Known Member

    Hi people of xf, i'm needing that..


    I need a script for AutoChoose the style per gender or usergroup..

    so, if the gender are male, styleid = 1 and female = 2

    How i can make that and where?
     
  2. PoLiZe

    PoLiZe Well-Known Member

    Now i have that:

    PHP:
    $visitor XenForo_Visitor::getInstance();
            if (
    $visitor['gender'] == "male")
                {
                    
    $dw XenForo_DataWriter::create('XenForo_DataWriter_User');
                    
    $dw->setExistingData($visitor['user_id']);
                    
    $dw->set('style_id''3');
                    
    $dw->save();
                }
            if (
    $visitor['gender'] == "female")
                {
                    
    $dw XenForo_DataWriter::create('XenForo_DataWriter_User');
                    
    $dw->setExistingData($visitor['user_id']);
                    
    $dw->set('style_id''1');
                    
    $dw->save();
                }
    but dont work, i have that in controllerpublic index.

    and i put on misc and too, dont work!.
     
  3. PoLiZe

    PoLiZe Well-Known Member

    Any reply?
     
  4. Shadab

    Shadab Well-Known Member

    You could create a new event listener, attached to the "front_controller_pre_view" event;
    and change the selected style Id dynamically:

    (Untested)
    PHP:
    if (!is_subclass_of($controllerResponse->controllerName'XenForo_ControllerPublic_Abstract'))
    {
        return;
    }

    $visitor XenForo_Visitor::getInstance();

    switch (
    $visitor['gender'])
    {
        case 
    'male':
            
    $styleId 1;
            break;

        case 
    'female':
            
    $styleId 2;
            break;

        default:
            
    $styleId 3;
            break;
    }

    $fc->getDependencies()->mergeViewStateChanges(array('styleId' => $styleId));
     
  5. PoLiZe

    PoLiZe Well-Known Member

    I need put that on frontcontroller? Where? I need create a new public function?
     
  6. Shadab

    Shadab Well-Known Member

    Nah. You don't need to edit any core php files.

    Create a static method in your own class, for example, in /library/Polize/Addon.php with the code given in post #4. Then add a new event listener via Admin Panel for the "front_controller_pre_view" event and set its callback to the static method you created.

     

Share This Page