Help
Discuss or request ArrowChat modifications
User avatar
Jason
ArrowChat Team
 
Posts: 2180
Joined: 12 Dec 2009, 16:06

 

by Jason 24 Jan 2014, 23:25

What
This guide will show you how to get a user's group in phpBB and pass it into the JavaScript file.

Why
Having the user's group ID accessible in the includes/js/arrowchat_core.js file will allow you to limit a user's features based on their group. For example, you could only allow premium members to use video chat or chat rooms.

I don't use phpBB
Basically your installation will be the exact same except for a few things. Most importantly, you'll need to change the MySQL statement to get the user's group.


Installation

Getting the group ID
Open the includes/integration.php file. Create a new function in the file with the code below. If you are not using phpBB, you'll need to edit the MySQL statement here to work with your own integration.

Code: Select all
   function get_group_id($userid)
   {
      global $db;
      
      // Get the user's group ID
      $result = $db->execute("
         SELECT group_id
         FROM " . TABLE_PREFIX . "user_group
         WHERE user_id = '" . $db->escape_string($userid) . "'
            AND user_pending != 1
      ");
      
      if ($result AND $db->count_select() > 0)
      {
         // In phpBB, a user can be in multiple groups so we need an array
         $group_ids = array();
         
         // Process the results
         while ($row = $db->fetch_array($result))
         {
            $group_ids[] = $row['group_id'];
         }
         
         return json_encode($group_ids);
      }
      else
      {
         // MySQL statement didn't find a group ID or was invalid.  Return a 0
         return 0;
      }
   }


Passing the variable into the JavaScript
Open up the external.php file. Now you need to find where the DJS file loads and starts spitting out the JavaScript variables. At the time of writing this, it is line 348 with the code:

Code: Select all
$settings .= 'var T=0,';


Right after that code (on a new line) you can add the group ID variable to the settings.

Code: Select all
$group_id = get_group_id($userid);
$settings .= 'u_group_id=' . $group_id . ',';


Using the group ID
Now we can use the group ID in the /includes/js/arrowchat_core.js file (use .dev.js for a readable format). You simply need to check the 'u_group_id' variable to see which group the user is in. For example:

Get the user's first group ID in the array:
Code: Select all
alert(u_group_id[0]);


Check if the user is in group 5:
Code: Select all
if (a.inArray('5', u_group_id) != -1)
   alert('User in group');
else
   alert('User not in group');


Hide video chat if user is in group 4:
Code: Select all
if (a.inArray('4', u_group_id) != -1)
   a(".arrowchat_video_chat").hide();
User avatar
Jason
ArrowChat Team
 
Posts: 2180
Joined: 12 Dec 2009, 16:06

 

by Jason 20 Dec 2014, 14:03

Just a quick update to point out that you'll also be able to grab the user's group in any PHP file within ArrowChat as well. The below will work in any file:

Code: Select all
$group_id = get_group_id($userid);
User avatar
Voicecaster
Customer
 
Posts: 11
Joined: 13 Apr 2020, 21:14

 

by Voicecaster 13 Aug 2021, 09:55

Hello, we are looking for some sample code like this to make this happen. We can get started with code above, but just like any direction you can give.

ONLY show ROOMs X,Y,Z where ACF Variable club_Type = "dogs" . Can't use the Exclude WP User Type, because its different and Excluding. We want to Exclude the other 20 chat rooms on the left bar of the chat window and just leave X,Y,Z when club_Type = "dogs".

Also, on the PAID Push service is the 3 Room Limit Lifted?

Thank you!
User avatar
Voicecaster
Customer
 
Posts: 11
Joined: 13 Apr 2020, 21:14

 

by Voicecaster 25 Aug 2021, 14:21

Hello, I figured it out, just a quick where clause Additionin the SQL code.