function _facebook_tracking_pixel_roles in Facebook Tracking Pixel 7
Same name and namespace in other branches
- 8 facebook_tracking_pixel.module \_facebook_tracking_pixel_roles()
Based on visibility setting this function an integer. Anything greater than 0 is trackable.
Parameters
object $account: user object
Return value
bool
1 call to _facebook_tracking_pixel_roles()
- facebook_tracking_pixel_page_build in ./
facebook_tracking_pixel.module - Implements hook_page_build().
File
- ./
facebook_tracking_pixel.module, line 565 - facebook_tracking_pixel.module Facebook Tracking Module.
Code
function _facebook_tracking_pixel_roles($account) {
// Pull role information from database.
$sql = 'select * from {variable} where name like :name';
$result = db_query($sql, [
':name' => 'facebook_tracking_pixel_roles_%',
])
->fetchAll();
// Pull the visibility setting. A value of 1 means the roles are inverted in
// the selection UI.
$visibility = variable_get('facebook_tracking_pixel_visibility_roles', 0);
// If the selection is inverted we enable visibility. Otherwise default is
// no tracking.
$enabled = $visibility;
$roles = [];
// Build array of role information.
if (!empty($result)) {
foreach ($result as $item) {
if ($item->value == 'i:1;') {
$roles[$item->name] = 1;
}
elseif ($item->value == 'i:0;') {
$roles[$item->name] = 0;
}
}
}
if (array_sum($roles) > 0) {
// One or more roles are selected.
foreach ($account->roles as $rid => $rname) {
// Fixup the role name.
$rname = str_replace(' ', '_', $rname);
$rname = 'facebook_tracking_pixel_roles_' . $rname;
// Is the current user a member of one of these roles?
if (isset($roles[$rname]) && $roles[$rname] == 1) {
// Current user is a member of a role that should be tracked/excluded
// from tracking. The visibility variable is used and inverted. This
// accounts for the settings in the UI of tracking only selected or
// tracking all but selected.
$enabled = !$visibility;
break;
}
}
}
return $enabled;
}