![]() |
So I have some staff, and was thinking a good way to evaluate if they do whats required is to make sure they fill out the forms properly while they are on shift. The following example data is what the output of my function gets.
id - id of the user
name - name of the user
after - after date for range
before - before date for range
total_shifts - number of shifts within date range
total_forms - number of forms completed within range
total_hours - total shift hours
shifts - data for the shifts with shift after and before range
In this sample the 9733 number is the ID of the post for shift, after and before date range for the shift. Total Forms they have finished within that range and points.
The points are what I need to calculate if they are doing whats required. Requirements: 12 forms per shift (a form is just a form they fill out with data it creates a post) The issue I have is that sometimes shifts overlap as you can see in the sample data, and I only require 12 forms per shift even if two people are working. So what I want to do is give either 1 or 0 points for each shift form that hits the requirements for each person. eg: if dave is working alone and does 12 he gets 12 points max, if dave and steve are working and together they do 12 forms they both get 12 points max. I would append the points to the points array item for each shift. I can then take that array and review once a month to see who is working. I assume I would walk the array and figure this out but I am at a loss. Sample data that is output
Solution - 1It's not clear from your sample data whether shifts always align when more than one person is working. ie If two or more people are working, will their shifts always start and end at the same time? If not, then it could be tricky with the data you have. If they do, then a first walk of the array could create a second associative array with start time as the index. As you walk the array, add the forms_in_shift to the index for the time (creating that index if it doesn't exist. That will give you a total of forms for each shift. Then go back over your primary around setting the points value based on the secondary array. Personally, I would convert all dates to timestamps to make comparison obvious. Solution - 2I think you should be tracking the input time for a form in its own right. Why not create another post type for form entries that stores time entered, user ID, and shift ID. You can then query simply by form ID. Are your shift objects being generated automatically? They should be able to select them at the time of submission. |
Wordpress |
Type: | Code Example |
Category: | Coding |
Sub Category: | Code Example |
Uploaded by: | Admin |
Views: | 13 |