1 package BSE::TB::SeminarSession;
3 use base qw(Squirrel::Row);
4 use BSE::Util::SQL qw(now_sqldatetime);
6 our $VERSION = "1.001";
9 return qw/id seminar_id location_id when_at roll_taken/;
15 require BSE::TB::SiteUsers;
16 return BSE::TB::SiteUsers->getSpecial(sessionBookings => $self->{id});
19 # perhaps this should allow removing old sessions with no bookings
23 return $self->{when_at} gt now_sqldatetime();
29 require BSE::TB::Seminars;
31 return BSE::TB::Seminars->getByPkey($self->{seminar_id});
37 require BSE::TB::Locations;
38 return BSE::TB::Locations->getByPkey($self->{location_id});
42 my ($self, $other) = @_;
44 # ideally we could just update the column, but that has 2 problems:
45 # - the user might be booked in both the original and new session
46 # - this would be changing the primary key of a record, which is bad
47 my %conflicts = map { $_->{id} => 1 }
48 BSE::DB->query(conflictSeminarSessions => $self->{id}, $other->{id});
49 my @users_booked = map $_->{siteuser_id},
50 BSE::DB->query(seminarSessionBookedIds => $self->{id});
51 for my $userid (@users_booked) {
52 unless ($conflicts{$userid}) {
53 BSE::DB->run(seminarSessionBookUser => $other->{id}, $userid, 0);
56 BSE::DB->run(cancelSeminarSessionBookings => $self->{id});
64 BSE::DB->run(cancelSeminarSessionBookings => $self->{id});
68 sub roll_call_entries {
71 BSE::DB->query(seminarSessionRollCallEntries => $self->{id});
74 sub set_roll_present {
75 my ($self, $userid, $present) = @_;
77 $present = $present ? 1 : 0;
79 BSE::DB->run(updateSessionRollPresent => $present, $self->{id}, $userid);
82 my @attendee_attributes =
83 qw/roll_present options customer_instructions support_notes/;
84 my %attendee_defaults =
88 customer_instructions => '',
93 my ($self, $user, %attr) = @_;
95 my %work_attr = %attendee_defaults;
96 for my $key (keys %attr) {
97 exists $work_attr{$key} or
98 Carp::confess("Unknown attendee attribute '$key'");
99 $work_attr{$key} = $attr{$key};
102 my $user_id = ref $user ? $user->{id} : $user;
104 require BSE::TB::SeminarBookings;
105 BSE::TB::SeminarBookings->add($self->{id}, $user_id,
106 @work_attr{@attendee_attributes});
110 my ($self, $user) = @_;
112 my $siteuser_id = ref $user ? $user->{id} : $user;
114 require BSE::TB::SeminarBookings;
115 my @result = BSE::TB::SeminarBookings->
116 getBy(session_id => $self->{id}, siteuser_id => $siteuser_id);
123 my ($self, $user) = @_;
125 my $siteuser_id = ref $user ? $user->{id} : $user;
127 my $result = BSE::DB->run
128 (bse_cancelSessionBookingForUser => $self->{id}, $siteuser_id);
130 or die "No such booking\n";
134 my ($self, $user, %attr) = @_;
136 my $have_all = !grep !exists$attr{$_}, @attendee_attributes;
138 my $old_booking = $self->get_booking($user)
139 or die "No such booking\n";
140 %attr = ( %$old_booking, %attr );
143 my $siteuser_id = ref $user ? $user->{id} : $user;
145 BSE::DB->run(bse_updateSessionBookingForUser =>
146 @attr{@attendee_attributes},
147 $self->{id}, $siteuser_id)
148 or die "No such booking\n";