I want to create a schedule organizer for my work. I have a list of my colleagues and a list of our job positions/tasks/assignments. No one is supposed to be assigned the same task, say, more than 4 days each month and we are supposed to have somewhat of a mix so that not the same people are working together all the time.
I have achieved the latter by shuffling the array with the employees. I'm having the following logical problem: When I compare an employee against an assignment and against the history in the database, my script tries to assign each employee after the other comparing 2 arrays (one with the employees and the other with the assignments), if an employee has done the specific assignment, then it jumps to the next. if all the rest of the employees have done it then I get other code execuded. The problem is that if an employee is already assigned but at the same time the next task in the list is only available for him then I can't find a smart way to re-assign/reform/reschedule those places.
Here is the code that I've written so far:
function check_employee($shuffled_names,$positions,$conn)
{
for($i=0;$i<count($shuffled_names);$i++)
{
if(comparison($shuffled_names[$i],$positions[0],$conn))
{
$temp_names[] = $shuffled_names[$i];
$temp_positions[] = $positions[0];
if($positions[0] != "GMP")
{
unset($positions[0]);
$positions = array_values($positions);
}
}
else
{
foreach($temp_names as $tnames)
{
if(comparison($tnames,$positions[0],$conn))
{
$temp_names[] = $tnames;
unset($tnames);
echo "tnames: ",$tnames;
$temp_positions[] = $positions[0];
break;
}
}
}
}
//print_r($temp_positions);
for($i=0;$i<count($temp_names);$i++)
$sql[] = "INSERT INTO schedules(date,name,position) VALUES (CURDATE(),'$temp_names[$i]','$temp_positions[$i]')";
foreach($sql as $query)
$conn->query($query);
return [$temp_names,$temp_positions];
}