Skip to content

Commit 5d8d55d

Browse files
committed
feat: qr code in transcript
1 parent efe50a7 commit 5d8d55d

16 files changed

Lines changed: 1091 additions & 1193 deletions

.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,6 @@ VESTA_ISSUER=
5656
VESTA_SECRET=
5757
SENTRY_LARAVEL_DSN=
5858
SENTRY_TRACES_SAMPLE_RATE=0
59+
60+
KEYCLOAK_BASE_URL=https://acad-auth.md.chula.ac.th
61+
KEYCLOAK_REALM=mdcu

app/Http/Controllers/ProjectClosureController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ public function approvalIndex(Request $request) {
162162
$sortOrder = [5 => 0, 6 => 1, 1 => 2, -2 => 3, -1 => 4, 10 => 5, 3 => 6, -3 => 7, 0 => 8];
163163

164164
return Inertia::render('ProjectApprovalIndex', [
165+
// @todo docs Project::searchQuery() limits to 1 year back by default
165166
'list' => Project::searchQuery($keyword)->with('participants')
166167
->withCount('participants') // to get participants_count
167168
->addSelect(['closure_submitted_at', 'closure_approved_at', 'closure_approved_status', 'closure_approved_message'])

app/Http/Controllers/TranscriptController.php

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
namespace App\Http\Controllers;
44

55
use App\Models\User;
6+
use BaconQrCode\Renderer\Image\SvgImageBackEnd;
7+
use BaconQrCode\Renderer\ImageRenderer;
8+
use BaconQrCode\Renderer\RendererStyle\RendererStyle;
9+
use BaconQrCode\Writer;
610
use Illuminate\Http\Request;
11+
use Illuminate\Support\HtmlString;
712
use Inertia\Inertia;
813

914
class TranscriptController extends Controller {
@@ -23,8 +28,26 @@ public function index(Request $request) {
2328

2429
public function print(User $user) {
2530
$this->authorize('view-transcript');
31+
$writer = new Writer(new ImageRenderer(
32+
new RendererStyle(90),
33+
new SvgImageBackEnd
34+
));
35+
$link = $user->getTranscriptLink();
2636

27-
return view('my-projects', ['user' => $user]);
28-
// return response()->view('base64-pdf-viewer', ['encoded' => base64_encode(Pdf::loadView('my-projects', ['user' => $user])->output())]);
37+
return view('my-projects', [
38+
'user' => $user,
39+
'link' => $link,
40+
'qrCode' => new HtmlString($writer->writeString($link)),
41+
]);
42+
}
43+
44+
public function publicView($identifier) {
45+
$user = User::where('public_identifier', $identifier)->with(['participants', 'participants.project'])->firstOrFail();
46+
$user?->participants->where('project_type', 'App\Models\Project')->load('project.department');
47+
48+
return Inertia::render('TranscriptPublicView', [
49+
'user_name' => $user->name,
50+
'transcript' => $user?->getActivityTranscript()->filter(fn($item) => $item['approve_status'] >= 1),
51+
]);
2952
}
3053
}

app/Models/User.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Illuminate\Foundation\Auth\User as Authenticatable;
1212
use Illuminate\Notifications\Notifiable;
1313
use Illuminate\Support\Collection;
14+
use Illuminate\Support\Str;
1415
use Laravel\Fortify\TwoFactorAuthenticatable;
1516
use Laravel\Jetstream\HasProfilePhoto;
1617
use Laravel\Sanctum\HasApiTokens;
@@ -151,6 +152,15 @@ public function getActivityTranscript(): Collection {
151152
return $myParticipants->sortByDesc('approve_status')->values();
152153
}
153154

155+
public function getTranscriptLink(): string {
156+
if (!$this->public_identifier) {
157+
$this->public_identifier = Str::random(12);
158+
$this->save();
159+
}
160+
161+
return route('transcript.public-view', ['identifier' => $this->public_identifier]);
162+
}
163+
154164
public static function searchQuery(string $keyword = null): ?Builder {
155165
$query = self::query();
156166
if (empty($keyword) or strlen($keyword) < 3) {

composer.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"require": {
88
"php": "^8.2",
99
"ext-intl": "*",
10+
"bacon/bacon-qr-code": "^3.0",
1011
"docchula/vesta-client": "^1.0.0",
1112
"google/apiclient": "^2.15.0",
1213
"guzzlehttp/guzzle": "^7.3",
@@ -31,12 +32,12 @@
3132
"tightenco/ziggy": "^2.0"
3233
},
3334
"require-dev": {
34-
"fakerphp/faker": "^1.9.1",
35+
"fakerphp/faker": "^1.23",
36+
"itsgoingd/clockwork": "^5.3",
3537
"mockery/mockery": "^1.4.2",
36-
"nunomaduro/collision": "^8.1",
38+
"nunomaduro/collision": "^8.6",
3739
"pestphp/pest": "^4.0",
38-
"pestphp/pest-plugin-laravel": "^4.0",
39-
"spatie/laravel-ignition": "^2.0"
40+
"pestphp/pest-plugin-laravel": "^4.0"
4041
},
4142
"repositories": [
4243
{

0 commit comments

Comments
 (0)