vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3.6 Add-ons (https://vborg.vbsupport.ru/forumdisplay.php?f=194)
-   -   Miscellaneous Hacks - DevTracker : Search by usergroup (https://vborg.vbsupport.ru/showthread.php?t=123330)

grecostimpy 11-29-2007 11:50 PM

Quote:

Originally Posted by Blizzke (Post 1234173)
Actually, if you like to search by groups you can do it like this:
Code:

if ($vbulletin->GPC['searchuser'])
{
  // username too short
  if (!$vbulletin->GPC['exactname'] AND strlen($vbulletin->GPC['searchuser']) < 3)
  {
      $errors[] = 'searchnametooshort';
  }
  else
  {
      if ( $vbulletin->GPC['searchuser'] == 'devtracker' )
      {
        $aDevGroups = Array ( 1, 2, 3 );
        $q = 'SELECT posts, userid, username FROM `' . TABLE_PREFIX . 'user` where usergroupid IN ( ' . implode ( ',', $aDevGroups ) . ') ';
        foreach ( $aDevGroups as $nDevGroup )
            $q .= ' OR concat( membergroupids,"," ) LIKE "%' . $nDevGroup . ',%"';
      }
      else
      {

        $username = htmlspecialchars_uni($vbulletin->GPC['searchuser']);
        $q = "
            SELECT posts, userid, username
            FROM " . TABLE_PREFIX . "user AS user
            WHERE username " .
              ($vbulletin->GPC['exactname'] ?
                  "= '" . $db->escape_string($username) . "'" :
                  "LIKE('%" . sanitize_word_for_sql($username) . "%')"
              )
        ;
      }

      require_once(DIR . '/includes/functions_bigthree.php');
      $coventry = fetch_coventry();

The green section is what you should add in the search.php file, note that you need to replace the $aDevGroups = Array ( 1, 2, 3 ); with an array containing the id's of the groups you wish to track.

How does it work?
Pretty easy. The query returns all users that either have one of the specified groups as the primary group (usergroupid field) or user with one (or more) of the requested groups as secondary.

Why the concat in the query ?
The secondary grouplist consists of a comma separate list of group id's.
We have to add a comma to the search term because otherwise we could pick up partial groups (ie a user in group 10 will be returned if we are looking for group 1). Solution to that is to always include a comma, so look for "1," instead of simple "1".
This poses a second problem: Should a group be the the last, it will not be detected. (eg "1,2" and we are searching for group "2"). So, the logical thing is to add an extra comma to the end of the membergroupids and then search for the groupid with a comma, which will always return the correct user.

Please note the following:
Obviously this is a "decent query" when used on a large board with a lot of users, so you might want to consider taking the initial query out and caching it's results into a small separate table, that way you would only have to select the rows from that table. You could have a script update that table so that you only have to run that once when you add or remove "devs".

I know this is extremely old, but can someone expand on this? Where would I enter the usergroup id? I changed the numbers in the line $aDevGroups = Array ( 1, 2, 3 ); to my usergroup id's. But it just ended up with me getting a blank white screen anytimeI did ANY type of search.

Help? Thanks!

LuBi 03-21-2008 11:38 PM

Since this is such an old thread, has anyone created a formal modification yet?

furnival 03-26-2008 09:56 AM

Returns all users for me, regardless of usergroup. How odd

tonjohn 02-11-2010 08:01 AM

Wouldn't it be possible to do this via the plugin system without having to edit the actual .php file?

I want some sort of dev tracker but am trying to avoid editing any of the actual files on the server.

gabbariele 07-31-2011 05:30 PM

Hi, sorry if I bump up this old topic. Is there a way to do the same thing in vBulletin 4.1.5 ? Thanks

Deimos 09-16-2012 09:43 PM

Wouldn't mind getting this updated for VB 4.2, any takers?


All times are GMT. The time now is 03:38 PM.

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.00982 seconds
  • Memory Usage 1,734KB
  • 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
  • (1)bbcode_code_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (6)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