Back to PhocaDownloadUser class

Method usersList

public static array
usersList
(mixed $name, mixed $id, mixed $active, mixed $nouser = 0, mixed $javascript = NULL, mixed $order = 'name', mixed $reg = 1, mixed $returnArray = 0)
Method to display multiple select box
Parameters
  • string $name Name (id, name parameters)
  • array $active Array of items which will be selected
  • int $nouser Select no user
  • string $javascript Add javascript to the select box
  • string $order Ordering of items
  • int $reg Only registered users
Returns
  • array of id

Method usersList - Source code

/**
 * Method to display multiple select box
 * @param string $name Name (id, name parameters)
 * @param array $active Array of items which will be selected
 * @param int $nouser Select no user
 * @param string $javascript Add javascript to the select box
 * @param string $order Ordering of items
 * @param int $reg Only registered users
 * @return array of id
 */
public static function usersList($name, $id, $active, $nouser = 0, $javascript = NULL, $order = 'name', $reg = 1, $returnArray = 0)
{
    $activeArray = $active;
    if ($active != '') {
        $activeArray = explode(',', $active);
    }
    $db = Factory::getDBO();
    $and = '';
    if ($reg) {
        // does not include registered users in the list
        $and = ' AND m.group_id != 2';
    }
    $query = 'SELECT u.id AS value, u.name AS text' . ' FROM #__users AS u' . ' JOIN #__user_usergroup_map AS m ON m.user_id = u.id' . ' WHERE u.block = 0' . $and . ' GROUP BY u.id' . ' ORDER BY ' . $order;
    $db->setQuery($query);
    if ($nouser) {
        // Access rights (Default open for all)
        // Upload and Delete rights (Default closed for all)
        switch ($name) {
            case 'jform[accessuserid][]':
                $idInput1 = -1;
                $idText1 = Text::_('COM_PHOCADOWNLOAD_ALL_REGISTERED_USERS');
                $idInput2 = -2;
                $idText2 = Text::_('COM_PHOCADOWNLOAD_NOBODY');
                break;
            default:
                $idInput1 = -2;
                $idText1 = Text::_('COM_PHOCADOWNLOAD_NOBODY');
                $idInput2 = -1;
                $idText2 = Text::_('COM_PHOCADOWNLOAD_ALL_REGISTERED_USERS');
                break;
        }
        $users[] = HTMLHelper::_('select.option', $idInput1, '- ' . $idText1 . ' -');
        $users[] = HTMLHelper::_('select.option', $idInput2, '- ' . $idText2 . ' -');
        $users = array_merge($users, $db->loadObjectList());
    } else {
        $users = $db->loadObjectList();
    }
    if ($returnArray == 1) {
        return $users;
    }
    $users = HTMLHelper::_('select.genericlist', $users, $name, 'class="form-select" size="4" multiple="multiple"' . $javascript, 'value', 'text', $activeArray, $id);
    return $users;
}