예제 #1
0
function insert_dbDates_project(BSCAHdate $d)
{
    connect();
    $query = sprintf('UPDATE DATE SET PROJECTS = "%s" WHERE DATE_ID = "%s"', $d->get_projects(), $d->get_id());
    error_log("in insert_dbDates, query is" . $query);
    $result = mysql_query($query);
    if (!$result) {
        echo "unable to insert into DATE: " . $d->get_id() . mysql_error();
        mysql_close();
        return false;
    }
    mysql_close();
    return true;
}
예제 #2
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;
}
function testConstructor()
{
    $my_shifts[] = new Shift("02-28-10-9-13", "Garden", 1, [], [], "");
    //This may have an error because id is trying to pass itself to a new shift - GIOVI
    $my_project[] = new Project("02-28-10", null, "Food Delivery", 8, 11, 3, null, "notes");
    $test_date = new BSCAHdate("02-28-10", $my_shifts, "manager notes", $my_project);
    $replacement_project = new Project("02-28-14", null, "Truck Delivery", 9, 12, 3, null, "new notes");
    echo "Testing get shifts and get projects" . '</br>';
    $shifts = $test_date->get_shifts();
    $projects = $test_date->get_projects();
    //$replacement_project = new Project("02-28-14", null, "Truck Delivery", 9, 12, 3, null, "new notes");
    foreach ($my_shifts as $value) {
        if ($value instanceof Shift) {
            echo "This is a shift value" . '</br>';
        } else {
            echo "This is suppose to be a shift value" . '</br>';
        }
    }
    foreach ($my_project as $value) {
        if ($value instanceof Project) {
            echo "This is a project value" . '</br>';
        } else {
            echo "This is suppose to be a project value" . '</br>';
        }
    }
    if ($test_date->get_id() == "02-28-10") {
        echo "ID test succedded" . '</br>';
    } else {
        echo "ID test failed" . '</br>';
    }
    if ($test_date->get_day() == "Sun") {
        echo "Day test succedded" . '</br>';
    } else {
        echo "Day test failed" . '</br>';
    }
    if ($test_date->get_day_of_week() == 7) {
        echo "Day of week test succedded" . '</br>';
    } else {
        echo "Day of week test failed" . '</br>';
    }
    if ($test_date->get_day_of_year() == 59) {
        echo "Day of year test succedded" . '</br>';
    } else {
        echo "Day of Year test failed" . '</br>';
    }
    if ($test_date->get_year() == 2010) {
        echo "Year test succedded" . '</br>';
    } else {
        echo "Year test failed" . '</br>';
    }
    if ($test_date->get_dom() == 28) {
        echo "Day of Month test succedded" . '</br>';
    } else {
        echo "Day of Month test failed" . '</br>';
    }
    if ($test_date->get_mgr_notes() == "manager notes") {
        echo "Manager Notes  test succedded" . '</br>';
    } else {
        echo "Manager notes test failed" . '</br>';
    }
    if ($test_date->get_name() == "February 28, 2010") {
        echo "Name test succedded" . '</br>';
    } else {
        echo "Name test failed" . '</br>';
    }
    if ($test_date->get_num_projects() == 1) {
        echo "Number of projects test succedded" . '</br>';
    } else {
        echo "Number of projects test failed" . '</br>';
    }
    //$this->assertTrue($my_date->get_project($key) ==);
    //Tests the method of $my_date->get_projects() to see if each element mateches the elments in $my_project
    if ($projects == $my_project) {
        echo "Projects test succedded" . '</br>';
    } else {
        echo "Projects test failed" . '</br>';
    }
    //Tests the method of $my_date->get_shifts() to see if each element mateches the elments in $my_shifts
    if ($shifts == $my_shifts) {
        echo "Shifts test succedded" . '</br>';
    } else {
        echo "Shifts test failed" . '</br>';
    }
    /**if($test_date->get_shift_id() == "02-28-10-9-13")
       {
           echo "Shift ID test succedded" . '</br>';
       }
       else
       {
            echo "Shift ID test failed" . '</br>';
       }
       **/
    //$this->assertTrue($my_date->get_shift($key) == "Tue");
    //This test if $my_date->replace_project actually replaces the project
    //$test_date->replace_project($projects, $replacement_project);
    /**if($test_date->get_projects() == $replacement_project)
       {
           echo "Replace project test succedded" . '</br>';
       }
       else
       {
            echo "Replace project test failed" . '</br>';
       }
       **/
    $test_date->set_mgr_notes("new manager notes");
    if ($test_date->get_mgr_notes() == "new manager notes") {
        echo "Set Manager Notes test succedded" . '</br>';
    } else {
        echo "Set Manger Notes test failed" . '</br>';
    }
    echo "testBSCAHdate complete";
}