public function getEvents()
    {
        if (empty($this->events)) {
            return [];
        }

        $events = call_user_func_array('array_merge', $this->events);

        foreach ($events as &$e) {
            if (!$e['timestamp'] instanceof \DateTime) {
                $dt             = new DateTimeHelper($e['timestamp'], 'Y-m-d H:i:s', 'UTC');
                $e['timestamp'] = $dt->getDateTime();
                unset($dt);
            }
        }

        if (!empty($this->orderBy)) {
            usort(
                $events,
                function ($a, $b) {
                    switch ($this->orderBy[0]) {
                        case 'eventLabel':
                            $aLabel = '';
                            if (isset($a['eventLabel'])) {
                                $aLabel = (is_array($a['eventLabel'])) ? $a['eventLabel']['label'] : $a['eventLabel'];
                            }

                            $bLabel = '';
                            if (isset($b['eventLabel'])) {
                                $bLabel = (is_array($b['eventLabel'])) ? $b['eventLabel']['label'] : $b['eventLabel'];
                            }

                            return strnatcmp($aLabel, $bLabel);

                        case 'date_added':
                            if ($a['timestamp'] == $b['timestamp']) {
                                $aPriority = isset($a['eventPriority']) ? (int) $a['eventPriority'] : 0;
                                $bPriority = isset($b['eventPriority']) ? (int) $b['eventPriority'] : 0;

                                return $aPriority - $bPriority;
                            }

                            return $a['timestamp'] < $b['timestamp'] ? -1 : 1;

                        case 'contact_id':
                            if ($a['contactId'] == $b['contactId']) {
                                return 0;
                            }

                            return $a['contactId'] < $b['contactId'] ? -1 : 1;

                        case 'type':

                            return strnatcmp($a['eventType'], $b['eventType']);

                        default:

                            return strnatcmp($a[$this->orderBy[0]], $b[$this->orderBy[0]]);
                    }
                }
            );

            if ('DESC' == $this->orderBy[1]) {
                $events = array_reverse($events);
            }
        }

        return $events;
    }
public function getEvents()
    {
        if (empty($this->events)) {
            return [];
        }

        $events = call_user_func_array('array_merge', $this->events);

        foreach ($events as &$e) {
            if (!$e['timestamp'] instanceof \DateTime) {
                $dt             = new DateTimeHelper($e['timestamp'], 'Y-m-d H:i:s', 'UTC');
                $e['timestamp'] = $dt->getDateTime();
                unset($dt);
            }
        }

        if (!empty($this->orderBy)) {
            usort(
                $events,
                function ($a, $b) {
                    switch ($this->orderBy[0]) {
                        case 'eventLabel':
                            $aLabel = '';
                            if (isset($a['eventLabel'])) {
                                $aLabel = (is_array($a['eventLabel'])) ? $a['eventLabel']['label'] : $a['eventLabel'];
                            }

                            $bLabel = '';
                            if (isset($b['eventLabel'])) {
                                $bLabel = (is_array($b['eventLabel'])) ? $b['eventLabel']['label'] : $b['eventLabel'];
                            }

                            return strnatcmp($aLabel, $bLabel);

                        case 'date_added':
                            if ($a['timestamp'] == $b['timestamp']) {
                                $aPriority = isset($a['eventPriority']) ? (int) $a['eventPriority'] : 0;
                                $bPriority = isset($b['eventPriority']) ? (int) $b['eventPriority'] : 0;

                                return $aPriority - $bPriority;
                            }

                            return $a['timestamp'] < $b['timestamp'] ? -1 : 1;

                        case 'contact_id':
                            if ($a['contactId'] == $b['contactId']) {
                                return 0;
                            }

                            return $a['contactId'] < $b['contactId'] ? -1 : 1;

                        case 'type':

                            return strnatcmp($a['eventType'], $b['eventType']);

                        default:

                            return strnatcmp($a[$this->orderBy[0]], $b[$this->orderBy[0]]);
                    }
                }
            );

            if ('DESC' == $this->orderBy[1]) {
                $events = array_reverse($events);
            }
        }

        return $events;
    }
public function getEvents ( ) { if ( empty ( $ this -> events ) ) { return [ ] ; } $ events = call_user_func_array ( 'array_merge' , $ this -> events ) ; foreach ( $ events as & $ e ) { if ( ! $ e [ 'timestamp' ] instanceof \ DateTime ) { $ dt = new DateTimeHelper ( $ e [ 'timestamp' ] , 'Y-m-d H:i:s' , 'UTC' ) ; $ e [ 'timestamp' ] = $ dt -> getDateTime ( ) ; unset ( $ dt ) ; } } if ( ! empty ( $ this -> orderBy ) ) { usort ( $ events , function ( $ a , $ b ) { switch ( $ this -> orderBy [ 0 ] ) { case 'eventLabel' : $ aLabel = '' ; if ( isset ( $ a [ 'eventLabel' ] ) ) { $ aLabel = ( is_array ( $ a [ 'eventLabel' ] ) ) ? $ a [ 'eventLabel' ] [ 'label' ] : $ a [ 'eventLabel' ] ; } $ bLabel = '' ; if ( isset ( $ b [ 'eventLabel' ] ) ) { $ bLabel = ( is_array ( $ b [ 'eventLabel' ] ) ) ? $ b [ 'eventLabel' ] [ 'label' ] : $ b [ 'eventLabel' ] ; } return strnatcmp ( $ aLabel , $ bLabel ) ; case 'date_added' : if ( $ a [ 'timestamp' ] == $ b [ 'timestamp' ] ) { $ aPriority = isset ( $ a [ 'eventPriority' ] ) ? ( int ) $ a [ 'eventPriority' ] : 0 ; $ bPriority = isset ( $ b [ 'eventPriority' ] ) ? ( int ) $ b [ 'eventPriority' ] : 0 ; return $ aPriority - $ bPriority ; } return $ a [ 'timestamp' ] < $ b [ 'timestamp' ] ? - 1 : 1 ; case 'contact_id' : if ( $ a [ 'contactId' ] == $ b [ 'contactId' ] ) { return 0 ; } return $ a [ 'contactId' ] < $ b [ 'contactId' ] ? - 1 : 1 ; case 'type' : return strnatcmp ( $ a [ 'eventType' ] , $ b [ 'eventType' ] ) ; default : return strnatcmp ( $ a [ $ this -> orderBy [ 0 ] ] , $ b [ $ this -> orderBy [ 0 ] ] ) ; } } ) ; if ( 'DESC' == $ this -> orderBy [ 1 ] ) { $ events = array_reverse ( $ events ) ; } } return $ events ; }
Fetch the events.

@return array Events sorted by timestamp with most recent event first
Fetch the events .