Esempio n. 1
0
function parseData($dataString, $defaultIncrement, $decimal = 2, $sign = 0)
{
    $paramArray = explodeString($dataString);
    //see if the values include a range - if it does it will include the word "to"
    $valueArray = array();
    // the new string
    foreach ($paramArray as $string) {
        if (strpos($string, "to")) {
            $valueArray = array_merge($valueArray, parseRange($string, $defaultIncrement, $decimal, $sign));
        } else {
            $valueArray = array_merge($valueArray, (array) $string);
        }
    }
    //print_r($valueArray);
    //sort the values in the array and remove duplicates
    usort($valueArray, "sorter");
    $valueArray = array_unique($valueArray);
    return $valueArray;
}
function parseSlots($daysNode, $timesNode, $roomsNode)
{
    $days = myToArray($daysNode);
    $times = myToArray($timesNode);
    $rooms = myToArray($roomsNode);
    $slots = array();
    for ($i = 0; $i < count($days); $i++) {
        $d = trim($days[$i]);
        $t = trim($times[$i]);
        if (isset($rooms[$i])) {
            $l = preg_replace('/\\s\\s+/', ' ', $rooms[$i]);
            if (strlen($l) === 0) {
                $l = null;
            }
        } else {
            $l = null;
        }
        $r = parseRange($t);
        if (strlen($d) != 1 && $d != "TBA") {
            for ($j = 0; $j < strlen($d); $j++) {
                // NOTE:
                $dayOfWeek = strpos(SINGLE_CHAR_DAY_ENCODING, $d[$j]);
                $slots[] = new TimeSlot($dayOfWeek + 1, $r[0], $r[1], $l);
            }
        } else {
            $slots[] = new TimeSlot($d == "TBA" ? 0 : strpos(SINGLE_CHAR_DAY_ENCODING, $d) + 1, $r[0], $r[1], $l);
        }
    }
    return $slots;
}