static function addVisibilityRestrict()
{
$restrict = '';
if (Session::getLoginUserID()) {
$restrict = "(`glpi_knowbaseitems_users`.`users_id` = '" . Session::getLoginUserID() . "' ";
// Users
$restrict .= " OR `glpi_knowbaseitems_users`.`users_id` = '" . Session::getLoginUserID() . "' ";
// Groups
if (isset($_SESSION["glpigroups"]) && count($_SESSION["glpigroups"])) {
$restrict .= " OR (`glpi_groups_knowbaseitems`.`groups_id`\n IN ('" . implode("','", $_SESSION["glpigroups"]) . "')\n AND (`glpi_groups_knowbaseitems`.`entities_id` < 0\n " . getEntitiesRestrictRequest("OR", "glpi_groups_knowbaseitems", '', '', true) . ")) ";
}
// Profiles
if (isset($_SESSION["glpiactiveprofile"]) && isset($_SESSION["glpiactiveprofile"]['id'])) {
$restrict .= " OR (`glpi_knowbaseitems_profiles`.`profiles_id`\n = '" . $_SESSION["glpiactiveprofile"]['id'] . "'\n AND (`glpi_knowbaseitems_profiles`.`entities_id` < 0\n " . getEntitiesRestrictRequest("OR", "glpi_knowbaseitems_profiles", '', '', true) . ")) ";
}
// Entities
if (isset($_SESSION["glpiactiveentities"]) && count($_SESSION["glpiactiveentities"])) {
// Force complete SQL not summary when access to all entities
$restrict .= getEntitiesRestrictRequest("OR", "glpi_entities_knowbaseitems", '', '', true, true);
}
$restrict .= ") ";
} else {
$restrict = '1';
}
return $restrict;
}