/** * Adds a RMHDate to the table * If the date already exists, the date is deleted and replaced. */ function insert_dbDates($d) { if (!$d instanceof RMHdate) { die("Invalid argument for dbDates->insert_dbdates function call"); } connect(); $query = "SELECT * FROM dbDates WHERE id =\"" . $d->get_id() . "\""; $result = mysql_query($query); if (mysql_num_rows($result) != 0) { delete_dbDates($d); connect(); } $query = "INSERT INTO dbDates VALUES\n\t\t\t\t(\"" . $d->get_id() . "\",\"" . get_shifts_text($d) . "\",\"" . $d->get_mgr_notes() . "\")"; $result = mysql_query($query); if (!$result) { echo "unable to insert into dbDates: " . $d->get_id() . mysql_error(); mysql_close(); return false; } mysql_close(); $shifts = $d->get_shifts(); foreach ($shifts as $key => $value) { insert_dbShifts($d->get_shift($key)); } return true; }
/** * Adds a {@link BSCAHdate} to the table * If the date already exists, the date is deleted and replaced. */ function insert_dbDates(BSCAHdate $d) { connect(); $query = "SELECT * FROM DATE WHERE DATE_ID =\"" . $d->get_id() . "\""; $result = mysql_query($query); if (!$result) { error_log('ERROR on select in insert_dbDates() ' . mysql_error()); die('Invalid query: ' . mysql_error()); } if (mysql_num_rows($result) != 0) { delete_dbDates($d); connect(); } $query = sprintf('INSERT INTO DATE VALUES ("%s", "%s", "%s", "%s")', $d->get_id(), get_shifts_text($d), $d->get_mgr_notes(), $d->get_projects()); $result = mysql_query($query); if (!$result) { echo "unable to insert into DATE: " . $d->get_id() . mysql_error(); mysql_close(); return false; } mysql_close(); $shifts = $d->get_shifts(); foreach ($shifts as $key => $value) { insert_dbShifts($d->get_shift($key)); } return true; }
/** * Updates a shift in the db by deleting it (if it exists) and then replacing it * * @param $s the shift to update */ function update_dbShifts($s) { error_log("updating SHIFT in database"); if (!$s instanceof Shift) { error_log("Invalid argument for shift->replace_shift function call"); die("Invalid argument for shift->replace_shift function call"); } delete_dbShifts($s); insert_dbShifts($s); return true; }
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"; }