/**
* Method to get a value from option
*
* @param User $user a UserInstance
*
* @return array
*
* @since 4.0.0
*/
protected function getGroups($user) : array
{
$groups = $this->getApplication()->getConsoleInput()->getOption('group');
$db = Factory::getDbo();
$groupList = [];
// Group names have been supplied as input arguments
if ($groups) {
$groups = explode(',', $groups);
foreach ($groups as $group) {
$groupId = $this->getGroupId($group);
if (empty($groupId)) {
$this->ioStyle->error("Invalid group name '" . $group . "'");
throw new InvalidOptionException("Invalid group name " . $group);
}
$groupList[] = $this->getGroupId($group);
}
return $groupList;
}
$userGroups = Access::getGroupsByUser($user->id, false);
// Generate select list for user
$query = $db->getQuery(true)->select($db->quoteName('title'))->from($db->quoteName('#__usergroups'))->whereNotIn($db->quoteName('id'), $userGroups)->order($db->quoteName('id') . ' ASC');
$db->setQuery($query);
$list = $db->loadColumn();
$choice = new ChoiceQuestion('Please select a usergroup (separate multiple groups with a comma)', $list);
$choice->setMultiselect(true);
$answer = (array) $this->ioStyle->askQuestion($choice);
foreach ($answer as $group) {
$groupList[] = $this->getGroupId($group);
}
return $groupList;
}