yanweiyuan3
2023-08-09 588bc7829387dfc761cc25f06f77d4c81818bd10
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
Quintiq file version 2.0
#parent: #root
Method CanSubscribe (
  Date startOfSubscription_i,
  Date endOfSubscription_i,
  Boolean isWithoutEnd_i
) remote as Boolean
{
  TextBody:
  [*
    // Explicitly collect the FeedbackText, in order to be able to show it in a MessageBox.
    feedback := FeedbackObject::LocalFeedback();
    feedback.EnableLocalFeedbackText();
    
    context              := "     -  Subscription to event '" + this.Subject() + "'"; // + "' : ";
    leadingParticipation := this.LeadingParticipation();
    startOfCalendar      := leadingParticipation.Calendar().StartDate();
    canSubscribe         := true;
    
    if( leadingParticipation.IsRecurring() )
    {
      period := leadingParticipation.RecurrencePeriod();
      
      // Additional restrictions if the event that is subscribed to has an end.
      // These checks are done on period-level, so on Dates, not DateTimes.
      if( period.PeriodType() = LibCal_RecurrencePeriod::TYPE_WITHENDDATE() )
      {
        // The subscription should start before the end of the recurrence period of the event.
        canSubscribe := startOfSubscription_i <= period.EndDate();
        
        if( not feedback.CheckHard( canSubscribe ) )
        {
          feedback.AddHard( context );
          /* Might be useful later
          feedback.AddHard( context + Translations::Period_StartMustBeBeforeEndOfEvent( "subscription",
                                                                                        startOfSubscription_i.Format( Translations::DateFormat() ),
                                                                                        period.EndDate().Format( Translations::DateFormat() ) ) + String::NewLine() );
         */
        }
      }
      
      // If the subscription has an end...
      if( feedback.IsAllowed() and
          isWithoutEnd_i = false )
      {
        if( period.StartDate() >= startOfCalendar )
        {
          // ...the end must be greater that the start of the recurrence period of the event.
          canSubscribe := endOfSubscription_i >= period.StartDate();
    
          if( not feedback.CheckHard( canSubscribe ) )
          {
            feedback.AddHard( context );
            
            /* Might be useful later
            feedback.AddHard( context + Translations::Period_EndMustBeGreaterThanStartOfEvent( "subscription",
                                                                                               period.StartDate() .Format( Translations::DateFormat() ),
                                                                                               endOfSubscription_i.Format( Translations::DateFormat() ) ) + String::NewLine() );
            */
          }
        }
        else
        {
          // ...the end must be greater than the start of the calendar
          canSubscribe :=  endOfSubscription_i >= startOfCalendar;
    
          if( not feedback.CheckHard( canSubscribe ) )
          {
            feedback.AddHard( context );
            
            /*
            feedback.AddHard( context + Translations::Period_EndMustBeGreaterThanStartOfCalendar( "subscription",
                                                                                                  endOfSubscription_i.Format( Translations::DateFormat() ),
                                                                                                  startOfCalendar    .Format( Translations::DateFormat() ) ) + String::NewLine() );
            */
          }
        }
      }
    }
    else
    {
      // No restrictions in case of a non-recurring event.
    }
    
    return feedback.IsAllowed();
  *]
  InterfaceProperties { Accessibility: 'Module' }
}