예제 #1
0
/**
 * 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;
}
예제 #2
0
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>.');
}