Skip to main content
Known Participant
August 2, 2010
Question

adding events in calendar administration

  • August 2, 2010
  • 1 reply
  • 510 views

Hi we have an application called calendar administration and i need to add some more options to calendar to add events , i am new to coldfusion and i need help in this

When adding events in Calendar Administration, there are three types available:

Single date
Date Range
Weekly Recurring

Can we have these additional options:


Bimonthly Recurring - Same day of week, every other week
Period Recurring - Same day of week, every period

here is the query doing the inserts of events , i need to know how to add these bimonthly and period recurring events to calendar , any ideas please help me

<cfset inserted=0>
    <cfswitch expression="#attributes.EVENT_DATE_TYPE_ID#">
      <cfcase value="1">
        <!--- SINGLE DATE --->
        <cfquery name="ieventdate"
                 datasource="#request.dsnCalendar#">
          INSERT INTO  #cal_event_date_tbl#(event_id,event_date)
          VALUES (#eventid#,<cfqueryparam value="#DateFormat(attributes.event_start_date, "mm/dd/yyyy")#" cfsqltype="cf_sql_timestamp" />)
        </cfquery>

        <cfset inserted=inserted+1>
      </cfcase>
      <cfcase value="2">
        <!--- DATE RANGE --->
        <cfset tempStartDate=attributes.EVENT_START_DATE>
        <cfloop condition="DateCompare(tempStartDate, attributes.EVENT_END_DATE) IS NOT 1">
          <cfquery name="ieventdate"
                   datasource="#request.dsnCalendar#">
            INSERT INTO  #cal_event_date_tbl#(event_id,event_date)
            VALUES (#eventid#,
            '#dateformat(tempstartdate, "mm/dd/yyyy")#')
          </cfquery>

          <cfset tempStartDate=DateAdd("d", 1, tempStartDate)>
          <cfset inserted=inserted+1>
        </cfloop>
      </cfcase>
      <cfcase value="3">
        <!--- WEEKLY RECURRING --->
        <cfset tempStartDate=attributes.EVENT_START_DATE>
        <cfloop condition="DayOfWeek(tempStartDate) IS NOT attributes.DATE_INCREMENT_DOW">
          <cfset tempStartDate=DateAdd("d", 1, tempStartDate)>
        </cfloop>
        <cfif attributes.EVENT_DATE_INCREMENT_ID IS "1">
          <cfloop condition="DateCompare(tempStartDate, attributes.EVENT_END_DATE) IS NOT 1">
            <cfquery name="ieventdate"
                     datasource="#request.dsnCalendar#">
              INSERT INTO  #cal_event_date_tbl#(event_id,event_date)
              VALUES (#eventid#,
              '#dateformat(tempstartdate, "mm/dd/yyyy")#')
            </cfquery>

            <cfset tempStartDate=DateAdd("d", 7, tempStartDate)>
            <cfset inserted=inserted+1>
          </cfloop>
        <cfelseif DateCompare(tempStartDate, attributes.EVENT_END_DATE) IS NOT 1>
          <cfset bopDates=ArrayNew(1)>
          <cfquery name="qfiscalcalendarbop"
                   datasource="#request.dsnCalendar#">
            SELECT DISTINCT bop
            FROM common.dbo.fiscal_calendar_tbl
            WHERE [date] BETWEEN '#dateformat(tempstartdate, "mm/dd/yyyy")#' and <cfqueryparam value="#DateFormat(attributes.event_end_date, "mm/dd/yyyy")#" cfsqltype="cf_sql_timestamp" />
          </cfquery>

          <cfloop query="qFiscalCalendarBOP">
            <cfset ArrayAppend(bopDates, "#DateFormat(qFiscalCalendarBOP.bop, "mm/dd/yyyy")#")>
          </cfloop>
          <cfloop index="i" from="1" to="#ArrayLen(bopDates)#">
            <cfset dates=ArrayNew(1)>
            <cfset insertRecord="FALSE">
            <cfquery name="qfiscalcalendardate"
                     datasource="#request.dsnCalendar#">
              SELECT [date]
              FROM common.dbo.fiscal_calendar_tbl
              WHERE bop = '#dateformat(bopdates, "mm/dd/yyyy")#'
              AND datepart(dw, date) = #attributes.date_increment_dow#
              ORDER BY [date]
            </cfquery>

            <cfloop query="qFiscalCalendarDate">
              <cfif qFiscalCalendarDate.CurrentRow IS 1 AND
                    attributes.EVENT_DATE_INCREMENT_ID IS "2" AND
                    DateCompare(tempStartDate, qFiscalCalendarDate.date) IS NOT 1>
                <cfset tempStartDate=qFiscalCalendarDate.date>
                <cfset insertRecord="TRUE">
              </cfif>
              <cfif qFiscalCalendarDate.CurrentRow IS 2 AND
                    attributes.EVENT_DATE_INCREMENT_ID IS "3" AND
                    DateCompare(tempStartDate, qFiscalCalendarDate.date) IS NOT 1>
                <cfset tempStartDate=qFiscalCalendarDate.date>
                <cfset insertRecord="TRUE">
              </cfif>
              <cfif qFiscalCalendarDate.CurrentRow IS 3 AND
                    attributes.EVENT_DATE_INCREMENT_ID IS "4" AND
                    DateCompare(tempStartDate, qFiscalCalendarDate.date) IS NOT 1>
                <cfset tempStartDate=qFiscalCalendarDate.date>
                <cfset insertRecord="TRUE">
              </cfif>
              <cfif qFiscalCalendarDate.CurrentRow IS 4 AND
                    attributes.EVENT_DATE_INCREMENT_ID IS "5" AND
                    DateCompare(tempStartDate, qFiscalCalendarDate.date) IS NOT 1>
                <cfset tempStartDate=qFiscalCalendarDate.date>
                <cfset insertRecord="TRUE">
              </cfif>
            </cfloop>
            <cfif insertRecord IS "TRUE" AND
                  DateCompare(tempStartDate, attributes.EVENT_END_DATE) IS NOT 1>
              <cfquery name="ieventdate"
                       datasource="#request.dsnCalendar#">
                INSERT INTO  #cal_event_date_tbl#(event_id,event_date)
                VALUES (#eventid#,
                '#dateformat(tempstartdate, "mm/dd/yyyy")#')
              </cfquery>

This topic has been closed for replies.

1 reply

Inspiring
August 2, 2010

I think the simplest approach would be build a list of dates that you need and then loop through through that list and insert your db records.  A big advantage of this approach is that you can dump your list as you go to see if you are doing it correctly.

I noticed a couple of things in your code.  First, since your tablename is a variable, your database design may be sub-optimal.  Second, you are using dateformat in your query.  Since that returns a string, you are at best running an unnecessary function thus slowing down production, or, at worst, storing dates as strings which is just a bad idea.