public function toArray()
    {
        $threads = [];
        $p = [];
        $p['timestamp'] = time();
        $p['direction'] = $this->direction;
        $p['activity'] = [];
        $p['objects'] = [];
        $p['lastItem'] = null;
        $p['mostRecentItem'] = null;
        $lastKey = null;
        $lastTimestamp = null;
        foreach ($this as $item) {
            $eventObject = $item->eventObject;
            $eventObject->context = $this->context;
            $package = $eventObject->package;
            if (empty($p['lastItem']) || (float)$package['timestamp'] < $p['lastItem']) {
                $p['lastItem'] = (float)$package['timestamp'];
            }
            if (empty($p['mostRecentItem']) || (float)$package['timestamp'] > $p['mostRecentItem']) {
                $p['mostRecentItem'] = (float)$package['timestamp'];
            }
            if (!isset($threads[$package['key']])) {
                $threads[$package['key']] = 0;
            }
            if ($package['key'] !== $lastKey
                || (abs((float)$package['timestamp'] - $lastTimestamp) > ($this->similarThreshold))) {
                if (isset($threads[$lastKey])) {
                    $threads[$lastKey]++;
                }
                $lastKey = $package['key'];
                $lastTimestamp = (float)$package['timestamp'];
            }
            $key = $package['key'] . '-' . $threads[$lastKey];
            if (isset($p['activity'][$key])) {
                $p['activity'][$key]['details'][$item->primaryKey] = $package['details'];
                continue;
            }
            $p['activity'][$key] = [];
            $p['activity'][$key]['id'] = $item->primaryKey;
            $p['activity'][$key]['primaryObject'] = $package['primaryObject'];
            $p['activity'][$key]['agent'] = $package['agent'];
            $p['activity'][$key]['story'] = $package['story'];
            $p['activity'][$key]['timestamp'] = $package['timestamp'];
            $p['activity'][$key]['details'] = [$item->primaryKey => $package['details']];

            foreach ($package['objects'] as $object) {
                if (isset($p['objects'][$object->primaryKey])) {
                    continue;
                }
                $p['objects'][$object->primaryKey] = $object->package;
                $p['objects'][$object->primaryKey]['descriptor'] = htmlspecialchars(strip_tags($p['objects'][$object->primaryKey]['descriptor']));
                unset($p['objects'][$object->primaryKey]['id']);
            }
        }
        //\d($p);exit;
        return $p;
    }
public function toArray()
    {
        $threads = [];
        $p = [];
        $p['timestamp'] = time();
        $p['direction'] = $this->direction;
        $p['activity'] = [];
        $p['objects'] = [];
        $p['lastItem'] = null;
        $p['mostRecentItem'] = null;
        $lastKey = null;
        $lastTimestamp = null;
        foreach ($this as $item) {
            $eventObject = $item->eventObject;
            $eventObject->context = $this->context;
            $package = $eventObject->package;
            if (empty($p['lastItem']) || (float)$package['timestamp'] < $p['lastItem']) {
                $p['lastItem'] = (float)$package['timestamp'];
            }
            if (empty($p['mostRecentItem']) || (float)$package['timestamp'] > $p['mostRecentItem']) {
                $p['mostRecentItem'] = (float)$package['timestamp'];
            }
            if (!isset($threads[$package['key']])) {
                $threads[$package['key']] = 0;
            }
            if ($package['key'] !== $lastKey
                || (abs((float)$package['timestamp'] - $lastTimestamp) > ($this->similarThreshold))) {
                if (isset($threads[$lastKey])) {
                    $threads[$lastKey]++;
                }
                $lastKey = $package['key'];
                $lastTimestamp = (float)$package['timestamp'];
            }
            $key = $package['key'] . '-' . $threads[$lastKey];
            if (isset($p['activity'][$key])) {
                $p['activity'][$key]['details'][$item->primaryKey] = $package['details'];
                continue;
            }
            $p['activity'][$key] = [];
            $p['activity'][$key]['id'] = $item->primaryKey;
            $p['activity'][$key]['primaryObject'] = $package['primaryObject'];
            $p['activity'][$key]['agent'] = $package['agent'];
            $p['activity'][$key]['story'] = $package['story'];
            $p['activity'][$key]['timestamp'] = $package['timestamp'];
            $p['activity'][$key]['details'] = [$item->primaryKey => $package['details']];

            foreach ($package['objects'] as $object) {
                if (isset($p['objects'][$object->primaryKey])) {
                    continue;
                }
                $p['objects'][$object->primaryKey] = $object->package;
                $p['objects'][$object->primaryKey]['descriptor'] = htmlspecialchars(strip_tags($p['objects'][$object->primaryKey]['descriptor']));
                unset($p['objects'][$object->primaryKey]['id']);
            }
        }
        //\d($p);exit;
        return $p;
    }
Returns the collection as a PHP array.
The array keys are item names, and the array values are the corresponding item objects.

@return array the array representation of the collection.