vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3.7 Add-ons (https://vborg.vbsupport.ru/forumdisplay.php?f=228)
-   -   Miscellaneous Hacks - Yet Another Awards System (https://vborg.vbsupport.ru/showthread.php?t=187600)

RedSpiral 04-16-2009 04:47 PM

Thanks!

This is exactly what I needed for my forum!

jcline 04-21-2009 04:42 PM

bug with the drop down in the settings... Sorting: Awards Listings always reverts to "Issue Time-Newest First" so if you don't notice, and change a different setting, it changes your sort order back to newest first.

titodj 06-25-2009 02:33 AM

Quote:

Originally Posted by Gandalf-LoJ (Post 1749688)


On another note, I've also got the award system plugged into the permissions now and when an award is given to a user a scheduled task runs and checks for new awards and assigns them to a usergroup based on the award. There is also a script that checks for removed awards and will remove the relevant usergroup too.

Can you let us know how to do it?
Im trying to have a way for the mods to change a user from groups based on one award.

Gandalf-LoJ 06-25-2009 06:14 AM

Quote:

Originally Posted by titodj (Post 1836839)
Can you let us know how to do it?
Im trying to have a way for the mods to change a user from groups based on one award.

Sure. A few things to note. Firstly, this assumes you have a reasonable knowledge of php as they are manual files. Secondly, you need to work out what awards (specifically their ID's) need to belong to what group (again you need to know the ID's)

All the groups are set in the arrays at the top. The first column (value) in the array is the award ID. The second column (value) is the usergroup that you want to assign this award to.

The reason there are two arrays is because we have one particular award that we want to assign to two separate usergroups. This may not apply to you, if it doesn't then you can remove $arr2 and comment out the while loop.

Here is the code. I called it award2group.php and placed it in the modules folder of the forum.

PHP Code:

<?php

// ######################## SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);
if (!
is_object($vbulletin->db))
{
    exit;
}

// ########################### SET VARIABLES ##############################

$arr1 = array(    
                
=> 50,
                
=> 38,
                
=> 50,
                
=> 53,
                
12 => 23,
                
13 => 43,
                
14 => 43,
                
17 => 51,
                
18 => 37,
                
20 => 53,
                
21 => 53,
                
24 => 53,
                
25 => 53,
                
29 => 48,
                
31 => 40,
                
32 => 39,
                
38 => 46,
                
39 => 52    
            
);
            
$arr2 = array(    
                
=> 7    
            
);

// ########################################################################
// ######################### USERGROUP UPDATES ############################
// #########################    GIVE ACCESS    ############################
// ########################################################################

$i 1;
while (
$i <= 2)
{
    if (
$i == 1)
    {
        
$arr $arr1;
    }
    else
    {
        
$arr $arr2;
    }
    foreach (
$arr as $awardval => $aw2gr)
    {
        
// check for award and update secondary usergroup if required
        
$giveawards $vbulletin->db->query_read("
            SELECT aw.award_id, us.userid, us.membergroupids 
            FROM " 
TABLE_PREFIX "award_user as aw
            LEFT OUTER JOIN " 
TABLE_PREFIX "user AS us ON us.userid = aw.userid AND (aw.award_id = $awardval)
            WHERE FIND_IN_SET(
$aw2gr, us.membergroupids) = 0
        "
);
        
        if (
$vbulletin->db->num_rows($giveawards) > 0)
        {
            while (
$giveawardsrow $vbulletin->db->fetch_array($giveawards))
            { 
// for each award, check to see if they are a member of the relevant group and update accordingly
                
$userdm =& datamanager_init('User'$vbulletinERRTYPE_ARRAY); 
                
$userinfo fetch_userinfo($giveawardsrow['userid']);
                
$userdm->set_existing($userinfo); 
                
$membergroupids $userdm->fetch_field('membergroupids');
                if (
$membergroupids != "")
                {
                    
// Explode to an array
                    
$mbrgrp_array explode(","$membergroupids);
                    
// Add remove/add group to array
                    
$mbrgrp_array[] = $aw2gr;
                    
// Make it a comma seperated string again
                    
$membergroupids implode(","$mbrgrp_array);  
                }
                else
                {
                    
$membergroupids $aw2gr;
                }
                
$userdm->set('membergroupids'$membergroupids);
                
$userdm->pre_save();
                if (
count($userdm->errors))
                {
                    for (
$i 0$i count($userdm->errors); $i++)
                    {
                        echo 
"ERROR{$i}:{$userdm->errors[$i]}\n";
                    }
                }
                else
                {
                    
// If everything is OK
                    
$userdm->save();
                    unset(
$mbrgrp_array);
                }
            }
            
$vbulletin->db->free_result($giveawardsrow);
        }
    }
    
$i++;
}

// ########################################################################
// ######################### USERGROUP UPDATES ############################
// #########################    GIVE ACCESS    ############################
// ########################################################################

unset($giveawards$giveawardsrow$userdm$userinfo$membergroupids$awardval$aw2gr$mbrgrp_array$i);     

log_cron_action(''$nextitem1);
?>

That will assign anyone who has an award to the relevant usergroup. NOTE: It will assign the group as a SECONDARY group only. It will not change or replace the users primary group membership.

Now for the removing part. If a user has an award taken away, you will need a script to remove that user from the assigned usergroup. This is handled in this script which I called delaward2group.php and placed in the same folder as the above.

You may notice that the arrays at the top of each file matches. This is so it only removes groups that have been assigned by awards. The array could be put in a separate php file and included into the two scripts so you only have one list to maintain but that all depends on your coding method.

PHP Code:

<?php

// ######################## SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);
if (!
is_object($vbulletin->db))
{
    exit;
}

// ########################### SET VARIABLES ##############################

$arr1 = array(    
                
=> 50,
                
=> 38,
                
=> 50,
                
=> 53,
                
12 => 23,
                
13 => 43,
                
14 => 43,
                
17 => 51,
                
18 => 37,
                
20 => 53,
                
21 => 53,
                
24 => 53,
                
25 => 53,
                
29 => 48,
                
31 => 40,
                
32 => 39,
                
38 => 46,
                
39 => 52    
            
);
            
$arr2 = array(    
                
=> 7    
            
);

// ########################################################################
// ######################### USERGROUP UPDATES ############################
// #########################   REMOVE ACCESS   ############################
// ########################################################################

$i 1;
while (
$i <= 2)
{
    if (
$i == 1)
    {
        
$arr $arr1;
    }
    else
    {
        
$arr $arr2;
    }
    foreach (
$arr as $awardval => $aw2gr)
    {
        
// need to get the keys from the array to use as an or in the query. This will make sure that a user that has one award that belongs to a multi award group does not get removed
        
$awardkeys array_keys($arr$aw2gr);
        
$keycount count($awardkeys);
        if (
$keycount == 1)
        { 
// single key then there only needs to be one value for the query
            
$awardor $awardkeys[0];
        }
        else
        {
            for (
$ac 0$ac $keycount$ac++)
            { 
// more than one key then the query OR needs to be constructed here
                
if ($ac $keycount 1)
                {
                    
$awardor .= $awardkeys[$ac] . " OR aw.award_id = ";
                }
                else
                {
                    
$awardor .= $awardkeys[$ac];
                }
            }
        }
        unset(
$awardkeys$ac);
        
// check for groups that no longer have the award and remove them from the secondary user group
        
$delawards $vbulletin->db->query_read("
            SELECT DISTINCT us.userid, us.membergroupids
            FROM " 
TABLE_PREFIX "user AS us
            WHERE NOT EXISTS (
            SELECT aw.userid, aw.award_id
            FROM " 
TABLE_PREFIX "award_user AS aw
            WHERE (aw.award_id = 
$awardor) AND us.userid = aw.userid) AND FIND_IN_SET($aw2gr, us.membergroupids) <> 0
        "
);
        unset(
$awardor); // unset the OR query here or it'll continue to add to it on the next loop
        
if ($vbulletin->db->num_rows($delawards) > 0)
        {
            while (
$delawardsrow $vbulletin->db->fetch_array($delawards))
            { 
// remove group from users that no longer have the award
                
$userdm =& datamanager_init('User'$vbulletinERRTYPE_ARRAY); 
                
$userinfo fetch_userinfo($delawardsrow['userid']);
                
$userdm->set_existing($userinfo); 
                
$membergroupids $userdm->fetch_field('membergroupids');
                if (
$membergroupids != "")
                {
                    
// Explode to an array
                    
$mbrgrp_array explode(","$membergroupids);
                    
// Add remove/add group to array
                    
$key array_search($aw2gr$mbrgrp_array);
                    unset(
$mbrgrp_array[$key]);
                    
// Make it a comma seperated string again
                    
$membergroupids implode(","$mbrgrp_array);
                }
                
$userdm->set('membergroupids'$membergroupids);
                
$userdm->pre_save();
                if (
count($userdm->errors))
                {
                    for (
$i 0$i count($userdm->errors); $i++)
                    {
                        echo 
"ERROR{$i}:{$userdm->errors[$i]}\n";
                    }
                }
                else
                {
                    
// If everything is OK
                    
$userdm->save();
                    unset(
$mbrgrp_array);
                }
            }
            
$vbulletin->db->free_result($delawardsrow);
        }
    }
    
$i++;
}

// ########################################################################
// ######################### USERGROUP UPDATES ############################
// #########################   REMOVE ACCESS   ############################
// ########################################################################

unset($delawards$delawardsrow$userdm$userinfo$membergroupids$awardval$aw2gr$i);     

log_cron_action(''$nextitem1);
?>

All you need to do now is setup two scheduled tasks to call the two scripts. I have the award2group.php running every hour and the delaward2group.php running every 12 hours. You can choose a schedule to suit your particular needs.

titodj 06-25-2009 01:46 PM

Thank you !! Let see if I can figure this out....

katie hunter 07-13-2009 05:53 PM

Hi, I've posted this before but it kinda get forgotten.
i think it will give the award system new look and functions.

https://vborg.vbsupport.ru/showpost....&postcount=373

I've added to new screenshots

Cadellin 08-11-2009 08:56 PM

A really useful facility would be the ability to have some awards awarded automatically - e.g based on time since regitation - or if your a member of a certain group (I know you can become a member because of an award I'm after the opposite :))

Great mod though :)

SBlueman 08-12-2009 03:59 AM

I am running 3.6.12....is this compatible with that version?

wapsilog 08-27-2009 12:02 AM

unable to set display format to ASC...
anybody ecounter same problem?

jaderollie 09-17-2009 11:08 PM

i cant see an awards section in admincp, so how do i give a user a medal??


All times are GMT. The time now is 02:50 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01838 seconds
  • Memory Usage 1,867KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (4)pagenav_pagelink
  • (2)pagenav_pagelinkrel
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete