예제 #1
0
 /**
  * Gets the list of calendar events
  *
  * @param int       $organizationId The id of an organization for which this information is requested
  * @param int       $userId         The id of an user requested this information
  * @param int       $calendarId     The target calendar id
  * @param \DateTime $start          A date/time specifies the begin of a time interval
  * @param \DateTime $end            A date/time specifies the end of a time interval
  * @param bool      $subordinate    Determines whether events from connected calendars should be included or not
  * @param array     $extraFields
  *
  * @return array
  */
 public function getCalendarEvents($organizationId, $userId, $calendarId, $start, $end, $subordinate, $extraFields = [])
 {
     // make sure input parameters have proper types
     $calendarId = (int) $calendarId;
     $subordinate = (bool) $subordinate;
     $allConnections = $this->calendarPropertyProvider->getItemsVisibility($calendarId, $subordinate);
     $result = [];
     foreach ($this->providers as $alias => $provider) {
         $connections = [];
         foreach ($allConnections as $c) {
             if ($c['calendarAlias'] === $alias) {
                 $connections[$c['calendar']] = $c['visible'];
             }
         }
         $events = $provider->getCalendarEvents($organizationId, $userId, $calendarId, $start, $end, $connections, $extraFields);
         if (!empty($events)) {
             foreach ($events as &$event) {
                 $event['calendarAlias'] = $alias;
                 if (!isset($event['editable'])) {
                     $event['editable'] = true;
                 }
                 if (!isset($event['removable'])) {
                     $event['removable'] = true;
                 }
                 if (!isset($event['notifiable'])) {
                     $event['notifiable'] = false;
                 }
             }
             $result = array_merge($result, $events);
         }
     }
     return $result;
 }
 public function testGetItemsVisibilityCurrentCalendarOnly()
 {
     $calendarId = 123;
     $subordinate = false;
     $items = [['calendarAlias' => 'test', 'calendar' => 1, 'visible' => true]];
     $repo = $this->getMockBuilder('Doctrine\\ORM\\EntityRepository')->disableOriginalConstructor()->getMock();
     $this->doctrineHelper->expects($this->once())->method('getEntityRepository')->with(CalendarPropertyProvider::CALENDAR_PROPERTY_CLASS)->will($this->returnValue($repo));
     $qb = $this->getMockBuilder('Doctrine\\ORM\\QueryBuilder')->disableOriginalConstructor()->getMock();
     $repo->expects($this->once())->method('createQueryBuilder')->with('o')->will($this->returnValue($qb));
     $qb->expects($this->once())->method('select')->with('o.calendarAlias, o.calendar, o.visible')->will($this->returnSelf());
     $qb->expects($this->once())->method('where')->with('o.targetCalendar = :calendar_id')->will($this->returnSelf());
     $qb->expects($this->at(2))->method('setParameter')->with('calendar_id', $calendarId)->will($this->returnSelf());
     $qb->expects($this->once())->method('andWhere')->with('o.calendarAlias = :alias AND o.calendar = :calendar_id')->will($this->returnSelf());
     $qb->expects($this->at(4))->method('setParameter')->with('alias', Calendar::CALENDAR_ALIAS)->will($this->returnSelf());
     $query = $this->getMockBuilder('Doctrine\\ORM\\AbstractQuery')->disableOriginalConstructor()->setMethods(['getArrayResult'])->getMockForAbstractClass();
     $qb->expects($this->once())->method('getQuery')->will($this->returnValue($query));
     $query->expects($this->once())->method('getArrayResult')->will($this->returnValue($items));
     $result = $this->provider->getItemsVisibility($calendarId, $subordinate);
     $this->assertSame($items, $result);
 }