Question

I am currently using the FullCalendar JQuery module to allow a user to create a personal timetable. The events are added/updated to an SQL Server database. This is working fine.

I am trying to create a facility where each user has a database which has stored all of their events for the year, some of which can be recurring and occur every week.

I then wish to have users be able to organize meetings with other users based on the timeslots available in their timetables.

I'm not sure how to integrate these recurring events into my system, or how my algorithm would work with these recurring events.

The design I have at the moment is :

CREATE TABLE Users (
  user_id INT NOT NULL AUTO_INCREMENT,
  email VARCHAR(80) NOT NULL,
  password CHAR(41) NOT NULL,
  PRIMARY KEY (user_id)
);

CREATE TABLE Events (
    event_id INT NOT NULL AUTO_INCREMENT,
    title VARCHAR(80) NOT NULL,
    description VARCHAR(200),
    start_time DATETIME,
    end_time DATETIME,
    group_id INT NOT NULL,
        recurring boolean
);

CREATE TABLE Groups (
    group_id INT NOT NULL,
    user_id INT NOT NULL
);

Will this be sufficient? How will I have it so that recurring events are rendered on the calendar for every week? If I am lacking in any detail, please ask! Thank you very much.

Was it helpful?

Solution

You could use something like the following:

SELECT  *
FROM    Events
WHERE   Recurring = 0
UNION
SELECT  Event_ID,
        Title,
        Description, 
        DATEADD(WEEK, Interval, Start_Time) [Start_Time],
        DATEADD(WEEK, Interval, End_Time) [End_Time],
        Group_ID,
        Recurring
FROM    Events, 
        (   SELECT  ROW_NUMBER() OVER(ORDER BY Object_ID) [Interval]
            FROM    SYS.ALL_OBJECTS
        ) i
WHERE   Recurring = 1
AND     Interval <= 52 -- reccurs for 1 year

This will make all events repeat for 52 weeks (or whatever period you want).

As an aside, in the question you mentioned sql server, and you have tagged the question as SQL server but all your syntax appears to be MySQL (AUTO_INCREMENT, Boolean data type).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top