예제 #1
0
/**
 * Inserts a week into the db
 *
 * @param $w Week the week to insert
 */
function insert_dbWeeks(Week $w)
{
    if (!assert_week_format($w)) {
        error_log("ERROR: Your week object did not start on a Sunday or did not have a length of 7 days");
        return false;
    }
    connect();
    $query = sprintf('SELECT * FROM WEEKS WHERE ID=\'%s\'', $w->get_id());
    $result = mysql_query($query);
    if (mysql_num_rows($result) != 0) {
        delete_dbWeeks($w);
        connect();
    }
    $query = sprintf('INSERT INTO WEEKS VALUES("%s", "%s", "%s", %d)', $w->get_id(), get_dates_text($w->get_dates()), $w->get_status(), $w->get_end());
    $result = mysql_query($query);
    mysql_close();
    if (!$result) {
        echo "<br>unable to insert into week: " . $w->get_id() . get_dates_text($w->get_dates()) . $w->get_status() . $w->get_name() . $w->get_end();
        return false;
    } else {
        foreach ($w->get_dates() as $i) {
            insert_dbDates($i);
        }
    }
    return true;
}
예제 #2
0
/**
 * Inserts a week into the db
 * @param $w the week to insert
 */
function insert_dbWeeks($w)
{
    if (!$w instanceof Week) {
        die("Invalid argument for dbWeeks->insert_dbWeeks function call");
    }
    connect();
    $query = "SELECT * FROM dbWeeks WHERE id =\"" . $w->get_id() . "\"";
    $result = mysql_query($query);
    if (mysql_num_rows($result) != 0) {
        delete_dbWeeks($w);
        connect();
    }
    $query = "INSERT INTO dbWeeks VALUES (\"" . $w->get_id() . "\"," . get_dates_text($w->get_dates()) . ",\"" . $w->get_venue() . "\",\"" . $w->get_status() . "\",\"" . $w->get_name() . "\",\"" . $w->get_end() . "\")";
    $result = mysql_query($query);
    mysql_close();
    if (!$result) {
        echo "<br>unable to insert into dbWeeks: " . $w->get_id() . get_dates_text($w->get_dates()) . $w->get_venue() . $w->get_status() . $w->get_name() . $w->get_end();
        return false;
    } else {
        foreach ($w->get_dates() as $i) {
            insert_dbDates($i);
        }
    }
    return true;
}
예제 #3
0
 function testdbDatesModule()
 {
     $my_shifts = array();
     $my_shifts[] = new Shift("10-02-28:9-1", "house", 1, array(), array(), null, "");
     $my_shifts[] = new Shift("10-02-28:1-5", "house", 1, array(), array(), null, "");
     $my_date = new RMHdate("10-02-28", "house", $my_shifts, "");
     $this->assertTrue(insert_dbDates($my_date));
     $this->assertTrue(delete_dbDates($my_date));
     echo "testdbDates complete";
 }
function test_get_shifts_text()
{
    $newDate = new BSCAHdate("01-01-15", "9-11", "notes", []);
    $nd = insert_dbDates($newDate);
    echo 'will test get_shifts_text</br>';
    $result = get_shifts_text($newDate);
    if ($result == null) {
        echo 'get_shifts_text failed</br>';
    } else {
        echo 'get_shifts_text succeeded</br>';
    }
    $res = delete_dbDates($newDate);
    if ($res == null) {
        echo 'Delete failed</br>';
    }
}
예제 #5
0
/**
 * updates a date in the dbDates table
 */
function update_dbDates($d)
{
    if (!$d instanceof BSCAHdate) {
        die("Invalid argument for date->update_dbDates function call");
    }
    delete_dbDates($d);
    insert_dbDates($d);
    return true;
}