Plugin Directory

Changeset 1936148


Ignore:
Timestamp:
09/05/2018 11:36:43 AM (8 years ago)
Author:
muniyandibg
Message:

version 1.1.0

Location:
qnotsquiz
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • qnotsquiz/trunk/README.txt

    r1926810 r1936148  
    66Requires at least: 4.9.8
    77Tested up to: 4.9.8
    8 Stable tag: 1.0.0
     8Stable tag: 1.1.0
    99License: GPLv2 or later
    1010License URI: http://www.gnu.org/licenses/gpl-2.0.html
    1111
    12 Create quizzes with eazy navigations.
     12Create quizzes and show results and answers in awesome way.
    1313
    1414== Description ==
    15 create quizzes with easy navigations.
     15create quizzes with easy navigations. view result in a pie chart.
     16view solutions and leaderboard.
    1617
    1718== Installation ==
     
    1920This section describes how to install the plugin and get it working.
    2021
    21 1. Upload qnotsquiz.zip file in plugins
    22 2. This plugin requires ACF- Advanced custom fields plugin to run properly. Please make sure it is installed before activating qnotsquiz plugin.
    23 2. Activate and start make quizzes
     221. Upload qnotsquiz.zip file in plugins folder.
     232. Activate and create questions. Add questions to quizzes.
    24243. Find the shortcode for each quiz at quiz dashboard
    25254. Paste the shortcode anywhere in yours posts or pages
     
    3636== Screenshots ==
    3737
    38 1.starting point of the quiz
    39 2.question with navigation
    40 3.result screen
    41 4.show solutions
    42 5.add new question
    43 6.creating a new quiz. find and copy the shortcode to be pasted
    44 7.paste the shortcode in posts or pages
     381.QnotQuiz menu shows general screen with option to customise quiz starting text
     392.Question dashboard
     403.Add new question
     414.Add new quiz
     425.Quiz dashboard with shortcode to be copied and pasted at pages or posts
     436.Paste the shortcode on pages or posts with quiz instructions
     447.Click on the start button to start the quiz
     458.Quiz starting page shows quiz numbers and option to toggle(view) navigator
     469.Navigator visible
     4710.Result screen
     4811.View solutions screen
     4912.Leaderboard
    4550
    4651== Changelog ==
     52
     53= 1.1.0 =
     54* Structured admin menu.
     55* Show result in a pie chart
     56* Packaged ACF plugin. So no need to install it separately.
     57* Shows view solutions in a separate link
     58* View leaderboard
    4759
    4860= 1.0.0 =
     
    5264== Upgrade Notice ==
    5365
     66=1.0.0=
     67Improved QnotsQuiz with result chart and leaderboard sections.
     68
    5469= 1.0.0 =
    5570Initial version
  • qnotsquiz/trunk/css/style.css

    r1926809 r1936148  
    1616    border-style: solid;
    1717    overflow: auto;
    18 
     18    box-sizing: border-box;
     19    padding: 20px;
     20}
     21.chart-container{
     22    position: relative;
     23    height:20vh;
     24    width:40vw;
     25    min-height: 320px;
     26    min-width: 320px;
     27    margin-left: auto;
     28    margin-right: auto
     29}
     30
     31
     32.solutionInstruction{
     33
     34    text-align: center;
     35}
     36
     37.lbdisplayheader{
     38    list-style-type: none;
     39    background-color: lightblue;
     40    width:320px;
     41    padding: 10px;
     42    margin: 1px auto auto;
     43    text-align: left
     44}
     45
     46.lbdisplayheader li{
     47
     48    display: inline-flex;
     49    padding: 5px;
     50    color:white;
     51    width: 33%;
     52
     53}
     54.lbdisplay{
     55    list-style-type: none;
     56
     57    width:320px;
     58    padding: 10px;
     59    margin: auto;
     60    text-align: left;
     61
     62    border-width:0px;
     63    border-bottom: 1px;
     64    border-style: solid;
     65    border-color: lightblue;
     66}
     67
     68
     69.lbdisplay li{
     70
     71    display: inline-flex;
     72    padding: 5px;
     73    color:lightblue;
     74    width: 33%
     75
     76
     77}
     78
     79.final ul{
     80    list-style-type: none;
     81}
     82.final li{
     83    display: inline-flex;
     84    background-color:white ;
     85    padding: 10px;
     86    margin: 3px;
     87    color: lightblue;
     88    font-weight: 300px;
     89
     90}
     91
     92.final .active{
     93    background-color: lightblue;
     94    color: white;
    1995}
    2096.hiddenID{
     
    2298}
    2399#result li{
    24 background-color: lightblue;
     100
    25101color: white;
    26 width:60%;
    27 margin: auto;
    28 
     102
     103margin: 1px;
     104margin-left: auto;
     105margin-right: auto;
     106display: inline-grid;
     107
     108}
     109
     110.resultSections_score{
     111    background-color: lightblue;
     112    width: 100px;
     113    height: 100px;
     114}
     115.resultSections_correct{
     116    width: 100px;
     117    height: 100px;
     118    background-color: lightgreen;
     119}
     120.resultSections_incorrect{
     121    width: 100px;
     122    height: 100px;
     123    background-color: red;
     124}
     125.resultSections_notattempted{
     126    width: 100px;
     127    height: 100px;
     128    background-color: grey;
     129}
     130
     131.scoreDisplay{
     132    font-size: 40px;
    29133}
    30134#result{
     
    36140}
    37141.questnav{
    38     margin-top: 3%;
     142    margin: 0px;
    39143    list-style-type: none;
    40     padding-right: 24px;
     144    padding: 0px;
     145    margin-top:10px;
    41146    display: inline-flex;
    42147    width: 100%;
     
    48153    position: relative;
    49154    top: 10%;
    50 
    51 
    52 
    53     text-align: center;
    54 
     155    text-align: center;
    55156    background-color:white;
    56157}
     
    72173}
    73174
     175.option:hover{
     176    background-color: lightblue;
     177    }
     178
     179.insideQuest{
     180    margin: 5px;
     181}
     182
    74183.attempted{
    75184    background-color: lightblue;
     
    78187
    79188.question{
    80     padding: 20px;
     189      padding: 20px;
    81190    margin-top: 10px;
    82191    margin-bottom: 10px;
    83192    text-align: center;
     193    max-width: 80%;
     194    min-width: 60%;
     195    margin-left: auto;
     196    margin-right: auto;
     197    font-size: 1.5rem;
     198    font-weight: 100px;
    84199
    85200}
    86201#startQuizBtn{
    87202    background-color: lightblue;
    88 
     203    width: fit-content;
     204    padding: 10px;
     205    color: white;
     206    font-weight: bold;
    89207}
    90208#next{
     
    108226
    109227    }
    110 
     228.showprogress{
     229    font-size: 1rem;
     230    color: lightblue;
     231}
     232.hideprogress{
     233    font-size: 1rem;
     234    color: lightgrey;
     235}
     236
     237button{
     238    padding:10px 24px;
     239        border: none;
     240    border-radius: 0px;
     241}
    111242
    112243.progress{
    113     display: flex;
     244
    114245    padding:10px;
    115     width: 100%;
     246
    116247    border: 1px;
    117248    border-style: solid;
     
    122253    margin-bottom:15%;
    123254}
     255
     256.progressBtn{
     257    border-radius: 100%;
     258    border-style:solid;
     259    padding: 8px 15px;
     260
     261
     262
     263
     264}
     265
    124266.holder{
    125     width: 30px;
     267
    126268    margin: 5px;
    127269    text-align: center;
     
    130272}
    131273.holderUnattempted{
    132     width: 30px;
     274
    133275    margin: 5px;
    134276    text-align: center;
     
    137279}
    138280.holderupdated{
    139     width: 30px;
     281
    140282    margin: 5px;
    141283    text-align: center;
     
    153295
    154296.correctflag{
    155     width: 30px;
     297
    156298    margin: 5px;
    157299    text-align: center;
     
    161303}
    162304.wrongflag{
    163     width: 30px;
     305
    164306    margin: 5px;
    165307    text-align: center;
  • qnotsquiz/trunk/js/script.js

    r1926809 r1936148  
    66  var quizposts = new Object();
    77  var post1 = new Object();
    8   var url=jQuery("#url").text();
     8  var url=jQuery("#url").data('url');
    99  var notattempted=0;
    1010  var totQuestions=0;
    1111  var resp=new Array();
    12   var quizid=jQuery("#quizid").text();
     12  var quizid=jQuery("#quizid").data('quizid');
    1313  jQuery.getJSON(url+'/wp-json/wp/v2/quiz/'+quizid,function(post){
    1414            quizposts=post;
     
    3030          });
    3131
    32 
     32//jQuery("#close").confirm();
    3333
    3434  jQuery("#close").click(function() {
     35          if(confirm("Are you sure you want to exit this quiz?")){
    3536          document.getElementById("quiz").style.display = "none";
    3637          jQuery("#startQuizBtn").removeClass("nav");
    37         });
     38        } });
    3839
    3940         jQuery("#startQuizBtn").click(function() {
    4041          document.getElementById("quiz").style.display = "block";
    41           jQuery(".progress").removeClass("hide");
     42          //jQuery(".progress").removeClass("hide");
    4243            jQuery(".totalQuestions").addClass("nav");
    4344            jQuery(".quizTitle").addClass("nav");
     
    5253
    5354         function afterQuizOver(){
    54           jQuery(".insideQuest").html(`
    55                 <ul id="result">
    56                 <li class="resultSections">Your score ${correct}/${totQuestions}</li>
    57                 <li class="resultSections">Correct : ${correct}</li>
    58                 <li class="resultSections">InCorrect : ${wrong}</li>
    59                 <li class="resultSections">Unattempted : ${notattempted}<br></li>
    60                 </ul>
    61                 <div id="afterquiz">
    62                 <div class="question"></div>
    63                 <div class="option1 option"></div>
    64                 <div class="option2 option"></div>
    65                 <div class="option3 option"></div>
    66                 <div class="option4 option"></div>
    67                 </div>
    68 
    69               `);
     55          jQuery(".insideQuest").removeClass("hide");
     56          jQuery(".option1").removeClass("correct incorrect");
     57          jQuery(".option2").removeClass("correct incorrect");
     58          jQuery(".option3").removeClass("correct incorrect");
     59          jQuery(".option4").removeClass("correct incorrect");
     60          // jQuery(".insideQuest").html(`
     61          //       <ul id="result">
     62          //       <li class="resultSections">Your score ${correct}/${totQuestions}</li>
     63          //       <li class="resultSections">Correct : ${correct}</li>
     64          //       <li class="resultSections">InCorrect : ${wrong}</li>
     65          //       <li class="resultSections">Unattempted : ${notattempted}<br></li>
     66          //       </ul>
     67          //       <div id="afterquiz">
     68          //       <div class="question"></div>
     69          //       <div class="option1 option"></div>
     70          //       <div class="option2 option"></div>
     71          //       <div class="option3 option"></div>
     72          //       <div class="option4 option"></div>
     73          //       </div>
     74
     75          //     `);
    7076
    7177         }
     
    108114});
    109115
     116
     117
     118
     119
     120
    110121         jQuery(document).on('click', '.holder', function (e) {
    111122
     
    120131         jQuery(document).on('click', '.holderupdated', function (e) {
    121132
    122           var viewAnsID=(this.innerHTML)-1;
    123         getQuestion(quizid,viewAnsID);
    124 
    125 
    126 
    127     e.preventDefault();
     133            var viewAnsID=(this.innerHTML)-1;
     134            getQuestion(quizid,viewAnsID);
     135            e.preventDefault();
    128136});
    129137
     
    212220
    213221          });
     222//show hide navigator
     223
     224jQuery(document).on('click', '.showprogress', function (e) {
     225            jQuery(".progress").removeClass("hide");
     226            jQuery(".navigator").addClass("hideprogress");
     227            jQuery(".navigator").removeClass("showprogress")
     228
     229e.preventDefault();
     230          });
     231
     232
     233
     234          jQuery(document).on('click', '.hideprogress', function (e) {
     235
     236            jQuery(".progress").addClass("hide");
     237            jQuery(".navigator").addClass("showprogress");
     238            jQuery(".navigator").removeClass("hideprogress");
     239            e.preventDefault();
     240          });
     241
     242         // jQuery(".hideprogress").click(function() {
     243
     244         //    jQuery(".progress").addClass("hide");
     245         //    jQuery(".navigator").addClass("showprogress");
     246         //    jQuery(".navigator").removeClass("hideprogress");
     247
     248
     249         //  });
    214250
    215251//after finishing the quiz result and solution navigation should be present
     
    247283            jQuery(".insideQuest").html(`
    248284
    249 
     285                <h1>Your have scored ${correct} out of ${totQuestions}</h1>
    250286                <ul id="result">
    251                 <li class="resultSections">Your score ${correct}/${totQuestions}</li>
    252                 <li class="resultSections">Correct : ${correct}</li>
    253                 <li class="resultSections">InCorrect : ${wrong}</li>
    254                 <li class="resultSections">Unattempted : ${notattempted}<br></li>
     287                <li class="resultSections resultSections_correct">Correct<span class="scoreDisplay">${correct}</span></li>
     288                <li class="resultSections resultSections_incorrect">InCorrect<span class="scoreDisplay">${wrong}</span></li>
     289                <li class="resultSections resultSections_notattempted">Skipped<span class="scoreDisplay">${notattempted}</span><br></li>
    255290                </ul>
     291                <div class="chart-container">
     292                <canvas id="myChart" ></canvas>
     293                </div>
    256294
    257295              `);
    258             jQuery("#qno").text("RESULTS");
     296            var ctx = document.getElementById("myChart");
     297            var myChart = new Chart(ctx, {
     298  type: 'pie',
     299  data: {
     300    labels: ['correct','incorrect','skipped'],
     301
     302    datasets: [
     303      {
     304        data: [correct,wrong,notattempted],
     305        backgroundColor: [
     306          "green",
     307          "red",
     308          "grey"
     309        ]
     310      }
     311    ]
     312  }
     313});
     314            jQuery("#qno").text("");
     315            jQuery(".progress").addClass("hide");
     316            jQuery(".navigator").addClass("hide");
     317            jQuery(".final").removeClass("hide");
    259318            document.getElementById("next").style.display = "none";
    260319            document.getElementById("prev").style.display = "none";
    261320            document.getElementById("finish").style.display = "none";
    262 
    263 
    264           });
     321            //creating new attempt post via json
     322            i=0;
     323            var attemptLog='';
     324            while(i<totQuestions){
     325              attemptLog+=resp[i][0]+'|'+resp[i][1]+',';
     326              i++;
     327            }
     328
     329        jQuery.ajax({
     330            method: "POST",
     331            url: POST_SUBMITTER.root + 'qnotsAttempts/v1/qnots_attempts',
     332            data : {
     333              'quiz_id':quizid,
     334              'attempts_log':attemptLog,
     335              'score':correct},
     336            beforeSend: function ( xhr ) {
     337                xhr.setRequestHeader( 'X-WP-Nonce', POST_SUBMITTER.nonce );
     338            },
     339            success : function( response ) {
     340                //console.log( response );
     341                alert( POST_SUBMITTER.success );
     342            },
     343            fail : function( response ) {
     344                //console.log( response );
     345                alert( POST_SUBMITTER.failure );
     346            }
     347
     348        });
     349
     350          });
     351
     352          jQuery("#finalSectionSolutions").click(function() {
     353            jQuery("#qno").html('<div class="solutionInstruction">Click on a question to view solution.</div>');
     354            jQuery("#finalSectionResult").removeClass("active");
     355            jQuery("#finalSectionLeaderBoard").removeClass("active");
     356            jQuery("#finalSectionSolutions").addClass("active");
     357            jQuery(".progress").removeClass("hide");
     358
     359
     360            jQuery(".insideQuest").html(`
     361
     362
     363                <div id="afterquiz">
     364                <div class="question"></div>
     365                <div class="option1 option"></div>
     366                <div class="option2 option"></div>
     367                <div class="option3 option"></div>
     368                <div class="option4 option"></div>
     369                </div>
     370
     371              `);
     372            jQuery(".insideQuest").addClass("hide");
     373
     374          });
     375          jQuery("#finalSectionResult").click(function() {
     376            jQuery("#qno").text("");
     377            jQuery(".progress").addClass("hide");
     378            jQuery("#finalSectionSolutions").removeClass("active");
     379            jQuery("#finalSectionLeaderBoard").removeClass("active");
     380            jQuery("#finalSectionResult").addClass("active");
     381            jQuery(".insideQuest").removeClass("hide");
     382            jQuery(".insideQuest").html(`
     383
     384                <h1>Your have scored ${correct} out of ${totQuestions}</h1>
     385                <ul id="result">
     386                <li class="resultSections resultSections_correct">Correct<span class="scoreDisplay">${correct}</span></li>
     387                <li class="resultSections resultSections_incorrect">InCorrect<span class="scoreDisplay">${wrong}</span></li>
     388                <li class="resultSections resultSections_notattempted">Skipped<span class="scoreDisplay">${notattempted}</span><br></li>
     389                </ul>
     390                <div class="chart-container">
     391                <canvas id="myChart" ></canvas>
     392                </div>
     393
     394              `);
     395            var ctx = document.getElementById("myChart");
     396            var myChart = new Chart(ctx, {
     397  type: 'pie',
     398  data: {
     399    labels: ['correct','incorrect','skipped'],
     400
     401    datasets: [
     402      {
     403        data: [correct,wrong,notattempted],
     404        backgroundColor: [
     405          "green",
     406          "red",
     407          "grey"
     408        ]
     409      }
     410    ]
     411  }
     412});
     413
     414
     415          });
     416
     417
     418          //Leaderboard section
     419          jQuery("#finalSectionLeaderBoard").click(function() {
     420            jQuery("#qno").text("");
     421            jQuery(".progress").addClass("hide");
     422            jQuery("#finalSectionResult").removeClass("active");
     423            jQuery("#finalSectionSolutions").removeClass("active");
     424            jQuery("#finalSectionLeaderBoard").addClass("active");
     425            jQuery(".insideQuest").removeClass("hide");
     426            //jQuery.getJSON(url+'/wp-json/wp/v2/qnots_attempts/?filter[orderby]=meta_value_num&filter[meta_key]=score&filter[order]=desc&filter[meta_key]=quiz_id&filter[meta_value]='+quizid,function(attempts){
     427              //for(i = 0; i < Object.keys(attempts).length; i++) {
     428              // attempts.sort(function(a, b){
     429              //   return b.score - a.score;
     430              // });
     431            jQuery.getJSON(url+'/wp-json/qnotsAttempts/v1/qnots_attempts/?quiz_id='+quizid,function(attempts){
     432            var attemptsData='<div>Top 10 scorers</div><br><div><ul class="lbdisplayheader"><li>Rank</li><li>Name</li><li>Score</li></ul></div>';
     433              for(i = 0; i < Object.keys(attempts).length&&i<10; i++) {
     434
     435                     attemptsData+='<div><ul class="lbdisplay"><li>'+(i+1)+'</li><li>'+attempts[i].user_name+'</li><li>'+attempts[i].score+'</li></ul></div>';
     436                  }
     437
     438              jQuery(".insideQuest").html(`
     439                ${attemptsData}
     440
     441              `);
     442
     443              });
     444          });
     445
     446
    265447          //sets the attempt flag
    266448         function setAttemptFlag(flag){
     
    313495
    314496  while(i<qcount)
    315        { questHolder+='<button class="holder" id="q'+i+'">'+(i+1)+'</button>';
     497       { questHolder+='<button class="progressBtn holder" id="q'+i+'">'+(i+1)+'</button>';
    316498        i++; }
    317499  jQuery(".progress").html(questHolder);
  • qnotsquiz/trunk/qnotsquiz.php

    r1926809 r1936148  
    1111//if this file accessed directly then exit
    1212
     13
     14
    1315if( !defined('ABSPATH')){
    1416    die;
     
    1618
    1719//check for ACF installed or not
    18 if( !function_exists( 'the_field' ) ) {
     20/*if( !function_exists( 'the_field' ) ) {
    1921  add_action( 'admin_notices', 'qnotsquiz_my_acf_notice' );
    2022}
     
    2830  </div>
    2931  <?php
    30 }
     32}*/
     33
     34//packaging acf
     35// 1. customize ACF path
     36add_filter('acf/settings/path', 'my_acf_settings_path');
     37
     38function my_acf_settings_path( $path ) {
     39
     40    // update path
     41    $path = plugin_dir_path( __FILE__ ) .('/acf/');
     42
     43    // return
     44    return $path;
     45
     46}
     47
     48
     49// 2. customize ACF dir
     50add_filter('acf/settings/dir', 'my_acf_settings_dir');
     51
     52function my_acf_settings_dir( $dir ) {
     53
     54    // update path
     55    $dir = plugins_url('/acf/');
     56
     57    // return
     58    return $dir;
     59
     60}
     61
     62
     63// 3. Hide ACF field group menu item
     64add_filter('/acf/settings/show_admin', '__return_false');
     65
     66
     67// 4. Include ACF
     68include_once( plugin_dir_path( __FILE__ ) .('/acf/acf.php') );
    3169
    3270
     
    3573  wp_register_style( 'qnotsquiz_style',plugins_url('/css/style.css', __FILE__), array(), '1.1', 'all');
    3674  wp_register_script( 'qnotsquiz_script',plugins_url('/js/script.js', __FILE__), array ( 'jquery' ), 1.1, true);
     75  wp_register_script( 'qnotsquiz_chart_script','https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.2/Chart.min.js', array ( 'jquery' ), 1.1, true);
    3776  wp_enqueue_style('qnotsquiz_style');
    3877  wp_enqueue_script('qnotsquiz_script');
     78   wp_enqueue_script('qnotsquiz_chart_script');
     79  //localize data for script
     80  wp_localize_script( 'qnotsquiz_script', 'POST_SUBMITTER', array(
     81      'root' => esc_url_raw( rest_url() ),
     82      'nonce' => wp_create_nonce( 'wp_rest' ),
     83      'success' => __( 'Thanks for your submission!', 'your-text-domain' ),
     84      'failure' => __( 'Your submission could not be processed.', 'your-text-domain' ),
     85      'current_user_id' => get_current_user_id()
     86    )
     87  );
    3988}
    4089add_action( 'wp_enqueue_scripts', 'qnotsquiz_add_scripts' );
     
    64113    'get_callback' => function(){return get_field('correctanswer');}
    65114    ));
    66 }
     115  register_rest_field('qnots_attempts','user_id',array(
     116    'get_callback' => function(){return get_field('user_id');}
     117    ));
     118  register_rest_field('qnots_attempts','user_name',array(
     119    'get_callback' => function(){return get_field('user_name');}
     120    ));
     121  register_rest_field('qnots_attempts','quiz_id',array(
     122    'get_callback' => function(){return get_field('quiz_id');}
     123    ));
     124  register_rest_field('qnots_attempts','attempts_log',array(
     125    'get_callback' => function(){return get_field('attempts_log');}
     126    ));
     127  register_rest_field('qnots_attempts','score',array(
     128    'get_callback' => function(){return get_field('score');}
     129    ));
     130  register_rest_route( 'qnotsAttempts/v1/','/qnots_attempts',array(
     131    'methods'=>'POST',
     132    'callback'=>'updateQnotsAttempts'
     133    ));
     134  register_rest_route( 'qnotsAttempts/v1/','/qnots_attempts',array(
     135            'methods'             => WP_REST_SERVER::READABLE,
     136            'callback'            => 'getQnotsAttempts',
     137
     138    ));
     139}
     140
     141function getQnotsAttempts($data){
     142  $qnotsAmps=new WP_Query(array(
     143    'post_type'=>'qnots_attempts',
     144    'posts_per_page' => -1,
     145    'nopaging' => true,
     146    'orderby'=>'meta_value_num',
     147    'meta_key'=>'score',
     148    'order'=>'desc'
     149    ));
     150  $attempsList=array();
     151  while($qnotsAmps->have_posts()){
     152    $qnotsAmps->the_post();
     153    if($data['quiz_id']==get_field('quiz_id')){
     154      array_push($attempsList,array(
     155        'user_name'=>get_field('user_name'),
     156        'score'=>get_field('score')
     157        ));
     158    }
     159  }
     160  return $attempsList;
     161    }
     162
     163//     flush_rewrite_rules(true); // FIXME: <------- DONT LEAVE ME HERE
     164// }
     165
     166
    67167add_action('rest_api_init','qnotsquiz_qnotsquiz_rest');
     168
     169add_action( 'rest_api_init', 'wp_rest_filter_add_filters' );
     170 /**
     171  * Add the necessary filter to each post type
     172  **/
     173function wp_rest_filter_add_filters() {
     174    foreach ( get_post_types( array( 'show_in_rest' => true ), 'objects' ) as $post_type ) {
     175        add_filter( 'rest_' . $post_type->name . '_query', 'wp_rest_filter_add_filter_param', 10, 2 );
     176    }
     177}
     178/**
     179 * Add the filter parameter
     180 *
     181 * @param  array           $args    The query arguments.
     182 * @param  WP_REST_Request $request Full details about the request.
     183 * @return array $args.
     184 **/
     185function wp_rest_filter_add_filter_param( $args, $request ) {
     186    // Bail out if no filter parameter is set.
     187    if ( empty( $request['filter'] ) || ! is_array( $request['filter'] ) ) {
     188        return $args;
     189    }
     190    $filter = $request['filter'];
     191    if ( isset( $filter['posts_per_page'] ) && ( (int) $filter['posts_per_page'] >= 1 && (int) $filter['posts_per_page'] <= 100 ) ) {
     192        $args['posts_per_page'] = $filter['posts_per_page'];
     193    }
     194    global $wp;
     195    $vars = apply_filters( 'rest_query_vars', $wp->public_query_vars );
     196    function allow_meta_query( $valid_vars )
     197    {
     198        $valid_vars = array_merge( $valid_vars, array( 'meta_query', 'meta_key', 'meta_value', 'meta_compare' ) );
     199        return $valid_vars;
     200    }
     201    $vars = allow_meta_query( $vars );
     202
     203    foreach ( $vars as $var ) {
     204        if ( isset( $filter[ $var ] ) ) {
     205            $args[ $var ] = $filter[ $var ];
     206        }
     207    }
     208    return $args;
     209}
     210
     211//save quiz attempts
     212function updateQnotsAttempts($data){
     213  $current_user = wp_get_current_user();
     214    if ( 0 == $current_user->ID ) {
     215        $user_name='Guest';
     216    } else {
     217        $user_name=$current_user->display_name;
     218
     219    }
     220  wp_insert_post(array(
     221
     222              'post_title'=>'new quizAttempt',
     223              'post_type'=>'qnots_attempts',
     224
     225
     226            'post_status' => 'publish',
     227
     228            meta_input=>array(
     229              'user_id'=> get_current_user_id(),
     230              'user_name'=> $user_name,
     231            'quiz_id'=> $data['quiz_id'],
     232            'attempts_log'=> $data['attempts_log'],
     233              'score'=>$data['score']
     234              )
     235    ));
     236}
    68237
    69238
    70239// overall template of the qnotsquiz
    71240function qnotsquiz_shortcode ($qnotsquizID) {
     241ob_start();
     242
     243   if(!get_option( 'qnotsquiz_start_text' ))
     244    $qnotsquiz_custom_start_text="START";
     245  else
     246    $qnotsquiz_custom_start_text=get_option( 'qnotsquiz_start_text' );
     247
     248
     249
    72250 ?>
    73251<div class="quiz" id="quiz">
    74   <label id="qno">Question 1 of totalQuestions</label>
     252  <!-- <div class="quizTitle hide"><?php echo get_the_title();?></div>
     253  <div class="quizLink hide"><?php echo the_permalink();?></div> -->
    75254  <button id="close">close</button>
     255  <div class="final hide">
     256    <ul>
     257                <li  id="finalSectionResult" class=" active">Results</li>
     258                <li  id="finalSectionSolutions"class="">View Solutions</li>
     259                <li  id="finalSectionLeaderBoard"class="">LeaderBoard</li>
     260
     261                </ul>
     262  </div>
     263
     264    <label id="qno">Question 1 of totalQuestions</label>
     265
    76266  <div class="questcontent">
    77     <div class="hide" id="url"><?php echo get_site_url();?></div>
    78     <div class="hiddenID" id="quizid"><?php echo $qnotsquizID[0]; ?></div>
     267    <div class="hide" data-url="<?php echo get_site_url();?>"  id="url"></div>
     268    <div class="hiddenID" data-quizid="<?php echo $qnotsquizID[0]; ?>" id="quizid"></div>
    79269    <div class="hiddenID" id="questionid">0</div>
    80270
     
    95285<li class="next"><button class="nav" id="next">Next</button></li>
    96286</ul>
    97 
    98 <div class="progress">
     287<div class="navigator showprogress">
     288 Toggle Navigator
     289  </div>
     290<div class="progress hide">
    99291</div>
     292
    100293</div>
    101294
    102295</div>
    103 <button id="startQuizBtn">START</button>
     296<div id="startQuizBtn"><?php echo $qnotsquiz_custom_start_text; ?></div>
    104297
    105298<?php
     299
     300 $ReturnString = ob_get_contents();
     301    ob_end_clean();
     302    return $ReturnString;
    106303}
    107304add_shortcode('qnotsquiz', 'qnotsquiz_shortcode');
     
    128325register_post_type('quiz',array(
    129326  'show_in_rest' => true,
    130 
     327  'show_in_menu' => false,
    131328  'supports'=>array('title','editor'),
    132329  'rewrite' => array('slug'=>'quiz'),
     
    141338register_post_type('questions',array(
    142339  'show_in_rest' => true,
     340  'show_in_menu' => false,
    143341  'supports'=>array('title'),
    144342  'rewrite' => array('slug'=>'questions'),
     
    147345  'labels' => array(
    148346    'name' => 'questions'
     347    ),
     348
     349  ));
     350
     351register_post_type('qnots_attempts',array(
     352  'show_in_rest' => true,
     353
     354  'rest_controller_class' => 'WP_REST_Posts_Controller',
     355  'show_in_menu' => false,
     356  'supports'=>array('title'),
     357  'rewrite' => array('slug'=>'qnots_attempts'),
     358  'has_archive' => true,
     359  'public' => true,
     360  'labels' => array(
     361    'name' => 'qnots_attempts'
    149362    ),
    150363
     
    305518    'menu_order' => 0,
    306519  ));
     520  register_field_group(array (
     521    'id' => 'acf_qnots_attempts',
     522    'title' => 'qnots_attempts',
     523    'fields' => array (
     524      array (
     525        'key' => 'field_5b7f9e3407c34',
     526        'label' => 'user_id',
     527        'name' => 'user_id',
     528        'type' => 'text',
     529        'default_value' => '',
     530        'placeholder' => '',
     531        'prepend' => '',
     532        'append' => '',
     533        'formatting' => 'html',
     534        'maxlength' => '',
     535      ),
     536      array (
     537        'key' => 'field_5b838ec788f58',
     538        'label' => 'user_name',
     539        'name' => 'user_name',
     540        'type' => 'text',
     541        'default_value' => '',
     542        'placeholder' => '',
     543        'prepend' => '',
     544        'append' => '',
     545        'formatting' => 'html',
     546        'maxlength' => '',
     547      ),
     548      array (
     549        'key' => 'field_5b7f9ea607c35',
     550        'label' => 'quiz_id',
     551        'name' => 'quiz_id',
     552        'type' => 'text',
     553        'default_value' => '',
     554        'placeholder' => '',
     555        'prepend' => '',
     556        'append' => '',
     557        'formatting' => 'html',
     558        'maxlength' => '',
     559      ),
     560      array (
     561        'key' => 'field_5b7f9f5107c36',
     562        'label' => 'attempts_log',
     563        'name' => 'attempts_log',
     564        'type' => 'text',
     565        'default_value' => '',
     566        'placeholder' => '',
     567        'prepend' => '',
     568        'append' => '',
     569        'formatting' => 'html',
     570        'maxlength' => '',
     571      ),
     572      array (
     573        'key' => 'field_5b7fa03107c37',
     574        'label' => 'score',
     575        'name' => 'score',
     576        'type' => 'number',
     577        'default_value' => '',
     578        'placeholder' => '',
     579        'prepend' => '',
     580        'append' => '',
     581        'min' => '',
     582        'max' => '',
     583        'step' => '',
     584      ),
     585    ),
     586    'location' => array (
     587      array (
     588        array (
     589          'param' => 'post_type',
     590          'operator' => '==',
     591          'value' => 'qnots_attempts',
     592          'order_no' => 0,
     593          'group_no' => 0,
     594        ),
     595      ),
     596    ),
     597    'options' => array (
     598      'position' => 'normal',
     599      'layout' => 'no_box',
     600      'hide_on_screen' => array (
     601      ),
     602    ),
     603    'menu_order' => 0,
     604  ));
    307605}
    308606
     
    312610//while initialisation show custom post types
    313611add_action('init','qnotsquiz_postTypes');
     612
     613//Add admin menu
     614add_action( 'admin_menu', 'qnotsquiz_admin_menu' );
     615
     616function qnotsquiz_admin_menu(){
     617
     618  $page_title = 'QnotsQuiz';
     619  $menu_title = 'QnotsQuiz';
     620  $capability = 'manage_options';
     621  $menu_slug  = 'qnotsquiz';
     622  $function   = 'qnotsquiz_settings_page';
     623  $icon_url   = 'dashicons-editor-help';
     624  $position   = 99;
     625
     626  add_menu_page( $page_title,
     627                 $menu_title,
     628                 $capability,
     629                 $menu_slug,
     630                 $function,
     631                 $icon_url,
     632                 $position );
     633
     634  add_submenu_page('qnotsquiz', 'General', 'General', 'manage_options', 'qnotsquiz');
     635  add_submenu_page('qnotsquiz', 'Quizzes', 'Quizzes', 'manage_options', 'edit.php?post_type=quiz');
     636  add_submenu_page('qnotsquiz', 'Questions', 'Questions', 'manage_options', 'edit.php?post_type=questions');
     637
     638}
     639
     640if( !function_exists("qnotsquiz_settings_page") )
     641{
     642function qnotsquiz_settings_page(){
     643  if(!get_option( 'qnotsquiz_start_text' ))
     644    $qnotsquiz_custom_start_text="START";
     645  else
     646    $qnotsquiz_custom_start_text=get_option( 'qnotsquiz_start_text' );
     647?>
     648
     649  <h1>QnotsQuiz Settings</h1>
     650  <form method="post" action="options.php">
     651    <?php settings_fields( 'qnotsquiz-settings' ); ?>
     652    <?php do_settings_sections( 'qnotsquiz-settings' ); ?>
     653    <table class="form-table">
     654      <tr valign="top">
     655      <th scope="row">Text to appear on start button:</th>
     656      <td><input type="text" name="qnotsquiz_start_text" value="<?php echo $qnotsquiz_custom_start_text; ?>"/></td>
     657      </tr>
     658    </table>
     659    <?php submit_button(); ?>
     660  </form>
     661
     662
     663<?php
     664}
     665}
     666register_setting('qnotsquiz-settings','qnotsquiz_start_text');
     667
     668
     669
     670
     671
     672?>
  • qnotsquiz/trunk/uninstall.php

    r1926809 r1936148  
    66    exit;
    77}
    8 
    9 
     8//delete options
     9delete_option( 'qnotsquiz_start_text' );
    1010//delete posts with types questions and quiz upon uninstallation of qnotsquiz
    1111$args = array (
    12     'post_type' =>  array('questions','quiz'),
     12    'post_type' =>  array('questions','quiz','qnots_attempts'),
    1313    'nopaging' => true
    1414  );
Note: See TracChangeset for help on using the changeset viewer.