Welcome Guest, Not a member yet? Register   Sign In
Calendar and Sheduler, how to?
#1

[eluser]Référencement Google[/eluser]
Hi,

One of my client that is DJ need that I code for him an availability Scheduler.

He want something really simple, just to show in the public website that he is available or not on a specific date or range of dates. The admin area should be simple too, I can imagine that I can make him select a range of dates or pick a single date on a JS calendar. There is no plan yet to do a reservation depending on available dates, but that's a functionality that can come later.

So my question is:
How would you go for this kind of things with the DB fields / tables, with CI libs,... ? If you have some PHP libs that I can rely my code on, I would be very happy too !

Thanks in advance.
#2

[eluser]Eric Cope[/eluser]
Your database should have two tables. The first table allows for appointment information (Name, Address, Service needed). The next table should have the date information. If its a recurring appointment, each recurring event needs to be in that table.

I have software for this, but its very beta, and not releasable. Let me know how yours goes, or if you have any questions.
#3

[eluser]Référencement Google[/eluser]
Thanks for the reply, I will have to think about that, still now I don't see how I can do it. If you have some DB script to show me I would be very happy to see how you've done.
#4

[eluser]Eric Cope[/eluser]
Here is a starting point for the event databases.
table - eventInfo
Code:
eventID eventTitle eventType customerName recurrance
0       Title 1    Wedding   Bill Smith   single
1       Title 2    Birthday  Jane Smith   annually
2       Title 3    Meeting   Bill Jones   Monthly

table - events
Code:
eventID date                location
0       2007-06-02 07:15:00 1st Street and Central Ave.
1       2007-03-21 13:45:00 2nd Street and Main Street
2       2007-01-01 05:15:00 3rd Street and Gainey Road
2       2007-02-01 05:15:00 3rd Street and Gainey Road
2       2007-03-01 06:15:00 3rd Street and Gainey Road
2       2007-04-01 06:15:00 3rd Street and Gainey Road
...

When you add a single event, you place a single record with information regarding the event in the top table. Then, you add a record to the second table about the events date and time, and location, things specfic to the specific event. So if you have a re-occuring event (monthly party), then add an event entry for each date, for as long as you want (I did it for 30 years). Does this clear things up?
#5

[eluser]Référencement Google[/eluser]
That makes sense, I will go in that way. Thanks for the help.
#6

[eluser]Eric Cope[/eluser]
I tried to find a better way. One way I thought was one entry per event, then calculate future dates. That turned into a nightmare very quickly. The problem I have not solved yet is, how often to I update the table. For instance, I create a recurring event for 30 years (I calculated the hard drive space and it seemed worth it). But, what happens after 30 years. I made the assumption that by then, I would have retired, but that is not a good answer. I am still solving that one. Let me know how your project comes out and if you have any clever ways of solving it.
#7

[eluser]Référencement Google[/eluser]
Hoo I see, but for my small calendar app I won't do recurring events, it will be really really simple.

I can think of another solution for recurring events it is to make a kind of "stop date". Some thing like it goes forever until it matches the stop date. But that need to be worked out, I just put words as I think them...
#8

[eluser]Ben Luedtke[/eluser]
Hey Eric,

Did you ever solve your recurring events issue? I'm working through an events calendar and am running into the same issue. What is the most efficient way to store recurring events?
#9

[eluser]fesweb[/eluser]
Probably not efficient, but one way to do repeating events is this.

Use a form (with checkboxes) to pass an array of selected days of the week and an end date.

IMPORTANT: this code requires that the beginning date's day of the week be passed as a "0", and that all other days are easily offset in relation to that day (example: first date is a Tuesday, so Tuesday = 0, Thursday = 2, Saturday = 4, etc). It keeps the logic much simpler for the part shown below.

Note: all dates are already in UNIX timestamp format

Code:
$baseDate = $this->validation->baseDate;
$endDate = strtotime($this->validation->end_date);
$tempdate =   mktime(0, 0, 0, date('m', $this->validation->baseDate), date('d', $this->validation->baseDate), date('Y', $this->validation->baseDate));
// echo 'tempdate = '.unix_to_human($tempdate);
// echo $tempdate.' : '.$this->validation->baseDate.' : '.$endDate;

// make the array of weekly offset numbers to be looped through
// the start date of the event is always 0, then we add from there
$selectedDaysArray = $_POST['days'];
// echo var_dump($selectedDaysArray); echo '<p>form days: '.$_POST['days'].'</p>';

// create an empty array to hold the new instances
$newInstances = array();
// fill the array with all of the future dates...
// WEEK loop start
$weekoffset = 0;
while($tempdate < $endDate) {
    // DAYS loop start
    foreach($selectedDaysArray as $dayoffset) {
        $totaloffset = $dayoffset + $weekoffset;
        // echo '<p>'.$totaloffset.' ('.$dayoffset.' + '.$weekoffset.')</p>';

// IMPORTANT PART
// add the total offset using the days portion of the mktime function
// (date('d', $this->validation->baseDate) + $totaloffset)
        $tempdate =  mktime(0, 0, 0, date('m', $this->validation->baseDate), (date('d', $this->validation->baseDate) + $totaloffset), date('Y', $this->validation->baseDate));
        
        // make sure that it's not after the endDate
        if($tempdate <= $endDate) {
            // make the future-date START datetime
            $tempStart = mktime(date('H', $this->validation->baseStart), date('i', $this->validation->baseStart), 0, date('m', $tempdate), date('d', $tempdate), date('Y', $tempdate));
            // make the future-date END datetime
            $tempEnd = mktime(date('H', $this->validation->baseEnd), date('i', $this->validation->baseEnd), 0, date('m', $tempdate), date('d', $tempdate), date('Y', $tempdate));
            // echo date( 'Y-m-d H:i:s', $tempdate ).' | '.date( 'Y-m-d H:i:s', $tempStart ).'<br />';
            // APPEND the newInstances array with an array of the start and end time
            $newInstances[] = array(date( 'Y-m-d H:i:s', $tempStart), date( 'Y-m-d H:i:s', $tempEnd));
        }
    }
    // next WEEK
    $weekoffset = $weekoffset + 7;
}
Then, you can loop through that array (of arrays) of future dates and add them to the database.

Sorry that I don't have more time to explain it now, but I've left my commented out debugging echos in there to help try it out...

Good luck.
#10

[eluser]Ben Luedtke[/eluser]
Thanks for the great reply. How would you handle an option for an event with no ending date? I'm thinking of limiting recurring events to only one year. If they are still going after that, the submitter will need to resubmit them. That way they are not filling my database up with events that are forgotten, but ongoing.




Theme © iAndrew 2016 - Forum software by © MyBB