Exemplo n.º 1
0
 /**
  * @expectedException Respect\Validation\Exceptions\ValidationException
  * @expectedExceptionMessage Exception for ElseNotValid:check() method
  */
 public function testShouldThrowExceptionForTheElseRuleWhenTheIfRuleIsNotValidAndTheElseRuleIsNotOnCheckMethod()
 {
     $if = $this->getRuleMock(false);
     $then = $this->getRuleMock(false);
     $else = $this->getRuleMock(false, 'ElseNotValid');
     $rule = new When($if, $then, $else);
     $rule->check('');
 }
 protected function decodeRecurrence()
 {
     $recurr = $this->event->getRecurrence();
     if ($recurr) {
         foreach ($recurr as $recurrence) {
             $when = new When();
             $rule = substr($recurrence, 6);
             $when->recur($this->event->getStart()->dateTime)->rrule($rule);
             $this->recurrences[] = $when;
         }
     }
 }
Exemplo n.º 3
0
function generate_tasks($verbose = true)
{
    include_once 'when/When.php';
    $mysqli = connectdb(true);
    $mysqli2 = connectdb(true);
    $mysqli3 = connectdb(true);
    $start = new DateTime();
    $stmt = $mysqli->prepare("Select TaskID, Title, Details, RRule, Time FROM tasks_master WHERE Active='Y'");
    $stmt->execute();
    $stmt->bind_result($rtaskid, $rtitle, $rdetails, $rrrule, $rtime);
    while ($stmt->fetch()) {
        $r = new When();
        $r->recur($start)->rrule($rrrule . ";COUNT=30");
        if ($verbose) {
            echo $rtaskid . " " . $rtitle . " " . $rrrule . " " . $rdetails . "<br />";
        }
        while ($result = $r->next()) {
            if (strtotime($result->format('Y-m-d')) < strtotime('+30 days')) {
                $nextime = $result->format('Y-m-d') . ' ' . $rtime;
                if ($verbose) {
                    echo $nextime . " ";
                }
                $checkexistingstmt = $mysqli3->query("SELECT TaskWorkingID FROM tasks_working WHERE TaskID={$rtaskid} AND Scheduled='{$nextime}'");
                if ($checkexistingstmt->num_rows > 0) {
                    if ($verbose) {
                        echo " - Already exists... skipping!!<br />";
                    }
                } else {
                    $statement = $mysqli2->prepare("INSERT INTO tasks_working (TaskID, Scheduled) Values (?,?)");
                    if (!$statement->bind_param('is', $rtaskid, $nextime)) {
                        if ($verbose) {
                            echo "Binding parameters failed: (" . $statement->errno . ") " . $statement->error;
                        }
                    }
                    if (!$statement->execute()) {
                        if ($verbose) {
                            echo " - Executing query failed: (" . $statement->errno . ") " . $statement->error;
                        }
                    } else {
                        if ($verbose) {
                            echo " - Sucessfully added task<br />";
                        }
                    }
                }
            }
        }
    }
    $mysqli3->close();
    $mysqli2->close();
    $mysqli->close();
}
Exemplo n.º 4
0
 protected function takeChildFromDOM($child)
 {
     $absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
     switch ($absoluteNodeName) {
         case $this->lookupNamespace('gd') . ':' . 'when':
             $when = new When();
             $when->transferFromDOM($child);
             $this->_when = $when;
             break;
         default:
             parent::takeChildFromDOM($child);
             break;
     }
 }
Exemplo n.º 5
0
 /** @test */
 public function shouldReturnAPromiseForAPromisedRejectionValue()
 {
     $d = new Deferred();
     $mock = $this->createCallableMock();
     $mock->expects($this->once())->method('__invoke')->with($this->identicalTo(1));
     // Both the returned promise, and the deferred's own promise should
     // be rejected with the same value
     $d->resolver()->resolve(When::reject(1))->then($this->expectCallableNever(), $mock);
 }
Exemplo n.º 6
0
 /** @test */
 public function shouldRejectARejectedPromise()
 {
     $expected = 123;
     $d = new Deferred();
     $d->reject($expected);
     $mock = $this->createCallableMock();
     $mock->expects($this->once())->method('__invoke')->with($this->identicalTo($expected));
     When::reject($d->promise())->then($this->expectCallableNever(), $mock);
 }
Exemplo n.º 7
0
 /** @test */
 public function shouldNotRelyOnArryIndexesWhenUnwrappingToASingleResolutionValue()
 {
     $mock = $this->createCallableMock();
     $mock->expects($this->once())->method('__invoke')->with($this->identicalTo(2));
     $d1 = new Deferred();
     $d2 = new Deferred();
     When::any(array('abc' => $d1->promise(), 1 => $d2->promise()), $mock);
     $d2->resolve(2);
     $d1->resolve(1);
 }
Exemplo n.º 8
0
 /** @test */
 public function shouldSupportDeepNestingInPromiseChains()
 {
     $d = new Deferred();
     $d->resolve(false);
     $result = When::resolve(When::resolve($d->then(function ($val) {
         $d = new Deferred();
         $d->resolve($val);
         $identity = function ($val) {
             return $val;
         };
         return When::resolve($d->then($identity))->then(function ($val) {
             return !$val;
         });
     })));
     $mock = $this->createCallableMock();
     $mock->expects($this->once())->method('__invoke')->with($this->identicalTo(true));
     $result->then($mock);
 }
Exemplo n.º 9
0
 public function valid()
 {
     if ($this->cache === true) {
         // check to see if the current position has already been stored
         if (!empty($this->results[$this->position])) {
             return isset($this->results[$this->position]);
         } elseif ($next_date = parent::next()) {
             $this->results[] = $next_date;
             return isset($next_date);
         }
     } else {
         // check to see if there is another result and set that as the result
         if ($next_date = parent::next()) {
             $this->result = $next_date;
             return isset($this->result);
         }
     }
     // end the foreach loop when all options are exhausted
     return false;
 }
Exemplo n.º 10
0
 /**
  * changing only WKST from MO to SU, yields different results...
  * DTSTART;TZID=America/New_York:19970805T090000
  * RRULE:FREQ=WEEKLY;INTERVAL=2;COUNT=4;BYDAY=TU,SU;WKST=SU
  */
 function testThirtyTwo()
 {
     $results[] = new DateTime('1997-08-05 09:00:00');
     $results[] = new DateTime('1997-08-17 09:00:00');
     $results[] = new DateTime('1997-08-19 09:00:00');
     $results[] = new DateTime('1997-08-31 09:00:00');
     $r = new When();
     $r->recur('19970805T090000')->rrule('FREQ=WEEKLY;INTERVAL=2;COUNT=4;BYDAY=TU,SU;WKST=SU');
     foreach ($results as $result) {
         $this->assertEquals($result, $r->next());
     }
 }
Exemplo n.º 11
0
 /**
  * Every year on the -1th, -100th, and -200th day for 5 occurrences (checked via google calendar import below)
  * BEGIN:VCALENDAR
  * PRODID:-//Google Inc//Google Calendar 70.9054//EN
  * VERSION:2.0
  * CALSCALE:GREGORIAN
  * METHOD:PUBLISH
  * BEGIN:VTIMEZONE
  * TZID:America/New_York
  * X-LIC-LOCATION:America/New_York
  * BEGIN:DAYLIGHT
  * TZOFFSETFROM:-0500
  * TZOFFSETTO:-0400
  * TZNAME:EDT
  * DTSTART:19700308T020000
  * RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=2SU
  * END:DAYLIGHT
  * BEGIN:STANDARD
  * TZOFFSETFROM:-0400
  * TZOFFSETTO:-0500
  * TZNAME:EST
  * DTSTART:19701101T020000
  * RRULE:FREQ=YEARLY;BYMONTH=11;BYDAY=1SU
  * END:STANDARD
  * END:VTIMEZONE
  * BEGIN:VEVENT
  * DTSTART;VALUE=DATE:20101231
  * RRULE:FREQ=YEARLY;COUNT=5;BYYEARDAY=-1,-100,-200
  * DTSTAMP:20101231T090000
  * CREATED:20101231T090000
  * DESCRIPTION:
  * LAST-MODIFIED:20101231T090000
  * LOCATION:
  * SEQUENCE:2
  * STATUS:CONFIRMED
  * SUMMARY:testing yearly event
  * TRANSP:TRANSPARENT
  * END:VEVENT
  * END:VCALENDAR
  */
 function testTwentyFour()
 {
     $results[] = new DateTime('2010-12-31 09:00:00');
     $results[] = new DateTime('2010-09-23 09:00:00');
     $results[] = new DateTime('2010-06-15 09:00:00');
     $results[] = new DateTime('2011-12-31 09:00:00');
     $results[] = new DateTime('2011-09-23 09:00:00');
     $r = new When();
     $r->recur('20101231T090000')->rrule('FREQ=YEARLY;COUNT=5;BYYEARDAY=-1,-100,-200');
     foreach ($results as $result) {
         $this->assertEquals($result, $r->next());
     }
 }
Exemplo n.º 12
0
 /**
  * Every day in January, for 3 years:
  * DTSTART;TZID=America/New_York:19980101T090000
  * RRULE:FREQ=DAILY;UNTIL=20000131T140000Z;BYMONTH=1
  */
 function testThirtySeven()
 {
     $results[] = new DateTime('1998-01-01 09:00:00');
     $results[] = new DateTime('1998-01-02 09:00:00');
     $results[] = new DateTime('1998-01-03 09:00:00');
     $results[] = new DateTime('1998-01-04 09:00:00');
     $results[] = new DateTime('1998-01-05 09:00:00');
     $results[] = new DateTime('1998-01-06 09:00:00');
     $results[] = new DateTime('1998-01-07 09:00:00');
     $results[] = new DateTime('1998-01-08 09:00:00');
     $results[] = new DateTime('1998-01-09 09:00:00');
     $results[] = new DateTime('1998-01-10 09:00:00');
     $results[] = new DateTime('1998-01-11 09:00:00');
     $results[] = new DateTime('1998-01-12 09:00:00');
     $results[] = new DateTime('1998-01-13 09:00:00');
     $results[] = new DateTime('1998-01-14 09:00:00');
     $results[] = new DateTime('1998-01-15 09:00:00');
     $results[] = new DateTime('1998-01-16 09:00:00');
     $results[] = new DateTime('1998-01-17 09:00:00');
     $results[] = new DateTime('1998-01-18 09:00:00');
     $results[] = new DateTime('1998-01-19 09:00:00');
     $results[] = new DateTime('1998-01-20 09:00:00');
     $results[] = new DateTime('1998-01-21 09:00:00');
     $results[] = new DateTime('1998-01-22 09:00:00');
     $results[] = new DateTime('1998-01-23 09:00:00');
     $results[] = new DateTime('1998-01-24 09:00:00');
     $results[] = new DateTime('1998-01-25 09:00:00');
     $results[] = new DateTime('1998-01-26 09:00:00');
     $results[] = new DateTime('1998-01-27 09:00:00');
     $results[] = new DateTime('1998-01-28 09:00:00');
     $results[] = new DateTime('1998-01-29 09:00:00');
     $results[] = new DateTime('1998-01-30 09:00:00');
     $results[] = new DateTime('1998-01-31 09:00:00');
     $results[] = new DateTime('1999-01-01 09:00:00');
     $results[] = new DateTime('1999-01-02 09:00:00');
     $results[] = new DateTime('1999-01-03 09:00:00');
     $results[] = new DateTime('1999-01-04 09:00:00');
     $results[] = new DateTime('1999-01-05 09:00:00');
     $results[] = new DateTime('1999-01-06 09:00:00');
     $results[] = new DateTime('1999-01-07 09:00:00');
     $results[] = new DateTime('1999-01-08 09:00:00');
     $results[] = new DateTime('1999-01-09 09:00:00');
     $results[] = new DateTime('1999-01-10 09:00:00');
     $results[] = new DateTime('1999-01-11 09:00:00');
     $results[] = new DateTime('1999-01-12 09:00:00');
     $results[] = new DateTime('1999-01-13 09:00:00');
     $results[] = new DateTime('1999-01-14 09:00:00');
     $results[] = new DateTime('1999-01-15 09:00:00');
     $results[] = new DateTime('1999-01-16 09:00:00');
     $results[] = new DateTime('1999-01-17 09:00:00');
     $results[] = new DateTime('1999-01-18 09:00:00');
     $results[] = new DateTime('1999-01-19 09:00:00');
     $results[] = new DateTime('1999-01-20 09:00:00');
     $results[] = new DateTime('1999-01-21 09:00:00');
     $results[] = new DateTime('1999-01-22 09:00:00');
     $results[] = new DateTime('1999-01-23 09:00:00');
     $results[] = new DateTime('1999-01-24 09:00:00');
     $results[] = new DateTime('1999-01-25 09:00:00');
     $results[] = new DateTime('1999-01-26 09:00:00');
     $results[] = new DateTime('1999-01-27 09:00:00');
     $results[] = new DateTime('1999-01-28 09:00:00');
     $results[] = new DateTime('1999-01-29 09:00:00');
     $results[] = new DateTime('1999-01-30 09:00:00');
     $results[] = new DateTime('1999-01-31 09:00:00');
     $results[] = new DateTime('2000-01-01 09:00:00');
     $results[] = new DateTime('2000-01-02 09:00:00');
     $results[] = new DateTime('2000-01-03 09:00:00');
     $results[] = new DateTime('2000-01-04 09:00:00');
     $results[] = new DateTime('2000-01-05 09:00:00');
     $results[] = new DateTime('2000-01-06 09:00:00');
     $results[] = new DateTime('2000-01-07 09:00:00');
     $results[] = new DateTime('2000-01-08 09:00:00');
     $results[] = new DateTime('2000-01-09 09:00:00');
     $results[] = new DateTime('2000-01-10 09:00:00');
     $results[] = new DateTime('2000-01-11 09:00:00');
     $results[] = new DateTime('2000-01-12 09:00:00');
     $results[] = new DateTime('2000-01-13 09:00:00');
     $results[] = new DateTime('2000-01-14 09:00:00');
     $results[] = new DateTime('2000-01-15 09:00:00');
     $results[] = new DateTime('2000-01-16 09:00:00');
     $results[] = new DateTime('2000-01-17 09:00:00');
     $results[] = new DateTime('2000-01-18 09:00:00');
     $results[] = new DateTime('2000-01-19 09:00:00');
     $results[] = new DateTime('2000-01-20 09:00:00');
     $results[] = new DateTime('2000-01-21 09:00:00');
     $results[] = new DateTime('2000-01-22 09:00:00');
     $results[] = new DateTime('2000-01-23 09:00:00');
     $results[] = new DateTime('2000-01-24 09:00:00');
     $results[] = new DateTime('2000-01-25 09:00:00');
     $results[] = new DateTime('2000-01-26 09:00:00');
     $results[] = new DateTime('2000-01-27 09:00:00');
     $results[] = new DateTime('2000-01-28 09:00:00');
     $results[] = new DateTime('2000-01-29 09:00:00');
     $results[] = new DateTime('2000-01-30 09:00:00');
     $results[] = new DateTime('2000-01-31 09:00:00');
     $r = new When();
     $r->recur('19980101T090000', 'daily')->until('20000131T140000')->bymonth(array(1));
     foreach ($results as $result) {
         $this->assertEquals($result, $r->next());
     }
 }
Exemplo n.º 13
0
 public static function reduce($promisesOrValues, $reduceFunc, $initialValue = null)
 {
     return When::resolve($promisesOrValues)->then(function ($array) use($reduceFunc, $initialValue) {
         if (!is_array($array)) {
             $array = array();
         }
         $total = count($array);
         $i = 0;
         // Wrap the supplied $reduceFunc with one that handles promises and then
         // delegates to the supplied.
         $wrappedReduceFunc = function ($current, $val) use($reduceFunc, $total, &$i) {
             return When::resolve($current)->then(function ($c) use($reduceFunc, $total, &$i, $val) {
                 return When::resolve($val)->then(function ($value) use($reduceFunc, $total, &$i, $c) {
                     return call_user_func($reduceFunc, $c, $value, $i++, $total);
                 });
             });
         };
         return array_reduce($array, $wrappedReduceFunc, $initialValue);
     });
 }
Exemplo n.º 14
0
 /** @test */
 public function shouldResolveToEmptyArrayWhenInputPromiseDoesNotResolveToArray()
 {
     $mock = $this->createCallableMock();
     $mock->expects($this->once())->method('__invoke')->with($this->identicalTo(array()));
     When::some(When::resolve(1), 1, $mock);
 }
Exemplo n.º 15
0
 function getAllEventsOfRecurringEvent($obj)
 {
     $events = array();
     $event = array();
     $event["etag"] = $obj->getEtag();
     $event["url"] = $obj->getUrl();
     $event["eventgroupid"] = 0;
     $props = $obj->getBaseComponent()->getProperties();
     $xDateArr = array();
     $repeated = false;
     foreach ($props as $prop) {
         switch ($prop->name) {
             case "SUMMARY":
                 $event["summary"] = $prop->content;
                 break;
             case "DTSTART":
                 $event["dtstart"] = $prop->content;
                 $event["dtstartzone"] = isset($prop->parameters["TZID"]) ? $prop->parameters["TZID"] : "";
                 break;
             case "DTEND":
                 $event["dtend"] = $prop->content;
                 $event["dtendzone"] = isset($prop->parameters["TZID"]) ? $prop->parameters["TZID"] : "";
                 break;
             case "RRULE":
                 $event["rrule"] = $prop->content;
                 if (!empty($prop->content)) {
                     $repeated = true;
                 }
                 $start = new When();
                 $start->recur($event["dtstart"])->rrule($event["rrule"]);
                 $end = new When();
                 $end->recur($event["dtend"])->rrule($event["rrule"]);
                 break;
             case "LOCATION":
                 $event["location"] = $prop->content;
                 break;
             case "DESCRIPTION":
                 $event["description"] = $prop->content;
                 break;
             case "UID":
                 $event["uid"] = $prop->content;
                 break;
             case "EXDATE":
                 $event["exdate"][] = $prop->content;
                 break;
             case "RECURRENCE-ID":
                 $event["recurrence-id"] = $prop->content;
                 $repeated = false;
                 break;
         }
     }
     if ($repeated) {
         $tempEtag = $event['url'];
         $maxRepeatLimit = CalendarManager::MAX_REPEAT_LIMIT;
         for ($i = 0; $i < $maxRepeatLimit; $i++) {
             $sDate = $start->next();
             if (!is_object($sDate)) {
                 break;
             }
             $event['dtstart'] = $sDate->format("Ymd\\THis\\Z");
             $eDate = $end->next();
             if (!is_object($eDate)) {
                 break;
             }
             $event['dtend'] = $eDate->format("Ymd\\THis\\Z");
             $event["eventgroupid"] = 1;
             $event["url"] = $tempEtag . '_' . $i;
             // we appending '_$i' because in case of repeated eevents there is same id. to show event there should be different id.
             $events[] = $event;
         }
     } else {
         $events[] = $event;
     }
     return $events;
 }
Exemplo n.º 16
0
 public static function decodeRepeat($repeat, $start, $end)
 {
     date_default_timezone_set('UTC');
     require_once ROOTPATH . '/plugins/when/When.php';
     $r = new When();
     if ($repeat['frequency'] === 'none') {
         return array();
     }
     //Nao deve ser usando o horário da repeticao pois nela contem apenas o dias,
     //deve se recuperar o horário do evento para um correto calculo.
     if (max($start, $repeat['startTime']) != $repeat['startTime']) {
         $time = new DateTime('@' . (int) ($repeat['startTime'] / 1000), new DateTimeZone('UTC'));
         $hoursOcurrence = new DateTime('@' . (int) ($start / 1000), new DateTimeZone('UTC'));
         $hoursOcurrence = $hoursOcurrence->format('H');
         $diffTime = ($time->format('H') - $hoursOcurrence) * 3600000 + $time->format('i') * 60000;
         $start = new DateTime('@' . (int) (($start + $diffTime) / 1000), new DateTimeZone('UTC'));
     } else {
         $start = new DateTime('@' . (int) (max($start, $repeat['startTime']) / 1000), new DateTimeZone('UTC'));
     }
     foreach ($repeat as $rule => $value) {
         if (!isset($value) || !$value || $value === "0") {
             continue;
         }
         switch (strtolower($rule)) {
             case "starttime":
                 break;
             case "frequency":
                 $r->recur($start, $value);
                 break;
             case "endtime":
                 $r->until(new DateTime('@' . (int) ($value / 1000)));
                 break;
             case "count":
             case "interval":
             case "wkst":
                 $r->{$rule}($value);
                 break;
             default:
                 $r->{$rule}(!is_array($value) ? explode(',', $value) : $value);
                 break;
         }
     }
     $return = array();
     while ($result = $r->next()) {
         $u = $result->format('U') * 1000;
         if ($u > $end) {
             //data da repetição atual maior que a data final da busca do usuario ?
             break;
         }
         $return[] = $u;
     }
     return $return;
 }
Exemplo n.º 17
0
 protected function createIcal($data, $params = false)
 {
     $ical = new icalCreatorVcalendar();
     $ical->setProperty('method', isset($params['method']) ? $params['method'] : 'PUBLISH');
     /*
      * Seta propiedades obrigatorias para alguns softwares (Outlook)
      */
     $ical->setProperty('x-wr-calname', 'Calendar Expresso');
     $ical->setProperty('X-WR-CALDESC', 'Calendar Expresso');
     $ical->setProperty('X-WR-TIMEZONE', $params['X-WR-TIMEZONE']);
     foreach ($data as $i => $v) {
         switch ($v['type']) {
             case EVENT_ID:
                 $vevent = $ical->newComponent('vevent');
                 $vevent->setProperty('summary', $v['summary']);
                 $vevent->setProperty('description', isset($v['description']) ? $v['description'] : '');
                 $vevent->setProperty('location', $v['location']);
                 $vevent->setProperty('tranp', isset($v['tranparent']) && $v['tranparent'] == TRANSP_TRANSPARENT ? 'TRANSPARENT' : 'OPAQUE');
                 $timezone = new DateTimeZone('UTC');
                 $apTimezone = self::nomalizeTZID(isset($v['timezone']) && $v['timezone'] != 'null' ? $v['timezone'] : $params['defaultTZI']);
                 $apTimezoneOBJ = new DateTimeZone($apTimezone);
                 $sTime = new DateTime('@' . (int) ($v['startTime'] / 1000), $timezone);
                 $sTime->setTimezone($apTimezoneOBJ);
                 $eTime = new DateTime('@' . (int) ($v['endTime'] / 1000), $timezone);
                 $eTime->setTimezone($apTimezoneOBJ);
                 if (isset($v['repeat']) && (isset($v['repeat']['frequency']) && $v['repeat']['frequency'] && $v['repeat']['frequency'] != 'none')) {
                     $vevent->setProperty('rrule', $this->formatIcalRepeat($v['repeat']));
                 }
                 $vevent->setProperty('dtstamp', array('timestamp' => $v['dtstamp'] / 1000));
                 if (isset($v['allDay']) && $v['allDay'] == 1) {
                     $vevent->setProperty('dtstart', $sTime->format(DATE_RFC822), array("VALUE" => "DATE"));
                     $vevent->setProperty('X-MICROSOFT-CDO-ALLDAYEVENT', 'TRUE');
                     $vevent->setProperty('dtend', $eTime->format(DATE_RFC822), array("VALUE" => "DATE"));
                     $vevent->setProperty('X-MICROSOFT-CDO-ALLDAYEVENT', 'TRUE');
                 } else {
                     $vevent->setProperty('dtstart', $sTime->format(DATE_RFC822), array('TZID' => $apTimezone));
                     $vevent->setProperty('X-MICROSOFT-CDO-ALLDAYEVENT', 'FALSE');
                     $vevent->setProperty('dtend', $eTime->format(DATE_RFC822), array('TZID' => $apTimezone));
                     $vevent->setProperty('X-MICROSOFT-CDO-ALLDAYEVENT', 'FALSE');
                 }
                 if (isset($v['participants']) && is_array($v['participants']) && count($v['participants']) > 0) {
                     $participants = $v['participants'];
                 } else {
                     $participants = Controller::find(array('concept' => 'participant'), false, array('filter' => array('=', 'schedulable', $v['id'])));
                 }
                 if (is_array($participants) && count($participants) > 0) {
                     foreach ($participants as $ii => $vv) {
                         if (isset($participants[$ii]['user']) && !is_array($participants[$ii]['user'])) {
                             if ($vv['isExternal'] == 1) {
                                 $participants[$ii]['user'] = Controller::read(array('concept' => 'user', 'id' => $vv['user'], 'service' => 'PostgreSQL'));
                             } else {
                                 $participants[$ii]['user'] = Controller::read(array('concept' => 'user', 'id' => $vv['user']));
                             }
                         }
                         if ($participants[$ii]['user']['id'] == Config::me('uidNumber')) {
                             $alarms = isset($participants[$ii]['alarms']) ? $participants[$ii]['alarms'] : Controller::find(array('concept' => 'alarm'), null, array('filter' => array('AND', array('=', 'participant', $vv['id']), array('=', 'schedulable', $v['id']))));
                             if (is_array($alarms)) {
                                 self::createAlarms($alarms, $vevent);
                             }
                         }
                     }
                 }
                 if (isset($v['participants']) && is_array($v['participants']) && count($v['participants']) > 0) {
                     $this->createAttendee($v['participants'], $vevent);
                 }
                 if (isset($v['attachments']) && is_array($v['attachments']) && count($v['attachments']) > 0) {
                     $this->createAttachment($v['attachments'], $vevent);
                 }
                 $vevent->setProperty('uid', $v['uid']);
                 $timezoneDayligth = Controller::read(array('concept' => 'timezones'), null, array('filter' => array('=', 'tzid', $apTimezone)));
                 if (!empty($timezoneDayligth) && count($timezoneDayligth) > 0) {
                     if (array_key_exists(0, $timezoneDayligth)) {
                         $timezoneDayligth = $timezoneDayligth[0];
                     }
                     date_default_timezone_set('UTC');
                     require_once ROOTPATH . '/plugins/when/When.php';
                     $r = new When();
                     $start = new DateTime('1970-01-01 ' . $timezoneDayligth['standardDtstart']);
                     $r = new When();
                     $r->recur($start, $timezoneDayligth['standardFrequency'])->until($start->modify('+1 years'))->bymonth(array($timezoneDayligth['standardBymonth']))->byday(array($timezoneDayligth['daylightByday']));
                     $date = $r->next();
                     $timezone = $ical->newComponent('vtimezone');
                     $timezone->setProperty('tzid', $apTimezone);
                     $standard = $timezone->newComponent("standard");
                     $standard->setProperty("tzoffsetfrom", $timezoneDayligth['standardFrom']);
                     $standard->setProperty("tzoffsetto", $timezoneDayligth['standardTo']);
                     $standard->setProperty("dtstart", $date->format(DATE_RFC822), array("VALUE" => "DATE"));
                     $rrule = array('FREQ' => $timezoneDayligth['standardFrequency'], 'BYMONTH' => $timezoneDayligth['standardBymonth'], 'BYday' => array(preg_replace("/[^0-9]/", "", $timezoneDayligth['standardByday']), "DAY" => preg_replace("/[^a-zA-Z\\s]/", "", $timezoneDayligth['standardByday'])));
                     $standard->setProperty('rrule', $rrule);
                     $daylight = $timezone->newComponent("daylight");
                     $daylight->setProperty("tzoffsetfrom", $timezoneDayligth['daylightFrom']);
                     $daylight->setProperty("tzoffsetto", $timezoneDayligth['daylightTo']);
                     $start = new DateTime('1970-01-01 ' . $timezoneDayligth['daylightDtstart']);
                     $r->recur($start, $timezoneDayligth['daylightFrequency'])->until($start->modify('+1 years'))->bymonth(array($timezoneDayligth['daylightBymonth']))->byday(array($timezoneDayligth['daylightByday']));
                     $date = $r->next();
                     $daylight->setProperty("dtstart", $date->format(DATE_RFC822), array("VALUE" => "DATE"));
                     $rrule = array('FREQ' => $timezoneDayligth['daylightFrequency'], 'BYMONTH' => $timezoneDayligth['daylightBymonth'], 'BYday' => array(preg_replace("/[^0-9]/", "", $timezoneDayligth['daylightByday']), "DAY" => preg_replace("/[^a-zA-Z\\s]/", "", $timezoneDayligth['daylightByday'])));
                     $daylight->setProperty('rrule', $rrule);
                 }
                 break;
             case TODO_ID:
                 $todo = $ical->newComponent('todo');
                 $todo->setProperty('summary', $v['summary']);
                 $todo->setProperty('description', isset($v['description']) ? $v['description'] : '');
                 $todo->setProperty('priority', $v['priority']);
                 $todo->setProperty('percent-complete', $v['percentage']);
                 $todo->setProperty('status', $this->_getStatusTodo($v['status']));
                 $timezone = new DateTimeZone('UTC');
                 $apTimezone = self::nomalizeTZID(isset($v['timezone']) && $v['timezone'] != 'null' ? $v['timezone'] : $params['defaultTZI']);
                 $apTimezoneOBJ = new DateTimeZone($apTimezone);
                 $sTime = new DateTime('@' . (int) ($v['startTime'] / 1000), $timezone);
                 $sTime->setTimezone($apTimezoneOBJ);
                 $eTime = new DateTime('@' . (int) ($v['endTime'] / 1000), $timezone);
                 $eTime->setTimezone($apTimezoneOBJ);
                 $todo->setProperty('dtstamp', array('timestamp' => $v['dtstamp'] / 1000));
                 if (isset($v['allDay']) && $v['allDay'] == 1) {
                     $todo->setProperty('dtstart', $sTime->format(DATE_RFC822), array("VALUE" => "DATE"));
                     $todo->setProperty('dtend', $eTime->format(DATE_RFC822), array("VALUE" => "DATE"));
                     //$todo->setProperty('X-MICROSOFT-CDO-ALLDAYEVENT', 'TRUE');
                 } else {
                     $todo->setProperty('dtstart', $sTime->format(DATE_RFC822), array('TZID' => $apTimezone));
                     $todo->setProperty('dtend', $eTime->format(DATE_RFC822), array('TZID' => $apTimezone));
                     //$todo->setProperty('X-MICROSOFT-CDO-ALLDAYEVENT', 'FALSE');
                 }
                 if (isset($v['due']) && $v['due'] != '' && (int) $v['due'] > 0) {
                     $dueTime = new DateTime('@' . (int) ($v['due'] / 1000), $timezone);
                     $dueTime->setTimezone($apTimezoneOBJ);
                     $todo->setProperty('due', $dueTime->format(DATE_RFC822), array('TZID' => $apTimezone));
                     $todo->setProperty('dueTime', $dueTime->format(DATE_RFC822), array('TZID' => $apTimezone));
                 }
                 if (isset($v['participants']) && is_array($v['participants']) && count($v['participants']) > 0) {
                     $participants = $v['participants'];
                 } else {
                     $participants = Controller::find(array('concept' => 'participant'), false, array('filter' => array('=', 'schedulable', $v['id'])));
                 }
                 if (is_array($participants) && count($participants) > 0) {
                     foreach ($participants as $ii => $vv) {
                         if (isset($participants[$ii]['user']) && !is_array($participants[$ii]['user'])) {
                             if ($vv['isExternal'] == 1) {
                                 $participants[$ii]['user'] = Controller::read(array('concept' => 'user', 'id' => $vv['user'], 'service' => 'PostgreSQL'));
                             } else {
                                 $participants[$ii]['user'] = Controller::read(array('concept' => 'user', 'id' => $vv['user']));
                             }
                         }
                         if ($participants[$ii]['user']['id'] == Config::me('uidNumber')) {
                             $alarms = isset($participants[$ii]['alarms']) ? $participants[$ii]['alarms'] : Controller::find(array('concept' => 'alarm'), null, array('filter' => array('AND', array('=', 'participant', $vv['id']), array('=', 'schedulable', $v['id']))));
                             if (is_array($alarms)) {
                                 self::createAlarms($alarms, $todo);
                             }
                         }
                     }
                 }
                 if (isset($v['participants']) && is_array($v['participants']) && count($v['participants']) > 0) {
                     $this->createAttendee($v['participants'], $todo);
                 }
                 if (isset($v['attachments']) && is_array($v['attachments']) && count($v['attachments']) > 0) {
                     $this->createAttachment($v['attachments'], $todo);
                 }
                 $todo->setProperty('uid', $v['uid']);
                 break;
             default:
                 break;
         }
     }
     return $ical->createCalendar();
 }
Exemplo n.º 18
0
/**
 * If the event is recurring, this function calculates the best
 * possible end date to use for the series. It will attempt to calculate
 * an end date from the RRULE if possible, and will fall back to the PHP
 * max date otherwise. The generateInstances function will still limit
 * the results regardless. For non-recurring events, it simply returns
 * the existing end date value as-is.
 */
function calculateEndDate($event)
{
    global $date_format, $mappings;
    $end = $event[$mappings['end_date']];
    $rrule = $event[$mappings['rrule']];
    $isRecurring = isset($rrule) && $rrule !== '';
    if ($isRecurring) {
        $max_date = new DateTime('9999-12-31');
        $recurrence = new When();
        $recurrence->rrule($rrule);
        if (isset($recurrence->end_date) && $recurrence->end_date < $max_date) {
            // The RRULE includes an explicit end date, so use that
            $end = $recurrence->end_date->format($date_format) . 'Z';
        } else {
            if (isset($recurrence->count) && $recurrence->count > 0) {
                // The RRULE has a limit, so calculate the end date based on the instance count
                $count = 0;
                $newEnd;
                $rdates = $recurrence->recur($event[$mappings['start_date']])->rrule($rrule);
                while ($rdate = $rdates->next()) {
                    $newEnd = $rdate;
                    if (++$count > $recurrence->count) {
                        break;
                    }
                }
                // The 'minutes' portion should match Extensible.calendar.data.EventModel.resolution:
                $newEnd->modify('+' . $event[$mappings['duration']] . ' minutes');
                $end = $newEnd->format($date_format) . 'Z';
            } else {
                // The RRULE does not specify an end date or count, so default to max date
                $end = date($date_format, PHP_INT_MAX) . 'Z';
            }
        }
    }
    return $end;
}
Exemplo n.º 19
0
 /**
  * Every year on the -1th, -100th, and -200th day for 5 occurrences (checked via google calendar import below)
  * BEGIN:VCALENDAR
  * PRODID:-//Google Inc//Google Calendar 70.9054//EN
  * VERSION:2.0
  * CALSCALE:GREGORIAN
  * METHOD:PUBLISH
  * BEGIN:VTIMEZONE
  * TZID:America/New_York
  * X-LIC-LOCATION:America/New_York
  * BEGIN:DAYLIGHT
  * TZOFFSETFROM:-0500
  * TZOFFSETTO:-0400
  * TZNAME:EDT
  * DTSTART:19700308T020000
  * RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=2SU
  * END:DAYLIGHT
  * BEGIN:STANDARD
  * TZOFFSETFROM:-0400
  * TZOFFSETTO:-0500
  * TZNAME:EST
  * DTSTART:19701101T020000
  * RRULE:FREQ=YEARLY;BYMONTH=11;BYDAY=1SU
  * END:STANDARD
  * END:VTIMEZONE
  * BEGIN:VEVENT
  * DTSTART;VALUE=DATE:20101231
  * RRULE:FREQ=YEARLY;COUNT=5;BYYEARDAY=-1,-100,-200
  * DTSTAMP:20101231T090000
  * CREATED:20101231T090000
  * DESCRIPTION:
  * LAST-MODIFIED:20101231T090000
  * LOCATION:
  * SEQUENCE:2
  * STATUS:CONFIRMED
  * SUMMARY:testing yearly event
  * TRANSP:TRANSPARENT
  * END:VEVENT
  * END:VCALENDAR
  */
 function testTwentyFour()
 {
     $results[] = new DateTime('2010-12-31 09:00:00');
     $results[] = new DateTime('2010-09-23 09:00:00');
     $results[] = new DateTime('2010-06-15 09:00:00');
     $results[] = new DateTime('2011-12-31 09:00:00');
     $results[] = new DateTime('2011-09-23 09:00:00');
     $r = new When();
     $r->recur('20101231T090000', 'yearly')->count(5)->byyearday(array(-1, -100, -200));
     foreach ($results as $result) {
         $this->assertEquals($result, $r->next());
     }
 }
 /**
  * changing only WKST from MO to SU, yields different results...
  * DTSTART;TZID=America/New_York:19970805T090000
  * RRULE:FREQ=WEEKLY;INTERVAL=2;COUNT=4;BYDAY=TU,SU;WKST=SU
  */
 function testThirtyTwo()
 {
     $results[] = new DateTime('1997-08-05 09:00:00');
     $results[] = new DateTime('1997-08-17 09:00:00');
     $results[] = new DateTime('1997-08-19 09:00:00');
     $results[] = new DateTime('1997-08-31 09:00:00');
     $r = new When();
     $r->recur('19970805T090000', 'weekly')->interval(2)->count(4)->byday(array('TU', 'SU'))->wkst('SU');
     foreach ($results as $result) {
         $this->assertEquals($result, $r->next());
     }
 }
Exemplo n.º 21
0
 public static function generateEventOutput($event, $start, $end)
 {
     $output = array();
     if (isset($event['calendardata'])) {
         $object = OC_VObject::parse($event['calendardata']);
         $vevent = $object->VEVENT;
     } else {
         $vevent = $event['vevent'];
     }
     $last_modified = @$vevent->__get('LAST-MODIFIED');
     $lastmodified = $last_modified ? $last_modified->getDateTime()->format('U') : 0;
     $output = array('id' => (int) $event['id'], 'title' => $event['summary'] != NULL || $event['summary'] != '' ? $event['summary'] : self::$l10n->t('unnamed'), 'description' => isset($vevent->DESCRIPTION) ? $vevent->DESCRIPTION->value : '', 'lastmodified' => $lastmodified);
     $dtstart = $vevent->DTSTART;
     $start_dt = $dtstart->getDateTime();
     $dtend = OC_Calendar_Object::getDTEndFromVEvent($vevent);
     $end_dt = $dtend->getDateTime();
     if ($dtstart->getDateType() == Sabre_VObject_Element_DateTime::DATE) {
         $output['allDay'] = true;
     } else {
         $output['allDay'] = false;
         $start_dt->setTimezone(new DateTimeZone(self::$tz));
         $end_dt->setTimezone(new DateTimeZone(self::$tz));
     }
     // Handle exceptions to recurring events
     $exceptionDateObjects = $vevent->select('EXDATE');
     $exceptionDateMap = array();
     foreach ($exceptionDateObjects as $exceptionObject) {
         foreach ($exceptionObject->getDateTimes() as $datetime) {
             $ts = $datetime->getTimestamp();
             $exceptionDateMap[idate('Y', $ts)][idate('m', $ts)][idate('d', $ts)] = true;
         }
     }
     $return = array();
     if ($event['repeating'] == 1) {
         $duration = (double) $end_dt->format('U') - (double) $start_dt->format('U');
         $r = new When();
         $r->recur($start_dt)->rrule((string) $vevent->RRULE);
         /*$r = new iCal_Repeat_Generator(array('RECUR'  => $start_dt,
          *									   'RRULE'  => (string)$vevent->RRULE
          *									   'RDATE'  => (string)$vevent->RDATE						
          *									   'EXRULE' => (string)$vevent->EXRULE
          *									   'EXDATE' => (string)$vevent->EXDATE));*/
         while ($result = $r->next()) {
             if ($result < $start) {
                 continue;
             }
             if ($result > $end) {
                 break;
             }
             // Check for exceptions to recurring events
             $ts = $result->getTimestamp();
             if (isset($exceptionDateMap[idate('Y', $ts)][idate('m', $ts)][idate('d', $ts)])) {
                 continue;
             }
             unset($ts);
             if ($output['allDay'] == true) {
                 $output['start'] = $result->format('Y-m-d');
                 $output['end'] = date('Y-m-d', $result->format('U') + --$duration);
             } else {
                 $output['start'] = $result->format('Y-m-d H:i:s');
                 $output['end'] = date('Y-m-d H:i:s', $result->format('U') + $result->format('Z') + $duration);
             }
             $return[] = $output;
         }
     } else {
         if ($output['allDay'] == true) {
             $output['start'] = $start_dt->format('Y-m-d');
             $end_dt->modify('-1 sec');
             $output['end'] = $end_dt->format('Y-m-d');
         } else {
             $output['start'] = $start_dt->format('Y-m-d H:i:s');
             $output['end'] = $end_dt->format('Y-m-d H:i:s');
         }
         $return[] = $output;
     }
     return $return;
 }
Exemplo n.º 22
0
 function testTwentyFive()
 {
     $results[] = new DateTime('2010-01-15 09:00:00');
     $results[] = new DateTime('2011-01-15 09:00:00');
     $results[] = new DateTime('2012-01-15 09:00:00');
     $results[] = new DateTime('2013-01-15 09:00:00');
     $results[] = new DateTime('2014-01-15 09:00:00');
     $results[] = new DateTime('2015-01-15 09:00:00');
     $r = new When();
     $r->recur('20100115T090000')->rrule('FREQ=YEARLY');
     foreach ($results as $result) {
         $this->assertEquals($result, $r->next());
     }
 }
Exemplo n.º 23
0
 public function testValidFrequencies()
 {
     $this->setExpectedException('InvalidArgumentException');
     $r = new When();
     $r->recur('2000-01-01', 'yearlyy');
 }
Exemplo n.º 24
0
 /**
  * The same day of every month:
  * RRULE:FREQ=MONTHLY
  */
 function testTwentyThree()
 {
     $results[] = new DateTime('1997-09-14 09:00:00');
     $results[] = new DateTime('1997-10-14 09:00:00');
     $results[] = new DateTime('1997-11-14 09:00:00');
     $results[] = new DateTime('1997-12-14 09:00:00');
     $results[] = new DateTime('1998-01-14 09:00:00');
     $results[] = new DateTime('1998-02-14 09:00:00');
     $results[] = new DateTime('1998-03-14 09:00:00');
     $results[] = new DateTime('1998-04-14 09:00:00');
     $results[] = new DateTime('1998-05-14 09:00:00');
     $results[] = new DateTime('1998-06-14 09:00:00');
     $results[] = new DateTime('1998-07-14 09:00:00');
     $results[] = new DateTime('1998-08-14 09:00:00');
     $results[] = new DateTime('1998-09-14 09:00:00');
     $results[] = new DateTime('1998-10-14 09:00:00');
     $results[] = new DateTime('1998-11-14 09:00:00');
     $results[] = new DateTime('1998-12-14 09:00:00');
     $results[] = new DateTime('1999-01-14 09:00:00');
     $r = new When();
     $r->recur('19970914T090000')->count(17)->rrule('FREQ=MONTHLY');
     foreach ($results as $result) {
         $date = $r->next();
         $this->assertEquals($result, $date);
     }
 }
 /**
  * RRULE:FREQ=DAILY
  */
 function testThirtyNine()
 {
     $results[] = new DateTime('1999-12-25 09:00:00');
     $results[] = new DateTime('1999-12-26 09:00:00');
     $results[] = new DateTime('1999-12-27 09:00:00');
     $results[] = new DateTime('1999-12-28 09:00:00');
     $results[] = new DateTime('1999-12-29 09:00:00');
     $results[] = new DateTime('1999-12-30 09:00:00');
     $results[] = new DateTime('1999-12-31 09:00:00');
     $results[] = new DateTime('2000-01-01 09:00:00');
     $results[] = new DateTime('2000-01-02 09:00:00');
     $results[] = new DateTime('2000-01-03 09:00:00');
     $results[] = new DateTime('2000-01-04 09:00:00');
     $r = new When();
     $r->recur('19991225T090000')->rrule('FREQ=DAILY');
     foreach ($results as $result) {
         $this->assertEquals($result, $r->next());
     }
 }
Exemplo n.º 26
0
 /**
  * This function takes criterias saved in civicrm_action_schedule table
  * and creates recursion rule
  *
  * @param array $scheduleReminderDetails
  *   Array of repeat criterias saved in civicrm_action_schedule table .
  *
  * @return object
  *   When object
  */
 public function getRecursionFromSchedule($scheduleReminderDetails = array())
 {
     $r = new When();
     //If there is some data for this id
     if ($scheduleReminderDetails['repetition_frequency_unit']) {
         if ($scheduleReminderDetails['start_action_date']) {
             $currDate = date('Y-m-d H:i:s', strtotime($scheduleReminderDetails['start_action_date']));
         } else {
             $currDate = date("Y-m-d H:i:s");
         }
         $start = new DateTime($currDate);
         $this->recursion_start_date = $start;
         if ($scheduleReminderDetails['repetition_frequency_unit']) {
             $repetition_frequency_unit = $scheduleReminderDetails['repetition_frequency_unit'];
             if ($repetition_frequency_unit == "day") {
                 $repetition_frequency_unit = "dai";
             }
             $repetition_frequency_unit = $repetition_frequency_unit . 'ly';
             $r->recur($start, $repetition_frequency_unit);
         }
         if ($scheduleReminderDetails['repetition_frequency_interval']) {
             $r->interval($scheduleReminderDetails['repetition_frequency_interval']);
         } else {
             $r->errors[] = 'Repeats every: is a required field';
         }
         //week
         if ($scheduleReminderDetails['repetition_frequency_unit'] == 'week') {
             if ($scheduleReminderDetails['start_action_condition']) {
                 $startActionCondition = $scheduleReminderDetails['start_action_condition'];
                 $explodeStartActionCondition = explode(',', $startActionCondition);
                 $buildRuleArray = array();
                 foreach ($explodeStartActionCondition as $key => $val) {
                     $buildRuleArray[] = strtoupper(substr($val, 0, 2));
                 }
                 $r->wkst('MO')->byday($buildRuleArray);
             }
         }
         //month
         if ($scheduleReminderDetails['repetition_frequency_unit'] == 'month') {
             if ($scheduleReminderDetails['entity_status']) {
                 $startActionDate = explode(" ", $scheduleReminderDetails['entity_status']);
                 switch ($startActionDate[0]) {
                     case 'first':
                         $startActionDate1 = 1;
                         break;
                     case 'second':
                         $startActionDate1 = 2;
                         break;
                     case 'third':
                         $startActionDate1 = 3;
                         break;
                     case 'fourth':
                         $startActionDate1 = 4;
                         break;
                     case 'last':
                         $startActionDate1 = -1;
                         break;
                 }
                 $concatStartActionDateBits = $startActionDate1 . strtoupper(substr($startActionDate[1], 0, 2));
                 $r->byday(array($concatStartActionDateBits));
             } elseif ($scheduleReminderDetails['limit_to']) {
                 $r->bymonthday(array($scheduleReminderDetails['limit_to']));
             }
         }
         //Ends
         if ($scheduleReminderDetails['start_action_offset']) {
             if ($scheduleReminderDetails['start_action_offset'] > 30) {
                 $r->errors[] = 'Occurrences should be less than or equal to 30';
             }
             $r->count($scheduleReminderDetails['start_action_offset']);
         }
         if (!empty($scheduleReminderDetails['absolute_date'])) {
             $absoluteDate = CRM_Utils_Date::setDateDefaults($scheduleReminderDetails['absolute_date']);
             // absolute_date column of scheduled-reminder table is of type date (and not datetime)
             // and we always want the date to be included, and therefore appending 23:59
             $endDate = new DateTime($absoluteDate[0] . ' ' . '23:59');
             $r->until($endDate);
         }
         if (!$scheduleReminderDetails['start_action_offset'] && !$scheduleReminderDetails['absolute_date']) {
             $r->errors[] = 'Ends: is a required field';
         }
     } else {
         $r->errors[] = 'Repeats: is a required field';
     }
     return $r;
 }
Exemplo n.º 27
0
 /**
  * @expectedException Respect\Validation\Exceptions\NotEmptyException
  */
 public function testWhenException_on_else_failfast()
 {
     $v = new When(new Int(), new Between(1, 5), new NotEmpty());
     $this->assertFalse($v->check(''));
 }
Exemplo n.º 28
0
 /** @test */
 public function shouldProvideCorrectBasisValue()
 {
     $insertIntoArray = function ($arr, $val, $i) {
         $arr[$i] = $val;
         return $arr;
     };
     $d1 = new Deferred();
     $d2 = new Deferred();
     $d3 = new Deferred();
     $mock = $this->createCallableMock();
     $mock->expects($this->once())->method('__invoke')->with($this->identicalTo(array(1, 2, 3)));
     When::reduce(array($d1->promise(), $d2->promise(), $d3->promise()), $insertIntoArray, array())->then($mock);
     $d3->resolve(3);
     $d1->resolve(1);
     $d2->resolve(2);
 }
Exemplo n.º 29
0
 /**
  * The second-to-last weekday of the month:
  * DTSTART;TZID=America/New_York:19970929T090000
  * RRULE:FREQ=MONTHLY;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=-2
  */
 function testTwentyTwo()
 {
     $results[] = new DateTime('1997-09-29 09:00:00');
     $results[] = new DateTime('1997-10-30 09:00:00');
     $results[] = new DateTime('1997-11-27 09:00:00');
     $results[] = new DateTime('1997-12-30 09:00:00');
     $results[] = new DateTime('1998-01-29 09:00:00');
     $results[] = new DateTime('1998-02-26 09:00:00');
     $results[] = new DateTime('1998-03-30 09:00:00');
     $r = new When();
     $r->recur('19970929T090000', 'monthly')->count(7)->byday(array('MO', 'TU', 'WE', 'TH', 'FR'))->bysetpos(array(-2));
     foreach ($results as $result) {
         $this->assertEquals($result, $r->next());
     }
 }
Exemplo n.º 30
0
 public function updateEvent($params)
 {
     $filter = array(CalendarManager::CALENDAR_KEY_ID => $params['calendarId']);
     $calendarData = self::retrieveCalendarData($filter);
     $cal = self::getRemoteCalendar($calendarData);
     $urls = explode('_', $params['id']);
     $url = $urls[0];
     foreach ($cal as $obj1) {
         if ($url == $obj1->getUrl()) {
             $thisEvent = $obj1;
         }
     }
     $props = $thisEvent->getBaseComponent()->getProperties();
     foreach ($props as $prop) {
         if ($prop->name == "DTSTART") {
             $dtstartzone = isset($prop->parameters["TZID"]) ? $prop->parameters["TZID"] : "";
             $params['dtstartzone'] = $dtstartzone;
             $dtStartForAll = $prop->content;
         }
         if ($prop->name == "DTEND") {
             $dtEndForAll = $prop->content;
         }
     }
     //if (!$params['isEditAll'] && $params['eventGroup'] > 0)
     if (!$params['isEditAll']) {
         // edit on only this.
         $thisEvent = $cal->newComponent('VEVENT');
         $thisEvent->update($params, $cal);
         $repeated = false;
         /*$startDate=  date("Ymd\THis\Z",$params['timeStart']);  
         		$endDate=  date("Ymd\THis\Z",$params['timeEnd']); */
         $startDate = date("Ymd\\THis\\Z", CalDavConverter::dateCalDavToEyeos($dtStartForAll) - $params['gmtTimeDiffrence'] * 3600);
         $endDate = date("Ymd\\THis\\Z", CalDavConverter::dateCalDavToEyeos($dtEndForAll) - $params['gmtTimeDiffrence'] * 3600);
     } else {
         // edit all events
         $newValues = array('DTSTART' => $params['dtstart'], 'DTEND' => $params['dtend'], 'SUMMARY' => $params['subject'], 'LOCATION' => $params['location'], 'DESCRIPTION' => $params['description']);
         $thisEvent->setAllProperties($newValues);
         $cal->update($thisEvent->getUrl(), $thisEvent->getEtag());
         $repeated = true;
         $startDate = date("Ymd\\THis\\Z", CalDavConverter::dateCalDavToEyeos($dtStartForAll) - $params['gmtTimeDiffrence'] * 3600);
         $endDate = date("Ymd\\THis\\Z", CalDavConverter::dateCalDavToEyeos($dtEndForAll) - $params['gmtTimeDiffrence'] * 3600);
     }
     $creator = ProcManager::getInstance()->getCurrentProcess()->getLoginContext()->getEyeosUser();
     $start = new When();
     $start->recur($startDate)->rrule($rrule);
     $end = new When();
     $end->recur($endDate)->rrule($rrule);
     /*$repeated=false;
     		if($params['repeatType']!='n'){
     			$repeated=true;
     		}*/
     $maxRepeatLimit = CalendarManager::MAX_REPEAT_LIMIT;
     $repeated = true;
     if ($repeated) {
         for ($i = 0; $i < $maxRepeatLimit; $i++) {
             $sDate = $start->next();
             if (!is_object($sDate)) {
                 break;
             }
             $timeStart = $sDate->getTimestamp();
             $eDate = $end->next();
             $timeEnd = $eDate->getTimestamp();
             $newEvent = CalendarManager::getInstance()->getNewEvent();
             $eventId = $url . '_' . $i;
             $newEvent->setId($eventId);
             $newEvent->setSubject($params['subject']);
             $newEvent->setTimeStart($timeStart);
             $newEvent->setTimeEnd($timeEnd);
             $newEvent->setCalendarId($params['calendarId']);
             $newEvent->setIsAllDay($params['isAllDay']);
             $newEvent->setRepetition($params['repetition']);
             $newEvent->setRepeatType($params['repeatType']);
             $newEvent->setLocation($params['location']);
             $newEvent->setDescription($params['description']);
             $newEvent->setFinalType($params['finalType']);
             $newEvent->setFinalValue($params['finalValue']);
             //$newEvent->seteventGroup(1);	// its repeat event so we need to set it to greater then 0
             $newEvent->setCreatorId($creator->getId());
             $newEvent->setEventGroup(1);
             $newRepeatEventArr[] = $newEvent;
         }
     } else {
         $newEvent = CalendarManager::getInstance()->getNewEvent();
         $eventId = $url;
         $newEvent->setId($eventId);
         $newEvent->setSubject($params['subject']);
         $newEvent->setTimeStart($params['timeStart']);
         $newEvent->setTimeEnd($params['timeEnd']);
         $newEvent->setCalendarId($params['calendarId']);
         $newEvent->setIsAllDay($params['isAllDay']);
         $newEvent->setRepetition($params['repetition']);
         $newEvent->setRepeatType($params['repeatType']);
         $newEvent->setLocation($params['location']);
         $newEvent->setDescription($params['description']);
         $newEvent->setFinalType($params['finalType']);
         $newEvent->setFinalValue($params['finalValue']);
         //$newEvent->seteventGroup(1);	// its repeat event so we need to set it to greater then 0
         $newEvent->setCreatorId($creator->getId());
         $newEvent->setEventGroup(0);
         $newRepeatEventArr[] = $newEvent;
     }
     //print_r($newRepeatEventArr);
     return $newRepeatEventArr;
 }