Functions in addon config

Posts from previous Beta sessions

Functions in addon config

Postby boyo » Wed Oct 24, 2007 1:28 am

I currently use
Code: Select all
$installer->add_config("'1305','guild_protected_group','0','function{getProtectedGroup','smf_menu_guild'");

in my installer, I would like to rewrite the function getProtectedGroup to just getGroup("guild_protected_group").
I changed the installer to
Code: Select all
$installer->add_config("'1305','guild_protected_group','0','function{getProtectedGroup("guild_protected_group")','smf_menu_guild'");

I tried to get it to work and got this error
Code: Select all
Fatal error: Call to undefined function getProtectedGroup("guild_protected_group")() in C:\wamp\www\roster20\lib\config.lib.php on line 390


I can see what is happening, but was wondering if there was already a way to do this..
boyo
Roster AddOn Dev
Roster AddOn Dev
 
Posts: 103
Joined: Wed Jan 24, 2007 7:37 am

Functions in addon config

Postby zanix » Wed Oct 24, 2007 7:07 am

The config api uses that full name as the function call and doesn't account for parameters

As a work around, you could make a new function that passes what you need to this one
Code: Select all
function{getGuildProtectedGroup


Looking at the code, a called function already accepts an argument when its a data field
Code: Select all
$input_field = $input_type[1]($values);

$values contains all the db data
Code: Select all
['id'] = $row['id'];
['name'] = $row['config_name'];
['config_type'] = $row['config_type'];
['value'] = $row['config_value'];
['form_type'] = $row['form_type'];


When it's a menu item, or page item, it doesn't accept any parameters

To be continued after I play with the code some more...
Read the Forum Rules, the WiKi, and Search before posting!
WoWRoster v2.1 - SigGen v0.3.3.523 - WoWRosterDF
User avatar
zanix
Admin
Admin
WoWRoster.net Dev Team
WoWRoster.net Dev Team
UA/UU Developer
UA/UU Developer
 
Posts: 5546
Joined: Mon Jul 03, 2006 8:29 am
Location: Idaho Falls, Idaho
Realm: Doomhammer (PvE) - US

Functions in addon config

Postby boyo » Thu Oct 25, 2007 5:21 pm

Ah, that should actually work out perfectly for what i'm trying to do.
All I really need it to do is pull out all of the groups and return the dropdown for them.

Right now I have two functions that are identical except for 3 lines,
Code: Select all
$return = '<select name="config_guild_protected_group">';
if ($addon['config']['guild_protected_group'] == 0){
if ($row['ID_GROUP'] == $addon['config']['guild_protected_group']){

What I should be able to do is change everywhere that says guild_protected_group to use what is in $values['name'].
And I can always do additional testing inside the function if need be.

I will test this and see what it does.

Edit: Played with this for a few mins, and I had to change the function to getGroups($values) and I could then access $values['name'].
Last edited by boyo on Thu Oct 25, 2007 5:37 pm, edited 2 times in total.
boyo
Roster AddOn Dev
Roster AddOn Dev
 
Posts: 103
Joined: Wed Jan 24, 2007 7:37 am

Re: Functions in addon config

Postby boyo » Thu Oct 25, 2007 5:46 pm

And here is the function, it works beautifully..
The important part of it, is the function getGroups($values){
After that you can access the $values array like normal.

Function:
Code: Select all
function getGroups($values){
    global 
$roster;
    global 
$addon;
    if (!
$addon['config']['forum_prefix'] || $addon['config']['forum_prefix'] == ''){
        
$return 'Set forum_prefix.';
    }else{
        
$configName $values['name'];
        
$query "SELECT * FROM `{$addon['config']['forum_prefix']}membergroups` WHERE `minPosts` = '-1'";
        
$result $roster->db->query $query );

        
$return '<select name="config_' $configName '">';
        if (
$addon['config'][$configName] == 0){
            
$return .= '<option value="0" selected="selected">-[ Disabled ]-</option>';
        }else{
            
$return .= '<option value="0">Disabled</option>';
        }

        while (
$row $roster->db->fetch $result ) ){
            if (
$row['ID_GROUP'] == $addon['config'][$configName]){
                
$return .= '<option value="'$row['ID_GROUP'] .'" selected="selected">-[ '$row['groupName'] .' ]-</option>';
            }else{
                
$return .= '<option value="'$row['ID_GROUP'] .'">'$row['groupName'] .'</option>';
            }
        }
        
$return .= '</select>';
    }
    return 
$return;


$values:
Code: Select all
Array
(
    [id] => 1306
    [name] => guild_protected_group
    [config_type] => smf_menu_guild
    [value] => 1
    [form_type] => function{getGroups
    [description] => Protected group
    [tooltip] => Members of this group will not have their account suspended or any of their settings changed.<br />To use, create a group in SMF that you wish to use, and set permissions accordingly.<br />Then select the appropriate group here.<br /><br /><span style="color:#FFFFFF;font-size:10px;">db name: <span style="color:#0099FF;">guild_protected_group</span></span>
)
boyo
Roster AddOn Dev
Roster AddOn Dev
 
Posts: 103
Joined: Wed Jan 24, 2007 7:37 am

Functions in addon config

Postby PleegWat » Thu Oct 25, 2007 9:44 pm

You can use $values['value'] instead of $addon['config'][$configName]. That makes it clearer you're referring to the value of the option you're drawing the control for.
I <3 /bin/bash
User avatar
PleegWat
WoWRoster.net Dev Team
WoWRoster.net Dev Team
 
Posts: 1636
Joined: Tue Jul 04, 2006 1:43 pm

Functions in addon config

Postby zanix » Fri Oct 26, 2007 12:29 am

Nice
Read the Forum Rules, the WiKi, and Search before posting!
WoWRoster v2.1 - SigGen v0.3.3.523 - WoWRosterDF
User avatar
zanix
Admin
Admin
WoWRoster.net Dev Team
WoWRoster.net Dev Team
UA/UU Developer
UA/UU Developer
 
Posts: 5546
Joined: Mon Jul 03, 2006 8:29 am
Location: Idaho Falls, Idaho
Realm: Doomhammer (PvE) - US

Re: Functions in addon config

Postby boyo » Fri Oct 26, 2007 2:13 pm

PleegWat wrote:You can use $values['value'] instead of $addon['config'][$configName]. That makes it clearer you're referring to the value of the option you're drawing the control for.


To be honest, I hadn't looked that deep into it, but will definitely take the suggestion.
boyo
Roster AddOn Dev
Roster AddOn Dev
 
Posts: 103
Joined: Wed Jan 24, 2007 7:37 am


Return to Archived

Who is online

Users browsing this forum: No registered users and 1 guest

cron