Coder Social home page Coder Social logo

cleaniquecoders / attendance Goto Github PK

View Code? Open in Web Editor NEW
33.0 4.0 18.0 45 KB

An Adaptive Attendance for Laravel - enabled developers to integrate with existing attendance system and devices such as Access Card, Biometric, etc

License: MIT License

PHP 100.00%
laravel attendance api mobile biometric ble access-card

attendance's Introduction

Build Status Latest Stable Version Total Downloads License

About Your Package

This is an Adaptive Attendance package - enabled developers to integrate with existing attendance system and devices such as Access Card, Biometric, etc.

This package comes with common attendance adapaters:

  1. Web Adapter - use for Web based attendance system
  2. API Adapter - use for Mobile based attendance system
  3. Console Adapter - use for Queue based attendance system

See usage section below for custom adapters.

Installation

  1. In order to install cleaniquecoders/attendance in your Laravel project, just run the composer require command from your terminal:
$ composer require cleaniquecoders/attendance
  1. Then in your config/app.php add the following to the providers array:
CleaniqueCoders\Attendance\AttendanceServiceProvider::class,
  1. In the same config/app.php add the following to the aliases array:
'Attendance' => CleaniqueCoders\Attendance\AttendanceFacade::class,
  1. Install the package:
$ php artisan attendance:install
  1. Setup AttendanceTrait to your user model.
<?php

namespace App;

use CleaniqueCoders\Attendance\Traits\AttendanceTrait;
use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Notifiable, AttendanceTrait;
...

Usage

Artisan Commands

Log Attendance from console:

// log user with 1 as time in
$ php artisan attendance:log 1 1

// log user with 1 as time out
$ php artisan attendance:log 1 2

// log user with email [email protected] as time in
$ php artisan attendance:log "[email protected]" 1 "email"

// log user with email [email protected] as time out
$ php artisan attendance:log "[email protected]" 2 "email"

API

When running attendance:install, API routes to for attendance will be append into your routes/api.php file.

Scopes

To get all entries for today, you can use todayEntries() scope.

\CleaniqueCoders\Attendance\Models\Attendance::todayEntries()->get();

To get based on one or more drivers.

\CleaniqueCoders\Attendance\Models\Attendance::todayEntries('web')->get();
\CleaniqueCoders\Attendance\Models\Attendance::todayEntries(['api', 'access-card'])->get();

Custom adapter

You can create custom adapter if you want to have custom integration with Slack, Telegram, etc.

$ php artisan make:attendance SlackAdapter --driver=slack

This will create a class located at app/Adapters/SlackAdapter.php.

<?php 

namespace App\Adapters;

use CleaniqueCoders\Attendance\Models\AttendanceType;

class SlackAdapter extends BaseAdapter
{
	protected $driver = 'slack';

	public function timeIn()
	{
		// your implementation to determine user is time in
		$this->capture(AttendanceType::TIME_IN);
	}

	public function timeOut()
	{
		// your implementation to determine user is time out
		$this->capture(AttendanceType::TIME_OUT);
	}
}

Once created, you may want to create routes to accept Slack webhook into your app. Following is an example of route setup.

Route::get('attendance/slack/time-in', function() {
	$user = \App\User::whereSlackId(request()->slack_id)->firstOrFail();
	(new \App\Adapters\SlackAdapter($user, now()))->timeIn();
})->name('attendance.slack.time-in');

Route::get('attendance/slack/time-out', function() {
	$user = \App\User::whereSlackId(request()->slack_id)->firstOrFail();
	(new \App\Adapters\SlackAdapter($user, now()))->timeOut();
})->name('attendance.slack.time-out');

Test

Run the following command:

$ vendor/bin/phpunit  --testdox --verbose

Contributing

Thank you for considering contributing to the cleaniquecoders/attendance!

Bug Reports

To encourage active collaboration, it is strongly encourages pull requests, not just bug reports. "Bug reports" may also be sent in the form of a pull request containing a failing test.

However, if you file a bug report, your issue should contain a title and a clear description of the issue. You should also include as much relevant information as possible and a code sample that demonstrates the issue. The goal of a bug report is to make it easy for yourself - and others - to replicate the bug and develop a fix.

Remember, bug reports are created in the hope that others with the same problem will be able to collaborate with you on solving it. Do not expect that the bug report will automatically see any activity or that others will jump to fix it. Creating a bug report serves to help yourself and others start on the path of fixing the problem.

Coding Style

cleaniquecoders/attendance follows the PSR-2 coding standard and the PSR-4 autoloading standard.

You may use PHP CS Fixer in order to keep things standardised. PHP CS Fixer configuration can be found in .php_cs.

License

This package is open-sourced software licensed under the MIT license.

attendance's People

Contributors

nasrulhazim avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

attendance's Issues

Laravel 8 support?

Just curious if this was on your radar to make compatible with Laravel 8? I noticed some of its dependencies have been updated, so I thought maybe this was on the docket as well. I forked and played around with it but wasn't able to get it working -- I'm still quite new to the Laravel universe. :)

Cannot add foreign key constraint in Laravel 5.8

Illuminate\Database\QueryException : SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL: alter tableattendancesadd constraintattendances_user_id_foreign foreign key (user_id) references users (id`))

at C:\laragon\www\Attendance\vendor\laravel\framework\src\Illuminate\Database\Connection.php:664
660| // If an exception occurs when attempting to run a query, we'll format the error
661| // message to include the bindings with SQL, which will make this exception a
662| // lot more helpful to the developer instead of just the database's errors.
663| catch (Exception $e) {

664| throw new QueryException(
665| $query, $this->prepareBindings($bindings), $e
666| );
667| }
668|

Exception trace:

1 Doctrine\DBAL\Driver\PDOException::("SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint")
C:\laragon\www\Prep50Attendance\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOStatement.php:119

2 PDOException::("SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint")
C:\laragon\www\Prep50Attendance\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOStatement.php:117
`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.