Laravel - php Identifying multiple check in / check out in attendance - php

We are developing a simple attendance system based on Laravel Framework. We are new to Laravel framework.
We use the basic auth system of Laravel. The user can check in / check out using the system. While doing,the user is supposed to take a photo of their own and we also get the location details from browser.
For attendance, we have the following schema:
id (primary Key) (int)
userid (int) (foreign key to id of the user table)
status (boolean) ( 0 - out / 1 - in)
attendancedatetime (datetime)
gpslat (float)
gpslon (float)
photourl (varchar)
Now we wish to avoid check-in/check-out by an user within few minutes (say for example within 10 minutes).
Also, we wish to avoid multiple check-in or multiple check-out by the same user at a time.
Is it possible to do this in Laravel Controller?
Will this provide any solution to our problem?

Firstly Find out last checked details by
select max(time(attendancedatetime)) as last_checked_time
From<TableName>
WHERE userid=<USERID> and DATE(attendancedatetime)=<Current Date>
after that in Laravel, compare this returned last_checked_time with current time. If it is less then 30 minutes return false else run your insert statement!

Related

Automating a update function in laravel

I have a table called users in my laravel application database.
There is a column called active_status in the user's table
if the active_status=0 then user is inactive and active_status=1 user is active.
Also there is a column called, user_score in the users table. If the user score is less than 50 user's active_status should change to 0 and greater than 50 then user will remain as active user.
I have already written an update function to change this active_status but How can I automate the process, checking the user_score and updating the active_status accordingly?
You are reffering something related to the laravel task scheduling.
Here is the official documentation.
I would prefer using Event is this case - since it is fully Model Related:
You can set up your listener following the instructions here:
https://laravel.com/docs/7.x/events#registering-events-and-listeners
You can listen to the Model Update event as seen here:
https://laravel.com/docs/master/eloquent#events
It's better if you can use eloquent observers to do this.
https://laravel.com/docs/7.x/eloquent#observers

Get online users with Laravel 4

I am trying to get online users count in Laravel 4.
I am using Sentry 2 with Laravel.
There are 2 columns in users table which are last_login and updated_at.
I am confused at this point, because everytime last_login and updated_at columns have same value.
How do i set new update value in which user operation, even page reload?
If it so i can calculate the time between last_login and updated_at, so i can see online users easly.
Or is there an easy way to find online users in Laravel?
Thanks for helping.
Personally I would go with the suggestion from this link:
https://stackoverflow.com/a/4073355/3353724
In laravel, I would do this:
Add 'last_seen' column in users table
In App::before filter, add a logic to update the 'last_seen' column if user is logged in.
To check for online user, check if current time minus "last seen"-time is greater than some threshold you like.

Query and Display referrer details

I have a website built with PHP and mysqli and now I am building administration panel for this website. I am facing some difficulties for querying and displaying referral data I do not have any idea how to do it.
I have a table called user_registration and the fields include, user_name, email, password, referrer. Whenever any of the registered member is referring others the referrer username will be saved in the field "referrer".
Now what I want is to fetch only the rows of the members who has referrals (means referred by my registered members) and also want to count how many referrals a member have and echo it.
For example: I have 20 registered members and from it 5 members have some referrals so I want to query and echo those member's username who has referrals and also count how many referrals they have:
Member's Username Total Referrals
user7 8
user6 6
user1 5
user9 3
user5 2
My solution would be. Make a new column in your user table like "totalreferrals". In this way you can easily keep track of the amount of people they have referred. You could also make a new table "referral". In here you would save the referrals name, the new persons name and a timestamp or something. Now it is even possible to make queries for different periods.
I think that you need to rethink about your database setup, instead of trying to make way to complicated queries, to make your database work.
I am just giving an idea in short which may help you to complete your project -
Suppose your site URL is http://yoursite.com.
1) Whenever a user is registered, you can generate a random key for that user and save it in the database for that particular user. e.g. user1 => abc123
2) Now, you can tell your user (may be on a page after their successful registration) that his/her referrer id is http://yoursite.com/?ref_id=abc123 (by appending it as a new parameter)
or if your register page is http://yoursite.com/register then http://yoursite.com/register/?ref_id=abc123
3) Now, they can share this link to their friends, colleague etc to whomever they want.
4) Now, suppose if a person (may be his friend to whom the user1 referred) clicks on the above link. He will land on your site with the parameter 'ref_id' appended.
5) Just using $_REQUEST['ref_id'] or $_GET['ref_id'], capture its value and store it in a SESSION variable. This you can do on the main page of your site e.g. index.php
6) Now, if that user does the registration, you can make an entry in the database that he has been referred once by the user who has referrer id abc123 i.e. user1.
7) So, you can add count = 1 for user1. If more people come with the same value for the 'ref_id' parameter, you can keep on increment the count.
8) If no such parameter is exists when user lands on your site, then that means he has not referred by anyone. So, that means he is the first kind of user i.e. user in point no. 1).
9) You may also need to take care of some validation part at some places in this.
EDIT:
SELECT user_name, referrer FROM user_registration WHERE referrer > 0;
Assuming that you have a proper insert query ready which gives you the result as you shown the table in your question.

php reservation system

i m creating a project with php and html use.i would like to create a ticket reservation system for my university.Firstly,the user will choose a date and the number of persons that he wants to reserve tickets.Then,by pressing the next button,he could see the list of the events that are available in the date he checked in the previous step.this list will be static,so i think that i have to create a data base which will have this data and if the users selects ex monday,he could see the data events for monday.Could you please help me do this because i have no big experience with php?i have created the two screens with html and css but now i would like 1st to let me know how to create a data base with my data and secondly how to connect them with my day oprtions!
Thanks a lot!
Take a look at:
PHP 101: A Simple Seat Reservation System
It is not a simple task as you seem to think and explaining it is almost writing the software but I'll try :
Create database tables in the database engine of your choice
required tables
table [events] : colums{id Integer,event_date Date,title Varchar,tickets Integer, description Varchar}
/*
How many tickets are availble for that event, depending on the reservations Count you will show less and less available tickets and eventually you will stop the reservation
*/
table [users] : columns(id Integer,name Varchar,username Varchar,password Varchar)
table [reservations] :
columns(id Integer,
user_id Integer [foreign key to users],
event_id Integer [foreign key to events],
reserved_tickets Integer,
reserved_at Datetime}
/*
reserved tickets are used if you want a user to be able to reserve more than one ticket per person, for safety reasons you can limit that either by adding a new field in the event table where the event creator can choose how many tickets one person can have or either hardcode it in the code, but this is not so "fancy")
*/
Now you will need a lot of views interfaces:
User management interfaces :
1 List + 1 Add/Edit(administrator) +1 register (user can register them selves, this is optional) = 2 (3)
Event management interfaces:
1 List(administration) + 1 Add/Edit + 1 Event listing (in a calendar or something for reservations) = 3
Reservation management interfaces:
1 List(administration) + 1 Manage (Cancel/confirm the reservation of a user etc) = 2
You will need a login page, maybe a recover password/username, a screen where a user can see his reservation and cancel/confirm whatever.
These should be all html/flash etc eventually mixed or comunicating with code (PHP,JSP,ASP whatever)
Every html should have a control script "behind" it, meaning the actuall code that gets/sets info into/from the database, this is recommended to be in a separate file then the view (at least) and should be contained in a function or class methods and here are a lot of details to be said, to many.
I recommend that you try and understand CakePHP, it should fit you at this level and anyway to me it seems the simplest framework that one could use and understand empirically.
It's not an easy job as I said, this should take about 12-16 hours to be written from scratch to a professional programmer, and I think it will take you 5 times more even if you use CakePhp. (of course considering a modern interface,approach and functionality otherwise it would take a pro 6 hours at most)

User's possibilities on site

I want to build a system on the website, that allows users to do some things depend on their rating. For example I have rule for rating value X:
1 post in 3 days
10 comments in 1 day
20 votes in 2 days
for rating value Y, rule may be following:
3 post in 1 day
50 comments in 1 day
30 votes in 1 day
Each night I recalculate users' ratings, so I know what each user is able to do.
Possibilities don't sum or reset on each rating's recalculation.
One more important thing is that admin can fill concrete user's possibilities at any time.
What is optimal database (MySQL) structure for desired?
I can count what concrete user has done:
SELECT COUNT(*) FROM posts WHERE UserID=XXX AND DateOfPost >= 'YYY'
SELECT COUNT(*) FROM comments WHERE UserID=XXX AND CommentOfPost >= 'YYY'
But how can I do admin filling possibilities in this case?
I would log the number of actions of each user each day and use that table to compare.
This table would contain the following fields:
date: the day when the action took place
count: the number of actions took that day
userId: who did this action
action: which action post/comment/vote/...
ignore: boolean, if this is set, admin has reset the values
Checking a rule: SELECT SUM(count) FROM log WHERE userId = XXX AND action = YYY AND ignore = 0 AND DATEDIFF(date, NOW()) <= DAYS
Resetting a rule: UPDATE ignore = 1 FROM log WHERE userId = XXX
If his rating changes the result is still valid (you'll just compare with on other total)
When you create a rules table:
action
limits
days
rating_min
rating_max
You can query for permissions like this:
SELECT action, IF(SUM(count) < MIN(limits), 1, 0) as can_do_action FROM log LEFT JOIN rules ON rules.action = log.action WHERE userId = XXX AND rating_min <= RATING AND rating_max >= RATING AND ignore = 0 AND DATEDIFF(date, NOW()) <= days
So you get a table loggin like this:
- comment => 1
- votes => 0
You do have to update this table every action (create a new row if first action of the day or update the count of the row)
The absence of a rule means no actions have been made, so we can ignore it.
If I understand you correctly you have a user that can post 1 blog, and comment 10 times. Now he/she has commented 5 times and posted a blog. You want the admin to click a button, and now the user can again post a blog and comment 10 times?
It might be a bit of a hack, but you could count the actions that are being reset/ignored, and substract that from the current actions?
e.g.: user has 1 blog and 5 comments. Admin presses "reset", and you save those values.
Now as the user posts another blog, and you check if that's allowed, you'll get
SELECT COUNT(*) FROM posts WHERE UserID=XXX AND DateOfPost >= 'YYY'
And you do something like this
SELECT changes FROM adminTable WHERE UserID=XXX AND type = 'post'
And if count - changes is ok, you're set.
What about having, in the user table, three columns called remainingPosts, remainingComments and remainingVotes? You'll decrease the columns when the user has performed a specific action, and in this way the admin can always "refill" those columns, even above the original limit.
===
Another option is to store the expiration of the permissions in those columns, so that you can reset the permissions just putting the expiry for a certain column to the day before. You can then use your queries to get the remaining number of posts/comments/votes for the user.
I suggest separating the two concerns entirely:
The process of enabling features/possibilities to users
The data model of user features
For example, you could have a simple many-to-many table representing user features:
user_features(
user_id
,feature_id
,source (admin|earned)
,primary key(user_id, feature_id)
);
This makes it really easy for an administrator to disable/enable parts or all of the feature set.
Your nightly job would query relevant tables and grant/revoke features by inserting/deleting from this table.
If you go with this approach, you can actually give the features either based on a rating or specific actions.
A rule such as "3 posts in 3 days", can be implemented like this:
when a user posts, check if the previous post was made within 24 hours.
if yes then
increment counter by 1
record current timestamp
if counter = 3 then
grant feature to user
else
reset counter to 1
record current timestamp
You would need two columns (post_count:int, last_post:date) in some table keyed by user_id.

Categories