Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.69 KB | None | 0 0
  1. function hdq_before_mubasher99($quizID)
  2. {
  3.     ?>
  4.     <script>
  5.     function hdq_custom_submit(){
  6.         let data = {};
  7.         let no_answers = 0;
  8.        
  9.         // mark each question with string on whether answer was right, wrong, or unanswered
  10.         jQuery("#hdq_<?php echo $quizID; ?> .hdq_question").each(function(){
  11.             let data = "";
  12.             if(!this.classList.contains("hdq_question_title") && !this.classList.contains("hdq_results_wrapper")){
  13.                 let sel = jQuery(this).find(".hdq_correct");
  14.                 if(sel.length > 0){
  15.                     data = "Correct answer";
  16.                 } else {
  17.                     sel = jQuery(this).find(".hdq_wrong");
  18.                     if(sel.length > 0){
  19.                         data = "Incorrect answer";
  20.                     } else {
  21.                         data = "No answer selected";
  22.                         no_answers ++;
  23.                     }
  24.                 }              
  25.             }
  26.  
  27.             jQuery("<h2>" + data +"</h2>").prependTo(this);
  28.         });
  29.        
  30.         // hdq_score is array of score (score/total questions)
  31.         let c = hdq_score[0];
  32.         let t = hdq_score[1];
  33.         let p = (parseFloat(c) / parseFloat(t)) * 100;
  34.         p = p.toFixed(2);
  35.         let d = `<p>Total correct answers: <strong>${c}</strong><br/>
  36.                     Total Wrong Answers: <strong>${t}</strong><br/>
  37.                     Total Skipped Questions: <strong>${no_answers}</strong><br/>
  38.                     Total percentage: <strong>${p}%</strong>
  39.                 </p>`;
  40.         let results_section = document.querySelectorAll(".hdq_share")[0];
  41.         results_section.insertAdjacentHTML("beforebegin", d);
  42.         return JSON.stringify(data); // expects a json string to be returned
  43.     }
  44.     </script>
  45. <?php
  46. }
  47. add_action('hdq_before', 'hdq_before_mubasher99');
  48.  
  49. function hdq_submit_mubasher99($quizOptions)
  50. {
  51.     array_push($quizOptions->hdq_submit, "hdq_custom_submit");
  52.     return $quizOptions;
  53. }
  54. add_action('hdq_submit', 'hdq_submit_mubasher99');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement