/** * uses the master schedule to create a new week in dbWeeks and * 7 new dates in dbDates and new shifts in dbShifts * * @param DateTime $date The Sunday that this week starts with * @return false if the week-creation process fails */ function generate_new_week(DateTime $date) { // set the group names the format used by master schedule $weekdays = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]; $dates = []; foreach ($weekdays as $day) { $venue_shifts = get_master_shifts($venue, $day); /* Each row in the array is an associative array * of (venue, my_group, day, time, start, end, slots,notes) */ $shifts = []; foreach ($venue_shifts as $venue_shift) { /** @noinspection PhpUndefinedMethodInspection */ $shifts[] = generate_and_populate_shift($date->format("m-d-y"), $venue, $venue_shift->get_start_time(), $venue_shift->get_end_time(), ""); } // makes a new date with these shifts $new_date = new BSCAHdate($date->format("m-d-y"), $shifts, "", ""); // Exits this method if the ID was not properly set in the constructor if ($new_date->get_id() == null) { return false; } $dates[] = $new_date; $date->modify("+1 day"); } // creates a new week from the dates // Week is set to "archived" if the week has already passed, otherwise is set to "unpublished" $newweek = new Week($dates, $date->getTimestamp() < time() ? "archived" : "unpublished"); if ($newweek == null) { return false; } $insert_status = insert_dbWeeks($newweek); add_log_entry('<a href=\\"personEdit.php?id=' . $_SESSION['_id'] . '\\">' . $_SESSION['f_name'] . ' ' . $_SESSION['l_name'] . '</a> generated a new week: <a href=\\"calendar.php?id=' . $newweek->get_id() . '&edit=true\\">' . $newweek->get_name() . '</a>.'); return $insert_status; }
function insert_nonoverlapping($shift) { $other_shifts = get_master_shifts($shift->get_schedule_type(), $shift->get_day()); foreach ($other_shifts as $other_shift) { if (masterslots_overlap($shift->get_start_time(), $shift->get_end_time(), $other_shift->get_start_time(), $other_shift->get_end_time())) { return false; } } insert_dbMasterSchedule($shift); return true; }
function generate_populate_and_save_new_week($m, $d, $y, $venue) { // set the group names the format used by master schedule $weekdays = array("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"); $weeksofmonth = array(1 => "1st", 2 => "2nd", 3 => "3rd", 4 => "4th", 5 => "5th"); $day_id = $y . "-" . $m . "-" . $d; $dates = array(); $daysinmonth = date("t", mktime(0, 0, 0, $m, $d, $y)); foreach ($weekdays as $day) { $my_date = mktime(0, 0, 0, $m, $d, $y); $week_of_month = $weeksofmonth[floor(($d - 1) / 7) + 1]; // echo "weekofmonth,day,month,year,daysinmonth= ",$week_of_month.",".$d.",".$m.",".$y.",".$daysinmonth; $weekno = date("W", $my_date); if (date("Y", $my_date) % 2 == 0) { // even years start at week 0 so that can't get 2 odds in a riw $weekno--; } if ($weekno % 2 == 1) { $week_of_year = "odd"; } else { $week_of_year = "even"; } $month_num = date("m", $my_date); $venue_shifts1 = get_master_shifts($venue, $week_of_month, $day); $venue_shifts2 = get_master_shifts($venue, $week_of_year, $day); $venue_shifts = array_merge($venue_shifts1, $venue_shifts2); /* Each row in the array is an associative array * of (venue, my_group, day, time, start, end, slots, persons, notes) * and persons is a comma-separated string of ids, like "alex2077291234" */ $shifts = array(); if (sizeof($venue_shifts) > 0) { foreach ($venue_shifts as $venue_shift) { $shifts[] = generate_and_populate_shift($day_id, $venue, $week_of_month, $week_of_year, $day, $venue_shift->get_hours(), ""); } } // makes a new date with these shifts $new_date = new RMHdate($day_id, $venue, $shifts, ""); $dates[] = $new_date; $d++; if ($d > $daysinmonth) { $d = 1; if ($m == 12) { $m = 1; $y++; } else { $m++; } } $day_id = date("y-m-d", mktime(0, 0, 0, $m, $d, $y)); } // creates a new week from the dates $newweek = new Week($dates, $venue, "unpublished"); insert_dbWeeks($newweek); add_log_entry('<a href=\\"personEdit.php?id=' . $_SESSION['_id'] . '\\">' . $_SESSION['f_name'] . ' ' . $_SESSION['l_name'] . '</a> generated a new week: <a href=\\"calendar.php?id=' . $newweek->get_id() . '&edit=true\\">' . $newweek->get_name() . '</a>.'); }
function insert_nonoverlapping($shift) { $other_shifts = get_master_shifts($shift->get_group(), $shift->get_day(), $shift->get_week_no()); foreach ($other_shifts as $other_shift) { if (masterslots_overlap($shift, $oher_shift)) { return false; } } insert_dbMasterSchedule($shift); return true; }
function generate_shifts($day) { //This may have an error because id is trying to pass itself to a new shift - GIOVI $venues = ["garden", "pantry"]; $days = [1 => "Mon", 2 => "Tue", 3 => "Wed", 4 => "Thu", 5 => "Fri", 6 => "Sat", 7 => "Sun"]; $this->shifts = []; /* $master[$i] is an array of * (venue, my_group, day, time, start, end, slots, notes) */ foreach ($venues as $venue) { $master = get_master_shifts($venue, $days[$day]); for ($i = 0; $i < sizeof($master); $i++) { $t = $master[$i]->get_time(); $s = $master[$i]->get_start_time(); $e = $master[$i]->get_end_time(); $this->shifts[$t . $venue] = new Shift($this->id, $s, $e, $venue, $master[$i]->get_slots(), null, null, ""); } } }
function generate_shifts($day, $venue) { $days = array(1 => "Mon", 2 => "Tue", 3 => "Wed", 4 => "Thu", 5 => "Fri", 6 => "Sat", 7 => "Sun"); $this->shifts = array(); $master1 = get_master_shifts($venue, $this->week_of_month, $days[$day]); $master2 = get_master_shifts($venue, $this->week_of_year, $days[$day]); $master = array_merge($master1, $master2); for ($i = 0; $i < sizeof($master); $i++) { // $master[$i] is a MasterScheduleEntry $t = $master[$i]->get_hours(); $this->shifts[$t] = new Shift(substr($this->id, 0, 8) . ":" . $t, $venue, $master[$i]->get_slots(), null, null, "", ""); } }