66use App \Exceptions \Handler ;
77use App \Question ;
88use App \ShownHint ;
9+ use App \Webwork ;
910use Exception ;
1011use Illuminate \Http \Request ;
1112use 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. ' ;
0 commit comments