/**
* Method to get a value from option
*
* @param object $user user object
*
* @return array
*
* @since 4.0.0
*/
protected function getGroups($user) : array
{
$option = $this->getApplication()->getConsoleInput()->getOption('group');
$db = Factory::getDbo();
$userGroups = Access::getGroupsByUser($user->id, false);
if (!$option) {
$query = $db->getQuery(true)->select($db->quoteName('title'))->from($db->quoteName('#__usergroups'))->whereIn($db->quoteName('id'), $userGroups);
$db->setQuery($query);
$result = $db->loadColumn();
$choice = new ChoiceQuestion('Please select a usergroup (separate multiple groups with a comma)', $result);
$choice->setMultiselect(true);
$answer = (array) $this->ioStyle->askQuestion($choice);
$groupList = [];
foreach ($answer as $group) {
$groupList[] = $this->getGroupId($group);
}
return $groupList;
}
$groupList = [];
$option = explode(',', $option);
foreach ($option 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;
}