module/Application/src/Application/Service/GoogleService.php
/**
     * list calendar events between 2 dates
     * @param array $config
     * @return array
     * @throws \Exception
     */
list calendar events between 2 dates
@param array $config
@return array
@throws \Exception
list calendar events between 2 dates @param array $config @return array @throws \ Exception
public function findCalendarEvents(array $config=array()) {
        if (!$this->hasGoogle()) {
            throw new \Exception('Google client unavailable');
        }
        $params = array();
        if (!empty($config['start'])) {
            $params['timeMin'] = date('c', $config['start']);
        }
        if (!empty($config['end'])) {
            $params['timeMax'] = date('c', $config['end']);
        }
        if (!empty($config['start']) && !empty($config['end'])) {
            if ($config['start'] > $config['end']) {
                throw new \Exception('invalid parameters');
            }
        }
        $client = $this->getGoogleClient();
        $owner = !empty($config['owner'])?$config['owner']:$this->getUser()->getEmail();
        $calendar = new \Google_Service_Calendar($client);
        $evts = $calendar->events->listEvents($owner, $params);
        if (!($evts instanceof \Google_Service_Calendar_Events)) {
            throw new \Exception('no results');
        }
        $data = array();
        $colours = array(
            'yellow'=>array (
                'textColor'=>'#c09853',
                'backgroundColor'=>'#fcf8e3',
                'borderColor'=>'#fbeed5',
            ),
            'green'=>array (
                'textColor'=>'#468847',
                'backgroundColor'=>'#dff0d8',
                'borderColor'=>'#d6e9c6',
            ),
            'red'=>array (
                'textColor'=>'#b94a48',
                'backgroundColor'=>'#f2dede',
                'borderColor'=>'#eed3d7',
            ),
            'blue'=>array (
                'textColor'=>'#3a87ad',
                'backgroundColor'=>'#d9edf7',
                'borderColor'=>'#bce8f1',
            ),
        );
        if ($evts->count()) {
            foreach ($evts as $event) {
                if (!empty($event->getstart())) {
                    if (!empty($event->getstart()->getdate())) {
                        $start = $event->getstart()->getdate();
                        $end = $event->getend()->getdate();
                    } else {
                        $start = $event->getstart()->getdatetime();
                        $end = $event->getend()->getdatetime();
                    }
                } else {
                    continue;
                }
                $owner = ($event->getCreator()->getEmail()==$owner);
                $item = array (
                    'title'=>$event->getSummary(),
                    'start'=>$start,
                    'end'=>$end,
                    'id'=>$event->getId(),
                    'description'=>$event->getDescription(),
                )+$colours[$owner?'green':'blue'];
                if (!empty($config['linkable'])) {
                    $item['url'] = '/calendar/advancededit/?eid='.$event->getId();
                }
                $data[] = $item;
            }
        }
        return $data;
    }
public function findCalendarEvents ( array $ config = array ( ) ) { if ( ! $ this -> hasGoogle ( ) ) { throw new \ Exception ( 'Google client unavailable' ) ; } $ params = array ( ) ; if ( ! empty ( $ config [ 'start' ] ) ) { $ params [ 'timeMin' ] = date ( 'c' , $ config [ 'start' ] ) ; } if ( ! empty ( $ config [ 'end' ] ) ) { $ params [ 'timeMax' ] = date ( 'c' , $ config [ 'end' ] ) ; } if ( ! empty ( $ config [ 'start' ] ) && ! empty ( $ config [ 'end' ] ) ) { if ( $ config [ 'start' ] > $ config [ 'end' ] ) { throw new \ Exception ( 'invalid parameters' ) ; } } $ client = $ this -> getGoogleClient ( ) ; $ owner = ! empty ( $ config [ 'owner' ] ) ? $ config [ 'owner' ] : $ this -> getUser ( ) -> getEmail ( ) ; $ calendar = new \ Google_Service_Calendar ( $ client ) ; $ evts = $ calendar -> events -> listEvents ( $ owner , $ params ) ; if ( ! ( $ evts instanceof \ Google_Service_Calendar_Events ) ) { throw new \ Exception ( 'no results' ) ; } $ data = array ( ) ; $ colours = array ( 'yellow' => array ( 'textColor' => '#c09853' , 'backgroundColor' => '#fcf8e3' , 'borderColor' => '#fbeed5' , ) , 'green' => array ( 'textColor' => '#468847' , 'backgroundColor' => '#dff0d8' , 'borderColor' => '#d6e9c6' , ) , 'red' => array ( 'textColor' => '#b94a48' , 'backgroundColor' => '#f2dede' , 'borderColor' => '#eed3d7' , ) , 'blue' => array ( 'textColor' => '#3a87ad' , 'backgroundColor' => '#d9edf7' , 'borderColor' => '#bce8f1' , ) , ) ; if ( $ evts -> count ( ) ) { foreach ( $ evts as $ event ) { if ( ! empty ( $ event -> getstart ( ) ) ) { if ( ! empty ( $ event -> getstart ( ) -> getdate ( ) ) ) { $ start = $ event -> getstart ( ) -> getdate ( ) ; $ end = $ event -> getend ( ) -> getdate ( ) ; } else { $ start = $ event -> getstart ( ) -> getdatetime ( ) ; $ end = $ event -> getend ( ) -> getdatetime ( ) ; } } else { continue ; } $ owner = ( $ event -> getCreator ( ) -> getEmail ( ) == $ owner ) ; $ item = array ( 'title' => $ event -> getSummary ( ) , 'start' => $ start , 'end' => $ end , 'id' => $ event -> getId ( ) , 'description' => $ event -> getDescription ( ) , ) + $ colours [ $ owner ? 'green' : 'blue' ] ; if ( ! empty ( $ config [ 'linkable' ] ) ) { $ item [ 'url' ] = '/calendar/advancededit/?eid=' . $ event -> getId ( ) ; } $ data [ ] = $ item ; } } return $ data ; }
list calendar events between 2 dates
 @param array $config
 @return array
 @throws \Exception
list calendar events between 2 dates @param array $config @return array @throws \ Exception
// calendar /**/