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

Extending extended class?

MattW

Well-known member
#1
So, I'm trying to get 2 of my addons to work with XenPorta. I've asked in the addon thread, but not had a response from the developer, so I'm asking in here hoping someone else might be able to help?

My addons both extend XenForo_ControllerPublic_Forum and allow the data to be added to the forum_stats block.

XenPorta seems to also extend XenForo_ControllerPublic_Forum

PHP:
case 'XenForo_ControllerPublic_Forum':
                $extend[] = 'EWRporta_ControllerPublic_Forum';
                break;
PHP:
class EWRporta_ControllerPublic_Forum extends XFCP_EWRporta_ControllerPublic_Forum
{
    public $perms;

    public function actionIndex()
    {
        $response = parent::actionIndex();
        $options = XenForo_Application::get('options');

        if ($response instanceof XenForo_ControllerResponse_View && $options->EWRporta_globalize['index'])
        {
            $response->params['layout1'] = 'index';
            $response->params['layout2'] = 'portal';
        }

        return $response;
    }
I'm stuck now how I get my data into that class EWRporta_ControllerPublic_Forum? I've tried to extend EWRporta_ControllerPublic_Forum but that doesn't work.

Thanks in advance.
 

Marcus

Well-known member
#2
Maybe you can set the listener priority to a higher value than the value from EWRporta. The regular priority value is 10. I think the higher value executes later, and you want the EWRporta addon to be executed before your addon. This is just a hint what could be improved.

But I do not know if you can extend an addon.
 

Chris D

XenForo developer
Staff member
#3
It should just be a case of extending the default controller but you may need to change the execution order as Marcus suggests.
 

MattW

Well-known member
#4
My add-on is set to just extend the default controller, but changing the priority doesn't change anything when the portal is enabled.

PHP:
<?php

class AttachStats_Listener
{
    public static function extendControllers($class, &$extend)
    {
        switch ($class)
        {
            case 'XenForo_ControllerAdmin_Home':
            $extend[] = 'AttachStats_ControllerAdmin_AttachStats';
            break;

            case 'XenForo_ControllerPublic_Forum':
            $extend[] = 'AttachStats_ControllerPublic_AttachStats';
            break;
        }
    }
}
If I echo out the variable in the template, it's just returning null

stats.PNG
 

MattW

Well-known member
#5
I can also see my results being fetched from the data_registry when the index page runs. I've no idea what these blocks are doing that is different from the default XF ones.

sql.PNG
 

Mike

XenForo developer
Staff member
#6
If your data is being retrieved, that means that your code is running. What is your controller code?
 

MattW

Well-known member
#7
If your data is being retrieved, that means that your code is running. What is your controller code?
PHP:
<?php

class AttachStats_ControllerPublic_AttachStats extends XFCP_AttachStats_ControllerPublic_AttachStats
{
    public function actionIndex()
    {
        $parent = parent::actionIndex();
       
        $options = XenForo_Application::get('options');
        $stats_format = $options->statsformat;
        $AttachStatsModel = $this->_getAttachStatsModel();
       
        switch ($stats_format)
        {
            case 'mb':
            $sizeAttachments = XenForo_Model::create('XenForo_Model_DataRegistry')->get('sizeAttachments');
            $parent->params['sizeAttachments'] = ($sizeAttachments * .0009765625) * .0009765625; // size in MB
            break;
           
            case 'gb':
            $sizeAttachments = XenForo_Model::create('XenForo_Model_DataRegistry')->get('sizeAttachments');
            $parent->params['sizeAttachments'] = (($sizeAttachments * .0009765625) * .0009765625) *.0009765625; // size in GB
            break; 
        }

        $parent->params['stats_format'] = $stats_format;

        $totalAttachments = XenForo_Model::create('XenForo_Model_DataRegistry')->get('totalAttachments');
        $parent->params['totalAttachments'] = $totalAttachments;
   
        return $parent;
    }

    protected function _getAttachStatsModel()
    {
        return $this->getModelFromCache('AttachStats_Model_AttachStats');
    }   
}
and I call the model via the cron

PHP:
<?php

class AttachStats_CronEntry_AttachStats
{
    public static function getTotalAttachments()
    {
        $attachCountModel = XenForo_Model::create('AttachStats_Model_AttachStats');
       
        $totalAttachments = $attachCountModel->getNumRecords();
        XenForo_Model::create('XenForo_Model_DataRegistry')->set('totalAttachments', $totalAttachments);
       
        $sizeAttachments = $attachCountModel->getTotalUsage();
        XenForo_Model::create('XenForo_Model_DataRegistry')->set('sizeAttachments', $sizeAttachments);
   
    $usageAttachments = $attachCountModel->getContentType();
    XenForo_Model::create('XenForo_Model_DataRegistry')->set('usageAttachments', $usageAttachments);

    $typeAttachments = $attachCountModel->getAttachmentType();
    XenForo_Model::create('XenForo_Model_DataRegistry')->set('typeAttachments', $typeAttachments);

    }
}
It only doesn't work when XenPorta is enabled, and no matter where I put the code in the template, it's not putting my data into the templates.