Jump to content

Recommended Posts

Hi i need some guidelines with a weekly timetable script that should work like this:

  • There are 4 shift a day, 7 days a week, two people each shift (volunteers)
  • The volunteers use a webform to declare their availability trough the week
  • each volunteer should be scheduled for maximum one shift per day, 2 shifts per week

I appreciate any idea, since i am new to php. Tnx

Edited by Jacob1
Link to comment
https://forums.phpfreaks.com/topic/282708-timetable-schedule-help/
Share on other sites

You might also want to have a second array, by volunteer, so you can easily check the constraints on their shift allocations

 

eg

$shifts = array (
        0 => array ('vol1', 'vol2'),
        1 => array ('vol3', 'vol4'),
        .
        .
        27 => array ('vol3', 'vol28')
    );
    
$volunteers = array (
        'vol1' => array (0, 18),
        'vol2' => array (0, 22),
        'vol3' => array (1, 27),
        .
        .
        'vol28' => array (20, 27)
    );
  • 1 month later...

Well, the script should make the schedule. And i give the availability of each user (volunteer) trough a form. Some of them are available only 1 shift while others even daily. Everyone should have a shift, but no more than 2 per week. So in one shift i may have 3 volunteers, and in other 15. There are 40 volunteers.

Here's how i did:

$shift_2tday_full = array( "Fam vol2", "vol5", "vol23", "vol38", "vol7", "vol10", "vol33", "vol21");

//This is how i make sure no volunteer has more than a shift
//a day or in consecutive days.
	$shift_2tday = array_diff ( $shift_2tday_full, $used_vol_moday_and_today);

			$rand_keys = array_rand($shift_2tday, 2);
			$tuesdaynoon1 = $shift_2tday[$rand_keys[0]];
			$tuesdaynoon2 =$shift_2tday[$rand_keys[1]];

//This is how i filter volunteers if is family to program them together on shift
			if (preg_match("/Fam/i", $tuesdaynoon1)) {
				$martiamiaz2 = NULL;
			}elseif (preg_match("/Fam/i", $tuesdaynoon2)) {
				$tuesdaynoon1 = NULL;	
			}else {
			
				//This is how i make sure no volunteer is alone in the shift
				$tuesdaynoon1 != $tuesdaynoon2;
			}

$tuesdaynoon = ($tuesdaynoon1 . "\n /\n" . $tuesdaynoon2);


//shift protection modules
$tuesdaynoon_module= array ($tuesdaynoon1, $tuesdaynoon2);
$tuesdaynoon_volunteers_merged_with_history= array_merge ($tuesdaynoon_module, $tuesday_monday_history);

echo $tuesdaynoon; 

Everything worked ok until Thu. The script used many volunteers already and by Thursday i get blanks or people that should not be there by the criterias. So how do i make the volunteer selection by the number of shifts available, and how do i make the shift programing by the number of volunteers available? 

 

Maybe i need different approach. I don't have experience with oop, is there a simple solution using oop style?

 

It's like i want to put stones and sand in a can. If i put the sand not all stones will fit. But if i put the stones, the sand will fit also.

Edited by Jacob1
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.