@@ -301,23 +301,36 @@ public function attachAction(Request $request) : JsonResponse {
301301
302302 //get rid of the old exam if there is one.
303303 $ old_exam = $ repo ->get_exam ($ art_id );
304- $ reponse = "" ;
305- if ($ old_exam ) {
306- $ old_exam ->setQuickcheckrefid (-1 ); //no article attached
307- }
308- if (isset ($ attach )) {
309- if (!isset ($ art_id ) || !isset ($ exam )) {
310- throw new NotFoundHttpException ($ this ->trans ('An article id or exam id are missing ' ));
304+ $ response = "" ;
305+ $ already_attached = false ;
306+ if (null !== $ old_exam ) {
307+ if (($ old_exam ->getId () == $ exam ) && $ attach ) {
308+ $ response = "<p>That exam is already attached.</p> " ;
309+ $ already_attached = true ;
310+ } else {
311+ $ old_exam ->setQuickcheckrefid (-1 ); //no article attached
312+ $ response = "<p> " . $ old_exam ->getQuickcheckname () . " was removed from the page. </p> " ;
311313 }
312- //modify the exam by grabbing it and then changing or adding the art_id
313- $ new_exam = $ em ->find ('PaustianQuickcheckModule:QuickcheckExamEntity ' , $ exam );
314- if (null === $ new_exam ) {
315- throw new \Doctrine \ORM \NoResultException ($ this ->trans ('An exam was not found, when it should have been. ' ));
314+ }
315+ if (!$ already_attached ){
316+ if (isset ($ attach )) {
317+ if (!isset ($ art_id ) || !isset ($ exam )) {
318+ throw new NotFoundHttpException ($ this ->trans ('An article id or exam id are missing ' ));
319+ }
320+ //modify the exam by grabbing it and then changing or adding the art_id
321+ $ new_exam = $ em ->find ('PaustianQuickcheckModule:QuickcheckExamEntity ' , $ exam );
322+ if (null === $ new_exam ) {
323+ throw new \Doctrine \ORM \NoResultException ($ this ->trans ('An exam was not found, when it should have been. ' ));
324+ }
325+ $ new_exam ->setQuickcheckrefid ((int )$ art_id );
326+ $ response .= "<p> " . $ new_exam ->getQuickcheckname () ." exam was attached to the page. Reload the page to see it.</p> " ;
327+ } else {
328+ if (null !== $ old_exam ){
329+ $ response = "<p> " . $ old_exam ->getQuickcheckname () ." exam was removed from the page. Reload the page to see it.</p> " ;
330+ } else {
331+ $ response = "<p> There is no exam to remove. Get it together you loser. " ;
332+ }
316333 }
317- $ new_exam ->setQuickcheckrefid ((int )$ art_id );
318- $ response = "<p> " . $ new_exam ->getQuickcheckname () ." exam was attached to the page. Reload the page to see it.</p> " ;
319- } else {
320- $ response = "<p> " . $ old_exam ->getQuickcheckname () ." exam was removed from the page. Reload the page to see it.</p> " ;
321334 }
322335 $ em ->flush ();
323336 //finally return to the page that called.
0 commit comments