高章伟
2022-02-18 8b5f4c6c281cfa548f92de52c8021e37aa81901e
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
public with sharing class OFSBulletinBoardController {
    public String pType {get; private set;}
    public List<HBBInfo> hbbInfoList {get; private set;}
    public void init(){
        hbbInfoList = new List<HBBInfo>();
        pType = System.currentPageReference().getParameters().get('type');
        // TODO 公開開始日<=today && 公開終了日>today
        // List<HBBInfo> tmpList = new List<HBBInfo>();
        // 今回は1種類しか出さないため、tmpList.sort(); が要らない、そのまま hbbInfoList.add()
        if (pType == 'Product_Documentation__c') {
            List<Product_Documentation__c> pdList = [select Id, Material_open_day__c, Material_category__c, Product_document_name__c
                                          from Product_Documentation__c 
                                          where Material_status__c = '公开中'
                                          order by Material_open_day__c desc limit 20];
            for (Product_Documentation__c pd : pdList) {
                hbbInfoList.add(new HBBInfo(pd));
            }
        }
        else if (pType == 'Solution') {
            List<Solution> faqList = [select Id, FAQ_disclosed_day__c, Question_category__c, SolutionName
                                          from Solution
                                          where Status = 'レビュー済み'
                                          order by FAQ_disclosed_day__c desc limit 20];
            for (Solution faq : faqList) {
                hbbInfoList.add(new HBBInfo(faq));
            }
        }
        else if (pType == 'Campaign') {
            List<Campaign> camList = [select Id, StartDate, RecordType.Name, Name
                                          from Campaign
                                          where (Status = '公开中' or Status = '已结束' or Status = '已提交报告')
                                          order by StartDate desc limit 20];
            for (Campaign cam : camList) {
                hbbInfoList.add(new HBBInfo(cam));
            }
        }
        else {
            List<Bulletin_Board__c> bbList = [select Id, Board_open_day__c, Board_category1__c, Name
                                          from Bulletin_Board__c
                                          where Board_status__c = '公开中'
                                          order by Board_open_day__c desc limit 20];
            for (Bulletin_Board__c bb : bbList) {
                hbbInfoList.add(new HBBInfo(bb));
            }
        }
    }
    public class HBBInfo implements Comparable {
        public Id linkId {get; private set;}
        public Date openday {get; private set;}
        public String daiBunrui {get; private set;}
        public String bunrui {get; private set;}
        public String subject {get; private set;}
        public Bulletin_Board__c bb {get; private set;}
 
        public HBBInfo(Product_Documentation__c pd) {
            linkId = pd.Id;
            openday = pd.Material_open_day__c;
            daiBunrui = Schema.SObjectType.Product_Documentation__c.Label;
            bunrui = pd.Material_category__c;
            subject = pd.Product_document_name__c;
        }
 
        public HBBInfo(Solution faq) {
            linkId = faq.Id;
            openday = faq.FAQ_disclosed_day__c;
            daiBunrui = Schema.SObjectType.Solution.Label;
            bunrui = faq.Question_category__c;
            subject = faq.SolutionName;
        }
 
        public HBBInfo(Campaign cam) {
            linkId = cam.Id;
            openday = cam.StartDate;
            daiBunrui = Schema.SObjectType.Campaign.Label;
            bunrui = cam.RecordType.Name;
            subject = cam.Name;
        }
 
        public HBBInfo(Bulletin_Board__c bb) {
            linkId = bb.Id;
            openday = bb.Board_open_day__c;
            daiBunrui = Schema.SObjectType.Bulletin_Board__c.Label;
            bunrui = bb.Board_category1__c;
            subject = bb.Name;
            this.bb = bb;
        }
 
        // openday順
        public Integer compareTo(Object compareTo) {
            HBBInfo bbInfo = (HBBInfo)compareTo;
            if (openday == bbInfo.openday) return 0;
            if (openday > bbInfo.openday) return 1;
            return -1;
        }
    }
}