# fluent-booking/2.5.0/app/Http/Controllers/AdminController.php

Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution, version 2.5.0. 147 lines.

- Page: https://pluginprobe.com/plugins/fluent-booking/2.5.0/code/app/Http/Controllers/AdminController.php
- Raw: https://pluginprobe.com/plugins/fluent-booking/2.5.0/raw/app/Http/Controllers/AdminController.php
- Modified: 2026-09-24T14:25:18+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/fluent-booking/2.5.0/code/app/Http/Controllers/AdminController.php#L10-L20`.

```php
<?php

namespace FluentBooking\App\Http\Controllers;

use FluentBooking\App\Models\Calendar;
use FluentBooking\Framework\Http\Request\Request;
use FluentBooking\App\Services\Helper;

class AdminController extends Controller
{
    public function getRemainingHosts(Request $request)
    {
        if (!current_user_can('list_users')) {
            $user = get_user_by('ID', get_current_user_id());
            return [
                'hosts' => [
                    [
                        'is_own' => true,
                        'id'     => $user->ID,
                        'label'  => $user->display_name . ' (' . $user->user_email . ')'
                    ]
                ]
            ];
        }

        $search_term = sanitize_text_field($request->get('search'));

        // The total is never used, and counting it forces a full scan of every matching user
        $baseArgs = [
            'role__not_in' => ['subscriber'],
            'number'       => 50,
            'fields'       => ['ID', 'user_email', 'display_name'],
            'count_total'  => false
        ];

        if ($search_term === '') {
            $users = get_users(apply_filters('fluent_booking/user_search_meta_query_arguments', $baseArgs, $search_term));
        } else {
            $queryArgs = array_merge($baseArgs, [
                'search' => '*' . $search_term . '*'
            ]);

            $metaQueryArgs = array_merge($baseArgs, [
                /* phpcs:disable WordPress.DB.SlowDBQuery.slow_db_query_meta_query */
                'meta_query' => [
                    'relation' => 'OR',
                    [
                        'key'     => 'first_name',
                        'value'   => $search_term,
                        'compare' => 'LIKE'
                    ],
                    [
                        'key'     => 'last_name',
                        'value'   => $search_term,
                        'compare' => 'LIKE'
                    ]
                ],
            ]);

            $metaQueryArgs = apply_filters('fluent_booking/user_search_meta_query_arguments', $metaQueryArgs, $search_term);

            $queryResult = get_users($queryArgs);
            $metaQueryResult = get_users($metaQueryArgs);

            $users = array_unique(array_merge($queryResult, $metaQueryResult), SORT_REGULAR);
        }
        
        $hosts = [];
        $pushedIds = [];
        $calendarUserIds = Calendar::where('type', 'simple')->pluck('user_id')->toArray();
        foreach ($users as $user) {
            $pushedIds[] = $user->ID;
            $hosts[] = [
                'id'       => $user->ID,
                'label'    => $user->display_name . ' (' . $user->user_email . ')',
                'avatar'   => Helper::fluentBookingUserAvatar($user->user_email, $user),
                'disabled' => in_array($user->ID, $calendarUserIds)
            ];
        }

        if ($selectedId = $request->get('selected_id')) {
            if (!in_array($selectedId, $pushedIds)) {
                $user = get_user_by('ID', $selectedId);
                if ($user) {
                    $hosts[] = [
                        'id'       => $user->ID,
                        'label'    => $user->display_name . ' (' . $user->user_email . ')',
                        'avatar'   => Helper::fluentBookingUserAvatar($user->user_email, $user),
                        'disabled' => in_array($user->ID, $calendarUserIds)
                    ];
                }
            }
        }

        return [
            'hosts' => $hosts
        ];
    }

    public function getOtherHosts(Request $request)
    {
        if (!current_user_can('list_users')) {
            return [
                'hosts' => []
            ];
        }

        $currentUserId = get_current_user_id();

        $calendars = Calendar::with(['user'])
            ->where('user_id', '!=', $currentUserId)
            ->where('type', 'simple')
            ->get();

        $allHosts = [];

        foreach ($calendars as $calendar) {
            $userName = __('Deleted User', 'fluent-booking');
            if ($calendar->user) {
                $userName = $calendar->user->full_name;
            }

            if ($currentUserId == $calendar->user_id) {
                $userName = __('My Meetings', 'fluent-booking');
            }

            $allHosts[] = [
                'id'    => (string)$calendar->user_id,
                'label' => $userName
            ];
        }

        return [
            'hosts' => $allHosts
        ];
    }

    public function getAllHosts(Request $request)
    {
        $allHosts = Calendar::getAllHosts();

        return [
            'hosts' => $allHosts
        ];
    }
}

```
