PHP / MySQL timetable comparison - php

I have an idea for a project that I am currently working on, I am however struggling to find a way to implement this in PHP/MySQL.
I have a database with a list of activities that a tattoo parlour has, basically he works from 9 to 5 and when an event is added it is added to the database using date and time
| --- DATE----- | TIME |
2012-11-02 ---| 10:00:00
What I am trying to do is list all the times and dates within the tattooist timetable in the following week that does not already have events going on, this will also ensure the tattooist doesn't double book too!
any assistance will help guys, any assistance will help

The best way to create the application is to store each scheduled event into a database and "black out" dates that are already taken by the applications "events" table (per say)... You will probably want to do your event creation checks during the point that the event would be created or written to the mysql db.... You will probably want to have an events table with a start and end time for each event.... when you go to schedule an event (assuming user input dictates event time and date) just write a mysql query that selects the event where the DATE(a.lastevent) = DATE(NOW())... let me know if you have further questions
Edit:
I would build the front end of the application calendar style using a JavaScript interface. In the long run it will be much more user friendly and much easier to create, I've implemented them in a day.
The framework I suggest using is ExtJS, there are many tutorials and extensions for calendars, I know that ExtJS 3 has a calendar built into it and you can view a tutorial on that here: http://www.sencha.com/learn/using-calendar
Additionally, if you decide to use ExtJS4, you can use this plugin: https://github.com/bmoeskau/Extensible/downloads or this one http://www.sencha.com/forum/showthread.php?142488-Extjs-4-based-open-source-Calendar-application
The second link is open source, the demo looks to be Spanish (it does what you need and more), but if you use Chrome you'll get a bar at the top asking if you want the page translated, click yes, it does a great job. From there you can do find and replaces to get it to English.
The ExtJS 3 tutorial will show you how to interface the calendar with a PHP page so that you can update your MySQL database via AJAX. It is much simpler than you might think, and you'll save a ton of time trying to code it from scratch.

Sometimes it depends on how long each scheduled event might be. Are you adding these events with just a timestamp or are you also tracking how long of a block is being assigned?
you could have an appointment set using a start and stop time and some math..
I have a annoying tendency to use a epoch timestamp instead of a mysql date time. then you can make calculations to see if an appointment overlaps or find the gaps. just have to learn to count in seconds or provide math to adjust :).

Related

PHP - Updating data yearly. -Process advice-

I have made an employee management system as such, and it calcualtes leave days. Although I am trying to work out how to make the leave days update yearly according to the staffs starting date.
I think I know how I will do this easily. Except it will involve the software being open on that date.
How would I account for each day, without the software having to be open?
Heres the process i was thinking:
-Loop through array of staff data and determine if starting date matches current date.
-If it matches then add an ammount of days to their leave days
I know this is very basic, and it has some flaws. Here are the flaws i am thinking:
-If the page were to be refreshed, or page opened again then it would add x2 of the staff days.
-Also, if the software was not to be opened on this day then the staff would not get the added leave days.
How would I get around this issues? I feel like it should be an easy thing, but I cant think on how to do it properly.
Any help would be greatly appreciated,
Create your php script I'll call it leavetime.php
Then if you have c-panel on your server, there is a thing called cron, in there you can select the time to call it. typically it will be something like this for the command
usr/bin/php -q locationof/leavetime.php
https://www.youtube.com/watch?v=ZAbefcWLxrw
As for the actual php code to do this, it's to broad a topic to cover in a single question.

Building a one week calendar / schedule

My website involves scheduling recurring lessons and events. At present I have built a table using php and javascript which scans through my mysql DB, time slot by timeslot, day by day to see if there is an event scheduled or if the timeslot is free.
It works fine, but is quite clunky and ugly and to be honest, not user friendly enough. I have now built the rest of the site using JQuery along with php, JS, HTML.
I have searched far and wide for a JQuery module to sort me out for this, but every calendar/scheduler I find is for ongoing time, i.e. like the Outlook Calendar.
I want one that ONLY displays Monday - Sunday, with time intervals of a half hour - what's the best way for me to achieve this?
Many thanks in advance,
Brett
may be this can be of help if you haven checked it out already https://github.com/robmonie/jquery-week-calendar/wiki/

Browser MMORPG basics ideas

I started making a MMORPG to improve my web design skills. I managed to make users able to move around the screen and get some items with a combination of Javascript, PHP and MySQL.
I want to show all logged users at the same time moving around and push info to the user on what the others I doing but I have no idea how to do it. What are the general ideas/methods to do this?
Thanks
Try using this engine to accomplish what you want: MMO.js... it allows you to build real-time MMORPGs in JavaScript using websockets =)
You basically create a table called "online" with two columns "ID,Time" and whenever a player does some action it updates "Time" that's for the logging part.
And you get a cron job to check the database and if the Time in the database is greater than the current time minus (for example) -5 minutes (timing out time) DELETE the row.

Cancel 1 instance of a repeating date

I've built a website for a local yoga studio (PHP). The site has a calendar. The instructor keeps needing to cancel a random class here and there. The problem is that we either have to cancel all the instances of a weekly repeating date to remove it from the calendar, or cancel none of them and hope that people read the announcements on the front page.
I'm trying to puzzle out how to have a mechanism where I can let her just cancel one instance of a weekly repeating date, but am neither able to comprehend the solution, nor to find anything on here that someone else has tried.
I have plenty of open source calendar scripts to hack up, and just need this one little feature. Any ideas?
Many thanks.
This is a not an entirely straightforward problem. You either need to:
To list all repeated dates in the database
To have a list of 'cancelled' dates in the database
How are the recurring dates currently implemented?

Best way to develop/manage/design recurring tasks/calendar

An example of what I'm talking about is similar to Google Calendar. When a new recurring task is created.
After creating the recurring task "template" - which all of the individual tasks are based on, do you create all of the individual tasks and store them in the database? or do you just store the "template" recurring events and their exceptions?
If the user requests a "month" view, and you want to display all of the events/tasks, it seems like creating the output in real time from the template, and including all of the exceptions would be a lot more resource intensive then if each individual recurring tasks was created from the template and inserted into the database.
This would make searching/sorting, etc, a lot more easier too.
Anybody create something like this before? ideas?
Store it all in the database.
You want to have a "Task Template" table and a "Task" table where there is a one->many relationship.
When the user indicates they want a task to reoccur, create a "Task Template" record and then create as many "Tasks" as the user has indicated (don't allow a user to create tasks too far into the future). Each Task is linked to the Task Template via a Foreign Key. The idea is that SQL is going to be more efficient at managing these records than trying to do this all in code based on one template. This way, you will have more option when your sorting and filtering your data. After all, writing a SQL query is easier than writing, testing, and maintaining a PHP function that manipulates the data.
Some other tips I would give you is:
Try to get a lot of information in your "Task Template" record. Keep the number of tasks the Template covers, the date the last task ends, the time elapsed between the first task and the last, etc.. This "Meta Data" can help save you query time when you're looking to sort and filter tasks.
Put an index on the Date and FK field, this will help query time as well.
I just built two calendar apps at work that were pretty well received by the bosses. I used the "FullCalendar" JQuery plugin (http://arshaw.com/fullcalendar/). I used JQuery AJAX to handle most of my events, and it had built in support for Month, Day, and Week view.
For recurring events I did the following a while back:
When a user entered an event I stored the event's date pattern GNU date style - the keyword for PHP is relative date formats.
Then I started off by creating events for e.g. the next year. And created actual records where I converted the relative date to an actual -- e.g. "every first Monday" to a "mm-dd-YYYY". This allowed me to display them and also allow the user to e.g. move a single event or cancel one, etc..
Then figure out how far to go into the future - my idea was to create events when the actual pages were browsed. E.g. if I had created events through June 2011 and someone skipped all the way to July 2011, I would iterate on my events and set them up transparently.
When the user changes the relative pattern, offer to update all following events -- unless they have a custom pattern already. Relative patterns make it super easy to calculate all that.
I went through the same problem a while back and instead of reinventing the wheel, I used Google Calendar APIs. (http://code.google.com/apis/calendar/data/2.0/developers_guide.html)
You create a Google Account and access the calendar information. There are APIs to create/edit/delete a recurring entry. Also, you can specify a date/time information and query for matching events.
When you create an event on Google Calendar, you will receive a token/id which you can store in your own database and reference it within the context of the application.
If the user requests a "month" view, and you want to display all of the events/tasks, it seems like creating the output in real time from the template, and including all of the exceptions would be a lot more resource intensive then if each individual recurring tasks was created from the template and inserted into the database.
I would disagree on that. What if a task repeats every saturday for the next 7 years... And what if there were a lot of these repeating tasks? That would cost you a lot of waste space. Therefor, I think it's better to save a recurring task as just one record + one record for every exception (since there are less exceptions than recurrences).
Well, the only problem left is how to set up a query to select each task (still thinking abou that)

Categories