function testdbWeeksModule() { //Create two weeks and add them to the database $days1 = array(); for ($i = 9; $i < 16; $i++) { $days1[] = new RMHDate(date('y-m-d', mktime(0, 0, 0, 2, $i, 2015)), "house", array(), ""); } $days2 = array(); for ($i = 16; $i < 23; $i++) { $days2[] = new RMHDate(date('y-m-d', mktime(0, 0, 0, 2, $i, 2015)), "fam", array(), ""); } $w1 = new Week($days1, "house", "archived"); $w2 = new Week($days2, "fam", "unpublished"); $this->assertTrue(insert_dbWeeks($w1)); $this->assertTrue(insert_dbWeeks($w2)); //retrieve the first Week and check its fields $w = get_dbWeeks("02-09-15:house"); $this->assertTrue($w !== false); $this->assertTrue($w->get_status() == "archived"); $this->assertTrue($w->get_venue() == "house"); $a = get_all_dbWeeks("house"); $this->assertEqual($a[0], $w1); //update the second Week by a change of status // $w2 = new Week($days2,"fam","published"); // $this->assertTrue(update_dbWeeks($w2)); // $this->assertEqual(get_dbWeeks($w2->get_id())->get_status(),"published"); //Remove the Weeks from the database $this->assertTrue(delete_dbWeeks($w1)); $this->assertTrue(delete_dbWeeks($w2)); echo "testdbWeeks complete"; }
/** * 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 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 testget_dates_test() { $newWeek = new Week("03-30-14", "Bscah", "Active"); $nd = insert_dbWeeks($newDate); $id = "03-30-14"; echo 'will test get_dates_test</br>'; $result = get_dates_text($dates); if ($result != null) { echo 'select_dbDates failed</br>'; } $res = delete_dbWeeks($newWeek); if ($res == null) { echo 'Delete failed</br>'; } }
/** * Updates a week in the db by deleting it and re-inserting it * * @param $w Week the week to update */ function update_dbWeeks(Week $w) { if (delete_dbWeeks($w)) { return insert_dbWeeks($w); } return false; }
/** * Updates a week in the db by deleting it and re-inserting it * @param $w the week to update */ function update_dbWeeks($w) { if (!$w instanceof Week) { die("Invalid argument for dbWeeks->replace_week function call"); } if (delete_dbWeeks($w)) { return insert_dbWeeks($w); } else { return false; } }