Coding an interface where user selects date reoccurnace - php

I need to create an interface where a user needs to select how many times his magizine/newspaper gets distributed. Some magazines/newspapers get distributed
Several times a week.
Several times a a month: --either by day (e.g. every second tuesday) or by date (e.g. on the 1st, 10th and 28th)
Several times a year.
Once the frequency has been chosen, I need to add additional information to each frequency item. e.g. if the user chose weekly on Mondays and Fridays, I need to add additional information for Monday and separate information for Friday.
Does anyone have any ideas on how to do this? Or where I can read more or get some examples?
I'm using PHP and javascript/jquery for this application.
Thanks in advance.

You would need to ask the end user a series of questions, and use jquery to display to next set of questions for the next set of results etc

Related

How to get first, second, third and fourth Monday of each month?

I'm working on an event based website. The user can create multiple events during the year and here is how the form works.
We have one select box with the following options :
The first
The second
The third
The fourth
And another select box with the names of the week days.
For example, he can choose to repeat his event every "second" "Monday" of each month during one year (or more).
Now, I'm looking for a way to get the date of each second Monday (as per the example above) with PHP.
I have this code which allows me to get what I want... But not sure about a great way to use it in a loop.
echo date("j, d-M-Y", strtotime("second monday 2017-11"));
Should I just loop over and change the year & month string?
Thanks!
Luckily, this problem has been solved already. The iCalendar standard has a Recurrence Rules component to deal with recurring events. There's an RFC specification, and there's an official PHP implementation as well. Alternatively, check out the tplaner/When library on GitHub.

fullcalendar - recurring events

I as wondering if anyone could help me with a problem? I am using fullcalendar and it works great, but I would like to add the ability to repeat events upon user requests (by the way i'm using the selectable calendar). In other words I want to give them an option to recure the events based off whatever they choose (weekly, daily, monthly, unorganized days). I have read the docs and I know that recurring events are based off of the id and you basically add the days to the original date, but I am not sure how to do it without making a loop adding multiple events that may or may not be necessary.
My thought was to provide a column in mysql that gives a recurring option based off of the selection. Any ideas on how I should approach this. Does anyone possibly have an example that I can brainstorm on? All help is greatly appreciated. Thanks
Here's what I did to implement recurring events in fullcalendar.
http://fajitanachos.com/Fullcalendar-and-recurring-events/
I did end up using a loop to add events to my events table based on the recurring frequency. I know it's not the most efficient but it works for my purposes.
One thing to consider is how much flexibility do you need? Do you need an event to repeat every Tuesday/Thursday, every 3rd Saturday, the last day of the month, or simply every week on a certain day? The more flexibility you need, the more complex your solution will need to be.
It's nothing to do with fullcalendar. You need to have this implemented in your back-end. I wouldn't recommend you creating a column in your events table in order to maintain recurring once you might need a recurring type (weekly, daily, monthly, yearly) or frequency for example.
I've faced this same type of solution few months ago and I would recommend you create another table called tb_events_recurring, for example, saving information like event_id, date_start, date_end and recurring type if necessary.
Create an event for each recurring are hard stuff to maintain. My advise is creating this events every time fullcalendar request them. You have the date_start and date_end in your post vars, so it won't be cost for your server. Put all events in an array and after encode 'em to json.

PHP Date Booking and Review methods

A bit of brainstorming is required.
We are building a booking system that allows users to book a date and a half an hour time slot on that day. Some days however based on a weekly timetable will not be available and others may be unavailable at certain time.
What would be the best way to go about something like this. There should be some information in the database saying what day of the week certain times are not available but I am not sure what the best way of going about this is.
Any ideas?
Marvellous

user generated / user specific functions

I'm looking for the most elegant and secure method to do the following.
I have a calendar, and groups of users.
Users can add events to specific days on the calendar, and specify how long each event lasts for.
I've had a few requests from users to add the ability for them to define that events of a specific length include a break, of a certain amount of time, or require that a specific amount of time be left between events.
For example, if event is >2 hours, include a 20min break. for each event, require 30 minutes before start of next event.
The same group that has asked for an event of >2 hours to include a 20 min break, could also require that an event >3 hours include a 30 minute break.
In the end, what the users are trying to get is an elapsed time excluding breaks calculated for them. Currently I provide them a total elapsed time, but they are looking for a running time.
However, each of these requests is different for each group. Where one group may want a 30 minute break during a 2 hour event, and another may want only 10 minutes for each 3 hour event.
I was kinda thinking I could write the functions into a php file per group, and then include that file and do the calculations via php and then return a calculated total to the user, but something about that doesn't sit right with me.
Another option is to output the groups functions to javascript, and have it run client-side, as I'm already returning the duration of the event, but where the user is part of more than one group with different rules, this seems like it could get rather messy.
I currently store the start and end time in the database, but no 'durations', and I don't think I should be storing the calculated totals in the db, because if a group decides to change their calculations, I'd need to change it throughout the db.
Is there a better way of doing this?
I would just store the variables in mysql, but I don't see how I can then say to mysql to calculate based on those variables.
I'm REALLY lost here. Any suggestions? I'm hoping somebody has done something similar and can provide some insight into the best direction.
If it helps, my table contains
eventid, user, group, startDate, startTime, endDate, endTime, type
The json for the event which I return to the user is
{"eventid":"'.$eventId.'", "user":"'.$userId.'","group":"'.$groupId.'","type":"'.$type.'","startDate":".$startDate.'","startTime":"'.$startTime.'","endDate":"'.$endDate.'","endTime":"'.$endTime.'","durationLength":"'.$duration.'", "durationHrs":"'.$durationHrs.'"}
where for example, duration length is 2.5 and duration hours is 2:30.
Store only the start time and end time for the event, and a BLOB field named notes.
I've worked on several systems that suffered from feature creep of these sorts of requirements until the code and data modeling became nothing but an unmaintainable collection of exception cases. It was a lot of work to add new permutations to the code, and typically these cases were used only once.
If you need enforcement of the rules and conditions described in the notes field, it's actually more cost-effective to hire an event coordinator instead of trying to automate everything in software. A detail-oriented human can adapt to the exception cases much more rapidly than you can adapt the code to handle them.

How to handle dates that repeat indefinitely

I am implementing a fairly simple calendar on a website using PHP and MySQL. I want to be able to handle dates that repeat indefinitely and am not sure of the best way to do it.
For a time limited repeating event it seems to make sense to just add each event within the timeframe into my db table and group them with some form of recursion id.
But when there is no limit to how often the event repeats, is it better to
a) put records in the db for a specific time frame (eg the next 2 years) and then periodically check and add new records as time goes by - The problem with this is that if someone is looking 3 years ahead, the event won't show up
b) not actually have records for each event but instead when i check in my php code for events within a specified time period, calculate wether a repeated event will occur within this time period - The problem with this is that it means there isn't a specific record for each event which i can see being a pain when i then want to associate other info (attendance etc) with that event. It also seems like it might be a bit slow
Has anyone tried either of these methods? If so how did it work out? Or is there some other ingenious crafty method i'm missing?
I'd take approach b and if someone adds something to it, I'd create a "real" event entry.
Edit:
How many periodic events do you expect and what kind of periodic events would that be? (eg: every monday, every two weeks etc.)
I would create a single record for a repeated event. Then in case more info has to be added to a specific date, I would create a record for the attachment with a reference to the repeated event.
Third vote for option B - rationale being that the data should only ever be queried for a limited timeframe (i.e. start and end). For performance reasons I'd suggest that, in addition to storing the date/time of the first occurrence, number of occurrences and frequency that you also maintain the last occurrence in the database.
C.
From my experience, generating recurring dates and checking if a specific date is in that pattern isn't all that bad performance-wise. There's only 365 days in a year. 10,000 days is already almost 30 years. which means, the size of the input/output is relatively small in a practical scenario.
This library may help (but it's javascript): http://github.com/mooman/recurring_dates

Categories