Extend XenForo_ControllerAdmin_UserGroupPromotion

Slind

Active member
hey,

I'm trying to extend the XenForo_ControllerAdmin_UserGroupPromotion class to add a variable to my MyAddon_user_criteria template which gets included into the user_group_promotion_edit template but it doesn't get executed. (Using load_class_controller)

What is the issue here?

PHP:
<?php
class MyAddon_ControllerAdmin_UserGroupPromotion extends XFCP_MyAddon_ControllerAdmin_UserGroupPromotion
{
    public function actionIndex()
    {
        $db = new Zend_Db_Adapter_Pdo_Mysql(array(
            'host'     => 'localhost',
            'port'     => '8889',
            'username' => 'root',
            'password' => 'root',
            'dbname'   => 'test'
        ));

        $sql = 'SELECT `group` FROM `table`';

        $result = $db->fetchCol($sql);

        $viewParams = array(
            'MyAddon_groups' => serialize($result)
        );

        return $this->responseView('MyAddon_ControllerAdmin_UserGroupPromotion', 'MyAddon_user_criteria', $viewParams);
    }

}
PHP:
<?php

class MyAddon_Listener_Controller
{
    public static function extendController($class, array &$extend)
    {
        if ($class == 'XenForo_ControllerAdmin_UserGroupPromotion')
        {
            $extend[] = 'MyAddon_ControllerAdmin_UserGroupPromotion';
        }
    }
}
 
You should use Zend_Db::factory(), not directly access an adapter.

Did you register the listener properly?

Why serialise it? Unless you're actually using a view here.
 
Did you register the listener properly?

R1fa91G.png

Why serialise it? Unless you're actually using a view here.
As I currently print out the variable to see if it works.
 
Right, use Zend_Db::factory(). Use Zend_Debug::dump() to dump the value of $db and $result
 
Right, use Zend_Db::factory(). Use Zend_Debug::dump() to dump the value of $db and $result
Okay, got this error with the debug (but the output looks fine):
Code:
array(2) {
  [0] => string(5) "value1"
  [1] => string(5) "value2"
}
An exception occurred: Argument 1 passed to XenForo_Controller::__construct() must be an instance of Zend_Controller_Request_Http, instance of XenForo_ViewRenderer_HtmlAdmin given, called in /Applications/MAMP/htdocs/forum/library/XenForo/ViewRenderer/Abstract.php on line 215 and defined in /Applications/MAMP/htdocs/forum/library/XenForo/Controller.php on line 81
 
Why don't you just use the user_criteria code event, and then use template modifications to add the data.

You can then extend the method (or use the template_create listener), to add the template param (although be sure to add it to the return value of the parent method, and return the return value of the parent method).

Liam
 
That only appears when you're dumping something or did it already appear before?
No but I no longer get the error if I use
PHP:
return $this->responseView('XenForo_ViewAdmin_UserGroupPromotion_Edit', 'MyAddon_user_criteria', $viewParams);
but this overrides the $viewParams which xenforo sets. Not exactly sure what to do here.

Why don't you just use the user_criteria code event, and then use template modifications to add the data.

You can then extend the method (or use the template_create listener), to add the template param (although be sure to add it to the return value of the parent method, and return the return value of the parent method).

Liam
I did use template_create before but it seems to run my code then multiple times and not only once. And I want to list groups for selection like xenforo does for the xenforo groups. So criteria_user event comes later when I got the groups in the user group promotion edit
 
Last edited:
Top Bottom