Copyright 2003-2016 Horde LLC (http://www.horde.org/) See the enclosed file COPYING for license information (LGPL). If you did not receive this file, see http://www.horde.org/licenses/lgpl21.
저자: Mike Cochrane (mike@graftonhall.co.nz)
상속: extends Horde_Icalendar
예제 #1
0
 /**
  * Merges the busy periods of another Horde_Icalendar_Vfreebusy object
  * into this one.
  *
  * This might lead to simplification no matter what you specify for the
  * "simplify" flag since periods with the same start date will lead to the
  * shorter period being removed (see addBusyPeriod).
  *
  * @param Horde_Icalendar_Vfreebusy $freebusy  A freebusy object.
  * @param boolean $simplify                    If true, simplify() will
  *                                             called after the merge.
  */
 public function merge(Horde_Icalendar_Vfreebusy $freebusy, $simplify = true)
 {
     $extra = $freebusy->getExtraParams();
     foreach ($freebusy->getBusyPeriods() as $start => $end) {
         // This might simplify the busy periods without taking the
         // "simplify" flag into account.
         $this->addBusyPeriod('BUSY', $start, $end, null, isset($extra[$start]) ? $extra[$start] : array());
     }
     foreach (array('DTSTART', 'DTEND') as $val) {
         try {
             $thisattr = $this->getAttribute($val);
         } catch (Horde_Icalendar_Exception $e) {
             $thisattr = null;
         }
         try {
             $thatattr = $freebusy->getAttribute($val);
         } catch (Horde_Icalendar_Exception $e) {
             $thatattr = null;
         }
         if (is_null($thisattr) && !is_null($thatattr)) {
             $this->setAttribute($val, $thatattr, array(), false);
         } elseif (!is_null($thatattr)) {
             switch ($val) {
                 case 'DTSTART':
                     $set = $thatattr < $thisattr;
                     break;
                 case 'DTEND':
                     $set = $thatattr > $thisattr;
                     break;
             }
             if ($set) {
                 $this->setAttribute($val, $thatattr, array(), false);
             }
         }
     }
     if ($simplify) {
         $this->simplify();
     }
     return true;
 }
예제 #2
0
파일: View.php 프로젝트: horde/horde
 /**
  * Render the blocks
  *
  * @param Horde_Icalendar_Vfreebusy $member  Member's freebusy info
  * @param array $periods                     Free periods
  * @param string $blockfile                  Template file to use for blocks
  * @param string $label                      Label to use
  *
  * @return string  The block html
  */
 protected function _getBlocks($member, $periods, $blockfile, $label)
 {
     $template = $GLOBALS['injector']->createInstance('Horde_Template');
     $template->set('label', $label);
     reset($periods);
     list($periodStart, $periodEnd) = each($periods);
     $blocks = '';
     foreach ($this->_timeBlocks as $span) {
         /* Horde_Icalendar_Vfreebusy only supports timestamps at the
          * moment. */
         $start = $span[0]->timestamp();
         $end = $span[1]->timestamp();
         if ($member->getStart() > $start || $member->getEnd() < $end) {
             $blocks .= $template->fetch(KRONOLITH_TEMPLATES . '/fbview/unknownblock.html');
             continue;
         }
         while ($start > $periodEnd && (list($periodStart, $periodEnd) = each($periods))) {
         }
         if ($periodStart <= $start && $periodEnd >= $start || $periodStart <= $end && $periodEnd >= $end || $periodStart <= $start && $periodEnd >= $end || $periodStart >= $start && $periodEnd <= $end) {
             $l_start = $periodStart < $start ? $start : $periodStart;
             $l_end = $periodEnd > $end ? $end : $periodEnd;
             $plen = ($end - $start) / 100.0;
             $left = ($l_start - $start) / $plen;
             $width = ($l_end - $l_start) / $plen;
             $template->set('left', $left . '%');
             $template->set('width', $width . '%');
             $blocks .= $template->fetch(KRONOLITH_TEMPLATES . '/fbview/' . $blockfile);
         } else {
             $blocks .= $template->fetch(KRONOLITH_TEMPLATES . '/fbview/emptyblock.html');
         }
     }
     return $blocks;
 }
예제 #3
0
파일: FreeBusy.php 프로젝트: horde/horde
 /**
  * Converts free/busy data to a simple object suitable to be transferred
  * as json.
  *
  * @param Horde_Icalendar_Vfreebusy $fb  A Free/busy component.
  *
  * @return object  A simple object representation.
  */
 public static function toJson(Horde_Icalendar_Vfreebusy $fb)
 {
     $json = new stdClass();
     $start = $fb->getStart();
     if ($start) {
         $start = new Horde_Date($start);
         $json->s = $start->dateString();
     }
     $end = $fb->getEnd();
     if ($end) {
         $end = new Horde_Date($end);
         $json->e = $end->dateString();
     }
     $b = $fb->getBusyPeriods();
     if (empty($b)) {
         $b = new StdClass();
     }
     $new = new StdClass();
     foreach ($b as $from => $to) {
         $from = new Horde_Date($from);
         $to = new Horde_Date($to);
         $new->{$from->toJson()} = $to->toJson();
     }
     $json->b = $new;
     return $json;
 }
예제 #4
0
파일: FreeBusy.php 프로젝트: DSNS-LAB/Dmail
 /**
  * Converts free/busy data to a simple object suitable to be transferred
  * as json.
  *
  * @param Horde_Icalendar_Vfreebusy $fb  A Free/busy component.
  *
  * @return object  A simple object representation.
  */
 public static function toJson(Horde_Icalendar_Vfreebusy $fb)
 {
     $json = new stdClass();
     $start = $fb->getStart();
     if ($start) {
         $start = new Horde_Date($start);
         $json->s = $start->dateString();
     }
     $end = $fb->getEnd();
     if ($end) {
         $end = new Horde_Date($end);
         $json->e = $end->dateString();
     }
     $b = $fb->getBusyPeriods();
     if (empty($b)) {
         $b = new StdClass();
     }
     $json->b = $b;
     return $json;
 }
예제 #5
0
 /**
  * @depends testRead
  */
 public function testMerge($vfb)
 {
     // Create new freebusy object for merging
     $mfb = new Horde_Icalendar_Vfreebusy();
     // 1. 3:55 / 10 minutes; summary "test4"
     $mfb->addBusyPeriod('BUSY', 1164254100, null, 600, array('X-SUMMARY' => 'dGVzdDQ='));
     // 2. 4:00 / 1 hours 5 Minutes; summary "test3"
     $mfb->addBusyPeriod('BUSY', 1164254400, null, 3900, array('X-SUMMARY' => 'dGVzdDM='));
     // 3. 5:55 / 10 minutes hours; summary "test5"
     $mfb->addBusyPeriod('BUSY', 1164261300, null, 600, array('X-SUMMARY' => 'dGVzdDU=='));
     // 4. 7:55 / 10 min
     $mfb->addBusyPeriod('BUSY', 1164268500, null, 600);
     // 5. 9:55 / 10 min
     $mfb->addBusyPeriod('BUSY', 1164275700, null, 600);
     // 6. 11:00 / 4 hours; summary "test2"
     $mfb->addBusyPeriod('BUSY', 1164279600, null, 14400, array('X-SUMMARY' => 'dGVzdDI='));
     // 7. 14:00 / 2 min
     $mfb->addBusyPeriod('BUSY', 1164290400, null, 120);
     // 8. 14:30 / 5 min; summary "test3"
     $mfb->addBusyPeriod('BUSY', 1164292200, null, 300, array('X-SUMMARY' => 'dGVzdDM='));
     // 9. 15:55 / 5 min
     $mfb->addBusyPeriod('BUSY', 1164297300, 1164297600);
     // Dump busy periods
     $this->assertEquals(array(1164254100 => 1164254700, 1164254400 => 1164258300, 1164261300 => 1164261900, 1164268500 => 1164269100, 1164275700 => 1164276300, 1164279600 => 1164294000, 1164290400 => 1164290520, 1164292200 => 1164292500, 1164297300 => 1164297600), $mfb->getBusyPeriods());
     $mfb->setAttribute('DTSTART', 1004297300);
     $mfb->setAttribute('DTEND', 1014297300);
     // Merge freebusy components without simplification
     $vfb->merge($mfb, false);
     $this->assertEquals(1004297300, $vfb->getAttribute('DTSTART'));
     $this->assertEquals(1169420400, $vfb->getAttribute('DTEND'));
     // Merged periods (there are some entries having the same start time ->
     // merged to longer of the two)
     $busy = $vfb->getBusyPeriods();
     $extra = $vfb->getExtraParams();
     $this->assertEquals(array(1164258000 => 1164261600, 1164268800 => 1164276000, 1164279600 => 1164294000, 1164290400 => 1164297600, 1164254100 => 1164254700, 1164254400 => 1164258300, 1164261300 => 1164261900, 1164268500 => 1164269100, 1164275700 => 1164276300, 1164292200 => 1164292500, 1164297300 => 1164297600), $busy);
     // Check merging process (should have selected longer period)
     // and dump extra information alongside
     //   4 hours (instead of 2 hours)
     $this->assertEquals(14400, $busy[1164279600] - 1164279600);
     $this->assertEquals('test2', base64_decode($extra[1164279600]['X-SUMMARY']));
     //   2 hours (instead of 2 minutes)
     $this->assertEquals(7200, $busy[1164290400] - 1164290400);
     $this->assertEquals('test', base64_decode($extra[1164290400]['X-SUMMARY']));
     // Merge freebusy components again, simplify this time
     $vfb->merge($mfb);
     // Dump merged periods
     $busy = $vfb->getBusyPeriods();
     $extra = $vfb->getExtraParams();
     // 1. 3:55 / 10 Minutes / test4
     $this->assertEquals('20061123T035500Z', $vfb->_exportDateTime(1164254100));
     $this->assertEquals('20061123T040500Z', $vfb->_exportDateTime($busy[1164254100]));
     $this->assertEquals('test4', base64_decode($extra[1164254100]['X-SUMMARY']));
     // 2. 4:05 / 1 hour / test3
     $this->assertEquals('20061123T040500Z', $vfb->_exportDateTime(1164254700));
     $this->assertEquals('20061123T050500Z', $vfb->_exportDateTime($busy[1164254700]));
     $this->assertEquals('test3', base64_decode($extra[1164254700]['X-SUMMARY']));
     // 3. 5:05 / 55 Minutes / testtermin
     $this->assertEquals('20061123T050500Z', $vfb->_exportDateTime(1164258300));
     $this->assertEquals('20061123T060000Z', $vfb->_exportDateTime($busy[1164258300]));
     $this->assertEquals('testtermin', base64_decode($extra[1164258300]['X-SUMMARY']));
     // 4. 6:00 / 5 Minutes / test5
     $this->assertEquals('20061123T060000Z', $vfb->_exportDateTime(1164261600));
     $this->assertEquals('20061123T060500Z', $vfb->_exportDateTime($busy[1164261600]));
     $this->assertEquals('test5', base64_decode($extra[1164261600]['X-SUMMARY']));
     // 5. 7:55 / 2 hours 10 Minutes
     $this->assertEquals('20061123T075500Z', $vfb->_exportDateTime(1164268500));
     $this->assertEquals('20061123T100500Z', $vfb->_exportDateTime($busy[1164268500]));
     $this->assertArrayNotHasKey('X-SUMMARY', $extra[1164268500]);
     // 6. 11:00 / 4 hours / test2
     $this->assertEquals('20061123T110000Z', $vfb->_exportDateTime(1164279600));
     $this->assertEquals('20061123T150000Z', $vfb->_exportDateTime($busy[1164279600]));
     $this->assertEquals('test2', base64_decode($extra[1164279600]['X-SUMMARY']));
     // 7. 15:00 / 1 hour / test
     $this->assertEquals('20061123T150000Z', $vfb->_exportDateTime(1164294000));
     $this->assertEquals('20061123T160000Z', $vfb->_exportDateTime($busy[1164294000]));
     $this->assertEquals('test', base64_decode($extra[1164294000]['X-SUMMARY']));
 }
예제 #6
0
파일: attendees.php 프로젝트: horde/horde
// Add the Free/Busy information for each attendee.
foreach ($session->get('kronolith', 'attendees') as $attendee) {
    if ($attendee->role != Kronolith::PART_REQUIRED && $attendee->role != Kronolith::PART_OPTIONAL) {
        continue;
    }
    try {
        if ($attendee->user) {
            $vfb = Kronolith_Freebusy::getForUser($attendee->user, $fbOpts);
        } elseif (is_null($attendee->addressObject->host)) {
            $vfb = new Horde_Icalendar_Vfreebusy();
        } else {
            $vfb = Kronolith_FreeBusy::get($attendee->email);
        }
    } catch (Exception $e) {
        $notification->push(sprintf(_("Error retrieving free/busy information for %s: %s"), $attendee, $e->getMessage()));
        $vfb = new Horde_Icalendar_Vfreebusy();
    }
    try {
        $organizer = $vfb->getAttribute('ORGANIZER');
    } catch (Horde_Icalendar_Exception $e) {
        $organizer = null;
    }
    if (empty($organizer)) {
        if (strlen($attendee->name)) {
            $name = array('CN' => $attendee->name);
        } else {
            $name = array();
        }
        $vfb->setAttribute('ORGANIZER', 'mailto:' . $attendee->email, $name, false);
    }
    if ($attendee->role == Kronolith::PART_REQUIRED) {