2021-09-30 13:33:23 +09:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
2021-10-01 13:17:11 +09:00
|
|
|
use Illuminate\Support\Facades\Validator;
|
2021-10-15 10:37:47 +09:00
|
|
|
use Illuminate\Http\Request;
|
2021-11-30 17:05:54 +09:00
|
|
|
use Illuminate\Support\Facades\DB;
|
2021-10-15 10:37:47 +09:00
|
|
|
use Illuminate\Support\Facades\Log;
|
2021-12-21 00:01:31 +09:00
|
|
|
use Illuminate\Support\Facades\Mail;
|
2021-11-01 00:22:21 +09:00
|
|
|
use Illuminate\Support\Facades\Storage;
|
2021-09-30 13:33:23 +09:00
|
|
|
|
|
|
|
use App\Models\Meeting;
|
|
|
|
use App\Models\MeetingImage;
|
|
|
|
use App\Models\MeetingApprovals;
|
|
|
|
use App\Models\Child;
|
|
|
|
use App\Models\Father;
|
2021-11-03 02:30:46 +09:00
|
|
|
use App\Models\FatherRelation;
|
2021-09-30 13:33:23 +09:00
|
|
|
|
2021-12-21 00:01:31 +09:00
|
|
|
use App\Mail\FathersApprovalMail;
|
|
|
|
|
2021-09-30 13:33:23 +09:00
|
|
|
class MeetingsController extends Controller {
|
2021-10-01 14:26:48 +09:00
|
|
|
public function register (Request $r) {
|
|
|
|
if (!isset($r->father_id)) {
|
2021-10-06 14:50:13 +09:00
|
|
|
return ['status_code' => 400, 'error_messages' => ['ミーティングの登録に失敗しました。']];
|
2021-10-01 14:26:48 +09:00
|
|
|
}
|
2021-09-30 13:33:23 +09:00
|
|
|
|
2021-11-28 17:10:40 +09:00
|
|
|
if (count(Storage::disk('private')->files('/')) >= 9999) {
|
|
|
|
Log::critical('ストレージの限界を超えています。9999個ファイルまで保存可能ですので、不要なファイルを削除して下さい。');
|
2021-11-26 16:15:22 +09:00
|
|
|
return ['status_code' => 400, 'error_messages' => ['親の更新に失敗しました。']];
|
|
|
|
}
|
|
|
|
|
2021-11-17 13:09:21 +09:00
|
|
|
if (isset($r->image)) {
|
|
|
|
$r->image = json_decode($r->image);
|
|
|
|
}
|
|
|
|
|
2021-11-30 12:45:32 +09:00
|
|
|
// 画像サイズは各5MiB以内、PDFサイズは50MiB以内
|
|
|
|
//// 画像
|
2021-11-16 21:31:26 +09:00
|
|
|
Validator::extend('image_size', function ($attribute, $value, $params, $validator) {
|
2021-11-22 21:48:48 +09:00
|
|
|
return $this->imagesizemulti($value);
|
2021-11-16 21:31:26 +09:00
|
|
|
});
|
|
|
|
|
2021-11-30 12:45:32 +09:00
|
|
|
//// PDF
|
|
|
|
Validator::extend('pdf_size', function ($attribute, $value, $params, $validator) {
|
|
|
|
return $this->pdfsize($value);
|
|
|
|
});
|
|
|
|
|
2021-11-16 21:31:26 +09:00
|
|
|
// ミームタイプ
|
2021-11-17 21:23:29 +09:00
|
|
|
//// 画像
|
2021-11-17 23:51:07 +09:00
|
|
|
Validator::extend('image_meme', function ($attribute, $value, $params, $validator) {
|
2021-11-22 21:48:48 +09:00
|
|
|
return $this->imagememeorfile($value);
|
2021-11-17 23:51:07 +09:00
|
|
|
});
|
2021-11-16 21:31:26 +09:00
|
|
|
|
2021-11-17 21:23:29 +09:00
|
|
|
//// PDF
|
2021-11-17 23:51:07 +09:00
|
|
|
Validator::extend('pdf_meme', function ($attribute, $value, $params, $validator) {
|
2021-11-22 21:48:48 +09:00
|
|
|
return $this->pdfmeme($value);
|
2021-11-17 23:51:07 +09:00
|
|
|
});
|
2021-11-10 22:13:09 +09:00
|
|
|
|
2021-10-01 14:26:48 +09:00
|
|
|
$validate = Validator::make($r->all(), [
|
2021-10-06 14:50:13 +09:00
|
|
|
'title' => 'required|max:100',
|
|
|
|
'text' => 'required|max:2000',
|
|
|
|
'memo' => 'max:2000',
|
2021-11-30 12:45:32 +09:00
|
|
|
'pdf' => 'pdf_size|pdf_meme',
|
2021-11-17 13:09:21 +09:00
|
|
|
'image' => 'image_size|image_meme',
|
2021-10-01 14:26:48 +09:00
|
|
|
]);
|
2021-10-01 13:17:11 +09:00
|
|
|
|
2021-10-01 14:26:48 +09:00
|
|
|
if ($validate->fails()) {
|
|
|
|
return ['status_code' => 422, 'error_messages' => $validate->errors()];
|
|
|
|
}
|
2021-10-01 13:17:11 +09:00
|
|
|
|
2021-11-28 17:21:55 +09:00
|
|
|
if ($r->pdf == 'null') {
|
|
|
|
$r->pdf = null;
|
|
|
|
}
|
|
|
|
if ($r->pdf == '/assets/default/default.pdf') {
|
|
|
|
$r->pdf = null;
|
|
|
|
}
|
|
|
|
|
2021-10-06 14:50:13 +09:00
|
|
|
$insert = [
|
|
|
|
'father_id' => $r->father_id,
|
|
|
|
'title' => $r->title,
|
|
|
|
'text' => $r->text,
|
2021-11-10 22:13:09 +09:00
|
|
|
'memo' => $r->memo
|
2021-10-01 14:26:48 +09:00
|
|
|
];
|
2021-10-01 13:17:11 +09:00
|
|
|
|
2021-11-23 11:36:07 +09:00
|
|
|
$filename = '';
|
|
|
|
$fnames = [];
|
2021-11-25 01:11:40 +09:00
|
|
|
$meeting = 0;
|
2021-11-23 11:36:07 +09:00
|
|
|
|
2021-10-06 14:50:13 +09:00
|
|
|
try {
|
2021-11-10 22:13:09 +09:00
|
|
|
if (isset($r->pdf)) {
|
2021-11-30 13:34:14 +09:00
|
|
|
$filename = $this->uuidv4().'.pdf';
|
2021-11-26 14:41:19 +09:00
|
|
|
$insert['pdf'] = '/files/'.$filename;
|
2021-11-18 00:31:39 +09:00
|
|
|
|
|
|
|
if (substr($r->pdf, -4) != '.pdf') {
|
|
|
|
$pdf = base64_decode(substr($r->pdf, strpos($r->pdf, ',') + 1));
|
|
|
|
|
2021-11-26 14:41:19 +09:00
|
|
|
Storage::disk('private')->put($filename, $pdf);
|
2021-11-18 00:31:39 +09:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$insert['pdf'] = $r->pdf;
|
|
|
|
}
|
2021-11-10 22:13:09 +09:00
|
|
|
}
|
|
|
|
|
2021-11-25 11:11:21 +09:00
|
|
|
$meeting = Meeting::create($insert);
|
|
|
|
$meeting = $meeting->id;
|
|
|
|
|
2021-11-18 00:31:39 +09:00
|
|
|
if (isset($r->image)) {
|
|
|
|
foreach ($r->image as $img) {
|
|
|
|
if (substr($img, -5) != '.jpeg' && substr($img, -4) != '.jpg' && substr($img, -4) != '.png' && substr($img, -4) != '.gif') {
|
2021-11-29 14:43:35 +09:00
|
|
|
$fname = $this->uuidv4() . '.jpg';
|
2021-11-23 11:36:07 +09:00
|
|
|
$fnames[] = $fname;
|
2021-11-18 00:31:39 +09:00
|
|
|
$image = base64_decode(substr($img, strpos($img, ',') + 1));
|
2021-11-26 14:41:19 +09:00
|
|
|
Storage::disk('private')->put($fname, $image);
|
2021-12-12 15:05:45 +09:00
|
|
|
$this->fiximg($fname);
|
2021-11-18 00:31:39 +09:00
|
|
|
|
2021-11-26 14:41:19 +09:00
|
|
|
$imgname = '/files/'.$fname;
|
2021-11-18 00:31:39 +09:00
|
|
|
}
|
|
|
|
else {
|
2021-11-25 01:11:40 +09:00
|
|
|
$imgname = $img;
|
2021-11-18 00:31:39 +09:00
|
|
|
}
|
|
|
|
|
2021-11-17 22:53:07 +09:00
|
|
|
$insert_image = [
|
2021-11-25 01:11:40 +09:00
|
|
|
'meeting_id' => (int)$meeting,
|
|
|
|
'image' => $imgname,
|
2021-11-17 22:53:07 +09:00
|
|
|
];
|
2021-11-18 00:31:39 +09:00
|
|
|
|
2021-11-17 22:53:07 +09:00
|
|
|
MeetingImage::create($insert_image);
|
|
|
|
}
|
2021-11-16 21:31:26 +09:00
|
|
|
}
|
|
|
|
|
2021-11-17 13:09:21 +09:00
|
|
|
foreach (json_decode($r->children) as $child) {
|
2021-11-16 22:07:18 +09:00
|
|
|
$insert_approval = [
|
|
|
|
'child_id' => $child,
|
2021-11-25 01:11:40 +09:00
|
|
|
'meeting_id' => (int)$meeting,
|
2021-11-17 20:44:35 +09:00
|
|
|
'approval_at' => null,
|
2021-11-16 22:07:18 +09:00
|
|
|
];
|
|
|
|
|
|
|
|
MeetingApprovals::create($insert_approval);
|
|
|
|
|
2021-12-21 00:11:14 +09:00
|
|
|
$c = Child::select('email')->where('id', $child)->first();
|
|
|
|
Mail::to($c->email)->send(new FathersApprovalMail(session()->get('fathers')['company'], (int)$meeting));
|
2021-12-21 00:01:31 +09:00
|
|
|
}
|
|
|
|
|
2021-11-25 01:11:40 +09:00
|
|
|
$params = ['meeting_id' => $meeting];
|
2021-10-06 14:50:13 +09:00
|
|
|
} catch (\Throwable $e) {
|
|
|
|
// 失敗
|
|
|
|
Log::critical($e->getMessage());
|
2021-11-25 01:11:40 +09:00
|
|
|
if (!is_null($meeting) && $meeting != 0) {
|
|
|
|
if (isset($r->pdf)) {
|
2021-11-26 14:41:19 +09:00
|
|
|
Storage::disk('private')->delete($filename);
|
2021-11-25 01:11:40 +09:00
|
|
|
}
|
|
|
|
if (isset($r->image)) {
|
|
|
|
foreach ($fnames as $f) {
|
2021-11-26 14:41:19 +09:00
|
|
|
Storage::disk('private')->delete($f);
|
2021-11-25 01:11:40 +09:00
|
|
|
}
|
2021-11-23 11:36:07 +09:00
|
|
|
}
|
|
|
|
}
|
2021-10-06 14:50:13 +09:00
|
|
|
return ['status_code' => 400, 'error_messages' => ['ミーティングの登録に失敗しました。']];
|
2021-10-01 14:26:48 +09:00
|
|
|
}
|
2021-10-01 13:17:11 +09:00
|
|
|
|
2021-11-16 20:24:19 +09:00
|
|
|
return ['status_code' => 200, 'success_messages' => ['ミーティングの登録に成功しました。'], 'params' => $params];
|
2021-10-01 13:17:11 +09:00
|
|
|
}
|
|
|
|
|
2021-10-01 14:26:48 +09:00
|
|
|
public function registerFavorite (Request $r) {
|
|
|
|
if (!isset($r->meeting_id) || !isset($r->is_favorite) || $r->is_favorite > 1) {
|
|
|
|
return ['status_code' => 400];
|
|
|
|
}
|
2021-10-01 13:17:11 +09:00
|
|
|
|
2021-10-01 14:26:48 +09:00
|
|
|
$update = ['is_favorite' => $r->is_favorite];
|
|
|
|
|
2021-10-07 13:51:53 +09:00
|
|
|
try {
|
2021-10-31 00:50:35 +09:00
|
|
|
Meeting::where('id', (int)$r->meeting_id)->update($update);
|
2021-10-07 13:51:53 +09:00
|
|
|
} catch (\Throwable $e) {
|
|
|
|
// 失敗
|
|
|
|
Log::critical($e->getMessage());
|
|
|
|
return ['status_code' => 400];
|
2021-10-01 14:26:48 +09:00
|
|
|
}
|
2021-10-01 13:17:11 +09:00
|
|
|
|
2021-11-18 01:25:31 +09:00
|
|
|
return ['status_code' => 200, 'params' => ['meeting_id' => (int)$r->meeting_id]];
|
2021-09-30 13:33:23 +09:00
|
|
|
}
|
|
|
|
|
2021-10-15 10:37:47 +09:00
|
|
|
public function search (Request $r) {
|
|
|
|
if (!isset($r->keyword)) {
|
|
|
|
return ['status_code' => 400];
|
|
|
|
}
|
2021-10-01 14:26:48 +09:00
|
|
|
$result = [];
|
2021-10-15 10:37:47 +09:00
|
|
|
$meeting_select = ['id', 'title', 'text', 'updated_at'];
|
|
|
|
$child_select = ['image'];
|
|
|
|
$meeting_approvals_select = ['child_id', 'approval_at'];
|
2021-09-30 13:33:23 +09:00
|
|
|
|
2021-10-01 14:26:48 +09:00
|
|
|
// 取得に成功
|
2021-12-23 18:38:54 +09:00
|
|
|
if (null === ($list = Meeting::select($meeting_select)->where('title', 'LIKE', '%'.$r->keyword.'%')->orWhere('text', 'LIKE', '%'.$r->keyword.'%')->orderBy('updated_at', 'desc')->get())) {
|
2021-10-07 13:51:53 +09:00
|
|
|
return ['status_code' => 400];
|
|
|
|
}
|
2021-09-30 13:33:23 +09:00
|
|
|
|
2021-10-07 13:51:53 +09:00
|
|
|
foreach ($list as $i => $l) {
|
|
|
|
$result[] = $l;
|
2021-10-31 00:50:35 +09:00
|
|
|
if (null === ($result[$i]['approval'] = MeetingApprovals::select($meeting_approvals_select)->where('meeting_id', (int)$l->id)->orderBy('approval_at', 'desc')->get())) {
|
2021-10-07 13:51:53 +09:00
|
|
|
return ['status_code' => 400];
|
|
|
|
}
|
2021-10-15 10:37:47 +09:00
|
|
|
|
|
|
|
foreach ($result[$i]['approval'] as $j => $k) {
|
|
|
|
if (null === ($result[$i]['approval'][$j]['child'] = Child::select($child_select)->where('id', $k->child_id)->first())) {
|
2021-11-06 23:09:48 +09:00
|
|
|
$result[$i]['approval'][$j]['child'] = new \stdClass();
|
2021-10-15 10:37:47 +09:00
|
|
|
}
|
2021-10-07 13:51:53 +09:00
|
|
|
}
|
2021-10-15 10:37:47 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
return ['status_code' => 200, 'params' => $result];
|
2021-09-30 13:33:23 +09:00
|
|
|
}
|
|
|
|
|
2021-10-01 14:26:48 +09:00
|
|
|
public function list () {
|
|
|
|
$result = [];
|
2021-10-15 10:37:47 +09:00
|
|
|
$meeting_select = ['id', 'title', 'text', 'updated_at'];
|
|
|
|
$child_select = ['image'];
|
|
|
|
$meeting_approvals_select = ['child_id', 'approval_at'];
|
2021-09-30 13:33:23 +09:00
|
|
|
|
2021-10-01 14:26:48 +09:00
|
|
|
// 取得に成功
|
2021-12-23 18:38:54 +09:00
|
|
|
if (null === ($list = Meeting::select($meeting_select)->orderBy('updated_at', 'desc')->get())) {
|
2021-10-15 10:37:47 +09:00
|
|
|
return ['status_code' => 400];
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($list as $i => $l) {
|
|
|
|
$result[] = $l;
|
2021-10-31 00:50:35 +09:00
|
|
|
if (null === ($result[$i]['approval'] = MeetingApprovals::select($meeting_approvals_select)->where('meeting_id', (int)$l->id)->orderBy('approval_at', 'desc')->get())) {
|
2021-10-07 13:51:53 +09:00
|
|
|
return ['status_code' => 400];
|
2021-10-01 14:26:48 +09:00
|
|
|
}
|
2021-09-30 13:33:23 +09:00
|
|
|
|
2021-10-15 10:37:47 +09:00
|
|
|
foreach ($result[$i]['approval'] as $j => $k) {
|
2021-10-31 00:50:35 +09:00
|
|
|
if (null === ($result[$i]['approval'][$j]['child'] = Child::select($child_select)->where('id', (int)$k->child_id)->first())) {
|
2021-10-15 10:37:47 +09:00
|
|
|
return ['status_code' => 400];
|
|
|
|
}
|
|
|
|
}
|
2021-09-30 13:33:23 +09:00
|
|
|
}
|
|
|
|
|
2021-10-07 13:51:53 +09:00
|
|
|
return ['status_code' => 200, 'params' => $result];
|
2021-09-30 13:33:23 +09:00
|
|
|
}
|
|
|
|
|
2021-10-01 14:26:48 +09:00
|
|
|
public function listOfApprovalOfChild (Request $r) {
|
|
|
|
if (!isset($r->child_id)) {
|
|
|
|
return ['status_code' => 400];
|
2021-09-30 13:33:23 +09:00
|
|
|
}
|
|
|
|
|
2021-10-01 14:26:48 +09:00
|
|
|
$result = [];
|
|
|
|
$meeting_select = ['id', 'father_id', 'title', 'text', 'memo', 'updated_at'];
|
|
|
|
$meeting_images_select = ['image'];
|
|
|
|
$father_select = ['image', 'company'];
|
|
|
|
$meeting_approvals_select = ['approval_at'];
|
|
|
|
|
|
|
|
// 取得に成功
|
2021-11-05 18:01:37 +09:00
|
|
|
if (null === ($approval = MeetingApprovals::select('meeting_id')->where('child_id', (int)$r->child_id)->whereNotNull('approval_at')->orderBy('updated_at', 'desc')->get())) {
|
2021-10-07 13:51:53 +09:00
|
|
|
return ['status_code' => 400];
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($approval as $a) {
|
2021-11-06 19:11:25 +09:00
|
|
|
if (null !== ($list = Meeting::select($meeting_select)->where('id', (int)$a->meeting_id)->get())) {
|
|
|
|
foreach ($list as $i => $l) {
|
|
|
|
if (null === ($fr = FatherRelation::select('id')->where('father_id', (int)$l->father_id)->where('child_id', (int)$r->child_id)->first())) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (null === ($l->father = Father::select($father_select)->where('id', (int)$l->father_id)->first())) {
|
|
|
|
$l->father = new \stdClass();
|
|
|
|
}
|
|
|
|
if (null === ($l->meeting_images = MeetingImage::select($meeting_images_select)->where('meeting_id', (int)$l->id)->get())) {
|
|
|
|
$l->meeting_images = [];
|
|
|
|
}
|
2021-11-06 23:09:48 +09:00
|
|
|
if (null === ($l->approval = MeetingApprovals::select($meeting_approvals_select)->whereNotNull('approval_at')->where('meeting_id', (int)$l->id)->first())) {
|
|
|
|
$l->approval = new \stdClass();
|
2021-11-06 19:11:25 +09:00
|
|
|
}
|
|
|
|
$result[] = $l;
|
2021-10-01 14:26:48 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-09-30 13:33:23 +09:00
|
|
|
|
2021-10-07 13:51:53 +09:00
|
|
|
return ['status_code' => 200, 'params' => $result];
|
2021-09-30 13:33:23 +09:00
|
|
|
}
|
|
|
|
|
2021-10-01 14:26:48 +09:00
|
|
|
public function listOfNonApprovalOfChild (Request $r) {
|
|
|
|
if (!isset($r->child_id)) {
|
|
|
|
return ['status_code' => 400];
|
2021-09-30 13:33:23 +09:00
|
|
|
}
|
|
|
|
|
2021-10-01 14:26:48 +09:00
|
|
|
$result = [];
|
|
|
|
$meeting_select = ['id', 'father_id', 'title', 'text', 'memo', 'updated_at'];
|
|
|
|
$meeting_images_select = ['image'];
|
|
|
|
$father_select = ['image', 'company'];
|
|
|
|
$meeting_approvals_select = ['approval_at'];
|
|
|
|
|
|
|
|
// 取得に成功
|
2021-12-23 18:38:54 +09:00
|
|
|
if (null === ($approval = MeetingApprovals::select('meeting_id')->where('child_id', (int)$r->child_id)->whereNull('approval_at')->orderBy('updated_at', 'asc')->get())) {
|
2021-10-07 13:51:53 +09:00
|
|
|
return ['status_code' => 400];
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($approval as $a) {
|
2021-11-06 19:11:25 +09:00
|
|
|
if (null !== ($list = Meeting::select($meeting_select)->where('id', (int)$a->meeting_id)->get())) {
|
|
|
|
foreach ($list as $i => $l) {
|
|
|
|
if (null === ($fr = FatherRelation::select('id')->where('father_id', (int)$l->father_id)->where('child_id', (int)$r->child_id)->first())) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (null === ($l->father = Father::select($father_select)->where('id', (int)$l->father_id)->first())) {
|
|
|
|
$l->father = new \stdClass();
|
|
|
|
}
|
|
|
|
if (null === ($l->meeting_images = MeetingImage::select($meeting_images_select)->where('meeting_id', (int)$l->id)->get())) {
|
|
|
|
$l->meeting_images = [];
|
|
|
|
}
|
2021-11-06 23:09:48 +09:00
|
|
|
if (null === ($l->approval = MeetingApprovals::select($meeting_approvals_select)->whereNull('approval_at')->where('meeting_id', (int)$l->id)->first())) {
|
|
|
|
$l->approval = new \stdClass();
|
2021-11-06 19:11:25 +09:00
|
|
|
}
|
|
|
|
$result[] = $l;
|
2021-10-01 14:26:48 +09:00
|
|
|
}
|
|
|
|
}
|
2021-09-30 13:33:23 +09:00
|
|
|
}
|
|
|
|
|
2021-10-07 13:51:53 +09:00
|
|
|
return ['status_code' => 200, 'params' => $result];
|
2021-09-30 13:33:23 +09:00
|
|
|
}
|
|
|
|
|
2021-10-01 14:26:48 +09:00
|
|
|
public function listOfCompleteOfFather (Request $r) {
|
|
|
|
if (!isset($r->father_id)) {
|
|
|
|
return ['status_code' => 400];
|
|
|
|
}
|
|
|
|
|
|
|
|
$result = [];
|
2021-10-10 23:08:06 +09:00
|
|
|
$meeting_select = ['id', 'father_id', 'title', 'text', 'memo', 'updated_at', 'is_favorite'];
|
2021-10-01 14:26:48 +09:00
|
|
|
$meeting_approvals_select = ['child_id', 'approval_at'];
|
|
|
|
$child_select = ['image'];
|
|
|
|
|
|
|
|
// 取得に成功
|
2021-12-23 18:38:54 +09:00
|
|
|
if (null === ($list = Meeting::select($meeting_select)->where('father_id', (int)$r->father_id)->orderBy('updated_at', 'desc')->get())) {
|
2021-10-07 13:51:53 +09:00
|
|
|
return ['status_code' => 400];
|
|
|
|
}
|
2021-11-16 02:32:48 +09:00
|
|
|
|
2021-10-07 13:51:53 +09:00
|
|
|
foreach ($list as $i => $l) {
|
2021-11-16 18:02:03 +09:00
|
|
|
if (null === ($l->approvals = MeetingApprovals::select($meeting_approvals_select)->whereNotNull('approval_at')->where('meeting_id', (int)$l->id)->get())) {
|
|
|
|
continue;
|
|
|
|
}
|
2021-11-13 13:16:03 +09:00
|
|
|
|
2021-11-29 15:14:10 +09:00
|
|
|
$cnt = MeetingApprovals::select('id')->where('meeting_id', (int)$l->id)->count();
|
|
|
|
$acnt = count($l->approvals->toArray());
|
|
|
|
|
|
|
|
if ($acnt != $cnt) {
|
2021-11-16 18:02:03 +09:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-11-29 15:14:10 +09:00
|
|
|
if ($acnt == 0 && $cnt == 0) {
|
|
|
|
if (!in_array($l, $result)) {
|
|
|
|
$result[] = $l;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-16 18:02:03 +09:00
|
|
|
foreach ($l->approvals as $ii => $ll) {
|
|
|
|
if (null === ($ll->child = Child::select($child_select)->where('id', (int)$ll->child_id)->first())) {
|
|
|
|
$ll->child = new \stdClass();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!in_array($l, $result)) {
|
|
|
|
$result[] = $l;
|
2021-11-15 12:42:00 +09:00
|
|
|
}
|
2021-11-13 14:38:02 +09:00
|
|
|
}
|
2021-10-01 14:26:48 +09:00
|
|
|
}
|
2021-09-30 13:33:23 +09:00
|
|
|
|
2021-10-07 13:51:53 +09:00
|
|
|
return ['status_code' => 200, 'params' => $result];
|
2021-09-30 13:33:23 +09:00
|
|
|
}
|
|
|
|
|
2021-10-01 14:26:48 +09:00
|
|
|
public function listOfIncompleteOfFather (Request $r) {
|
|
|
|
if (!isset($r->father_id)) {
|
|
|
|
return ['status_code' => 400];
|
2021-09-30 13:33:23 +09:00
|
|
|
}
|
|
|
|
|
2021-10-01 14:26:48 +09:00
|
|
|
$result = [];
|
2021-10-10 23:08:06 +09:00
|
|
|
$meeting_select = ['id', 'father_id', 'title', 'text', 'memo', 'updated_at', 'is_favorite'];
|
2021-10-01 14:26:48 +09:00
|
|
|
$meeting_approvals_select = ['child_id', 'approval_at'];
|
|
|
|
$child_select = ['image'];
|
|
|
|
|
|
|
|
// 取得に成功
|
2021-12-23 18:38:54 +09:00
|
|
|
if (null === ($list = Meeting::select($meeting_select)->where('father_id', (int)$r->father_id)->orderBy('updated_at', 'desc')->get())) {
|
2021-10-07 13:51:53 +09:00
|
|
|
return ['status_code' => 400];
|
|
|
|
}
|
2021-10-01 14:26:48 +09:00
|
|
|
|
2021-10-07 13:51:53 +09:00
|
|
|
foreach ($list as $i => $l) {
|
2021-11-16 18:02:03 +09:00
|
|
|
if (null === ($l->approvals = MeetingApprovals::select($meeting_approvals_select)->where('meeting_id', (int)$l->id)->get())) {
|
|
|
|
continue;
|
|
|
|
}
|
2021-10-01 14:26:48 +09:00
|
|
|
|
2021-11-29 15:14:10 +09:00
|
|
|
$cnt = MeetingApprovals::select('id')->whereNotNull('approval_at')->where('meeting_id', (int)$l->id)->count();
|
2021-11-17 18:36:56 +09:00
|
|
|
$acnt = count($l->approvals);
|
|
|
|
|
|
|
|
if ($acnt != 0 && $acnt == $cnt) {
|
2021-11-16 18:02:03 +09:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($l->approvals as $ii => $ll) {
|
|
|
|
if (null === ($ll->child = Child::select($child_select)->where('id', (int)$ll->child_id)->first())) {
|
|
|
|
$ll->child = new \stdClass();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!in_array($l, $result)) {
|
|
|
|
$result[] = $l;
|
2021-11-15 12:42:00 +09:00
|
|
|
}
|
2021-11-13 14:38:02 +09:00
|
|
|
}
|
2021-09-30 13:33:23 +09:00
|
|
|
}
|
|
|
|
|
2021-10-07 13:51:53 +09:00
|
|
|
return ['status_code' => 200, 'params' => $result];
|
2021-09-30 13:33:23 +09:00
|
|
|
}
|
|
|
|
|
2021-11-04 13:28:58 +09:00
|
|
|
public function listOfFavoriteOfFather (Request $r) {
|
2021-10-01 14:26:48 +09:00
|
|
|
if (!isset($r->father_id)) {
|
|
|
|
return ['status_code' => 400];
|
|
|
|
}
|
2021-09-30 13:33:23 +09:00
|
|
|
|
2021-10-01 14:26:48 +09:00
|
|
|
$result = [];
|
|
|
|
$meeting_select = ['id', 'father_id', 'title', 'text', 'memo', 'updated_at', 'is_favorite'];
|
|
|
|
$meeting_approvals_select = ['child_id', 'approval_at'];
|
|
|
|
$child_select = ['image'];
|
2021-09-30 13:33:23 +09:00
|
|
|
|
2021-10-01 14:26:48 +09:00
|
|
|
// 取得に成功
|
2021-12-23 18:38:54 +09:00
|
|
|
if (null === ($list = Meeting::select($meeting_select)->where('father_id', (int)$r->father_id)->where('is_favorite', 1)->orderBy('updated_at', 'desc')->get())) {
|
2021-11-16 18:02:03 +09:00
|
|
|
return ['status_code' => 400];
|
2021-10-07 13:51:53 +09:00
|
|
|
}
|
2021-09-30 13:33:23 +09:00
|
|
|
|
2021-10-07 13:51:53 +09:00
|
|
|
foreach ($list as $i => $l) {
|
2021-11-18 01:11:49 +09:00
|
|
|
if (null === ($l->approvals = MeetingApprovals::select($meeting_approvals_select)->where('meeting_id', (int)$l->id)->get())) {
|
2021-11-16 18:02:03 +09:00
|
|
|
continue;
|
2021-10-01 14:26:48 +09:00
|
|
|
}
|
2021-09-30 13:33:23 +09:00
|
|
|
|
2021-11-16 18:02:03 +09:00
|
|
|
foreach ($l->approvals as $ii => $ll) {
|
|
|
|
if (null === ($ll->child = Child::select($child_select)->where('id', (int)$ll->child_id)->first())) {
|
|
|
|
$ll->child = new \stdClass();
|
|
|
|
}
|
2021-11-16 19:28:11 +09:00
|
|
|
}
|
2021-11-16 18:02:03 +09:00
|
|
|
|
2021-11-16 19:28:11 +09:00
|
|
|
if (!in_array($l, $result)) {
|
|
|
|
$result[] = $l;
|
2021-11-16 18:02:03 +09:00
|
|
|
}
|
2021-09-30 13:33:23 +09:00
|
|
|
}
|
|
|
|
|
2021-10-07 13:51:53 +09:00
|
|
|
return ['status_code' => 200, 'params' => $result];
|
2021-09-30 13:33:23 +09:00
|
|
|
}
|
|
|
|
|
2021-11-04 13:28:58 +09:00
|
|
|
public function listOfNonFavoriteOfFather (Request $r) {
|
2021-10-01 14:26:48 +09:00
|
|
|
if (!isset($r->father_id)) {
|
|
|
|
return ['status_code' => 400];
|
|
|
|
}
|
2021-09-30 13:33:23 +09:00
|
|
|
|
2021-10-01 14:26:48 +09:00
|
|
|
$result = [];
|
|
|
|
$meeting_select = ['id', 'father_id', 'title', 'text', 'memo', 'updated_at', 'is_favorite'];
|
|
|
|
$meeting_approvals_select = ['child_id', 'approval_at'];
|
|
|
|
$child_select = ['image'];
|
2021-09-30 13:33:23 +09:00
|
|
|
|
2021-10-01 14:26:48 +09:00
|
|
|
// 取得に成功
|
2021-12-13 16:46:00 +09:00
|
|
|
if (null === ($list = Meeting::select($meeting_select)->where('father_id', (int)$r->father_id)->where('is_favorite', 0)->orderBy('created_at', 'desc')->get())) {
|
2021-11-16 18:02:03 +09:00
|
|
|
return ['status_code' => 400];
|
2021-10-07 13:51:53 +09:00
|
|
|
}
|
2021-09-30 13:33:23 +09:00
|
|
|
|
2021-10-07 13:51:53 +09:00
|
|
|
foreach ($list as $i => $l) {
|
2021-11-18 01:11:49 +09:00
|
|
|
if (null === ($l->approvals = MeetingApprovals::select($meeting_approvals_select)->where('meeting_id', (int)$l->id)->get())) {
|
2021-11-16 18:02:03 +09:00
|
|
|
continue;
|
2021-10-01 14:26:48 +09:00
|
|
|
}
|
2021-09-30 13:33:23 +09:00
|
|
|
|
2021-11-16 18:02:03 +09:00
|
|
|
foreach ($l->approvals as $ii => $ll) {
|
|
|
|
if (null === ($ll->child = Child::select($child_select)->where('id', (int)$ll->child_id)->first())) {
|
|
|
|
$ll->child = new \stdClass();
|
|
|
|
}
|
2021-11-16 19:28:11 +09:00
|
|
|
}
|
2021-11-16 18:02:03 +09:00
|
|
|
|
2021-11-16 19:28:11 +09:00
|
|
|
if (!in_array($l, $result)) {
|
|
|
|
$result[] = $l;
|
2021-11-16 18:02:03 +09:00
|
|
|
}
|
2021-09-30 13:33:23 +09:00
|
|
|
}
|
|
|
|
|
2021-10-07 13:51:53 +09:00
|
|
|
return ['status_code' => 200, 'params' => $result];
|
2021-09-30 13:33:23 +09:00
|
|
|
}
|
|
|
|
|
2021-10-01 14:26:48 +09:00
|
|
|
public function searchOfApprovalOfChild (Request $r) {
|
|
|
|
if (!isset($r->child_id) || !isset($r->keyword)) {
|
|
|
|
return ['status_code' => 400];
|
|
|
|
}
|
2021-09-30 13:33:23 +09:00
|
|
|
|
2021-10-01 14:26:48 +09:00
|
|
|
$result = [];
|
|
|
|
$meeting_select = ['id', 'father_id', 'title', 'text', 'memo', 'updated_at'];
|
|
|
|
$father_select = ['image', 'company'];
|
2021-11-08 21:53:56 +09:00
|
|
|
$meeting_approvals_select = ['approval_at'];
|
2021-09-30 14:32:15 +09:00
|
|
|
|
2021-10-01 14:26:48 +09:00
|
|
|
// 取得に成功
|
2021-12-23 18:38:54 +09:00
|
|
|
if (null === ($list = Meeting::select($meeting_select)->where('title', 'LIKE', '%'.$r->keyword.'%')->orWhere('text', 'LIKE', '%'.$r->keyword.'%')->orderBy('created_at', 'desc')->get())) {
|
2021-11-03 20:46:48 +09:00
|
|
|
$list = [];
|
2021-10-07 13:51:53 +09:00
|
|
|
}
|
2021-09-30 14:32:15 +09:00
|
|
|
|
2021-10-07 13:51:53 +09:00
|
|
|
foreach ($list as $i => $l) {
|
2021-12-25 14:21:32 +09:00
|
|
|
if (null === ($rel = FatherRelation::select('id')->where('father_id', (int)$l->father_id)->where('child_id', (int)$r->child_id)->first())) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ($rel->child_id != (int)$rel->child_id) {
|
2021-11-08 19:41:06 +09:00
|
|
|
continue;
|
|
|
|
}
|
2021-11-08 21:02:25 +09:00
|
|
|
if (null === ($ma = MeetingApprovals::select('id')->where('child_id', (int)$r->child_id)->where('meeting_id', (int)$l->id)->whereNotNull('approval_at')->first())) {
|
2021-11-08 18:36:53 +09:00
|
|
|
continue;
|
|
|
|
}
|
2021-11-06 18:24:18 +09:00
|
|
|
if (null === ($l->father = Father::select($father_select)->where('id', (int)$l->father_id)->first())) {
|
|
|
|
$l->father = new \stdClass();
|
2021-10-07 13:51:53 +09:00
|
|
|
}
|
2021-11-06 23:17:15 +09:00
|
|
|
if (null === ($l->approval = MeetingApprovals::select($meeting_approvals_select)->where('child_id', (int)$r->child_id)->whereNotNull('approval_at')->first())) {
|
2021-11-08 19:41:06 +09:00
|
|
|
$l->approval = new \stdClass();
|
2021-10-07 13:51:53 +09:00
|
|
|
}
|
2021-11-05 17:07:47 +09:00
|
|
|
$result[] = $l;
|
2021-10-01 14:26:48 +09:00
|
|
|
}
|
2021-09-30 14:32:15 +09:00
|
|
|
|
2021-10-07 13:51:53 +09:00
|
|
|
return ['status_code' => 200, 'params' => $result];
|
2021-09-30 14:32:15 +09:00
|
|
|
}
|
|
|
|
|
2021-10-01 14:26:48 +09:00
|
|
|
public function searchOfNonApprovalOfChild (Request $r) {
|
|
|
|
if (!isset($r->child_id) || !isset($r->keyword)) {
|
|
|
|
return ['status_code' => 400];
|
|
|
|
}
|
2021-09-30 14:32:15 +09:00
|
|
|
|
2021-10-01 14:26:48 +09:00
|
|
|
$result = [];
|
|
|
|
$meeting_select = ['id', 'father_id', 'title', 'text', 'memo', 'updated_at'];
|
|
|
|
$father_select = ['image', 'company'];
|
2021-11-08 21:53:56 +09:00
|
|
|
$meeting_approvals_select = ['approval_at'];
|
2021-09-30 14:32:15 +09:00
|
|
|
|
2021-10-01 14:26:48 +09:00
|
|
|
// 取得に成功
|
2021-12-23 18:38:54 +09:00
|
|
|
if (null === ($list = Meeting::select($meeting_select)->where('title', 'LIKE', '%'.$r->keyword.'%')->orWhere('text', 'LIKE', '%'.$r->keyword.'%')->orderBy('created_at', 'desc')->get())) {
|
2021-11-03 20:46:48 +09:00
|
|
|
$list = [];
|
2021-10-07 13:51:53 +09:00
|
|
|
}
|
2021-09-30 14:32:15 +09:00
|
|
|
|
2021-10-07 13:51:53 +09:00
|
|
|
foreach ($list as $i => $l) {
|
2021-12-25 14:21:32 +09:00
|
|
|
if (null === ($rel = FatherRelation::select('id')->where('father_id', (int)$l->father_id)->where('child_id', (int)$r->child_id)->first())) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ($rel->child_id != (int)$rel->child_id) {
|
2021-11-08 19:41:06 +09:00
|
|
|
continue;
|
|
|
|
}
|
2021-11-08 21:02:25 +09:00
|
|
|
if (null === ($ma = MeetingApprovals::select('id')->where('child_id', (int)$r->child_id)->where('meeting_id', (int)$l->id)->whereNull('approval_at')->first())) {
|
2021-11-08 18:36:53 +09:00
|
|
|
continue;
|
|
|
|
}
|
2021-11-06 18:24:18 +09:00
|
|
|
if (null === ($l->father = Father::select($father_select)->where('id', (int)$l->father_id)->first())) {
|
|
|
|
$l->father = new \stdClass();
|
2021-10-07 13:51:53 +09:00
|
|
|
}
|
2021-11-06 23:17:15 +09:00
|
|
|
if (null === ($l->approval = MeetingApprovals::select($meeting_approvals_select)->where('child_id', (int)$r->child_id)->whereNull('approval_at')->first())) {
|
|
|
|
$l->approval = new \stdClass();
|
2021-10-07 13:51:53 +09:00
|
|
|
}
|
2021-11-05 17:07:47 +09:00
|
|
|
$result[] = $l;
|
2021-10-01 14:26:48 +09:00
|
|
|
}
|
2021-09-30 14:32:15 +09:00
|
|
|
|
2021-10-07 13:51:53 +09:00
|
|
|
return ['status_code' => 200, 'params' => $result];
|
2021-09-30 14:32:15 +09:00
|
|
|
}
|
|
|
|
|
2021-10-01 14:26:48 +09:00
|
|
|
public function searchOfCompleteofFather (Request $r) {
|
|
|
|
if (!isset($r->father_id) || !isset($r->keyword)) {
|
|
|
|
return ['status_code' => 400];
|
|
|
|
}
|
2021-09-30 13:33:23 +09:00
|
|
|
|
2021-10-01 14:26:48 +09:00
|
|
|
$result = [];
|
2021-11-16 16:05:00 +09:00
|
|
|
$meeting_select = ['id', 'father_id', 'title', 'text', 'memo', 'updated_at', 'is_favorite'];
|
2021-10-01 14:26:48 +09:00
|
|
|
$meeting_approvals_select = ['approval_at', 'child_id'];
|
|
|
|
$child_select = ['image'];
|
|
|
|
|
|
|
|
// 取得に成功
|
2021-12-25 14:21:32 +09:00
|
|
|
if (null === ($list = Meeting::select($meeting_select)->where('title', 'LIKE', '%'.$r->keyword.'%')->orWhere('text', 'LIKE', '%'.$r->keyword.'%')->orderBy('updated_at', 'desc')->get())) {
|
|
|
|
return ['status_code' => 200, 'params' => $result];
|
2021-10-07 13:51:53 +09:00
|
|
|
}
|
2021-10-01 14:26:48 +09:00
|
|
|
|
2021-10-07 13:51:53 +09:00
|
|
|
foreach ($list as $i => $l) {
|
2021-12-25 14:21:32 +09:00
|
|
|
if ($l->father_id != (int)$r->father_id) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-11-16 18:02:03 +09:00
|
|
|
if (null === ($l->approvals = MeetingApprovals::select($meeting_approvals_select)->whereNotNull('approval_at')->where('meeting_id', (int)$l->id)->get())) {
|
|
|
|
continue;
|
|
|
|
}
|
2021-11-16 16:05:00 +09:00
|
|
|
|
2021-11-29 15:14:10 +09:00
|
|
|
$cnt = MeetingApprovals::select('id')->where('meeting_id', (int)$l->id)->count();
|
|
|
|
$acnt = count($l->approvals->toArray());
|
|
|
|
|
|
|
|
if ($acnt != $cnt) {
|
2021-11-16 18:02:03 +09:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-11-29 15:14:10 +09:00
|
|
|
if ($acnt == 0 && $cnt == 0) {
|
|
|
|
if (!in_array($l, $result)) {
|
|
|
|
$result[] = $l;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-16 18:02:03 +09:00
|
|
|
foreach ($l->approvals as $ii => $ll) {
|
|
|
|
if (null === ($ll->child = Child::select($child_select)->where('id', (int)$ll->child_id)->first())) {
|
|
|
|
$ll->child = new \stdClass();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!in_array($l, $result)) {
|
|
|
|
$result[] = $l;
|
2021-10-07 13:51:53 +09:00
|
|
|
}
|
|
|
|
}
|
2021-09-30 14:32:15 +09:00
|
|
|
}
|
|
|
|
|
2021-10-07 13:51:53 +09:00
|
|
|
return ['status_code' => 200, 'params' => $result];
|
2021-09-30 14:32:15 +09:00
|
|
|
}
|
|
|
|
|
2021-10-01 14:26:48 +09:00
|
|
|
public function searchOfIncompleteofFather (Request $r) {
|
|
|
|
if (!isset($r->father_id) || !isset($r->keyword)) {
|
|
|
|
return ['status_code' => 400];
|
|
|
|
}
|
2021-09-30 14:32:15 +09:00
|
|
|
|
2021-10-01 14:26:48 +09:00
|
|
|
$result = [];
|
2021-10-08 17:50:18 +09:00
|
|
|
$meeting_select = ['id', 'father_id', 'title', 'text', 'memo', 'updated_at', 'is_favorite'];
|
2021-10-01 14:26:48 +09:00
|
|
|
$meeting_approvals_select = ['approval_at', 'child_id'];
|
|
|
|
$child_select = ['image'];
|
|
|
|
|
|
|
|
// 取得に成功
|
2021-12-25 14:21:32 +09:00
|
|
|
if (null === ($list = Meeting::select($meeting_select)->where('title', 'LIKE', '%'.$r->keyword.'%')->orWhere('text', 'LIKE', '%'.$r->keyword.'%')->orderBy('updated_at', 'desc')->get())) {
|
|
|
|
return ['status_code' => 200, 'params' => $result];
|
2021-10-07 13:51:53 +09:00
|
|
|
}
|
2021-10-01 14:26:48 +09:00
|
|
|
|
2021-10-07 13:51:53 +09:00
|
|
|
foreach ($list as $i => $l) {
|
2021-12-25 14:21:32 +09:00
|
|
|
if ($l->father_id != (int)$r->father_id) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-11-16 18:02:03 +09:00
|
|
|
if (null === ($l->approvals = MeetingApprovals::select($meeting_approvals_select)->where('meeting_id', (int)$l->id)->get())) {
|
|
|
|
continue;
|
|
|
|
}
|
2021-11-16 16:05:00 +09:00
|
|
|
|
2021-11-29 15:14:10 +09:00
|
|
|
$cnt = MeetingApprovals::select('id')->whereNotNull('approval_at')->where('meeting_id', (int)$l->id)->count();
|
2021-11-17 19:42:21 +09:00
|
|
|
$acnt = count($l->approvals);
|
|
|
|
|
|
|
|
if ($acnt != 0 && $acnt == $cnt) {
|
2021-11-16 18:02:03 +09:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($l->approvals as $ii => $ll) {
|
|
|
|
if (null === ($ll->child = Child::select($child_select)->where('id', (int)$ll->child_id)->first())) {
|
|
|
|
$ll->child = new \stdClass();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!in_array($l, $result)) {
|
|
|
|
$result[] = $l;
|
2021-10-07 13:51:53 +09:00
|
|
|
}
|
|
|
|
}
|
2021-09-30 14:32:15 +09:00
|
|
|
}
|
|
|
|
|
2021-10-07 13:51:53 +09:00
|
|
|
return ['status_code' => 200, 'params' => $result];
|
2021-09-30 14:32:15 +09:00
|
|
|
}
|
|
|
|
|
2021-10-01 14:26:48 +09:00
|
|
|
public function detail (Request $r, $meeting_id) {
|
2021-10-15 10:37:47 +09:00
|
|
|
if (!isset($meeting_id)) {
|
2021-10-01 14:26:48 +09:00
|
|
|
return ['status_code' => 400];
|
|
|
|
}
|
2021-09-30 14:32:15 +09:00
|
|
|
|
2021-10-01 14:26:48 +09:00
|
|
|
$result = [];
|
2021-10-08 17:50:18 +09:00
|
|
|
$meeting_select = ['id', 'father_id', 'title', 'text', 'memo', 'pdf', 'updated_at', 'is_favorite'];
|
2021-10-31 22:56:36 +09:00
|
|
|
$meeting_images_select = ['id', 'image'];
|
2021-10-01 14:26:48 +09:00
|
|
|
$meeting_approvals_select = ['approval_at', 'child_id'];
|
2021-11-05 18:51:10 +09:00
|
|
|
$father_select = ['image', 'company', 'tel'];
|
|
|
|
$child_select = ['id', 'image', 'last_name', 'first_name', 'tel'];
|
2021-11-17 22:31:18 +09:00
|
|
|
$all_child_select = ['id', 'last_name', 'first_name'];
|
2021-10-01 14:26:48 +09:00
|
|
|
|
|
|
|
// 取得に成功
|
2021-10-31 13:38:12 +09:00
|
|
|
if (null === ($result = Meeting::select($meeting_select)->where('id', (int)$meeting_id)->first())) {
|
2021-10-07 13:51:53 +09:00
|
|
|
return ['status_code' => 400];
|
|
|
|
}
|
2021-10-01 14:26:48 +09:00
|
|
|
|
2021-11-29 16:10:40 +09:00
|
|
|
// 親画面から他の親としてアクセスすれば、404となります。
|
|
|
|
$err = 'アクセスできません。';
|
|
|
|
if (request()->route()->action['as'] == 'mdp') {
|
|
|
|
abort_if(null === session()->get('fathers') || (int)session()->get('fathers')['id'] != $result->father_id, 404, $err);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 同じく子画面から他の親の詳細ページをアクセスすれば、404となります。
|
|
|
|
if (request()->route()->action['as'] == 'mdc') {
|
|
|
|
abort_if(null === session()->get('children') || null === ($rel = FatherRelation::where('father_id', $result->father_id)->where('child_id', (int)session()->get('children')['id'])->first()), 404, $err);
|
|
|
|
}
|
|
|
|
|
2021-10-31 01:42:13 +09:00
|
|
|
if (null === ($result->meeting_image = MeetingImage::select($meeting_images_select)->where('meeting_id', (int)$result->id)->get())) {
|
2021-11-03 02:30:46 +09:00
|
|
|
$result->meeting_image = [];
|
2021-10-31 01:42:13 +09:00
|
|
|
}
|
2021-11-10 15:59:55 +09:00
|
|
|
|
|
|
|
if (request()->route()->action['as'] != 'mdc') {
|
2021-11-16 17:13:18 +09:00
|
|
|
if (null === ($result->approval = MeetingApprovals::select($meeting_approvals_select)->where('meeting_id', (int)$result->id)->get())) {
|
|
|
|
$result->approval = [];
|
2021-11-10 15:59:55 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2021-11-17 19:19:21 +09:00
|
|
|
if (null === ($result->approval = MeetingApprovals::select($meeting_approvals_select)->where('meeting_id', (int)$result->id)->where('child_id', (int)session()->get('children')['id'])->first())) {
|
2021-11-10 15:59:55 +09:00
|
|
|
$result->approval = new \stdClass();
|
|
|
|
}
|
2021-11-03 02:30:46 +09:00
|
|
|
}
|
|
|
|
|
2021-11-05 19:34:36 +09:00
|
|
|
if (request()->route()->action['as'] == 'mdc') {
|
2021-11-05 18:51:10 +09:00
|
|
|
if (null === ($result->father = Father::select($father_select)->where('id', (int)$result->father_id)->first())) {
|
|
|
|
$result->father = new \stdClass();
|
|
|
|
}
|
|
|
|
}
|
2022-01-06 14:01:49 +09:00
|
|
|
else $result->father = Father::select('company')->where('id', (int)$result->father_id)->first();
|
2021-11-05 18:51:10 +09:00
|
|
|
|
2021-11-05 19:34:36 +09:00
|
|
|
if (request()->route()->action['as'] != 'mdc') {
|
|
|
|
$result->children = [];
|
2021-11-16 01:38:16 +09:00
|
|
|
$rec = [];
|
2021-11-05 19:34:36 +09:00
|
|
|
|
2021-11-16 01:38:16 +09:00
|
|
|
if (null !== ($rel = FatherRelation::select('child_id')->where('father_id', (int)$result->father_id)->get())) {
|
|
|
|
foreach ($rel as $i => $re) {
|
|
|
|
if (null !== ($rech = Child::select($all_child_select)->where('id', $re->child_id)->first())) {
|
|
|
|
if (!in_array($rech, $rec)) {
|
|
|
|
$rec[$i] = $rech;
|
|
|
|
}
|
|
|
|
}
|
2021-11-05 19:34:36 +09:00
|
|
|
}
|
2021-11-16 01:38:16 +09:00
|
|
|
|
|
|
|
$result->children = $rec;
|
2021-11-03 02:30:46 +09:00
|
|
|
}
|
2021-10-01 14:26:48 +09:00
|
|
|
|
2021-11-16 17:13:18 +09:00
|
|
|
foreach ($result->approval as $i => $a) {
|
|
|
|
if (null === ($result->approval[$i]['child'] = Child::select($child_select)->where('id', (int)$a->child_id)->first())) {
|
|
|
|
$result->approval[$i]['child'] = new \stdClass();
|
2021-11-05 18:51:10 +09:00
|
|
|
}
|
2021-10-07 13:51:53 +09:00
|
|
|
}
|
2021-09-30 14:32:15 +09:00
|
|
|
}
|
|
|
|
|
2021-10-07 13:51:53 +09:00
|
|
|
return ['status_code' => 200, 'params' => $result];
|
2021-09-30 14:32:15 +09:00
|
|
|
}
|
|
|
|
|
2021-10-15 10:37:47 +09:00
|
|
|
public function update (Request $r, $meeting_id) {
|
|
|
|
if (!isset($meeting_id)) {
|
|
|
|
return ['status_code' => 400, 'error_messages' => ['ミーティングの登録に失敗しました。']];
|
|
|
|
}
|
|
|
|
|
2021-11-28 17:10:40 +09:00
|
|
|
if (count(Storage::disk('private')->files('/')) >= 9999) {
|
|
|
|
Log::critical('ストレージの限界を超えています。9999個ファイルまで保存可能ですので、不要なファイルを削除して下さい。');
|
2021-12-14 18:35:09 +09:00
|
|
|
return ['status_code' => 400, 'error_messages' => ['ミーティングの更新に失敗しました。']];
|
2021-11-26 16:15:22 +09:00
|
|
|
}
|
|
|
|
|
2021-11-30 12:45:32 +09:00
|
|
|
// ファイルサイズは50MiB以内
|
|
|
|
Validator::extend('pdf_size', function ($attribute, $value, $params, $validator) {
|
|
|
|
return $this->pdfsize($value);
|
|
|
|
});
|
|
|
|
|
2021-11-01 01:08:02 +09:00
|
|
|
// ミームタイプ
|
2021-11-22 21:48:48 +09:00
|
|
|
Validator::extend('pdf_meme', function ($attribute, $value, $params, $validator) {
|
|
|
|
return $this->pdfmeme($value);
|
|
|
|
});
|
2021-11-01 01:08:02 +09:00
|
|
|
|
2021-11-16 21:31:26 +09:00
|
|
|
$validate = Validator::make($r->all(), [
|
|
|
|
'title' => 'required|max:100',
|
|
|
|
'text' => 'required|max:2000',
|
|
|
|
'memo' => 'nullable|max:2000',
|
2021-11-30 15:14:30 +09:00
|
|
|
'pdf' => 'pdf_size|pdf_meme',
|
2021-11-16 21:31:26 +09:00
|
|
|
]);
|
|
|
|
|
2021-10-15 10:37:47 +09:00
|
|
|
if ($validate->fails()) {
|
|
|
|
return ['status_code' => 422, 'error_messages' => $validate->errors()];
|
2021-10-01 14:26:48 +09:00
|
|
|
}
|
2021-09-30 13:33:23 +09:00
|
|
|
|
2021-11-28 17:21:55 +09:00
|
|
|
if ($r->pdf == 'null') {
|
|
|
|
$r->pdf = null;
|
|
|
|
}
|
2021-11-23 00:47:15 +09:00
|
|
|
if ($r->pdf == '/assets/default/default.pdf') {
|
|
|
|
$r->pdf = null;
|
|
|
|
}
|
|
|
|
|
2021-10-15 10:37:47 +09:00
|
|
|
$update = [
|
|
|
|
'title' => $r->title,
|
|
|
|
'text' => $r->text,
|
|
|
|
];
|
|
|
|
|
|
|
|
if (isset($r->memo)) $update['memo'] = $r->memo;
|
2021-11-16 02:15:10 +09:00
|
|
|
else if (is_null($r->memo)) $update['memo'] = '';
|
2021-10-15 10:37:47 +09:00
|
|
|
|
2021-11-23 11:36:07 +09:00
|
|
|
$filename = '';
|
|
|
|
|
2021-10-15 10:37:47 +09:00
|
|
|
try {
|
2021-11-01 21:26:37 +09:00
|
|
|
// リクエストでPDFがある場合
|
2021-11-23 00:47:15 +09:00
|
|
|
if (isset($r->pdf) && !is_null($r->pdf)) {
|
2021-11-30 13:34:14 +09:00
|
|
|
$filename = $this->uuidv4().'.pdf';
|
2021-11-01 01:08:02 +09:00
|
|
|
|
2021-11-01 21:26:37 +09:00
|
|
|
// DBにミーティングがある場合
|
2021-11-01 15:18:40 +09:00
|
|
|
if ($chk = Meeting::select('pdf')->where('id', (int)$meeting_id)->first()) {
|
2021-11-01 21:26:37 +09:00
|
|
|
// base64の場合(ファイルパスだったら、スキップ)
|
2021-11-26 14:41:19 +09:00
|
|
|
if (!preg_match('/\/files\/(.*).pdf/', $r->pdf)) {
|
2021-11-01 21:26:37 +09:00
|
|
|
// もう存在しているPDFのファイル名からパスを外します。
|
2021-11-26 14:41:19 +09:00
|
|
|
$opdf = str_replace('/files/', '', $chk->pdf);
|
2021-11-01 21:26:37 +09:00
|
|
|
|
|
|
|
// PDFのbase64をGETします。
|
|
|
|
$pdf = base64_decode(substr($r->pdf, strpos($r->pdf, ',') + 1));
|
|
|
|
|
|
|
|
// 既にPDFが存在する場合(なければ、スキップ)
|
2021-11-26 14:41:19 +09:00
|
|
|
if (Storage::disk('private')->exists($opdf)) {
|
2021-11-01 23:17:07 +09:00
|
|
|
// 既に存在しているPDFとアップロードしているPDFを比べてみます。異なる場合、存在しているPDFを削除します。
|
2021-11-26 14:41:19 +09:00
|
|
|
if (strcmp(Storage::disk('private')->get($opdf), $pdf) !== 0) {
|
|
|
|
Storage::disk('private')->delete($opdf);
|
2021-11-01 21:26:37 +09:00
|
|
|
}
|
2021-11-01 01:31:14 +09:00
|
|
|
}
|
2021-11-01 23:15:48 +09:00
|
|
|
|
2021-11-26 14:41:19 +09:00
|
|
|
$update['pdf'] = '/files/'.$filename;
|
|
|
|
Storage::disk('private')->put($filename, $pdf);
|
2021-11-01 01:08:02 +09:00
|
|
|
}
|
|
|
|
}
|
2021-11-01 21:26:37 +09:00
|
|
|
// なければ、そのままストレージに保存します。
|
2021-11-01 16:06:39 +09:00
|
|
|
else {
|
2021-11-26 14:41:19 +09:00
|
|
|
$update['pdf'] = '/files/'.$filename;
|
|
|
|
Storage::disk('private')->put($filename, $pdf);
|
2021-11-01 16:06:39 +09:00
|
|
|
}
|
2021-10-31 23:50:54 +09:00
|
|
|
}
|
|
|
|
|
2021-11-01 21:26:37 +09:00
|
|
|
// データベースに保存します。
|
2021-10-31 00:50:35 +09:00
|
|
|
Meeting::where('id', (int)$meeting_id)->update($update);
|
2021-10-15 10:37:47 +09:00
|
|
|
} catch (\Throwable $e) {
|
|
|
|
Log::critical($e->getMessage());
|
2021-11-23 11:36:07 +09:00
|
|
|
if (isset($r->pdf) && !is_null($r->pdf)) {
|
2021-11-26 14:41:19 +09:00
|
|
|
Storage::disk('private')->delete($filename);
|
2021-11-23 11:36:07 +09:00
|
|
|
}
|
2021-10-15 10:37:47 +09:00
|
|
|
return ['status_code' => 400];
|
|
|
|
}
|
|
|
|
|
|
|
|
return ['status_code' => 200];
|
2021-10-01 14:26:48 +09:00
|
|
|
}
|
2021-09-30 13:33:23 +09:00
|
|
|
|
2021-10-01 14:26:48 +09:00
|
|
|
public function delete ($meeting_id) {
|
2021-11-30 15:14:30 +09:00
|
|
|
$delimg = false;
|
|
|
|
if (!isset($meeting_id)) {
|
|
|
|
return ['status_code' => 400];
|
|
|
|
}
|
|
|
|
|
2021-11-30 17:05:54 +09:00
|
|
|
if (null === (Meeting::select('id')->where('id', (int)$meeting_id)->get())) {
|
2021-11-30 15:14:30 +09:00
|
|
|
return ['status_code' => 400];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (null !== ($img = MeetingImage::select('image')->where('meeting_id', (int)$meeting_id)->get())) {
|
|
|
|
$delimg = true;
|
|
|
|
}
|
|
|
|
|
2021-10-07 13:51:53 +09:00
|
|
|
try {
|
2021-11-30 17:05:54 +09:00
|
|
|
// DBに入ります。
|
|
|
|
DB::beginTransaction();
|
|
|
|
|
|
|
|
$meeting = Meeting::find((int)$meeting_id);
|
|
|
|
$pdf = $meeting->pdf;
|
|
|
|
$meeting->delete();
|
|
|
|
|
|
|
|
if (!is_null($img)) {
|
|
|
|
$pdf = str_replace('/files/', '', $pdf);
|
|
|
|
if (!Storage::disk('private')->exists($pdf)) {
|
|
|
|
Log::warning($pdf.'というパスは不正です。');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Storage::disk('private')->delete($pdf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Storage::disk('private')->delete($pdf);
|
2021-11-30 15:14:30 +09:00
|
|
|
if ($delimg) {
|
|
|
|
foreach ($img as $m) {
|
2021-11-30 17:05:54 +09:00
|
|
|
$image = str_replace('/files/', '', $m->image);
|
|
|
|
if (!Storage::disk('private')->exists($image)) {
|
|
|
|
Log::warning($image.'というパスは不正です。');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Storage::disk('private')->delete($image);
|
|
|
|
}
|
2021-11-30 15:14:30 +09:00
|
|
|
}
|
|
|
|
}
|
2021-11-30 17:05:54 +09:00
|
|
|
|
|
|
|
DB::commit();
|
2021-10-07 13:51:53 +09:00
|
|
|
} catch (\Throwable $e) {
|
|
|
|
Log::critical($e->getMessage());
|
2021-11-30 17:05:54 +09:00
|
|
|
DB::rollback();
|
2021-10-07 13:51:53 +09:00
|
|
|
return ['status_code' => 400];
|
2021-10-01 14:26:48 +09:00
|
|
|
}
|
2021-09-30 13:33:23 +09:00
|
|
|
|
2021-10-07 13:51:53 +09:00
|
|
|
return ['status_code' => 200];
|
2021-10-01 14:26:48 +09:00
|
|
|
}
|
2021-12-13 22:07:15 +09:00
|
|
|
|
|
|
|
public function updateMemo (Request $r) {
|
|
|
|
if (!isset($r->meeting_id)) {
|
2021-12-18 12:40:12 +09:00
|
|
|
return ['status_code' => 400, 'error_messages' => ['メモの更新に失敗しました。']];
|
2021-12-13 22:07:15 +09:00
|
|
|
}
|
|
|
|
|
2021-12-18 12:40:12 +09:00
|
|
|
$validate = Validator::make($r->all(), ['memo' => 'required|max:2000']);
|
2021-12-13 22:07:15 +09:00
|
|
|
|
|
|
|
if ($validate->fails()) {
|
|
|
|
return ['status_code' => 422, 'error_messages' => $validate->errors()];
|
|
|
|
}
|
|
|
|
|
|
|
|
$update = ['memo' => $r->memo];
|
|
|
|
|
|
|
|
try {
|
|
|
|
// データベースに保存します。
|
|
|
|
Meeting::where('id', (int)$r->meeting_id)->update($update);
|
|
|
|
} catch (\Throwable $e) {
|
|
|
|
Log::critical($e->getMessage());
|
|
|
|
return ['status_code' => 400, 'error_messages' => 'メモの更新に失敗しました。'];
|
|
|
|
}
|
|
|
|
|
|
|
|
return ['status_code' => 200, 'success_messages' => 'メモを更新しました。'];
|
|
|
|
}
|
2021-09-30 13:33:23 +09:00
|
|
|
}
|