このリポジトリは2023-09-09にアーカイブされています。 ファイルの閲覧とクローンは可能ですが、プッシュ、イシューの作成、プルリクエストはできません。
kikikan/backend/app/Http/Middleware/NoticeIncomplete.php

54 行
1.4 KiB
PHP
Raw 通常表示 履歴

2021-11-10 23:01:50 +09:00
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
2021-11-11 18:49:09 +09:00
use App\Models\Meeting;
2021-11-10 23:01:50 +09:00
use App\Models\MeetingApprovals;
class NoticeIncomplete
{
/**
* 未完了ミーティング通知(親向け)
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle(Request $request, Closure $next)
{
2021-11-11 18:49:09 +09:00
$response = $next($request);
$count = 0;
2021-11-17 13:09:21 +09:00
if (is_null(session()->get('fathers'))) {
session()->forget('fathers');
return $response;
}
2021-11-13 15:33:48 +09:00
if (null !== ($list = Meeting::select('id')->where('father_id', (int)session()->get('fathers')['id'])->get())) {
foreach ($list as $i => $l) {
if (null === ($apr = MeetingApprovals::select('id')->where('meeting_id', (int)$l->id)->get())) {
continue;
}
2021-11-17 19:42:21 +09:00
$cnt = MeetingApprovals::select('id')->whereNotNull('approval_at')->where('meeting_id', (int)$l->id)->count();
$apr = count($apr);
if ($apr == $cnt) {
continue;
}
$count++;
2021-11-13 15:33:48 +09:00
}
2021-11-11 10:02:28 +09:00
}
2021-11-11 18:49:09 +09:00
$content = json_decode($response->content(), true);
if (json_last_error() == JSON_ERROR_NONE) {
2021-11-15 17:18:04 +09:00
$response->setContent(json_encode(array_merge($content, ['notice' => $count])));
2021-11-11 18:49:09 +09:00
}
2021-11-15 17:18:04 +09:00
return $response;
2021-11-10 23:01:50 +09:00
}
}