Skip to content

Commit 2d65d21

Browse files
committed
Can show the hint
1 parent 0d8276f commit 2d65d21

19 files changed

Lines changed: 608 additions & 70 deletions

app/Http/Controllers/AssignmentSyncQuestionController.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2397,7 +2397,7 @@ function getQuestionSummaryByAssignment(Request $request,
23972397
$columns['submission'] = 'forge (final)';
23982398
} elseif ($value->qti_json_type === 'forge_iteration') {
23992399
$columns['submission'] = 'forge (draft)';
2400-
} elseif ($value->qti_json_type === 'three_d_model_multiple_choice'){
2400+
} elseif ($value->qti_json_type === 'three_d_model_multiple_choice') {
24012401
$columns['submission'] = '3D multiple choice';
24022402
}
24032403

@@ -4020,9 +4020,7 @@ function getQuestionsToView(Request $request,
40204020
$assignment->questions[$key]['qti_answer_json'] = json_encode($qti_answer_json);
40214021
}
40224022
}
4023-
if (request()->user()->role === 3) {
4024-
$assignment->questions[$key]['webwork_code'] = null;
4025-
}
4023+
40264024
if ($show_solution
40274025
&& request()->user()->role === 3
40284026
&& ($render_webwork_solution || $imathas_solution)) {
@@ -4038,11 +4036,14 @@ function getQuestionsToView(Request $request,
40384036
: null;
40394037
$shown_hint = $assignment->can_view_hint && (Auth::user()->role === 2 || (Auth::user()->role === 3 && in_array($question->id, $shown_hints)));
40404038
$assignment->questions[$key]['shown_hint'] = $shown_hint;
4041-
$assignment->questions[$key]['hint_exists'] = $assignment->questions[$key]->hint !== null && $assignment->questions[$key]->hint !== '';
4039+
$assignment->questions[$key]['hint_exists'] = ($assignment->questions[$key]->hint !== null && $assignment->questions[$key]->hint !== '')
4040+
|| ($assignment->questions[$key]->webwork_code && str_contains($assignment->questions[$key]->webwork_code, 'BEGIN_PGML_HINT'));
40424041
$assignment->questions[$key]['hint'] = $shown_hint
40434042
? $question->addTimeToS3Files($assignment->questions[$key]->hint, $domd)
40444043
: null;
4045-
4044+
if (request()->user()->role === 3) {
4045+
$assignment->questions[$key]['webwork_code'] = null;
4046+
}
40464047
$assignment->questions[$key]['notes'] = Auth::user()->role === 2 ? $question->addTimeToS3Files($assignment->questions[$key]->notes, $domd) : null;
40474048

40484049
$custom_claims = [];

app/Http/Controllers/JWTController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ public function processAnswerJWT(Request $request)
157157

158158
if ($problemJWT->adapt->technology === 'webwork' && isset($answerJWT->score['answers'])) {
159159
$answers = $answerJWT->score['answers'];
160+
Log::info(json_encode($answers));
160161
foreach ($answers as $value) {
161162
if (isset($value['error_message']) && $value['error_message']) {
162163
$log_exception = false;

app/Http/Controllers/QuestionController.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2876,12 +2876,15 @@ function preview(Request $request,
28762876
$domain = $question->getWebworkDomain();
28772877
$endpoint = $question->getWebworkEndpoint();
28782878
$question['technology_iframe_src'] = "$domain/$endpoint?problemJWT=$problemJWT";
2879+
$question['technology_iframe'] = $question['technology_iframe_src'];
28792880
if ($webwork->algorithmicSolution($request) || $webwork->inCodeSolution($request)) {
2880-
$question['technology_iframe'] = $question['technology_iframe_src'];
28812881
$question['solution_html'] = null;
28822882
$question['solution_type'] = 'html';
28832883
$question['render_webwork_solution'] = true;
28842884
}
2885+
if ($webwork->hasHint($request)) {
2886+
$question['render_webwork_hint'] = true;
2887+
}
28852888
} else {
28862889
$problem_jwt = '';
28872890
$question['imathas_solution'] = false;

app/Http/Controllers/ShownHintController.php

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use App\Exceptions\Handler;
77
use App\Question;
88
use App\ShownHint;
9+
use App\Webwork;
910
use Exception;
1011
use Illuminate\Http\Request;
1112
use Illuminate\Support\Facades\Gate;
@@ -17,13 +18,15 @@ class ShownHintController extends Controller
1718
* @param Assignment $assignment
1819
* @param Question $question
1920
* @param ShownHint $shownHint
21+
* @param Webwork $webwork
2022
* @return array
2123
* @throws Exception
2224
*/
2325
public function store(Request $request,
2426
Assignment $assignment,
2527
Question $question,
26-
ShownHint $shownHint): array
28+
ShownHint $shownHint,
29+
Webwork $webwork): array
2730
{
2831

2932
$response['type'] = 'error';
@@ -36,12 +39,24 @@ public function store(Request $request,
3639

3740

3841
try {
39-
$shownHint->user_id = $request->user()->id;
40-
$shownHint->assignment_id = $assignment->id;
41-
$shownHint->question_id = $question->id;
42-
$shownHint->save();
43-
$question->addTimeToS3Files($question->hint, new \DOMDocument(), false);
44-
$response['hint'] = $question->hint;
42+
ShownHint::firstOrCreate([
43+
'user_id' => $request->user()->id,
44+
'assignment_id' => $assignment->id,
45+
'question_id' => $question->id,
46+
]);
47+
48+
if ($question->technology === 'webwork' && $request->problemJWT) {
49+
$webwork_response = $webwork->getHint($request->problemJWT);
50+
if ($webwork_response['type'] === 'error') {
51+
$response['message'] = $webwork_response['message'];
52+
return $response;
53+
}
54+
$response['hint'] = $webwork_response['message'];
55+
} else {
56+
$question->addTimeToS3Files($question->hint, new \DOMDocument(), false);
57+
$response['hint'] = $question->hint;
58+
}
59+
4560
$response['type'] = 'success';
4661
} catch (Exception $e) {
4762
$response['message'] = 'We were unable to confirm that you would like the hint to be shown.';

app/Http/Controllers/WebworkController.php

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,44 @@ public function solution(string $problemJWT, Webwork $webwork): array
2828
{
2929
try {
3030
$authorized = Gate::inspect('solution', [$webwork, $problemJWT]);
31-
31+
$response['type'] = 'error';
3232
if (!$authorized->allowed()) {
33-
return [
34-
'type' => 'success',
35-
'message' => sprintf(
36-
'<div class="alert alert-danger">%s</div>',
37-
e($authorized->message())
38-
)
39-
];
33+
$response['message'] = $authorized->message();
34+
return $response;
4035
}
4136

42-
return $webwork->getSolution($problemJWT);
37+
$response = $webwork->getSolution($problemJWT);
4338

4439
} catch (Exception $e) {
4540
app(Handler::class)->report($e);
41+
$response['message'] = 'We were unable to retrieve the solution to this problem. Please try again or contact support.';
42+
}
43+
return $response;
44+
}
4645

47-
return [
48-
'type' => 'error',
49-
'message' => '<div class="alert alert-danger">We were unable to retrieve the solution to this problem. Please try again or contact support.</div>'
50-
];
46+
/**
47+
* @param string $problemJWT
48+
* @param Webwork $webwork
49+
* @return array
50+
* @throws Exception
51+
*/
52+
public function hint(string $problemJWT, Webwork $webwork): array
53+
{
54+
try {
55+
$authorized = Gate::inspect('hint', $webwork);
56+
$response['type'] = 'error';
57+
if (!$authorized->allowed()) {
58+
$response['message'] = $authorized->message();
59+
return $response;
60+
}
61+
62+
$response = $webwork->getHint($problemJWT);
63+
64+
} catch (Exception $e) {
65+
app(Handler::class)->report($e);
66+
$response['message'] = 'We were unable to retrieve the hint to this problem. Please try again or contact support.';
5167
}
68+
return $response;
5269
}
5370

5471
/**

app/Http/Middleware/SetAppVersionHeader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function handle($request, Closure $next)
2121
$response = $next($request);
2222
//$app_version = env('VAPOR_COMMIT_HASH') ? env('VAPOR_COMMIT_HASH') : '1.0';
2323
if (!$response instanceof StreamedResponse) {
24-
$response->header('appversion', '5.47');
24+
$response->header('appversion', '5.49');
2525
}
2626
return $response;
2727
}

app/Policies/ShownHintPolicy.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ public function store(User $user, ShownHint $shownHint, $assignment, int $questi
5555
if (session()->get('instructor_user_id')) {
5656
//logged in as student
5757
$has_access = true;
58-
58+
}
59+
if (in_array($user->role, [2,4,5])){
60+
$has_access = true;
5961
}
6062
return $has_access
6163
? Response::allow()

app/Policies/WebworkPolicy.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,21 @@ public function templates(User $user): Response
3232

3333
}
3434

35+
/**
36+
* @param User $user
37+
* @return Response
38+
*/
39+
public function hint(User $user): Response
40+
{
41+
// Students must go through ShownHintController's confirm/penalty flow.
42+
// This endpoint is only for previewing/authoring contexts (instructors,
43+
// graders, admins, fake students), where there's no assignment/penalty
44+
// context to speak of.
45+
return $user->role !== 3 || $user->fake_student
46+
? Response::allow()
47+
: Response::deny('You are not allowed to access this hint directly.');
48+
}
49+
3550
/**
3651
* @param User $user
3752
* @param Webwork $webwork

app/Question.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,9 @@ function getTechnologySrcAndProblemJWT(Request $request,
430430

431431
$custom_claims['aud'] = $webwork_domain;
432432
$custom_claims['webwork']['problemSeed'] = $seed;
433-
$custom_claims['webwork']['isInstructor'] = +(request()->user()->role === 2 || (request()->user()->role === 3 && request()->user()->fake_student)); //for debugging
433+
$custom_claims['webwork']['isInstructor'] = 0;
434+
$custom_claims['webwork']['view_problem_debugging_info'] =+(request()->user()->role === 2 || (request()->user()->role === 3 && request()->user()->fake_student)); //for debugging
435+
434436
$custom_claims['webwork']['hideElements'] = ['.ww-feedback-btn'];
435437
if (!Helper::isWebworkMacroEditor()) {
436438
$custom_claims['webwork']['hideElements'][] = '.Warnings';
@@ -4022,11 +4024,13 @@ public function getPreviewWebworkProblemJWT(string $source_file_path): string
40224024

40234025
$custom_claims['aud'] = $webwork_domain;
40244026
$custom_claims['webwork']['problemSeed'] = 1234567;
4025-
$custom_claims['webwork']['isInstructor'] = true;
4027+
$custom_claims['webwork']['isInstructor'] = 0;
4028+
$custom_claims['webwork']['view_problem_debugging_info'] =true;
40264029
$custom_claims['webwork']['hideElements'] = ['.ww-feedback-btn'];
40274030
if (!Helper::isWebworkMacroEditor()) {
40284031
$custom_claims['webwork']['hideElements'][] = '.Warnings';
40294032
}
4033+
$custom_claims['webwork']['showHints'] = 0;
40304034
$custom_claims['webwork']['showSummary'] = 0;
40314035
$custom_claims['webwork']['showSolutions'] = true;
40324036
$custom_claims['webwork']['sourceFilePath'] = $source_file_path;

app/ShownHint.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66

77
class ShownHint extends Model
88
{
9-
//
9+
protected $guarded = [];
1010
}

0 commit comments

Comments
 (0)