Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I know this place is for uploading code that may need some help although I hope you won't mind helping as I'm not sure where to really start with this code. You are the experts and I am a novice requiring help with future coding. If there is a section aimed at this kind of thing, I will be happy to repost.
Here is the situation:
I am starting work on an advanced admin backend panel for my staff, an idea I currently have is to use a MySQLi database to create the staff rota, to be displayed in a simple calendar like table on the aPanel.
Now, the advanced part is the staff member will be able to click "Clock In" or "Clock Out" during the times/days they are issued on the rota.
The system will NOT let the staff member Clock In, unless they are on the rota for that time of day. I will then have access to a management section of the panel allowing me to view the amount of hours the staff member has been clocked in for for if they have missed days, or are late, etc... And pay them for recorded clocked in hours.
Maybe some added features would be that they are clocked out automatically at the end of their shift or the system would record overtime and such?
I have no idea how I would go about creating such system or if it is actually possible so if anybody may have any advice/tips/examples for such idea I would appreciate any help!
All the best!
Your system will necessarily consist of several parts:
Database Store - Houses all necessary information for the system, Staff Schedules, Timeclock Entries, User Information, etc. Sounds like you already have this mostly in place, though it may need some tweaking for your purposes.
Staff Assignment / Admin Interface - System to allow administrators or those with appropriate access to assign schedules to Staff, add new Staff to the system, etc.
Timeclock Frontend - Staff would use this to login to view their schedules, and clock in/out.
(Possibly) Automated Monitoring System - If you wanted the system to automatically monitor active Staff, and clock them out when their schedule is up, you'll need a recurring task, a script that runs every X minutes and clocks out those Staff required.
This isn't a quick and simple project, but it's not very complicated either. The major pitfall you'll need to avoid is the temptation to just code the whole thing yourself. It may seem like a good idea at first, you only need a few hard-coded pages, right? Trust me, though, that process always ends in major headaches later on. Find a Framework that you can base your application on. It's a bit more to learn, but you'll be able to focus more on building your application, and less re-inventing the wheel.
For PHP, I strongly recommend Symfony. It uses Doctrine for it's ORM, which will make it much easier to handle data interactions, and Twig Templating, which is far superior to mixing PHP/HTML directly. Symfony has decent documentation, and a number of tutorials. (And an active Stack Overflow tag.)
Regardless of the choice you make, the best thing to do is choose a framework to base your application on, it'll make all the numerous little design decisions much easier. (And less error-prone for any widely used framework.)
Your individual questions are a little too vague to answer directly without a system around them. I'll try to give some general advice for them, though.
I am starting work on an advanced admin backend panel for my staff, an idea I currently have is to use a MySQLi database to create the staff rota, to be displayed in a simple calendar like table on the aPanel.
You might want to take a look at Full Calendar, a nice customizable JS calendar.
Now, the advanced part is the staff member will be able to click "Clock In" or "Clock Out" during the times/days they are issued on the rota.
When the employee logs in to the application, the application will load the schedule for that employee. If they have a current (or shortly upcoming) assignment, display a Clock In form. The Clock In form, on submit, will change the Employee status to Clocked In, and insert a timestamp into the Timeclock Logs associated with the Employee. If the employee is currently Clocked In, instead display a Clock Out form (possibly with shift notes), that does much the same thing, only switching the status to Clocked Out.
The system will NOT let the staff member Clock In, unless they are on the rota for that time of day.
It's fairly easy to check these sort of things after the Clock In form is submitted. If they aren't supposed to Clock In yet, throw an error. (Note, never assume that the pre-submission validations are sufficient. I.e., don't rely on the fact that the Clock-In form will only show up when the Employee can Clock In.
I will then have access to a management section of the panel allowing me to view the amount of hours the staff member has been clocked in for for if they have missed days, or are late, etc... And pay them for recorded clocked in hours.
In the admin section, you can create a report by getting all the Timeclock logs for a given employee for a given date range, total the hours worked, and compare to the expected schedule.
Maybe some added features would be that they are clocked out automatically at the end of their shift or the system would record overtime and such?
Have a script that runs every X minutes (lower times will have greater resolution, but consume more resources) as a scheduled task on your server, checking every Clocked In employee, and Clocking Out those who should no longer be Clocked In. If you're using Symfony, I'd recommend creating a Custom Console Command for the job.
That's hopefully enough to get you started. Please feel free to come back with any more specific issues that you may run into.
Related
I just want a approach on how to build a database with live records, so don't just downvote. I don't expect any code.
At the moment I have a MySql database with about 2 thousand users, they are are getting more though. Each player/user has several points, which are increasing or decreasing by certain actions.
My goal is that this database gets refreshed about every second and the user with more points move up and others move down... and so on
My question is, what is the best approach for this "live database" where records have to be updated every second. In MySql I can run time based actions which are executing a SQL command but this isn't the greatest way I think. Can someone suggest a good way to handle this? E.g. other Database providers like MongoDB or anything else?
EDIT
This doesn't work client side, so I can't simply push/post it into the databse due some time based events. For explanation: A user is training his character in the application. This training (to get 1 level up) takes 12 hours. After the time is elapsed the record should be updated in the database AUTOMATICALLY also if the user doesn't send a post request by his self (if the user is not logged in) other users should see the updated data in his profile.
You need to accept the fact that rankings will be stale to some extent. Your predicament is no different than any other gaming platform (or SO rankings for that matter). Business decisions were put in place and constantly get reviewed for the level of staleness. Take the leaderboards on tags here, for instance. Or the recent change that has profile pages updated a lot more frequently, versus around 4AM GMT.
Consider the use of MySQL Events. It is built-in functionality that replaces the need for cron tasks. I have 3 event-related links off my profile page if interested. You could calculate ranks on a timed schedule (your tolerance for staleness) and the users' requests for them would be fast (faster than the below from Gordon). On the con-side, they are stale.
Consider not saving (writing) rank info but rather focus just on filling in the slots of your other data. And get your rankings on the fly. As an example, see this rankings answer here from Gordon. It is dynamic, runs upon request with at least at that moment non-staleness, and would not require Events.
Know that only you should decide what is tolerable for the UX.
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.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
PHP newbie here. My question is related to the logic/best practice for executing a certain task.
I have a news event/announcement being displayed on a website and needs to be removed/expire after a certain date/time. I have set a expiration date/time in the database, when a user visits the website after the date/time has passed a query is triggered and the news event/announcement is set to "0" (which is hidden).
I would like to know if this the best practice of accomplishing it or is there a better way?
Thanks.
The method you mention is usually effective, especially for small applications, but not a best practice. The reason it's not a best practice is because:
Issues
You are making the user wait for task execution
If there is no activity on your website, these tasks will not be done
If anything happens while executing a task, your user will receive the errors
The first two might not seem to matter much, but that's only because the tasks you have now are very fast and non-critical. However, if a task would take a second or two, that would mean the user now has to wait 2 extra seconds before he sees the page, which is bad.
Likewise, if nobody visits your site for a week and there's a list of 15 tasks that need to be done, the user now would have to wait for 30 seconds. It might even time out the whole page; which would mean your tasks are now unfinished and the user is annoyed with getting a timeout for seemingly no reason.
In addition, if one of your tasks is time critical, it still won't be done. For example if the task is to send someone a reminder email after 24 hours but nobody logs in, the mail won't be sent.
The last one is also a problem; both because this makes it hard to see when a task fails (as the error is logged as a user problem, if at all) and because your user (again for no reason) is now looking at an error screen.
Solution
If you want to use the best practice, move all these sorts of tasks to either a Scheduled Task (under windows) or a Cronjob (under unix). This means you have a system service that periodically starts up and executes a PHP script that can do maintenance to your site, such as removing these news messages, sending out emails, or other things.
This has a number of advantages:
The server will always be there on time to run the tasks when they need to be run
You can disable timeouts and upgrade memory availability to run intensive tasks
Users will not have to wait for anything to complete
You can add special logging to the server, so that you know when these important but hidden tasks fail
Most providers allow you to set these kinds of tasks even on cheap hosting packages.
By far the simplest way to do this is to have a publisheduntil field with a date time. Each time you get a list of events to be shown on a page check this field eg
Select * from my_table where published = true and published_until > todays_date
This is avery simple way of ensuring that events disappear when they should.
I am working on a web-based lease management application that needs to be able to generate various reports, reminders and alerts every day, based on information in the database at any given time. Some examples of the kind of reports, reminders and alerts include:
Send a transactional email letting a set of users know that their next invoice is due in 15 days.
Send a transactional email letting a set of users know that they have 1 or more past-due invoices
Alert a property manager that a particular property is X days past due and offer to print a set of eviction documents
etc.
It seems like the simplest approach is to define a collection of scripts that execute via a set of cron jobs every morning. Each script would check for the criteria needed to trigger a specific response from the system. For instance I may have a collection of scripts like, SendInvoiceDueIn15DaysEmail.php, SendInvoicePastDue30DaysEmail.php, etc.
My primary question is, given a database filled with test data, what is the best way to simulate the passage of time, say 90 days, to ensure that the data triggers the correct set of responses each day? Some of my daily tasks need to interact with third party APIs like Mandrill, Mail Chimp, some industry-specific accounting packages, etc.
My secondary question is, if anybody has experience developing applications that center around scheduled, recurring events that happen in the future, am I on the right track here? I've already built most of the core system (user management, property management, lease management), now it's time to test the automated side of things.
For what it's worth the core of application is using Laravel 4, but I don't think is strictly a PHP question.
TL;DR How do I go about simulating the passage of time in order to check that over a 90 day period the system correctly detects a set of events and triggers an appropriate response which completed successfully?
I think the answer here is the same as in everything else you wish to test - a Clock mock. Abstract the way you check what time it is right now. Then you could create a mock clock implementation that would work much faster (or report whatever you'd like) during tests and another implementation that would simply return the true time in production.
This way you could also test other scenarios like time changes on the server or Daylight saving time.
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?