private function get_attachments_for_posts(array $groupedposts) : array {
        $attachmentsbypostid = [];
        $postattachmentvault = $this->vaultfactory->get_post_attachment_vault();
        $postsbyforum = array_reduce($groupedposts, function($carry, $grouping) {
            ['forum' => $forum, 'posts' => $posts] = $grouping;

            $forumid = $forum->get_id();
            if (!isset($carry[$forumid])) {
                $carry[$forumid] = [
                    'forum' => $forum,
                    'posts' => []
                ];
            }

            $carry[$forumid]['posts'] = array_merge($carry[$forumid]['posts'], $posts);
            return $carry;
        }, []);

        foreach ($postsbyforum as $grouping) {
            ['forum' => $forum, 'posts' => $posts] = $grouping;
            $attachments = $postattachmentvault->get_attachments_for_posts($forum->get_context(), $posts);

            // Have to loop in order to maintain the correct indexes since they are numeric.
            foreach ($attachments as $postid => $attachment) {
                $attachmentsbypostid[$postid] = $attachment;
            }
        }

        return $attachmentsbypostid;
    }
private function get_attachments_for_posts(array $groupedposts) : array {
        $attachmentsbypostid = [];
        $postattachmentvault = $this->vaultfactory->get_post_attachment_vault();
        $postsbyforum = array_reduce($groupedposts, function($carry, $grouping) {
            ['forum' => $forum, 'posts' => $posts] = $grouping;

            $forumid = $forum->get_id();
            if (!isset($carry[$forumid])) {
                $carry[$forumid] = [
                    'forum' => $forum,
                    'posts' => []
                ];
            }

            $carry[$forumid]['posts'] = array_merge($carry[$forumid]['posts'], $posts);
            return $carry;
        }, []);

        foreach ($postsbyforum as $grouping) {
            ['forum' => $forum, 'posts' => $posts] = $grouping;
            $attachments = $postattachmentvault->get_attachments_for_posts($forum->get_context(), $posts);

            // Have to loop in order to maintain the correct indexes since they are numeric.
            foreach ($attachments as $postid => $attachment) {
                $attachmentsbypostid[$postid] = $attachment;
            }
        }

        return $attachmentsbypostid;
    }
private function get_attachments_for_posts ( array $ groupedposts ) : array { $ attachmentsbypostid = [ ] ; $ postattachmentvault = $ this -> vaultfactory -> get_post_attachment_vault ( ) ; $ postsbyforum = array_reduce ( $ groupedposts , function ( $ carry , $ grouping ) { [ 'forum' => $ forum , 'posts' => $ posts ] = $ grouping ; $ forumid = $ forum -> get_id ( ) ; if ( ! isset ( $ carry [ $ forumid ] ) ) { $ carry [ $ forumid ] = [ 'forum' => $ forum , 'posts' => [ ] ] ; } $ carry [ $ forumid ] [ 'posts' ] = array_merge ( $ carry [ $ forumid ] [ 'posts' ] , $ posts ) ; return $ carry ; } , [ ] ) ; foreach ( $ postsbyforum as $ grouping ) { [ 'forum' => $ forum , 'posts' => $ posts ] = $ grouping ; $ attachments = $ postattachmentvault -> get_attachments_for_posts ( $ forum -> get_context ( ) , $ posts ) ; // Have to loop in order to maintain the correct indexes since they are numeric. foreach ( $ attachments as $ postid => $ attachment ) { $ attachmentsbypostid [ $ postid ] = $ attachment ; } } return $ attachmentsbypostid ; }
Load the list of all attachments for the posts. The list of attachments will be
indexed by the post id.

@param array $groupedposts List of posts grouped by discussions.
@return stored_file[]
Load the list of all attachments for the posts . The list of attachments will be indexed by the post id .