Jacob1 Posted October 4, 2013 Share Posted October 4, 2013 (edited) 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 October 4, 2013 by Jacob1 Quote Link to comment https://forums.phpfreaks.com/topic/282708-timetable-schedule-help/ Share on other sites More sharing options...
Barand Posted October 4, 2013 Share Posted October 4, 2013 Which bit of your code are you having the problem with? Quote Link to comment https://forums.phpfreaks.com/topic/282708-timetable-schedule-help/#findComment-1452576 Share on other sites More sharing options...
Jacob1 Posted October 4, 2013 Author Share Posted October 4, 2013 The core part, how to express the conditions. I am thinking of making an array for each workshift with the users from database, but i am stuck here. Quote Link to comment https://forums.phpfreaks.com/topic/282708-timetable-schedule-help/#findComment-1452581 Share on other sites More sharing options...
Barand Posted October 4, 2013 Share Posted October 4, 2013 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) ); Quote Link to comment https://forums.phpfreaks.com/topic/282708-timetable-schedule-help/#findComment-1452597 Share on other sites More sharing options...
Jacob1 Posted November 9, 2013 Author Share Posted November 9, 2013 (edited) 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 November 9, 2013 by Jacob1 Quote Link to comment https://forums.phpfreaks.com/topic/282708-timetable-schedule-help/#findComment-1457665 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.