Certainly! What you're describing is a round-robin scheduling algorithm. This is a simple and fair way to distribute tasks among a set of resources (in your case, employees). Here's a basic implementation in PHP, which you can adapt to your specific needs:
class RoundRobinScheduler {
private $queue;
public function __construct($employees) {
// Initialize the queue with the employees
$this->queue = $employees;
}
public function getNextEmployee() {
// Take the first employee from the queue
$employee = array_shift($this->queue);
// Add the employee back to the end of the queue
$this->queue[] = $employee;
// Return the employee
return $employee;
}
public function getQueue() {
// Return the current state of the queue
return $this->queue;
}
}
// Example usage:
$employees = [1, 2, 3]; // Array of employee IDs
$scheduler = new RoundRobinScheduler($employees);
// Simulate customer service
for ($i = 0; $i < 6; $i++) {
$employeeId = $scheduler->getNextEmployee();
echo "Customer $i is being served by employee $employeeId\n";
echo "Queue is now: " . implode(', ', $scheduler->getQueue()) . "\n";
}
This script will output something like:
Customer 0 is being served by employee 1
Queue is now: 2, 3, 1
Customer 1 is being served by employee 2
Queue is now: 3, 1, 2
Customer 2 is being served by employee 3
Queue is now: 1, 2, 3
Customer 3 is being served by employee 1
Queue is now: 2, 3, 1
Customer 4 is being served by employee 2
Queue is now: 3, 1, 2
Customer 5 is being served by employee 3
Queue is now: 1, 2, 3
This demonstrates that each customer is being served by employees in a round-robin fashion. You can integrate this logic into your system, ensuring that when an employee becomes available (or "online"), they are added to the queue, and when they are no longer available, they are removed from the queue.