]> WPIA git - gigi.git/blob - src/club/wpia/gigi/output/AssurancesDisplay.java
upd: rename package name and all references to it
[gigi.git] / src / club / wpia / gigi / output / AssurancesDisplay.java
1 package club.wpia.gigi.output;
2
3 import java.io.PrintWriter;
4 import java.util.Map;
5
6 import club.wpia.gigi.dbObjects.Assurance;
7 import club.wpia.gigi.dbObjects.Name;
8 import club.wpia.gigi.localisation.Language;
9 import club.wpia.gigi.output.template.IterableDataset;
10 import club.wpia.gigi.output.template.Outputable;
11 import club.wpia.gigi.output.template.Template;
12
13 public class AssurancesDisplay implements Outputable {
14
15     private static final Template template = new Template(AssurancesDisplay.class.getResource("AssurancesDisplay.templ"));
16
17     private boolean assurer;
18
19     public String assuranceArray;
20
21     private boolean support;
22
23     public AssurancesDisplay(String assuranceArray, boolean assurer, boolean support) {
24         this.assuranceArray = assuranceArray;
25         this.assurer = assurer;
26         this.support = support;
27     }
28
29     @Override
30     public void output(PrintWriter out, Language l, Map<String, Object> vars) {
31         final Assurance[] assurances = (Assurance[]) vars.get(assuranceArray);
32         if (assurer) {
33             vars.put("verb", l.getTranslation("To (User Id)"));
34             vars.put("info", "");
35         } else {
36             vars.put("verb", l.getTranslation("From"));
37             vars.put("myName", "yes");
38             vars.put("info", l.getTranslation("Coloured rows show expired nucleus bonus verifications which are not counted to the total of verification points."));
39         }
40
41         IterableDataset assuranceGroup = new IterableDataset() {
42
43             private int i = 0;
44
45             @Override
46             public boolean next(Language l, Map<String, Object> vars) {
47                 if (i >= assurances.length) {
48                     return false;
49                 } else {
50                     Assurance assurance = assurances[i];
51                     vars.put("support", support);
52                     vars.put("id", assurance.getId());
53                     vars.put("method", assurance.getMethod());
54                     Name to = assurance.getTo();
55                     if (assurer) {
56                         vars.put("linkId", to == null ? "" : to.getOwner().getId());
57                         vars.put("verbVal", to == null ? l.getTranslation("applicant's name removed") : to.getOwner().getId());
58                         vars.put("myName", to == null ? l.getTranslation("applicant's name removed") : to);
59                     } else {
60                         vars.put("linkId", assurance.getFrom().getId());
61                         vars.put("verbVal", assurance.getFrom().getPreferredName());
62                         vars.put("myName", to == null ? l.getTranslation("own name removed") : to);
63                     }
64                     vars.put("date", assurance.getDate());
65                     vars.put("location", assurance.getLocation() + " (" + (assurance.getCountry() == null ? l.getTranslation("not given") : assurance.getCountry().getName()) + ")");
66                     vars.put("points", assurance.getPoints());
67                     vars.put("expired", assurance.isExpired());
68                     i++;
69                     return true;
70                 }
71             }
72         };
73         vars.put("assurances", assuranceGroup);
74         template.output(out, l, vars);
75     }
76
77 }