diff --git a/htdocs/user/class/usergroup.class.php b/htdocs/user/class/usergroup.class.php index a9884ca59d1..250fec08c30 100644 --- a/htdocs/user/class/usergroup.class.php +++ b/htdocs/user/class/usergroup.class.php @@ -100,6 +100,7 @@ class UserGroup extends CommonObject public $members = array(); // Array of users public $nb_rights; // Number of rights granted to the user + public $nb_users; // Number of users in the group private $_tab_loaded = array(); // Array of cache of already loaded permissions @@ -151,7 +152,7 @@ class UserGroup extends CommonObject * @param boolean $load_members Load all members of the group * @return int <0 if KO, >0 if OK */ - public function fetch($id = '', $groupname = '', $load_members = true) + public function fetch($id = '', $groupname = '', $load_members = false) { global $conf; @@ -166,7 +167,7 @@ class UserGroup extends CommonObject if ($result) { if ($load_members) { - $this->members = $this->listUsersForGroup(); + $this->members = $this->listUsersForGroup(); // This make a lot of subrequests } return 1; @@ -237,7 +238,7 @@ class UserGroup extends CommonObject $ret = array(); - $sql = "SELECT u.rowid"; + $sql = "SELECT u.rowid, u.login, u.lastname, u.firstname, u.photo, u.fk_soc, u.entity, u.employee, u.email"; if (!empty($this->id)) { $sql .= ", ug.entity as usergroup_entity"; } @@ -263,12 +264,23 @@ class UserGroup extends CommonObject dol_syslog(get_class($this)."::listUsersForGroup", LOG_DEBUG); $resql = $this->db->query($sql); + if ($resql) { while ($obj = $this->db->fetch_object($resql)) { if (!array_key_exists($obj->rowid, $ret)) { if ($mode != 1) { $newuser = new User($this->db); - $newuser->fetch($obj->rowid); + //$newuser->fetch($obj->rowid); // We are inside a loop, no subrequests inside a loop + $newuser->id = $obj->rowid; + $newuser->login = $obj->login; + $newuser->photo = $obj->photo; + $newuser->lastname = $obj->lastname; + $newuser->firstname = $obj->firstname; + $newuser->email = $obj->email; + $newuser->socid = $obj->fk_soc; + $newuser->entity = $obj->entity; + $newuser->employee = $obj->employee; + $ret[$obj->rowid] = $newuser; } else { $ret[$obj->rowid] = $obj->rowid; @@ -936,10 +948,10 @@ class UserGroup extends CommonObject $return .= '
'; $return .= ''.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).''; if (property_exists($this, 'members')) { - $return .= '
'.(!empty($this->members)? $this->members : 0).' '.$langs->trans('Users').''; + $return .= '
'.(empty($this->nb_users) ? 0 : $this->nb_users).' '.$langs->trans('Users').''; } if (property_exists($this, 'nb_rights')) { - $return .= '
'.$langs->trans('NbOfPermissions').' : '.$this->nb_rights.'
'; + $return .= '
'.$langs->trans('NbOfPermissions').' : '.(empty($this->nb_rights) ? 0 : $this->nb_rights).'
'; } $return .= '
'; $return .= ''; diff --git a/htdocs/user/group/card.php b/htdocs/user/group/card.php index a9a16826ee3..7bafaf5aee5 100644 --- a/htdocs/user/group/card.php +++ b/htdocs/user/group/card.php @@ -247,6 +247,7 @@ if (empty($reshook)) { /* * View */ + $title = $object->name.' - '.$langs->trans("Card"); if ($action == 'create') { $title = $langs->trans("NewGroup"); @@ -309,8 +310,6 @@ if ($action == 'create') { /* */ /* ************************************************************************** */ if ($id) { - $res = $object->fetch_optionals(); - $head = group_prepare_head($object); $title = $langs->trans("Group"); @@ -447,6 +446,8 @@ if ($action == 'create') { print ' '; print "\n"; + $object->fetch($object->id, '', true); // true to force load of all users, member of the group + if (!empty($object->members)) { foreach ($object->members as $useringroup) { print ''; diff --git a/htdocs/user/group/list.php b/htdocs/user/group/list.php index b0327eebe08..5f017da01c9 100644 --- a/htdocs/user/group/list.php +++ b/htdocs/user/group/list.php @@ -380,8 +380,8 @@ while ($i < $imaxinloop) { $object->name = $obj->name; $object->note = $obj->note; - $object->members = $obj->nb; $object->nb_rights = $obj->nbpermissions; + $object->nb_users = $obj->nb; if ($mode == 'kanban') { if ($i == 0) {