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

Extending 3rd Party Mod

Discussion in 'XenForo Development Discussions' started by Mythotical, Mar 23, 2013.

  1. Mythotical

    Mythotical Well-Known Member

    I'm trying to extend 3rd party mods so that my xfPoints mod can tie into them. The problem I'm having is extending to the point that my variables are accessible within the templates.

    Take for instance a Ice Shop, trying to tie into the public view where I can give a total of points accumulated before they purchase items. Once they purchase an item the points are deducted instead of using real currency. Don't know how Ice Shop works but using it as an example.

    I have this so far:
    Code:
    class xfPoints_ControllerPublic_Shop extends XFCP_xfPoints_ControllerPublic_Shop
    {
        public function actionIndex()
        {
        	$response = parent::actionIndex();
    
    	    	$user_id = XenForo_Visitor::getUserId();
    
    	    	$pointsModel = $this->getModelFromCache('xfPoints_Model_Currency');
    	    	$totalPoints = $pointsModel->getUserPointsId($user_id);
    	    	$totalPoints = $totalPoints['xfpoints_currency'];
    
    	    	$response = array(
    	    		'totalPoints' => $totalPoints,
    	    		);
    
    	    return $response;
        }
    }
    So if anyone can give me some guidance here it would be much appreciated.
     
  2. Chris D

    Chris D XenForo Developer Staff Member

    I can see what you're trying to achieve... but unfortunately you're not executing it properly.

    You're starting right...

    PHP:
    $response parent::actionIndex();
    That's correct. You're calling the parent function and storing it in a variable.

    Then you're getting your data.

    Where it's going wrong is where you're overwriting your parent variable with an array.

    PHP:
    $response = array('totalPoints' => $totalPoints);
    So now you've done that, when you do:

    PHP:
    return $response;
    You're not returning the parent.

    What you need to do is add your array of data into the existing parent function. Not overwrite the parent function with your data.
     
  3. Kim

    Kim Well-Known Member

    Basically you will need to do something like this. Instead of:
    PHP:
    $response = array('whatever');
    It needs to be:
    PHP:
    $response->params['totalPoints'] = $totalPoints;



    But of course I am not a coder, so it might not be :)
     
    Jeremy, SneakyDave, Shelley and 3 others like this.
  4. Mythotical

    Mythotical Well-Known Member

    LOL was beat to the reply.

    Thanks Chris again, and Kim.
     
  5. Shelley

    Shelley Well-Known Member

    :confused::ROFLMAO:
     
    tenants, Onimua, Bob and 2 others like this.
  6. Mythotical

    Mythotical Well-Known Member

    LOL Thanks for trying Kim, I'm sure it is the right idea but my variable still doesn't work so I'm assuming your method was off in some area or something. I have no idea.
     
  7. Chris D

    Chris D XenForo Developer Staff Member

    Kim's reply is spot on.

    What does your code event listener look like?
     
  8. Mythotical

    Mythotical Well-Known Member

    LoadControllerPublic.php
    Code:
    class xfPoints_Listener_LoadControllerPublic
    {
    
        public static function loadControllerPublic($class, &$extend)
        {
            if ($class == 'XenForo_ControllerPublic_Register') {
                $extend[] = 'xfPoints_ControllerPublic_Register';
            }
            if ($class == 'XenForo_ControllerPublic_Member') {
                $extend[] = 'xfPoints_ControllerPublic_Member';
            }
            if ($class == 'XenForo_ControllerPublic_Account') {
            	$extend[] = 'xfPoints_ControllerPublic_Account';
            }
            if ($class == 'IceShop_ControllerPublic_Index') {
    	        $extend[] = 'xfPoints_ControllerPublic_Shop';
            }
        }
    }
     
  9. Chris D

    Chris D XenForo Developer Staff Member

    OK...

    And what does the xfPoints_ControllerPublic_Shop class look like now you made the previous change?
     
  10. Mythotical

    Mythotical Well-Known Member

    Code:
    class xfPoints_ControllerPublic_Shop extends XFCP_xfPoints_ControllerPublic_Shop
    {
        public function actionIndex()
        {
        	$response = parent::actionIndex();
    
    	    	$user_id = XenForo_Visitor::getUserId();
    
    	    	$pointsModel = $this->getModelFromCache('xfPoints_Model_Currency');
    	    	$totalPoints = $pointsModel->getUserPointsId($user_id);
    	    	$totalPoints = $totalPoints['xfpoints_currency'];
    
    	    	$response->params['totalPoints'] = $totalPoints;
    
    	    return $response;
        }
    }
     
  11. Chris D

    Chris D XenForo Developer Staff Member

    I can't see anything obviously wrong.

    Try this just before the return line:

    PHP:
    Zend_Debug::dump($totalPoints);
     
  12. Mythotical

    Mythotical Well-Known Member

    That is interesting, no dump at all.
     
  13. Chris D

    Chris D XenForo Developer Staff Member

    Nothing at all?

    Not even a blank string?

    What if you just type something that would cause a deliberate exception or make a deliberate typo. Does it cause a error to be displayed?
     
  14. Mythotical

    Mythotical Well-Known Member

    Nothing at all, no blank string, and deliberate typo doesn't do anything.
     
  15. Mythotical

    Mythotical Well-Known Member

    If it helps I had the same issue trying to tie into XFArcade

    Code:
    class xfPoints_ControllerPublic_Arcade extends XFCP_xfPoints_ControllerPublic_Arcade
    {
        public function actionPlay()
        {
        	$response = parent::actionPlay();
    
    	    	$user_id = XenForo_Visitor::getUserId();
    
    	    	$pointsModel = $this->getModelFromCache('xfPoints_Model_Currency');
    	    	$totalPoints = $pointsModel->getUserPointsId($user_id);
    	    	$totalPoints = $totalPoints['xfpoints_currency'];
    	    	//echo $totalPoints;
    
    	    	 $response->params['totalPoints'] = $totalPoints['xfpoints_currency'];
    
    	    return $response;
        }
    }
    Code:
    class xfPoints_Listener_LoadControllerPublic
    {
    
        public static function loadControllerPublic($class, &$extend)
        {
            if ($class == 'XenForo_ControllerPublic_Register') {
                $extend[] = 'xfPoints_ControllerPublic_Register';
            }
            if ($class == 'XenForo_ControllerPublic_Member') {
                $extend[] = 'xfPoints_ControllerPublic_Member';
            }
            if ($class == 'XenForo_ControllerPublic_Account') {
            	$extend[] = 'xfPoints_ControllerPublic_Account';
            }
            if ($class == 'Arcade_ControllerPublic_Arcade') {
    	        $extend[] = 'xfPoints_ControllerPublic_Arcade';
            }
        }
    }
    I added edits from above and added to the Arcade with same results.
     
  16. Chris D

    Chris D XenForo Developer Staff Member

    Yeah so your extended code isn't firing at all.

    Double/triple check you're extending the right Ice Shop class and then accessing it correctly.
     
  17. Mythotical

    Mythotical Well-Known Member

    EDIT: display errors is on so at this point I'm stumped.
     
  18. Chris D

    Chris D XenForo Developer Staff Member

    The other classes you're loading. If you make changes to them, do they work?
     
  19. Mythotical

    Mythotical Well-Known Member

    Yep, they are doing just fine.
     
  20. Chris D

    Chris D XenForo Developer Staff Member

    I think the class name of IceShop is wrong so fix that first.

    Not sure why the arcade one isn't working though.
     

Share This Page