Skip to content

Commit 38f9bf9

Browse files
authored
Merge pull request #2162 from opensource-workshop/revise-report-submission
[課題管理]学生がレポート提出内容の修正を行えるようにしました
2 parents 71e6897 + 6ee1378 commit 38f9bf9

File tree

7 files changed

+207
-35
lines changed

7 files changed

+207
-35
lines changed

app/Enums/LearningtaskUseFunction.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ final class LearningtaskUseFunction extends EnumsBase
3232
const use_report_mail = 'use_'.self::report.'_mail';
3333
const use_report_end = 'use_'.self::report.'_end';
3434
const report_end_at = 'report_end_at';
35+
const use_report_revising = 'use_'.self::report.'_revising';
3536
// [利用する評価機能]
3637
const use_report_evaluate_file = 'use_'.self::report.'_evaluate_file';
3738
const use_report_evaluate_comment = 'use_'.self::report.'_evaluate_comment';
@@ -98,6 +99,7 @@ final class LearningtaskUseFunction extends EnumsBase
9899
self::use_report_mail => 'メール送信(教員宛)',
99100
self::use_report_end => 'レポート提出終了日時で制御する',
100101
self::report_end_at => 'レポート提出終了日時',
102+
self::use_report_revising => '提出修正',
101103
// 利用する評価機能
102104
self::use_report_evaluate_file => 'アップロード',
103105
self::use_report_evaluate_comment => 'コメント入力',

app/Plugins/User/Learningtasks/LearningtasksPlugin.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,6 +1124,7 @@ public function show($request, $page_id, $frame_id, $post_id)
11241124
'examination_files' => $examination_files,
11251125
'examinations' => $examinations,
11261126
'tool' => $tool,
1127+
'deleted_submissions' => $tool->fetchDeletedSubmissions(),
11271128
]);
11281129
}
11291130

@@ -3033,6 +3034,11 @@ private function changeStatus($request, $page_id, $frame_id, $post_id, $task_sta
30333034
$this->sendMailLocal($post, $task_status, $tool, $student_user_id);
30343035
}
30353036

3037+
// 評価前の再提出は、直前の提出の進捗ステータスを削除することで、提出の修正とする。
3038+
if ($task_status == 1 && $tool->shouldReviseReportSubmission($post->id)) {
3039+
$tool->prepareRevisingReportSubmission();
3040+
}
3041+
30363042
// ユーザーの進捗ステータス保存
30373043
LearningtasksUsersStatuses::create([
30383044
'post_id' => $post_id,

app/Plugins/User/Learningtasks/LearningtasksTool.php

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Illuminate\Support\Facades\Log;
88

99
use App\Enums\DayOfWeek;
10+
use App\Enums\LearningtaskUseFunction;
1011
use App\Models\Common\PageRole;
1112
use App\Models\Common\GroupUser;
1213
use App\Models\Common\Page;
@@ -924,9 +925,12 @@ private function canReportUploadImpl($post_id)
924925
if ($report_status->task_status == 2 && ($report_status->grade == 'A' || $report_status->grade == 'B' || $report_status->grade == 'C')) {
925926
return array(false, 'すでに合格しているため、提出不要です。');
926927
}
927-
// 提出済みがくればfalse、D 評価がくれば再提出でtrue
928-
if ($report_status->task_status == 1) {
928+
// D 評価がくれば再提出でtrue
929+
// 提出済みは締め切り前であれば修正可能
930+
if ($report_status->task_status == 1 && !$this->checkFunction(LearningtaskUseFunction::use_report_revising)) {
929931
$can_report_upload = array(false, '提出済みのため、現在は提出できません。');
932+
} elseif ($report_status->task_status == 1 && $this->checkFunction(LearningtaskUseFunction::use_report_revising)) {
933+
$can_report_upload = $this->checkReportUploadDeadline($can_report_upload);
930934
} elseif ($report_status->task_status == 2 && $report_status->grade == 'D') {
931935
$can_report_upload = array(true, '再提出が必要');
932936

@@ -1565,4 +1569,67 @@ public function canDeletetableUserStatus($users_statuses_id)
15651569
}
15661570
return false;
15671571
}
1572+
1573+
/**
1574+
* 提出内容が修正可能かを判定する
1575+
* @return bool
1576+
*/
1577+
public function shouldReviseReportSubmission($post_id): bool
1578+
{
1579+
if ($this->isOutOfDeadlineReportUpload()) {
1580+
// 提出期限オーバーなら、修正不可
1581+
return false;
1582+
}
1583+
1584+
// 提出内容が未評価の状態であれば、提出内容の修正を可能とする
1585+
$submissions = $this->report_statuses->where('post_id', $post_id)->where('task_status', 1);
1586+
$evaluations = $this->report_statuses->where('post_id', $post_id)->where('task_status', 2);
1587+
$evaluated = $submissions->count() > 0 && $submissions->count() === $evaluations->count(); # 提出は評価済みか
1588+
if ($submissions->count() > 0 && !$evaluated) {
1589+
return true;
1590+
}
1591+
1592+
Log::debug('shouldReviseReportSubmission checked', [
1593+
'submissions_count' => $submissions->count(),
1594+
'submissions_details' => $submissions->toArray(),
1595+
'evaluations_count' => $evaluations->count(),
1596+
'evaluations_details' => $evaluations->toArray(),
1597+
'evaluated' => $evaluated,
1598+
]);
1599+
1600+
return false;
1601+
}
1602+
1603+
/**
1604+
* 提出内容の修正の前準備
1605+
*/
1606+
public function prepareRevisingReportSubmission(): void
1607+
{
1608+
$last_submission = LearningtasksUsersStatuses::where('user_id', $this->student_id)
1609+
->where('task_status', 1)
1610+
->orderBy('id', 'desc')
1611+
->first();
1612+
1613+
if ($last_submission) {
1614+
$last_submission->delete();
1615+
}
1616+
}
1617+
1618+
/**
1619+
* 削除された提出内容を取得
1620+
*/
1621+
public function fetchDeletedSubmissions(): Collection
1622+
{
1623+
$query = LearningtasksUsersStatuses::onlyTrashed()
1624+
->where('task_status', 1)
1625+
->where('user_id', $this->student_id)
1626+
->orderBy('id', 'asc');
1627+
1628+
// ログインユーザが学生の場合は自身で削除した提出内容のみ
1629+
if ($this->isStudent()) {
1630+
$query->where('user_id', $this->student_id);
1631+
}
1632+
1633+
return $query->get();
1634+
}
15681635
}

resources/views/plugins/user/learningtasks/default/learningtasks_edit_learningtasks.blade.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,22 @@
221221
</div>
222222
</div>
223223
</div>
224-
224+
<div class="form-group row mb-0">
225+
<label class="{{$frame->getSettingLabelClass()}}">提出後の修正</label>
226+
<div class="{{$frame->getSettingInputClass(true)}}">
227+
<div class="custom-control custom-checkbox mr-3">
228+
<input type="checkbox"
229+
name="base_settings[{{LearningtaskUseFunction::use_report_revising}}]"
230+
value="on"
231+
class="custom-control-input"
232+
id="{{LearningtaskUseFunction::use_report_revising}}"
233+
@if(old("base_settings." . LearningtaskUseFunction::use_report_revising, $tool->getFunction(LearningtaskUseFunction::use_report_revising, true)) == 'on') checked="checked" @endif
234+
>
235+
<label class="custom-control-label" for="{{LearningtaskUseFunction::use_report_revising}}">提出後の修正を許可する</label>
236+
<small class="form-text text-muted">評価前もしくは提出期限まで、学生が提出内容の修正を行えます。</small>
237+
</div>
238+
</div>
239+
</div>
225240
<div class="form-group row mb-0">
226241
<label class="{{$frame->getSettingLabelClass()}}">提出期限</label>
227242
<div class="{{$frame->getSettingInputClass(true)}}">

resources/views/plugins/user/learningtasks/default/learningtasks_edit_report.blade.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,22 @@
112112
</div>
113113
</div>
114114
</div>
115-
115+
<div class="form-group row mb-0">
116+
<label class="{{$frame->getSettingLabelClass()}}">提出後の修正</label>
117+
<div class="{{$frame->getSettingInputClass(true)}}">
118+
<div class="custom-control custom-checkbox mr-3">
119+
<input type="checkbox"
120+
name="post_settings[{{LearningtaskUseFunction::use_report_revising}}]"
121+
value="on"
122+
class="custom-control-input"
123+
id="{{LearningtaskUseFunction::use_report_revising}}"
124+
@if(old("post_settings." . LearningtaskUseFunction::use_report_revising, $tool->getFunction(LearningtaskUseFunction::use_report_revising, true)) == 'on') checked="checked" @endif
125+
>
126+
<label class="custom-control-label" for="{{LearningtaskUseFunction::use_report_revising}}">提出後の修正を許可する</label>
127+
<small class="form-text text-muted">評価前もしくは提出期限まで、学生が提出内容の修正を行えます。</small>
128+
</div>
129+
</div>
130+
</div>
116131
<div class="form-group row mb-0">
117132
<label class="{{$frame->getSettingLabelClass()}}">提出期限</label>
118133
<div class="{{$frame->getSettingInputClass(true)}}">

resources/views/plugins/user/learningtasks/default/learningtasks_show.blade.php

Lines changed: 60 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -145,42 +145,59 @@ function downloadCsvReportUtf8{{$frame_id}}() {
145145

146146
@if ($tool->hasReportStatuses($post->id))
147147
<ol class="mb-3">
148+
@php
149+
$previous_report_submission_id = null;
150+
@endphp
148151
@foreach($tool->getReportStatuses($post->id) as $report_status)
152+
@php
153+
// $report_statusに関する修正履歴を取得する
154+
// 直前の提出と現在の提出の間にある削除されたレコードを修正履歴とする
155+
$submission_revisions = $deleted_submissions->where('id', '>', $previous_report_submission_id)->where('id', '<', $report_status->id);
156+
@endphp
149157
@if (!$loop->last)
150158
<div class="collapse multi-collapse" id="multiCollapseReport{{$loop->iteration}}">
151159
@endif
152160

153161
<li value="{{$loop->iteration}}">{{$report_status->getStstusName($tool->getStudentId())}}
154-
<table class="table table-bordered table-sm report_table">
155-
<tbody>
156-
<tr>
157-
<th>{{$report_status->getStstusPostTimeName()}}</th>
158-
<td>{{$report_status->created_at}}</td>
159-
</tr>
160-
@if ($tool->isUseFunction($report_status->task_status, 'file'))
161-
<tr>
162-
<th>{{$report_status->getUploadFileName()}}</th>
163-
@if (empty($report_status->upload_id))
164-
<td>なし</td>
165-
@else
166-
<td><a href="{{url('/')}}/file/{{$report_status->upload_id}}" target="_blank">{{$report_status->upload->client_original_name}}</a></td>
167-
@endif
168-
</tr>
169-
@endif
170-
@if ($report_status->hasGrade())
171-
<tr>
172-
<th>評価</th>
173-
<td><span class="text-danger font-weight-bold">{{$report_status->grade}}</span></td>
174-
</tr>
175-
@endif
176-
@if ($tool->isUseFunction($report_status->task_status, 'comment'))
177-
<tr>
178-
<th>コメント</th>
179-
<td>{!!nl2br(e($report_status->comment))!!}</td>
180-
</tr>
181-
@endif
182-
</tbody>
183-
</table>
162+
{{-- 修正履歴 --}}
163+
@if ($report_status->task_status == 1 && $submission_revisions->count() > 0)
164+
<small class="text text-muted">(修正済み)</small>
165+
@if ($tool->isTeacher())
166+
<button type="button" class="btn btn-link p-0" data-toggle="modal" data-target="#submissionRevisionsModal{{$loop->iteration}}">
167+
修正履歴を表示
168+
</button>
169+
{{-- Modal --}}
170+
<div class="modal fade" id="submissionRevisionsModal{{$loop->iteration}}" tabindex="-1" role="dialog" aria-labelledby="submissionRevisionsModalLabel{{$loop->iteration}}" aria-hidden="true">
171+
<div class="modal-dialog modal-lg" role="document">
172+
<div class="modal-content">
173+
<div class="modal-header">
174+
<h5 class="modal-title" id="submissionRevisionsModalLabel{{$loop->iteration}}">修正履歴</h5>
175+
<button type="button" class="close" data-dismiss="modal" aria-label="閉じる">
176+
<span aria-hidden="true">&times;</span>
177+
</button>
178+
</div>
179+
<div class="modal-body">
180+
<ul>
181+
@foreach ($submission_revisions as $revision)
182+
{{-- 履歴 --}}
183+
@include('plugins.user.learningtasks.default.learningtasks_show_report_status', ['user_status' => $revision])
184+
<p class="mb-2">
185+
<span class="text-info">{{$revision->deleted_at}} {{$revision->deleted_name}}が修正</span>
186+
</p>
187+
@endforeach
188+
</ul>
189+
</div>
190+
<div class="modal-footer">
191+
<button type="button" class="btn btn-secondary" data-dismiss="modal">閉じる</button>
192+
</div>
193+
</div>
194+
</div>
195+
</div>
196+
@endif
197+
@endif
198+
199+
{{-- 履歴 --}}
200+
@include('plugins.user.learningtasks.default.learningtasks_show_report_status', ['user_status' => $report_status])
184201

185202
@if ($loop->last)
186203
{{-- 履歴削除ボタン:課題管理者機能 --}}
@@ -190,6 +207,13 @@ function downloadCsvReportUtf8{{$frame_id}}() {
190207
@if (!$loop->last)
191208
</div>
192209
@endif
210+
211+
@php
212+
// 修正履歴を取得するため、直前のレポート提出IDを保持
213+
if ($report_status->task_status == 1) {
214+
$previous_report_submission_id = $report_status->id;
215+
}
216+
@endphp
193217
@endforeach
194218
</ol>
195219
@else
@@ -205,7 +229,12 @@ function downloadCsvReportUtf8{{$frame_id}}() {
205229
@if ($tool->checkFunction(LearningtaskUseFunction::use_report_file) || $tool->checkFunction(LearningtaskUseFunction::use_report_comment))
206230

207231
<h5 class="mb-1"><span class="badge badge-secondary" for="status1">提出</span></h5>
208-
232+
{{-- 修正可能のメッセージ --}}
233+
@if ($tool->checkFunction(LearningtaskUseFunction::use_report_revising))
234+
<div class="alert alert-info">
235+
<span class="text-info submit-info-message">評価が確定するまでは提出内容を修正できます。提出済みの内容を修正する場合は、再度レポート提出を行ってください。</span>
236+
</div>
237+
@endif
209238
<form action="{{url('/')}}/redirect/plugin/learningtasks/changeStatus1/{{$page->id}}/{{$frame_id}}/{{$post->id}}#frame-{{$frame_id}}" method="POST" name="form_status1" enctype="multipart/form-data">
210239
{{ csrf_field() }}
211240
<input type="hidden" name="redirect_path" value="{{url('/')}}/plugin/learningtasks/show/{{$page->id}}/{{$frame_id}}/{{$post->id}}#frame-{{$frame_id}}">
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{{--
2+
* 課題管理記事詳細のレポート履歴テンプレート。
3+
*
4+
* @author 永原 篤 <[email protected]>
5+
* @author 石垣 佑樹 <[email protected]>
6+
* @copyright OpenSource-WorkShop Co.,Ltd. All Rights Reserved
7+
* @category 課題管理プラグイン
8+
--}}
9+
<table class="table table-bordered table-sm report_table">
10+
<tbody>
11+
<tr>
12+
<th>{{$user_status->getStstusPostTimeName()}}</th>
13+
<td>{{$user_status->created_at}}</td>
14+
</tr>
15+
@if ($tool->isUseFunction($user_status->task_status, 'file'))
16+
<tr>
17+
<th>{{$user_status->getUploadFileName()}}</th>
18+
@if (empty($user_status->upload_id))
19+
<td>なし</td>
20+
@else
21+
<td><a href="{{url('/')}}/file/{{$user_status->upload_id}}" target="_blank">{{$user_status->upload->client_original_name}}</a></td>
22+
@endif
23+
</tr>
24+
@endif
25+
@if ($user_status->hasGrade())
26+
<tr>
27+
<th>評価</th>
28+
<td><span class="text-danger font-weight-bold">{{$user_status->grade}}</span></td>
29+
</tr>
30+
@endif
31+
@if ($tool->isUseFunction($user_status->task_status, 'comment'))
32+
<tr>
33+
<th>コメント</th>
34+
<td>{!!nl2br(e($user_status->comment))!!}</td>
35+
</tr>
36+
@endif
37+
</tbody>
38+
</table>

0 commit comments

Comments
 (0)