示例#1
0
function amr_process_RDATE($p, $start, $end)
{
    /* RDATE or EXDATE processes  a parsed array.  If the specified event repeats between the given start and
    	 * end times, return one or more nonrepeating date strings in array
    
    		RDATE:19970714T123000Z
    		RDATE:19970714T083000
    		RDATE;TZID=US-EASTERN:19970714T083000
    		RDATE;VALUE=PERIOD:19960403T020000Z/19960403T040000Z,19960404T010000Z/PT3H
    		RDATE;VALUE=DATE:19970101,19970120,19970217,19970421,19970526,19970704,19970901,19971014,19971128,19971129,19971225
    		should be passed as object now?  *** amr check!!
    	 */
    $repeats = array();
    if (is_object($p)) {
        if (isset($_REQUEST['debugexc'])) {
            echo '<br> R or exdate Object passed ' . amr_format_date('Y m j, g:i a P', $p);
        }
        if (amr_falls_between($p, $start, $end)) {
            $repeats[] = $p;
        }
    } else {
        if (is_array($p)) {
            //var_dump($p);
            foreach ($p as $i => $r) {
                if (amr_falls_between($r, $start, $end)) {
                    $repeats[] = $r;
                }
            }
        } else {
            if (isset($_REQUEST['rdebug'])) {
                echo '<br />****Cannot process RDATE - Not an Object, Not an array passed <br />';
                var_dump($p);
            }
            //if (amr_falls_between($p, $start, $end))  $repeats[] = $p;
        }
    }
    //if (isset($_REQUEST['debugexc'])) { echo '<br/>*** Array of repeats '; var_dump($repeats); }
    return $repeats;
}
function amr_constrain_components($events, $start, $end, $limit)
{
    global $amr_limits;
    $newevents = $events;
    /* should we be moving to destination date  */
    if (count($newevents) < 1 or !is_array($newevents)) {
        return false;
    }
    $newevents = apply_filters('amr_events_before_sort', $newevents);
    // used for example to exclude private events
    $newevents = amr_sort_by_key($newevents, 'EventDate');
    $newevents = apply_filters('amr_events_after_sort', $newevents);
    if (ICAL_EVENTS_DEBUG) {
        //var_dump($newevents);
        echo '<br>Sorted  ' . count($newevents) . ' events';
        echo '<br>first ' . $newevents[0]['EventDate']->format('c');
        echo '<br>last ' . $newevents[count($newevents) - 1]['EventDate']->format('c');
        echo '<br>start ' . $start->format('c');
        echo '<br>end   ' . $end->format('c');
        echo '<br>Now constrain them...<br> ';
    }
    $constrained = array();
    $count = 0;
    foreach ($newevents as $k => $event) {
        //
        if (isset($event['EventDate']) and is_object($event['EventDate'])) {
            if (amr_falls_between($event['EventDate'], $start, $end) or isset($event['EndDate']) and (amr_falls_between($event['EndDate'], $start, $end) or amr_falls_between($start, $event['EventDate'], $event['EndDate']))) {
                $constrained[] = $event;
                if (isset($_GET['debugall'])) {
                    echo '<br>Choosing no: ' . $k . ' ' . $event['EventDate']->format('c') . ' ending ' . (isset($event['EndDate']) ? $event['EndDate']->format('c') : ' no end');
                }
                ++$count;
            }
            if (isset($_GET['debugall'])) {
                echo '<br>Not choosing?' . $k . ' ' . $event['EventDate']->format('c') . ' ending ' . (isset($event['EndDate']) ? $event['EndDate']->format('c') : ' no end');
            }
        } else {
            $constrained[] = $event;
            if (isset($_GET['debugall'])) {
                echo '<br>Whats happening?';
                var_dump($event);
            }
        }
        if ($count >= $limit) {
            break;
        }
    }
    if (isset($amr_limits['eventsoffset']) and !empty($amr_limits['eventsoffset'])) {
        if (function_exists('amr_do_events_offset')) {
            $constrained = amr_do_events_offset($constrained);
        }
    }
    $constrained = apply_filters('amr_events_after_sort_and_constrain', $constrained);
    return $constrained;
}