CourseGeneralInformation.cs 3.1 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using iText.Layout;
using iText.Layout.Element;
using PDFGenerator.Models;
using PDFGenerator.Utilities;
using System.Collections.Generic;
using System.Linq;
using static PDFGenerator.Utilities.Globals;

namespace PDFGenerator.EvaluationReport
{
    public class CourseGeneralInformation : BaseSection
    {
        private PDFCourseGeneralInformation Information { get; }
        public Dictionary<string, byte[]> CustomUploads { get; private set; }

        public CourseGeneralInformation(PDFCourseGeneralInformation information, Document document, Bookmarks bookmarks, TableOfContents tableOfContents)
        : base(document, bookmarks, tableOfContents)
        {
            Information = information;
            CustomUploads = new Dictionary<string, byte[]>();
        }

        /// <summary>
        /// Renders the content for general course information.
        /// </summary>
        public override void Render()
        {
            int sectionCount = 0;
            string[] sections = Information.Sections.Keys.ToArray();
            Bookmarks.AddRootOutline(sections[sectionCount], RootOutline);

            TocItem tocItem = new TocItem
            {
                Title = sections[sectionCount],
                Indent = Information.Sections[sections[sectionCount]],
                Page = GetCurrentPage()
            };
            TableOfContents.AddToTOC(tocItem);

            Paragraph p = new Paragraph(new Text(sections[sectionCount]).AddStyle(Styles.H1)).SetDestination(sections[sectionCount++]);
            Document.Add(p);

            foreach (KeyValuePair<string, List<InformationForEvaluationCourse>> topic in Information.EvaluationCoursesForTopic)
            {
                Bookmarks.AddOutline(sections[sectionCount], OutlineLevel.Level1);

                tocItem = new TocItem
                {
                    Title = sections[sectionCount],
                    Indent = Information.Sections[sections[sectionCount]],
                    Page = GetCurrentPage()
                };
                TableOfContents.AddToTOC(tocItem);

                p = new Paragraph(new Text(sections[sectionCount]).AddStyle(Styles.H3)).SetDestination(sections[sectionCount++]);
                Document.Add(p);

                topic.Value.ForEach(item =>
                {
                    // course name if topic information is course specific
                    if (!string.IsNullOrEmpty(item.Paragraphs[0]))
                    {
                        Document.Add(ParagraphFactory.GetCustomParagraph(item.Paragraphs[0], Styles.H4, -0.3f, 3.3f, 1.5f));
                    }

                    if (item.UploadedFilesForTopic != null)
                    {
                        AddCustomUploads(item.UploadedFilesForTopic, CustomUploads);
                    }

Sebastian Drenckberg's avatar
Sebastian Drenckberg committed
71
                    // description for the current topic, if available (depends on topic)
72
73
74
75
76
77
78
79
80
81
82
                    if (item.Paragraphs.Count == 2)
                    {
                        Document.Add(ParagraphFactory.GetStandardParagraph(item.Paragraphs[1]));
                    }
                });
            }

            AddPageBreak();
        }
    }
}