~ubuntu-branches/ubuntu/hardy/steam/hardy

« back to all changes in this revision

Viewing changes to server/classes/Calendar.pike

  • Committer: Bazaar Package Importer
  • Author(s): Alain Schroeder
  • Date: 2006-11-21 16:03:12 UTC
  • mfrom: (2.1.4 feisty)
  • Revision ID: james.westby@ubuntu.com-20061121160312-nf96y6nihzsyd2uv
Tags: 2.2.31-3
Add patch to prevent inconsistent data after shutdown.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2000-2003  Thomas Bopp, Thorsten Hampel, Ludger Merkens
 
1
/* Copyright (C) 2000-2006  Thomas Bopp, Thorsten Hampel, Ludger Merkens
2
2
 *
3
3
 *  This program is free software; you can redistribute it and/or modify
4
4
 *  it under the terms of the GNU General Public License as published by
18
18
 
19
19
//! A Calendar is a room with Date Objects in it.
20
20
 
21
 
#define CALENDAR_DEBUG 1
 
21
//#define CALENDAR_DEBUG 1
22
22
 
23
23
#ifdef CALENDAR_DEBUG
24
24
#define DEBUG_CALENDAR(s, args...) write("Calendar: "+s+"\n", args)
28
28
 
29
29
#include <classes.h>
30
30
#include <attributes.h>
 
31
#include <macros.h>
31
32
 
32
33
string describe() 
33
34
{
41
42
{
42
43
  object factory = get_factory(CLASS_LINK);
43
44
  object link, calendar, ulink;
 
45
  array haves = ({ });
44
46
 
45
47
  DEBUG_CALENDAR("Creating links for date %O", date);
46
48
  foreach(creator->get_members(), object member) {
47
 
    DEBUG_CALENDAR("Link created for %O", member);
48
 
    calendar = member->query_attribute(USER_CALENDAR);
49
 
    link = factory->execute(([ "name": date->get_identifier(),
50
 
                               "attributes": date->query_attributes(),  
51
 
                               "link_to": date,   ]) );
52
 
    link->move(calendar);
 
49
    if ( member->get_object_class() & CLASS_USER )
 
50
      calendar = member->query_attribute(USER_CALENDAR);
 
51
    else if ( member->get_object_class() & CLASS_GROUP )
 
52
      calendar = member->query_attribute(GROUP_CALENDAR);
 
53
    else continue;
 
54
    DEBUG_CALENDAR("Checking link for %O", member);
 
55
    if ( !objectp(calendar) ) {
 
56
      werror( "Calendar: invalid calendar of member %O\n", member );
 
57
      continue;
 
58
    }
 
59
    if ( search( haves, calendar ) < 0 ) {
 
60
      DEBUG_CALENDAR("Creating link for %O", member);
 
61
      link = factory->execute(([ "name": date->get_identifier(),
 
62
                                 "attributes": date->query_attributes(),  
 
63
                                 "link_to": date,   ]) );
 
64
      if ( link->move(calendar) ) haves += ({ calendar });
 
65
    }
53
66
  }
54
67
  
55
68
  foreach(groups, object grp) {
56
69
    calendar = grp->query_attribute(GROUP_CALENDAR);
57
 
    link = factory->execute(([ "name": date->get_identifier(),
58
 
                               "attributes": date->query_attributes(),  
59
 
                               "link_to": date, ]) );
60
 
    link->move(calendar);
 
70
    if ( search( haves, calendar ) < 0 ) {
 
71
      DEBUG_CALENDAR("Creating link for group %O", grp);
 
72
      link = factory->execute(([ "name": date->get_identifier(),
 
73
                                 "attributes": date->query_attributes(),  
 
74
                                 "link_to": date, ]) );
 
75
      if ( link->move(calendar) ) haves += ({ calendar });
 
76
    }
61
77
    foreach(grp->get_members(), object member) {
62
 
      if ( creator->is_member(member) )
63
 
        continue; // they have original date!
64
 
      calendar = member->query_attribute(USER_CALENDAR);
65
 
      ulink = factory->execute(([ "name": date->get_identifier(),
66
 
                                  "attributes": date->query_attributes(), 
67
 
                                  "link_to": link, ]) );
68
 
      ulink->move(calendar);
 
78
      if ( member->get_object_class() & CLASS_USER )
 
79
        calendar = member->query_attribute(USER_CALENDAR);
 
80
      else if ( member->get_object_class() & CLASS_GROUP )
 
81
        calendar = member->query_attribute(GROUP_CALENDAR);
 
82
      else continue;
 
83
      if ( !objectp(calendar) ) {
 
84
        werror( "Calendar: invalid calendar of member %O\n", member );
 
85
        continue;
 
86
      }
 
87
      if ( search( haves, calendar ) < 0 ) {
 
88
        DEBUG_CALENDAR("Creating sub link for group member %O", member);
 
89
        ulink = factory->execute(([ "name": date->get_identifier(),
 
90
                                    "attributes": date->query_attributes(), 
 
91
                                    "link_to": link, ]) );
 
92
        if ( ulink->move(calendar) ) haves += ({ calendar });
 
93
      }
69
94
    }
70
95
  }
71
96
}
96
121
  return entry;
97
122
}
98
123
 
99
 
object filter_datelinks(object link)
100
 
{
101
 
  object linkobj = link->get_link_object();
102
 
  if ( !objectp(linkobj) ) return 0;
103
 
  
104
 
  if ( linkobj->get_object_class() & CLASS_DATE )
105
 
    return link;
106
 
  return 0;
 
124
object filter_datelinks ( object link ) {
 
125
  object linkobj = link;
 
126
  do {
 
127
    if ( !objectp(linkobj) ) return UNDEFINED;
 
128
    if ( linkobj->get_object_class() & CLASS_LINK )
 
129
      linkobj = linkobj->get_link_object();
 
130
    else if ( linkobj->get_object_class() & CLASS_DATE )
 
131
      return linkobj;
 
132
    else return UNDEFINED;
 
133
  } while ( true );
 
134
}
 
135
 
 
136
array get_all_entries_day ( void|int offset, void|int type )
 
137
{
 
138
  object start = Calendar.Day() + offset;
 
139
  object end = start + offset + 1;
 
140
  return get_all_entries( start->unix_time(), end->unix_time()-1, type );
 
141
}
 
142
 
 
143
array get_all_entries_week ( void|int offset, void|int type )
 
144
{
 
145
  object start = Calendar.Week() + offset;
 
146
  object end = start + offset + 1;
 
147
  return get_all_entries( start->unix_time(), end->unix_time()-1, type );
 
148
}
 
149
 
 
150
array get_all_entries_month ( void|int offset, void|int type )
 
151
{
 
152
  object start = Calendar.Month() + offset;
 
153
  object end = start + offset + 1;
 
154
  return get_all_entries( start->unix_time(), end->unix_time()-1, type );
 
155
}
 
156
 
 
157
array get_all_entries_year ( void|int offset, void|int type )
 
158
{
 
159
  object start = Calendar.Year() + offset;
 
160
  object end = start + offset + 1;
 
161
  return get_all_entries( start->unix_time(), end->unix_time()-1, type );
107
162
}
108
163
 
109
164
array get_all_entries(void|int start, void|int end, void|int type) 
110
165
{
111
 
  array dates = get_inventory_by_class(CLASS_DATE);
112
 
  array dlinks = get_inventory_by_class(CLASS_LINK);
113
 
  dlinks = filter(dlinks, filter_datelinks);
 
166
  int result;
 
167
  mixed  err;
 
168
 
 
169
  array dates = get_inventory_by_class( CLASS_DATE );
 
170
  array dlinks = get_inventory_by_class( CLASS_LINK );
 
171
  dlinks = filter( dlinks, filter_datelinks );
114
172
  if ( start > 0 ) {
115
173
    array matches = ({ });
116
174
    foreach(dates, object date) {
117
 
      if ( date->match(start, end) )
 
175
      err = catch( result =  date->match(start, end) );
 
176
      if ( err ) {
 
177
        FATAL("While getting entries: %s\n%O", err[0], err[1]);
 
178
      }
 
179
      else if ( result )
118
180
        matches += ({ date });
119
181
    }
120
182
    foreach(dlinks, object link) {
121
 
      object linkobj = link->get_link_object();
122
 
      if ( linkobj->match(start, end) )
 
183
      object linkobj = filter_datelinks( link );
 
184
      err = catch( result =  linkobj->match(start, end) );
 
185
      if ( err ) {
 
186
        FATAL("While getting entries: %s\n%O", err[0], err[1]);
 
187
      }
 
188
      else if ( result )
123
189
        matches += ({ link });
124
190
    }
125
191
    if ( intp(type) && type > 0 ) {