. * --------------------------------------------------------------------- */ if (!defined('GLPI_ROOT')) { die("Sorry. You can't access this file directly"); } /** * Group_User Class * * Relation between Group and User **/ class Group_User extends CommonDBRelation{ // From CommonDBRelation static $itemtype_1 = 'User'; static $items_id_1 = 'users_id'; static $itemtype_2 = 'Group'; static $items_id_2 = 'groups_id'; /** * Check if a user belongs to a group * * @since 9.4 * * @param integer $users_id the user ID * @param integer $groups_id the group ID * * @return boolean true if the user belongs to the group */ static function isUserInGroup($users_id, $groups_id) { return countElementsInTable( 'glpi_groups_users', [ 'users_id' => $users_id, 'groups_id' => $groups_id ] ) > 0; } /** * Get groups for a user * * @param integer $users_id User id * @param array $condition Query extra condition (default []) * * @return array **/ static function getUserGroups($users_id, $condition = []) { global $DB; $groups = []; $iterator = $DB->request([ 'SELECT' => [ 'glpi_groups.*', 'glpi_groups_users.id AS IDD', 'glpi_groups_users.id AS linkid', 'glpi_groups_users.is_dynamic AS is_dynamic', 'glpi_groups_users.is_manager AS is_manager', 'glpi_groups_users.is_userdelegate AS is_userdelegate' ], 'FROM' => self::getTable(), 'LEFT JOIN' => [ Group::getTable() => [ 'FKEY' => [ Group::getTable() => 'id', self::getTable() => 'groups_id' ] ] ], 'WHERE' => [ 'glpi_groups_users.users_id' => $users_id ] + $condition, 'ORDER' => 'glpi_groups.name' ]); while ($row = $iterator->next()) { $groups[] = $row; } return $groups; } /** * Get users for a group * * @since 0.84 * * @param integer $groups_id Group ID * @param array $condition Query extra condition (default []) * * @return array **/ static function getGroupUsers($groups_id, $condition = []) { global $DB; $users = []; $iterator = $DB->request([ 'SELECT' => [ 'glpi_users.*', 'glpi_groups_users.id AS IDD', 'glpi_groups_users.id AS linkid', 'glpi_groups_users.is_dynamic AS is_dynamic', 'glpi_groups_users.is_manager AS is_manager', 'glpi_groups_users.is_userdelegate AS is_userdelegate' ], 'FROM' => self::getTable(), 'LEFT JOIN' => [ User::getTable() => [ 'FKEY' => [ User::getTable() => 'id', self::getTable() => 'users_id' ] ] ], 'WHERE' => [ 'glpi_groups_users.groups_id' => $groups_id ] + $condition, 'ORDER' => 'glpi_users.name' ]); while ($row = $iterator->next()) { $users[] = $row; } return $users; } /** Show groups of a user * * @param $user User object **/ static function showForUser(User $user) { global $CFG_GLPI; $ID = $user->fields['id']; if (!Group::canView() || !$user->can($ID, READ)) { return false; } $canedit = $user->can($ID, UPDATE); $rand = mt_rand(); $iterator = self::getListForItem($user); $groups = []; //$groups = self::getUserGroups($ID); $used = []; while ($data = $iterator->next()) { $used[$data["id"]] = $data["id"]; $groups[] = $data; } if ($canedit) { echo "
| "; $header_top .= Html::getCheckAllAsCheckbox('mass'.__CLASS__.$rand); $header_bottom .= Html::getCheckAllAsCheckbox('mass'.__CLASS__.$rand); $header_end .= " | "; } $header_end .= "".Group::getTypeName(1)." | "; $header_end .= "".__('Dynamic')." | "; $header_end .= "".__('Manager')." | "; $header_end .= "".__('Delegatee')." |
|---|---|---|---|---|
| "; Html::showMassiveActionCheckBox(__CLASS__, $data["linkid"]); echo " | "; } echo "".$group->getLink()." | "; echo "";
if ($data['is_dynamic']) {
echo " | ";
if ($data['is_manager']) {
echo " | ";
if ($data['is_userdelegate']) {
echo " |
| ".__('None')." | ||||