Initial Commit
This commit is contained in:
@@ -0,0 +1,220 @@
|
||||
<?php
|
||||
|
||||
namespace App\Helpers;
|
||||
|
||||
use App\Models\Log;
|
||||
use App\Models\LogAction;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class Logger
|
||||
{
|
||||
public static function LogCreated(int $loggable_id, string $loggable_type,int $amount = Null, int $target = Null,string $logMessage = Null): void
|
||||
{
|
||||
$log = new Log();
|
||||
$log->user()->associate(Auth::id());
|
||||
$log->action()->associate(LogAction::firstWhere('name', '=', 'created'));
|
||||
$log->loggable_type = $loggable_type;
|
||||
$log->loggable_id = $loggable_id;
|
||||
$log->target_id = $target;
|
||||
$log->amount = $amount;
|
||||
$log->log = $logMessage;
|
||||
$log->save();
|
||||
}
|
||||
|
||||
public static function LogEdited(int $loggable_id, string $loggable_type,string $logMessage, int $amount = Null, int $target = Null): void
|
||||
{
|
||||
$log = new Log();
|
||||
$log->user()->associate(Auth::id());
|
||||
$log->action()->associate(LogAction::firstWhere('name', '=', 'edited'));
|
||||
$log->loggable_type = $loggable_type;
|
||||
$log->loggable_id = $loggable_id;
|
||||
$log->target_id = $target;
|
||||
$log->amount = $amount;
|
||||
$log->log = $logMessage;
|
||||
$log->save();
|
||||
}
|
||||
|
||||
public static function LogDeleted(int $loggable_id, string $loggable_type,int $amount = Null, int $target = Null,string $logMessage = Null): void
|
||||
{
|
||||
$log = new Log();
|
||||
$log->user()->associate(Auth::id());
|
||||
$log->action()->associate(LogAction::firstWhere('name', '=', 'deleted'));
|
||||
$log->loggable_type = $loggable_type;
|
||||
$log->loggable_id = $loggable_id;
|
||||
$log->target_id = $target;
|
||||
$log->amount = $amount;
|
||||
$log->log = $logMessage;
|
||||
$log->save();
|
||||
}
|
||||
|
||||
public static function LogForceDeleted(int $loggable_id, string $loggable_type, string $logMessage = Null,int $amount = Null,int $target = Null,): void
|
||||
{
|
||||
$log = new Log();
|
||||
$log->user()->associate(Auth::id());
|
||||
$log->action()->associate(LogAction::firstWhere('name', '=', 'force_deleted'));
|
||||
$log->loggable_type = $loggable_type;
|
||||
$log->loggable_id = $loggable_id;
|
||||
$log->target_id = $target;
|
||||
$log->amount = $amount;
|
||||
$log->log = $logMessage;
|
||||
$log->save();
|
||||
}
|
||||
|
||||
public static function LogRestored(int $loggable_id, string $loggable_type, int $amount = Null, int $target = Null,string $logMessage = Null): void
|
||||
{
|
||||
$log = new Log();
|
||||
$log->user()->associate(Auth::id());
|
||||
$log->action()->associate(LogAction::firstWhere('name', '=', 'restored'));
|
||||
$log->loggable_type = $loggable_type;
|
||||
$log->loggable_id = $loggable_id;
|
||||
$log->target_id = $target;
|
||||
$log->amount = $amount;
|
||||
$log->log = $logMessage;
|
||||
$log->save();
|
||||
}
|
||||
|
||||
public static function LogLent(int $loggable_id, string $loggable_type,int $amount, int $target,string $logMessage = Null): void
|
||||
{
|
||||
$log = new Log();
|
||||
$log->user()->associate(Auth::id());
|
||||
$log->action()->associate(LogAction::firstWhere('name', '=', 'lent'));
|
||||
$log->loggable_type = $loggable_type;
|
||||
$log->loggable_id = $loggable_id;
|
||||
$log->target_id = $target;
|
||||
$log->amount = $amount;
|
||||
$log->log = $logMessage;
|
||||
$log->save();
|
||||
}
|
||||
|
||||
public static function LogReturn(int $loggable_id, string $loggable_type,int $amount, int $target = Null,string $logMessage = Null): void
|
||||
{
|
||||
$log = new Log();
|
||||
$log->user()->associate(Auth::id());
|
||||
$log->action()->associate(LogAction::firstWhere('name', '=', 'returned'));
|
||||
$log->loggable_type = $loggable_type;
|
||||
$log->loggable_id = $loggable_id;
|
||||
$log->target_id = $target;
|
||||
$log->amount = $amount;
|
||||
$log->log = $logMessage;
|
||||
$log->save();
|
||||
}
|
||||
|
||||
public static function LogSetup(int $loggable_id, string $loggable_type,int $amount, int $target = Null,string $logMessage = Null): void
|
||||
{
|
||||
$log = new Log();
|
||||
$log->user()->associate(Auth::id());
|
||||
$log->action()->associate(LogAction::firstWhere('name', '=', 'set up'));
|
||||
$log->loggable_type = $loggable_type;
|
||||
$log->loggable_id = $loggable_id;
|
||||
$log->target_id = $target;
|
||||
$log->amount = $amount;
|
||||
$log->log = $logMessage;
|
||||
$log->save();
|
||||
}
|
||||
|
||||
public static function LogPickup(int $loggable_id, string $loggable_type, int $amount, int $target = Null,string $logMessage = Null): void
|
||||
{
|
||||
$log = new Log();
|
||||
$log->user()->associate(Auth::id());
|
||||
$log->action()->associate(LogAction::firstWhere('name', '=', 'picked up'));
|
||||
$log->loggable_type = $loggable_type;
|
||||
$log->loggable_id = $loggable_id;
|
||||
$log->target_id = $target;
|
||||
$log->amount = $amount;
|
||||
$log->log = $logMessage;
|
||||
$log->save();
|
||||
}
|
||||
|
||||
public static function LogAdjusted(int $loggable_id, string $loggable_type,string $logMessage, int $amount = Null, int $target = Null): void
|
||||
{
|
||||
$log = new Log();
|
||||
$log->user()->associate(Auth::id());
|
||||
$log->action()->associate(LogAction::firstWhere('name', '=', 'adjusted'));
|
||||
$log->loggable_type = $loggable_type;
|
||||
$log->loggable_id = $loggable_id;
|
||||
$log->target_id = $target;
|
||||
$log->amount = $amount;
|
||||
$log->log = $logMessage;
|
||||
$log->save();
|
||||
}
|
||||
|
||||
public static function LogAmountAdded(int $loggable_id, string $loggable_type,int $amount,string $logMessage = Null, int $target = Null): void
|
||||
{
|
||||
$log = new Log();
|
||||
$log->user()->associate(Auth::id());
|
||||
$log->action()->associate(LogAction::firstWhere('name', '=', 'amount_added'));
|
||||
$log->loggable_type = $loggable_type;
|
||||
$log->loggable_id = $loggable_id;
|
||||
$log->target_id = $target;
|
||||
$log->amount = $amount;
|
||||
$log->log = $logMessage;
|
||||
$log->save();
|
||||
}
|
||||
|
||||
public static function LogAmountRemoved(int $loggable_id, string $loggable_type,int $amount,string $logMessage = Null, int $target = Null): void
|
||||
{
|
||||
$log = new Log();
|
||||
$log->user()->associate(Auth::id());
|
||||
$log->action()->associate(LogAction::firstWhere('name', '=', 'amount_removed'));
|
||||
$log->loggable_type = $loggable_type;
|
||||
$log->loggable_id = $loggable_id;
|
||||
$log->target_id = $target;
|
||||
$log->amount = $amount;
|
||||
$log->log = $logMessage;
|
||||
$log->save();
|
||||
}
|
||||
|
||||
public static function LogReserved(int $loggable_id, string $loggable_type,int $amount, int $target, string $logMessage = Null): void
|
||||
{
|
||||
$log = new Log();
|
||||
$log->user()->associate(Auth::id());
|
||||
$log->action()->associate(LogAction::firstWhere('name', '=', 'reserved'));
|
||||
$log->loggable_type = $loggable_type;
|
||||
$log->loggable_id = $loggable_id;
|
||||
$log->target_id = $target;
|
||||
$log->amount = $amount;
|
||||
$log->log = $logMessage;
|
||||
$log->save();
|
||||
}
|
||||
|
||||
public static function LogValidated(int $loggable_id, string $loggable_type, int $target,int $amount = Null, string $logMessage = Null): void
|
||||
{
|
||||
$log = new Log();
|
||||
$log->user()->associate(Auth::id());
|
||||
$log->action()->associate(LogAction::firstWhere('name', '=', 'validated'));
|
||||
$log->loggable_type = $loggable_type;
|
||||
$log->loggable_id = $loggable_id;
|
||||
$log->target_id = $target;
|
||||
$log->amount = $amount;
|
||||
$log->log = $logMessage;
|
||||
$log->save();
|
||||
}
|
||||
|
||||
|
||||
public static function LogCancelled(int $loggable_id, string $loggable_type, int $target,int $amount = Null, string $logMessage = Null): void
|
||||
{
|
||||
$log = new Log();
|
||||
$log->user()->associate(Auth::id());
|
||||
$log->action()->associate(LogAction::firstWhere('name', '=', 'cancelled'));
|
||||
$log->loggable_type = $loggable_type;
|
||||
$log->loggable_id = $loggable_id;
|
||||
$log->target_id = $target;
|
||||
$log->amount = $amount;
|
||||
$log->log = $logMessage;
|
||||
$log->save();
|
||||
}
|
||||
|
||||
|
||||
public static function LogNote(int $loggable_id, string $loggable_type, int $target,string $logMessage, int $amount = Null): void
|
||||
{
|
||||
$log = new Log();
|
||||
$log->user()->associate(Auth::id());
|
||||
$log->action()->associate(LogAction::firstWhere('name', '=', 'note'));
|
||||
$log->loggable_type = $loggable_type;
|
||||
$log->loggable_id = $loggable_id;
|
||||
$log->target_id = $target;
|
||||
$log->amount = $amount;
|
||||
$log->log = $logMessage;
|
||||
$log->save();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
namespace App\Helpers;
|
||||
|
||||
use Illuminate\Container\Container;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Pagination\Paginator;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class PaginationHelper
|
||||
{
|
||||
public static function paginate(Collection $results, $pageSize)
|
||||
{
|
||||
$page = Paginator::resolveCurrentPage('page');
|
||||
|
||||
$total = $results->count();
|
||||
|
||||
return self::paginator($results->forPage($page, $pageSize), $total, $pageSize, $page, [
|
||||
'path' => Paginator::resolveCurrentPath(),
|
||||
'pageName' => 'page',
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new length-aware paginator instance.
|
||||
*
|
||||
* @param \Illuminate\Support\Collection $items
|
||||
* @param int $total
|
||||
* @param int $perPage
|
||||
* @param int $currentPage
|
||||
* @param array $options
|
||||
* @return \Illuminate\Pagination\LengthAwarePaginator
|
||||
*/
|
||||
protected static function paginator($items, $total, $perPage, $currentPage, $options)
|
||||
{
|
||||
return Container::getInstance()->makeWith(LengthAwarePaginator::class, compact(
|
||||
'items', 'total', 'perPage', 'currentPage', 'options'
|
||||
));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user