예제 #1
0
/**
 * deletes a date from the table
 */
function delete_dbDates($d)
{
    if (!$d instanceof BSCAHdate) {
        error_log("Invalid argument for shift->remove_date function call");
        die("Invalid argument for shift->remove_date function call");
    }
    connect();
    $query = "DELETE FROM DATE WHERE DATE_ID=\"" . $d->get_id() . "\"";
    $result = mysql_query($query);
    if (!$result) {
        error_log('ERROR on select in delete_dbDates() ' . mysql_error());
        die('Invalid query: ' . mysql_error());
    }
    if (!$result) {
        error_log("unable to delete from DATE: " . $d->get_id() . mysql_error());
        mysql_close();
        return false;
    }
    mysql_close();
    $shifts = $d->get_shifts();
    foreach ($shifts as $key => $value) {
        $s = $d->get_shift($key);
        delete_dbShifts($s);
    }
    return true;
}
예제 #2
0
 function testdbShiftsModule()
 {
     $s1 = new Shift("08-02-25:1-5", "house", 3, array(), array(), "", "");
     $this->assertTrue(insert_dbShifts($s1));
     $this->assertTrue(delete_dbShifts($s1));
     $s2 = new Shift("08-02-25:9-1", "house", 3, array(), array(), "", "");
     $this->assertTrue(insert_dbShifts($s2));
     $s2 = new Shift("08-02-25:9-1", "house", 2, array(), array(), "", "");
     $this->assertTrue(update_dbShifts($s2));
     $shifts[] = $s2;
     $this->assertTrue(delete_dbShifts($s2));
     echo "testdbShifts complete";
 }
예제 #3
0
/**
 * Tries to move a shift to a new start and end time.  New times must
 * not overlap with any other shift on the same date and venue
 * @return false if shift doesn't exist or there's an overlap
 * Otherwise, change the shift in the database and @return true
 */
function move_shift($s, $new_start, $new_end)
{
    // first, see if it exists
    $old_s = select_dbShifts($s->get_id());
    if ($old_s == null) {
        return false;
    }
    // now see if it can be moved by looking at all other shifts for the same date and venue
    $new_s = $s->set_start_end_time($new_start, $new_end);
    $current_shifts = selectDateVenue_dbShifts($s->get_date(), $s->get_venue());
    connect();
    for ($i = 0; $i < mysql_num_rows($current_shifts); ++$i) {
        $same_day_shift = mysql_fetch_row($current_shifts);
        if ($old_s->get_id() == $same_day_shift[0]) {
            // skip its own entry
            continue;
        }
        if (timeslots_overlap($same_day_shift[1], $same_day_shift[2], $new_s->get_start_time(), $new_s->get_end_time())) {
            $s = $old_s;
            mysql_close();
            return false;
        }
    }
    mysql_close();
    // we're good to go
    replace_dbDates($old_s, $new_s);
    delete_dbShifts($old_s);
    return true;
}
예제 #4
0
/**
 * deletes a date from the table
 */
function delete_dbDates($d)
{
    if (!$d instanceof RMHdate) {
        die("Invalid argument for dbShifts->delete_dbDates function call");
    }
    connect();
    $query = "DELETE FROM dbDates WHERE id=\"" . $d->get_id() . "\"";
    $result = mysql_query($query);
    if (!$result) {
        echo "unable to delete from dbDates: " . $d->get_id() . mysql_error();
        mysql_close();
        return false;
    }
    mysql_close();
    $shifts = $d->get_shifts();
    foreach ($shifts as $key => $value) {
        $s = $d->get_shift($key);
        delete_dbShifts($s);
    }
    return true;
}