function generateStationDropdown($role, $isMultiple = true, $default = '')
{
    $usersByRole = getUsersByRole('stationManager');
    $res = json_decode($usersByRole->value);
    if ($isMultiple) {
        foreach ($res as $userElement) {
            if (in_array($userElement->username, $default)) {
                $checked = ' checked="checked" ';
            } else {
                $checked = '';
            }
            echo '<input type="checkbox" name = "station[]" ' . $checked . ' id="' . $userElement->username . '" value="' . $userElement->username . '"><label for="' . $userElement->username . '">' . $userElement->username . '</label>';
        }
    } else {
        echo '<select name="station">' . '<option value="" selected="selected">Select Station</option>';
        foreach ($res as $userElement) {
            if (!empty($default) && $default == $userElement->username) {
                $selected = ' selected="selected" ';
            } else {
                $selected = '';
            }
            echo '<option' . $selected . ' value="' . $userElement->username . '">' . $userElement->username . '</option>';
        }
        echo '</select>';
    }
}
Beispiel #2
0
function midea_list_authors($user_role = 'author', $show_fullname = true)
{
    // Generate a list of authors for a given role
    // default is to list authors and show full name
    global $wpdb;
    $blog_url = get_bloginfo('url');
    // store base URL of blog
    $holding_pen = array();
    // this is cheap, a holder for author data
    echo '<ul>';
    // get array of all author ids for a role
    $authors = getUsersByRole($user_role);
    foreach ($authors as $item) {
        // get number of posts by this author; custom query
        $post_count = $wpdb->get_results("SELECT COUNT( * ) as cnt \n\t\tFROM  {$wpdb->posts}\n\t\tWHERE  post_author =" . $item . "\n\t\tAND  post_type =  'tribe_events'\n\t\tAND  post_status =  'publish'");
        // only output authors with posts; ugly way to get to the result, but it works....
        if ($post_count[0]->cnt) {
            // load info on this user
            $author = get_userdata($item);
            // store output in temp array; we use last names as an index in this array
            $holding_pen[$author->last_name] = '<li><a href="' . $blog_url . '/author/' . $author->user_login . '"> ' . $author->display_name . ' (' . $post_count[0]->cnt . ')</a> </li>';
        }
    }
    // now sort the array on the index to get alpha order
    ksort($holding_pen);
    // now we can spit the output out.
    foreach ($holding_pen as $key => $value) {
        echo $value;
    }
    echo '</ul>';
}