Pressbooks\Modules\Export\Mpdf\Pdf::getOrderedBookContents PHP Method

getOrderedBookContents() public method

Restructures \Pressbooks\Book::getBookContents() into a format more useful for direct iteration, and tracks a nesting level for Bookmark and ToC entries.
public getOrderedBookContents ( ) : array
return array
    function getOrderedBookContents()
    {
        $book_contents = \Pressbooks\Book::getBookContents();
        $ordered = array();
        foreach ($book_contents as $type => $struct) {
            if (strpos($type, '__') === 0) {
                continue;
                // Skip __magic keys
            }
            switch ($type) {
                case 'part':
                    foreach ($struct as $part) {
                        $part_content = trim(get_post_meta($part['ID'], 'pb_part_content', true));
                        if ($part_content || $this->atLeastOneExport($part['chapters'])) {
                            if (!empty($part['post_content'])) {
                                $part['mpdf_level'] = 1;
                                $part['post_content'] .= $part_content;
                            } else {
                                $part['post_content'] = $part_content;
                                $part['mpdf_level'] = 0;
                            }
                            $ordered[] = $part;
                            foreach ($part['chapters'] as $chapter) {
                                if (!$chapter['export']) {
                                    continue;
                                }
                                $chapter['mpdf_level'] = $part['mpdf_level'] + 1;
                                $ordered[] = $chapter;
                                if (\Pressbooks\Modules\Export\Export::isParsingSubsections() == true) {
                                    $sections = \Pressbooks\Book::getSubsections($chapter['ID']);
                                    if ($sections) {
                                        foreach ($sections as $section) {
                                            $section['mpdf_level'] = $part['mpdf_level'] + 2;
                                            $ordered[] = $section;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    break;
                default:
                    foreach ($struct as $item) {
                        if (!$item['export']) {
                            continue;
                        }
                        $item['mpdf_level'] = 1;
                        $ordered[] = $item;
                        if (\Pressbooks\Modules\Export\Export::isParsingSubsections() == true) {
                            $sections = \Pressbooks\Book::getSubsections($item['ID']);
                            if ($sections) {
                                foreach ($sections as $section) {
                                    $section['mpdf_level'] = 2;
                                    $ordered[] = $section;
                                }
                            }
                        }
                    }
                    break;
            }
        }
        return $ordered;
    }