With the help of ‘Role Based Access Control’ Feature admin can manage CometChat features for different User Role.
If you don’t want to use ‘Role Based Access Control’ keep $role_base_access
value ‘0’. You will find $role_base_access
value in integration.php
.
If you want to use ‘Role Based Access Control’ follow below steps
Step 1
If you want to activate ‘Role Based Access Control’ for your web site you have to edit integration.php
and search for ‘$role_base_access
‘ and replace ‘0’ with ‘1’.
Step 2
You will get getRolesDetails()
function in integration.php
. With the help of this function, You will get All Roles. By Default users role will be ‘Guest’. You can modify this function as per your Database Structure. Your getRolesDetails()
will look like:
function getRolesDetails($role = ''){
// You can write your code here.
if ($guestsMode) {
$roles["guest"] = array("name" => "Guest");
}
return $roles;
}
Params
$guestsMode = You will get this setting in CometChat ‘Admin Panel’. You can Be ‘Enabled or Disabled’ this setting following below steps.
1) Login onto your Admin panel (http://www.yoursitename.com/cometchat/admin/index.php). With proper Credentials.
2) Select ‘Setting->General’. In ‘General’ Setting search ‘Enable Guest Chat’ and make a selection (Yes/No) as per your requirement.
Return
getRolesDetails()
function should return associative array Roles details like below.
e.g. $roles = array(
"contributor" => array('name' => "Contributor"),
"author" => array('name' => "Author"),
"editor" => array('name' => "Editor"),
"administrator" => array('name' => "Administrator"));
Sample Code for ‘getRolesDetails()’
function getRolesDetails($role = ''){
global $guestsMode,$firstguestID;
// Query for fetching all user roles from User Table.
$sql = ("SELECT role FROM users WHERE role IS NOT NULL group by role order by role");
$result = sql_query($sql, array(), 1);
while ($row = sql_fetch_assoc($result)) {
$roles[$row['role']] = array('name' => ucwords($row['role']));
}
// Condition for guest
if ($guestsMode) {
$roles["guest"] = array("name" => "Guest");
}
// Return Array of All Roles Available in User Role Table
return $roles;
}
Step 3
You will get getRole()
function in integration.php
. With the help of this function, You will get users Role. By Default users role will be ‘Guest’. You can modify this function as per your Database Structure. Your getRole()
will look like:
function getRole($userid){
$role = '';
// You can write your code here.
if ($guestsMode) {
$role = 'guest';
}
return $role;
}
Params
$guestsMode = You will get this setting in CometChat ‘Admin Panel’. You can Be ‘Enabled or Disabled’ this setting following below steps.
$userid = Logged in user id.
Return
getRole()
function should return String of Role Title.
Sample Code for ‘getRole()’
function getRole($userid){
global $guestsMode
$role = '';
// Fetch Specific user role details.
$sql = ("SELECT role FROM users WHERE userid = $userid");
$result = sql_query($sql, array(), 1);
$row = sql_fetch_assoc($result);
if ($guestsMode) {
$role = 'guest';
}
if (count($row)>0) {
$role = $row['role'];
}
return $role;
}
With the help of ‘Role Based Access Control Feature’ admin can manage CometChat features for different User Role.
You have to set role
in your Web Site. Below is a code for the same.
<script>
var role = 'LOGGEDIN_USERS_ROLE_ID';
</script>
Where:
– role: Should store the role of the logged in user.
How to access ‘Role Based Access Control’ in CometChat?
Step 1
Login to CometChat Cloud Admin Panel using CometChat Credientials.
Step 2
In left side menu click on ‘Membership Level’.
Step 3
You can see different User Roles. Click on any one of the User Role.
Step 4
Now you can see three options.
Option | Description |
---|---|
Disable CometChat completely for this role | Disable CometChat Completely for selected role. |
Disable Specific Features of CometChat for this role | Disable Specific CometChat Feature for selected role. |
Disable Specific Platforms for this role | Disable platform for selected role. (Platform will be Web, Mobile, Desktop) |
Step 4
Make a changes in ‘Role Based Access Control’ for specific user and Click on “Update”.