migrate to gtea from bistbucket

This commit is contained in:
2026-03-15 17:08:23 +07:00
commit 129ca2260c
3716 changed files with 566316 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
<?php
namespace App\Traits;
use Exception;
trait Authenticatable
{
/**
* @throws Exception
*/
protected function getCurrentUserId(): int
{
if (app()->runningInConsole()) {
return 1;
}
if (! isset(request()->user()->id)) {
throw new Exception('You are not authenticated to view this.');
}
return (int) request()->user()->id;
}
/**
* @throws Exception
*/
protected function getCurrentRestaurantId(): int
{
if (app()->runningInConsole()) {
return 1;
}
if (! isset(request()->user()->restaurant_id)) {
throw new Exception('You are not authenticated to view this.');
}
return (int) request()->user()->restaurant_id;
}
}

View File

@@ -0,0 +1,24 @@
<?php
namespace App\Traits;
use Illuminate\Support\Facades\Auth;
trait HasPermissionTrait
{
use ResponseTrait;
public function checkPermission($permission)
{
if (Auth::user()->hasPermissionTo($permission, 'web')) {
return true;
}
return $this->responseError([], 'You have no access on this feature', 403);
}
public function handlePermission($permission)
{
return $this->checkPermission($permission);
}
}

View File

@@ -0,0 +1,78 @@
<?php
namespace App\Traits;
use Exception;
use Illuminate\Foundation\Application;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Routing\Redirector;
use Modules\Authentication\Models\SAASSetting;
use Modules\Authentication\Models\Setting;
trait PaymentProcess
{
use Authenticatable;
public function responseFormatter($constant, $content = null, $errors = []): array
{
$constant = (array) $constant;
$constant['content'] = $content;
$constant['errors'] = $errors;
return $constant;
}
public function errorProcessor($validator): array
{
$errors = [];
foreach ($validator->errors()->getMessages() as $index => $error) {
$errors[] = ['error_code' => $index, 'message' => $error[0]];
}
return $errors;
}
public function paymentResponse($payment_info, $payment_flag): Application|JsonResponse|Redirector|RedirectResponse|\Illuminate\Contracts\Foundation\Application
{
$getNewUser = (int) 0;
$additionalData = json_decode($payment_info->additional_data, true);
if (isset($additionalData['new_customer_id']) && isset($additionalData['is_guest_in_order'])) {
$getNewUser = (int) (($additionalData['new_customer_id'] != 0 && $additionalData['is_guest_in_order'] != 1) ? 1 : 0);
}
$token_string = 'payment_method='.$payment_info->payment_method.'&&transaction_reference='.$payment_info->transaction_id;
if (in_array($payment_info->payment_platform, ['web', 'app']) && $payment_info['external_redirect_link'] != null) {
return redirect($payment_info['external_redirect_link'].'?flag='.$payment_flag.'&&token='.base64_encode($token_string).'&&new_user='.$getNewUser);
}
return redirect()->route('payment-'.$payment_flag, ['token' => base64_encode($token_string), 'new_user' => $getNewUser]);
}
public function paymentConfig($key, $settingsType, $payment): ?object
{
if (empty($key) || empty($settingsType) || empty($payment)) {
return null;
}
if ($payment->payment_type == 'subscription_payment') {
try {
$config = SAASSetting::where('name', $key)
->where('type', $settingsType)->first();
} catch (Exception $exception) {
return new SAASSetting;
}
} else {
try {
$config = Setting::where('name', $key)
->where('restaurant_id', $payment->restaurant_id)
->where('type', $settingsType)->first();
} catch (Exception $exception) {
return new Setting;
}
}
return (isset($config)) ? $config : null;
}
}

View File

@@ -0,0 +1,13 @@
<?php
namespace App\Traits;
use Illuminate\Http\Request;
trait RequestSanitizerTrait
{
protected function getUpdateRequest(Request $request)
{
return $request->except(['_method', 'id']);
}
}

View File

@@ -0,0 +1,42 @@
<?php
namespace App\Traits;
use Illuminate\Http\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
trait ResponseTrait
{
/**
* Success response.
*
* @param object|array $data
*/
public function responseSuccess($data, string $message = 'Successful'): JsonResponse
{
return response()->json([
'status' => true,
'message' => $message,
'data' => $data,
'errors' => null,
], Response::HTTP_OK);
}
/**
* Error response.
*
* @param array|object $errors
*/
public function responseError(
$errors,
string $message = 'Something went wrong.',
int $responseCode = Response::HTTP_INTERNAL_SERVER_ERROR
): JsonResponse {
return response()->json([
'status' => false,
'message' => $message,
'data' => null,
'errors' => $errors,
], $responseCode);
}
}

View File

@@ -0,0 +1,48 @@
<?php
namespace App\Traits;
use Exception;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;
trait SlugAbleTrait
{
/**
* @throws Exception
*/
public function createUniqueSlug(string $title, string $tableName, string $columnName, string $separator = '-'): string
{
$id = 0;
$slug = preg_replace('/\s+/', $separator, (trim(strtolower($title))));
$slug = preg_replace('/\?+/', $separator, (trim(strtolower($slug))));
$slug = preg_replace('/\#+/', $separator, (trim(strtolower($slug))));
$slug = preg_replace('/\/+/', $separator, (trim(strtolower($slug))));
// // Replace all separator characters and whitespace by a single separator
$slug = preg_replace('!['.preg_quote($separator).'\s]+!u', $separator, $slug);
$allSlugs = $this->getRelatedSlugs($slug, $tableName, $columnName, $id);
// If we haven't used it before then we are all good.
if (! $allSlugs->contains("$columnName", $slug)) {
return $slug;
}
// Just append numbers like a savage until we find not used.
for ($i = 1; $i <= 1000000000; $i++) {
$newSlug = $slug.$separator.$i;
if (! $allSlugs->contains("$columnName", $newSlug)) {
return $newSlug;
}
}
throw new Exception('Can not create a unique slug');
}
private function getRelatedSlugs(string $slug, string $tableName, string $columnName, int $id = 0): Collection
{
return DB::table($tableName)
->select("$columnName")->where("$columnName", 'like', $slug.'%')
->where('id', '<>', $id)
->get();
}
}

View File

@@ -0,0 +1,36 @@
<?php
namespace App\Traits;
use Modules\Authentication\Models\UserLog;
trait Trackable
{
public function trackAction($action = 'create', $model = null, $model_id = null, $detail = null): void
{
try {
if (! auth()->check()) {
return;
}
$user = auth()->user();
$user_id = $user->id;
$ip_address = request()->ip();
$url = request()->fullUrl();
$userLog = new UserLog;
$userLog->user_id = $user_id;
$userLog->institute_id = getUserRestaurantId();
$userLog->user_id = $user_id;
$userLog->ip_address = $ip_address;
$userLog->action = $action;
$userLog->detail = $detail;
$userLog->model = $model;
$userLog->url = $url;
$userLog->model_id = $model_id;
$userLog->save();
} catch (\Throwable $th) {
//
}
}
}