public function store($updateNulls = true)
{
$k = $this->_tbl_key;
$key = $this->{$k};
$groups = $this->groups;
unset($this->groups);
if ($key) {
$this->_db->updateObject($this->_tbl, $this, $this->_tbl_key, $updateNulls);
} else {
$this->_db->insertObject($this->_tbl, $this, $this->_tbl_key);
}
$this->groups = $groups;
$query = $this->_db->getQuery(true);
if (\is_array($this->groups) && \count($this->groups)) {
$uid = (int) $this->id;
$query->clear()->select($this->_db->quoteName('group_id'))->from($this->_db->quoteName('#__user_usergroup_map'))->where($this->_db->quoteName('user_id') . ' = :userid')->bind(':userid', $uid, ParameterType::INTEGER);
$this->_db->setQuery($query);
$result = $this->_db->loadObjectList();
if (\count($result)) {
$mapGroupId = [];
foreach ($result as $map) {
if (\array_key_exists($map->group_id, $this->groups)) {
unset($groups[$map->group_id]);
} else {
$mapGroupId[] = (int) $map->group_id;
}
}
if (\count($mapGroupId)) {
$query->clear()->delete($this->_db->quoteName('#__user_usergroup_map'))->where($this->_db->quoteName('user_id') . ' = :uid')->whereIn($this->_db->quoteName('group_id'), $mapGroupId)->bind(':uid', $uid, ParameterType::INTEGER);
$this->_db->setQuery($query);
$this->_db->execute();
}
}
if (\count($groups)) {
$query->clear()->insert($this->_db->quoteName('#__user_usergroup_map'))->columns([$this->_db->quoteName('user_id'), $this->_db->quoteName('group_id')]);
foreach ($groups as $group) {
$query->values(implode(',', $query->bindArray([$this->id, $group], [ParameterType::INTEGER, ParameterType::INTEGER])));
}
$this->_db->setQuery($query);
$this->_db->execute();
}
unset($groups);
}
if ($this->block == 1) {
$query->clear()->delete($this->_db->quoteName('#__user_keys'))->where($this->_db->quoteName('user_id') . ' = :user_id')->bind(':user_id', $this->username);
$this->_db->setQuery($query);
$this->_db->execute();
}
return true;
}