CourseGeneralInformation.cs 3.23 KB
Newer Older
1
2
using iText.Layout;
using iText.Layout.Element;
3
using PDFGenerator.Models.EvaluationReport;
4
5
6
7
using PDFGenerator.Utilities;
using System.Collections.Generic;
using System.Linq;
using static PDFGenerator.Utilities.Globals;
8
using Styles = PDFGenerator.Utilities.Globals.Constants.EvaluationReport.Styles;
9

10
namespace PDFGenerator.DocumentStructures.EvaluationReport
11
{
12
    public class CourseGeneralInformation : EvaluationReportBaseSection
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
71
    {
        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
72
                    // description for the current topic, if available (depends on topic)
73
74
75
76
77
78
79
80
81
82
83
                    if (item.Paragraphs.Count == 2)
                    {
                        Document.Add(ParagraphFactory.GetStandardParagraph(item.Paragraphs[1]));
                    }
                });
            }

            AddPageBreak();
        }
    }
}