WordPress.org

Plugin Directory

Changeset 1719957


Ignore:
Timestamp:
08/26/17 21:04:15 (4 months ago)
Author:
goldhat
Message:

Release v0.8.0

Location:
quizmaster
Files:
164 added
8 edited

Legend:

Unmodified
Added
Removed
  • quizmaster/trunk/fields/fieldgroups/question.php

    r1717342 r1719957  
    567567            ), 
    568568        ), 
     569 
     570        array ( 
     571            'placement' => 'left', 
     572            'key' => 'field_5885e8b50cy2p', 
     573            'label' => 'Quizzes', 
     574            'type' => 'tab', 
     575            'instructions' => 'Attach this question to quizzes.', 
     576        ), 
     577 
     578        array ( 
     579            'post_type' => array ( 
     580                0 => 'quizmaster_quiz', 
     581            ), 
     582            'taxonomy' => array ( 
     583            ), 
     584            'allow_null' => 0, 
     585            'multiple' => 1, 
     586            'return_format' => 'id', 
     587            'ui' => 1, 
     588            'key' => 'qmqe_quizzes', 
     589            'label' => 'Quizzes', 
     590            'name' => 'qmqe_quizzes', 
     591            'type' => 'relationship', 
     592            'instructions' => 'Select quizzes from the quiz list on the left by clicking on them. Quizzes disabled from selection already include this quiz. Questions will appear at the end of the quiz, unless randomization settings for the quiz are applied. Edit the quiz question list directly to reorder the question list.', 
     593            'filters' => array ( 
     594                0 => 'search', 
     595            ), 
     596        ), 
     597 
     598 
     599 
    569600    ), 
     601 
    570602    'location' => array ( 
    571603        array ( 
  • quizmaster/trunk/fields/fieldgroups/quiz.php

    r1717342 r1719957  
    225225        ), 
    226226        array ( 
    227             'sub_fields' => array ( 
    228                 array ( 
    229                     'post_type' => array ( 
    230                         0 => 'quizmaster_question', 
    231                     ), 
    232                     'taxonomy' => array ( 
    233                     ), 
    234                     'allow_null' => 0, 
    235                     'multiple' => 0, 
    236                     'return_format' => 'id', 
    237                     'ui' => 1, 
    238                     'key' => 'field_588a50ca0d692', 
    239                     'label' => 'Question', 
    240                     'name' => 'qmqu_question', 
    241                     'type' => 'post_object', 
    242                     'instructions' => '', 
    243                     'required' => 1, 
    244                 ), 
    245             ), 
    246             'min' => 1, 
    247             'max' => 0, 
    248             'layout' => 'table', 
    249             'button_label' => '', 
    250             'collapsed' => '', 
    251             'key' => 'field_588a50ca0d691', 
     227            'post_type' => array ( 
     228                0 => 'quizmaster_question', 
     229            ), 
     230            'taxonomy' => array ( 
     231            ), 
     232            'allow_null' => 0, 
     233            'multiple' => 1, 
     234            'return_format' => 'id', 
     235            'ui' => 1, 
     236            'key' => 'qmqu_questions', 
    252237            'label' => 'Questions', 
    253238            'name' => 'qmqu_questions', 
    254             'type' => 'repeater', 
    255             'instructions' => '', 
     239            'type' => 'relationship', 
     240            'instructions' => 'Select questions on from the question pool on the left by clicking on them. Questions disabled from selection have already been added to the quiz. Questions will appear in the quiz in the order they appear in the selection box here, unless randomization settings are applied.', 
    256241            'required' => 1, 
    257             'conditional_logic' => 0, 
    258         ), 
    259         array ( 
    260             'default_value' => 0, 
    261             'message' => '', 
    262             'ui' => 0, 
    263             'ui_on_text' => '', 
    264             'ui_off_text' => '', 
     242            'filters' => array ( 
     243                0 => 'search', 
     244            ), 
     245        ), 
     246        array ( 
     247            'default_value' => 0, 
     248            'message' => '', 
    265249            'key' => 'field_58851018ab8aa', 
    266250            'label' => 'Show points', 
    267251            'name' => 'qmqu_show_points', 
    268252            'type' => 'true_false', 
    269             'instructions' => '', 
    270             'required' => 0, 
    271             'conditional_logic' => 0, 
    272             'wrapper' => array ( 
    273                 'width' => '', 
    274                 'class' => '', 
    275                 'id' => '', 
    276             ), 
    277253        ), 
    278254        array ( 
  • quizmaster/trunk/lib/helper/QuizMaster_Helper_Admin.php

    r1719320 r1719957  
    1717        add_filter('manage_quizmaster_score_posts_custom_column', array( get_class(), 'score_column_content' ), 10, 2); 
    1818        add_filter('manage_edit-quizmaster_score_sortable_columns', array( get_class(), 'score_sortable_column' )); 
     19 
     20        /* ACF Save Hooks to Associate Quiz Questions */ 
     21        add_action( quizmaster_get_fields_prefix() . '/save_post', array( get_class(), 'quiz_associate_questions'), 5 ); 
     22        add_action( quizmaster_get_fields_prefix() . '/save_post', array( get_class(), 'question_associate_quizzes'), 5 ); 
     23 
     24 
     25    } 
     26 
     27 
     28    public function question_associate_quizzes( $postId ) { 
     29 
     30        // bail early if no ACF data 
     31    if( 'quizmaster_question' != get_post_type( $postId ) || empty($_POST[ quizmaster_get_fields_prefix() ]) ) { 
     32      return; 
     33    } 
     34 
     35        // data setup 
     36        $questionId = $postId; 
     37        $newQuizzes = $_POST[ quizmaster_get_fields_prefix() ][ QUIZMASTER_QUESTION_QUIZ_SELECTOR_FIELD ]; 
     38        $currentQuizzes = get_field( QUIZMASTER_QUESTION_QUIZ_SELECTOR_FIELD, $questionId ); 
     39        $quizQuestion = new QuizMaster_Model_QuizQuestion; 
     40 
     41        // nothing to do if old and new are both empty 
     42        if( empty($newQuizzes) && empty($currentQuizzes)) { 
     43            return; 
     44        } 
     45 
     46        // disassociate questions removed from quiz question list 
     47        if( !empty( $currentQuizzes )) { 
     48 
     49            if( empty( $newQuizzes )) { 
     50                $quizzesRemoved = $currentQuizzes; 
     51            } else { 
     52                $quizzesRemoved = array_diff( $currentQuizzes, $newQuizzes ); 
     53            } 
     54 
     55            if( !empty( $quizzesRemoved )) { 
     56                foreach( $quizzesRemoved as $quizId ) { 
     57                    $quizQuestion->clearAssociatedQuestionsFromQuiz( $quizId, $questionId ); 
     58                } 
     59            } 
     60 
     61        } 
     62 
     63        // associate quizzes added to the quiz tab from question editor 
     64        if( !empty( $newQuizzes )) { 
     65 
     66            if( empty( $currentQuizzes )) { 
     67                $quizzesAdded = $newQuizzes; 
     68            } else { 
     69                $quizzesAdded = array_diff( $newQuizzes, $currentQuizzes ); 
     70            } 
     71 
     72            if( !empty( $quizzesAdded )) { 
     73                foreach( $quizzesAdded as $quizId ) { 
     74                    $quizQuestion->associateQuestionFromQuiz( $quizId, $questionId ); 
     75                } 
     76            } 
     77 
     78        } 
     79 
     80    } 
     81 
     82 
     83    public function quiz_associate_questions( $postId ) { 
     84 
     85        // bail early if no ACF data 
     86    if( 'quizmaster_quiz' != get_post_type( $postId ) || empty($_POST[ quizmaster_get_fields_prefix() ]) ) { 
     87      return; 
     88    } 
     89 
     90        // data setup 
     91        $quizId = $postId; 
     92        $newQuestions = $_POST[ quizmaster_get_fields_prefix() ][ QUIZMASTER_QUIZ_QUESTION_SELECTOR_FIELD ]; 
     93        $currentQuestions = get_field( QUIZMASTER_QUIZ_QUESTION_SELECTOR_FIELD, $quizId ); 
     94        $quizQuestion = new QuizMaster_Model_QuizQuestion; 
     95 
     96        if( empty($newQuestions) && empty($currentQuestions)) { 
     97            return; // nothing to do 
     98        } 
     99 
     100        // disassociate questions removed from quiz question list 
     101        if( !empty( $currentQuestions )) { 
     102 
     103            if( !empty( $newQuestions )) { 
     104                $questionsRemoved = array_diff( $currentQuestions, $newQuestions ); 
     105            } else { 
     106                $questionsRemoved = $currentQuestions; 
     107            } 
     108 
     109            foreach( $questionsRemoved as $questionId ) { 
     110                $quizQuestion->clearAssociatedQuizzesFromQuestion( $questionId, $quizId ); 
     111            } 
     112 
     113        } 
     114 
     115        if( !empty( $newQuestions )) { 
     116 
     117            // associate questions added to quiz question list 
     118            if( !empty( $currentQuestions )) { 
     119                $questionsAdded = array_diff( $newQuestions, $currentQuestions ); 
     120            } else { 
     121                $questionsAdded = $newQuestions; 
     122            } 
     123 
     124            if( !empty( $questionsAdded )) { 
     125 
     126                foreach( $questionsAdded as $questionId ) { 
     127                    $quizQuestion->associateQuizFromQuestion( $quizId, $questionId ); 
     128                } 
     129 
     130            } 
     131 
     132        } 
    19133 
    20134    } 
  • quizmaster/trunk/lib/model/QuizMaster_Model_Question.php

    r1717342 r1719957  
    397397        } 
    398398 
     399        public static function isAssociatedQuiz( $quizId ) { 
     400 
     401            $quiz = new QuizMaster_Model_Quiz( $quizId ); 
     402            $questions = $questionMapper->fetchAll( $quizId ); 
     403            if( in_array( $this->getId(), $questions )) { 
     404                return true; 
     405            } 
     406            return false; 
     407 
     408        } 
     409 
    399410    public function fieldGroupKey() { 
    400411      return 'question'; 
  • quizmaster/trunk/lib/model/QuizMaster_Model_QuestionMapper.php

    r1719136 r1719957  
    2626 
    2727  public static function questionTypeById( $id ) { 
     28 
    2829    $qType = get_field( self::QUESTION_TYPE_FIELD, $id ); 
    2930 
     
    4344      'free_answer'   => 'QuizMaster_Question_Free', 
    4445      'sort_answer'   => 'QuizMaster_Question_Sorting', 
    45       'fill_blank'  => 'QuizMaster_Question_FillBlank', 
     46      'fill_blank'      => 'QuizMaster_Question_FillBlank', 
    4647    ); 
    4748 
     
    6566  public function fetchAll( $quizId ) { 
    6667 
    67     $a = array(); 
     68    $questions = array(); 
    6869 
    6970        $quiz = new QuizMaster_Model_Quiz( $quizId ); 
    7071 
    71     $quizQuestions = get_field( QUIZMASTER_QUESTION_SELECTOR_FIELD, $quizId ); 
     72    $quizQuestions = get_field( QUIZMASTER_QUIZ_QUESTION_SELECTOR_FIELD, $quizId ); 
    7273 
    7374    if( empty($quizQuestions)) { 
     
    7576    } 
    7677 
    77     foreach( $quizQuestions as $qq ) { 
    78       $qId = $qq[ QUIZMASTER_QUESTION_REFERENCE_FIELD ]; 
    79       $a[] = $this->fetch( $qId ); 
    80     } 
     78        foreach( $quizQuestions as $questionId ) { 
     79            $questions[] = $this->fetch( $questionId ); 
     80        } 
    8181 
    82     return $a; 
     82    return $questions; 
    8383  } 
    8484 
  • quizmaster/trunk/lib/model/QuizMaster_Model_QuizQuestion.php

    r1663661 r1719957  
    2020        } 
    2121 
    22         // QUIZMASTER_QUESTION_REFERENCE_FIELD 
     22        // adds question to end of quiz 
     23        $questions = get_field( QUIZMASTER_QUIZ_QUESTION_SELECTOR_FIELD, $quizId ); 
     24        $questions[] = $questionId; 
     25        update_field( QUIZMASTER_QUIZ_QUESTION_SELECTOR_FIELD, $questions, $quizId ); 
    2326 
    24         // adds question to end of quiz 
    25         $questionRow = array( 
    26             QUIZMASTER_QUESTION_REFERENCE_FIELD => $questionId 
    27         ); 
    28         add_row( QUIZMASTER_QUESTION_SELECTOR_FIELD, $questionRow, $quizId ); 
    29         $existingQuestions = get_field( QUIZMASTER_QUESTION_SELECTOR_FIELD, $quizId ); 
     27        // adds quiz to list of selected quizzes associated from question editor 
     28        $quizzes = get_field( QUIZMASTER_QUIZ_QUESTION_SELECTOR_FIELD, $questionId ); 
     29        $quizzes[] = $quizId; 
     30        update_field( QUIZMASTER_QUIZ_QUESTION_SELECTOR_FIELD, $quizzes, $questionId ); 
     31 
     32    } 
     33 
     34    public function clearAssociatedQuizzesFromQuestion( $questionId, $quizId = false ) { 
     35 
     36        if( $quizId == false ) { 
     37            update_field( QUIZMASTER_QUESTION_QUIZ_SELECTOR_FIELD, array(), $questionId ); 
     38        } else { 
     39            // selective approach: remove one quiz 
     40            $quizzes = get_field( QUIZMASTER_QUESTION_QUIZ_SELECTOR_FIELD, $questionId ); 
     41            if( ( $key = array_search( $quizId, $quizzes )) !== false ) { 
     42                unset($quizzes[$key]); 
     43            } 
     44            update_field( QUIZMASTER_QUESTION_QUIZ_SELECTOR_FIELD, $quizzes, $questionId ); 
     45        } 
     46 
     47    } 
     48 
     49    /* 
     50     * Remove one or more questions from the given quiz 
     51     */ 
     52    public function clearAssociatedQuestionsFromQuiz( $quizId, $questionId = false ) { 
     53 
     54        if( $questionId == false ) { 
     55            update_field( QUIZMASTER_QUIZ_QUESTION_SELECTOR_FIELD, array(), $quizId ); 
     56        } else { 
     57 
     58            // selective approach: remove one quiz 
     59            $questions = get_field( QUIZMASTER_QUIZ_QUESTION_SELECTOR_FIELD, $quizId ); 
     60            if( ( $key = array_search( $questionId, $questions )) !== false ) { 
     61                unset($questions[$key]); 
     62            } 
     63            update_field( QUIZMASTER_QUIZ_QUESTION_SELECTOR_FIELD, $questions, $quizId ); 
     64 
     65        } 
     66 
     67    } 
     68 
     69    /* 
     70   * Associate question from quiz 
     71   * Quiz selected from quiz tab on question editor 
     72     */ 
     73    public static function associateQuestionFromQuiz( $quiz, $question ) { 
     74 
     75        if ( $quiz instanceof QuizMaster_Model_Quiz ) { 
     76          $quizId = $quiz->getId(); 
     77        } else { 
     78            $quizId = $quiz; 
     79        } 
     80 
     81        if ( $question instanceof QuizMaster_Model_Question ) { 
     82          $questionId = $question->getId(); 
     83        } else { 
     84            $questionId = $question; 
     85        } 
     86 
     87        // adds question to quiz 
     88        $questions = get_field( QUIZMASTER_QUIZ_QUESTION_SELECTOR_FIELD, $quizId ); 
     89        if( !in_array( $questionId, $questions )) { 
     90            $questions[] = $questionId; 
     91            update_field( QUIZMASTER_QUIZ_QUESTION_SELECTOR_FIELD, $questions, $quizId ); 
     92        } 
     93 
     94    } 
     95 
     96    public static function associateQuizFromQuestion( $quiz, $question ) { 
     97 
     98        if ( $quiz instanceof QuizMaster_Model_Quiz ) { 
     99          $quizId = $quiz->getId(); 
     100        } else { 
     101            $quizId = $quiz; 
     102        } 
     103 
     104        if ( $question instanceof QuizMaster_Model_Question ) { 
     105          $questionId = $question->getId(); 
     106        } else { 
     107            $questionId = $question; 
     108        } 
     109 
     110        // adds quiz to list of selected quizzes associated from question editor 
     111        $quizzes = get_field( QUIZMASTER_QUESTION_QUIZ_SELECTOR_FIELD, $questionId ); 
     112        if( !in_array( $quizId, $quizzes )) { 
     113            $quizzes[] = $quizId; 
     114            update_field( QUIZMASTER_QUESTION_QUIZ_SELECTOR_FIELD, $quizzes, $questionId ); 
     115        } 
    30116 
    31117    } 
  • quizmaster/trunk/quizmaster.php

    r1719320 r1719957  
    44Plugin URI: http://wordpress.org/extend/plugins/quizmaster 
    55Description: Best free quiz plugin for WordPress. 
    6 Version: 0.7.4 
     6Version: 0.8.0 
    77Author: GoldHat Group 
    88Author URI: https://goldhat.ca 
     
    1212*/ 
    1313 
    14 define('QUIZMASTER_VERSION', '0.7.4'); 
     14define('QUIZMASTER_VERSION', '0.8.0'); 
    1515define('QUIZMASTER_DEV', true); 
    1616define('QUIZMASTER_PATH', dirname(__FILE__)); 
     
    2121 
    2222define('QUIZMASTER_ANSWER_TYPE_FIELD', 'qmqe_answer_type'); 
    23 define('QUIZMASTER_QUESTION_SELECTOR_FIELD', 'qmqu_questions'); 
    24 define('QUIZMASTER_QUESTION_REFERENCE_FIELD', 'qmqu_question'); 
     23define('QUIZMASTER_QUIZ_QUESTION_SELECTOR_FIELD', 'qmqu_questions'); 
     24define('QUIZMASTER_QUESTION_QUIZ_SELECTOR_FIELD', 'qmqe_quizzes'); 
    2525 
    2626$uploadDir = wp_upload_dir(); 
     
    702702 * Setup Admin Columns, Filters 
    703703 */ 
    704 QuizMaster_Helper_Admin::init(); 
     704if( is_admin() ) { 
     705    add_action('init', 'setup_admin_helper'); 
     706} 
     707 
     708function setup_admin_helper() { 
     709    QuizMaster_Helper_Admin::init(); 
     710 
     711} 
    705712 
    706713/* Quiz Scores Filters */ 
  • quizmaster/trunk/readme.txt

    r1719320 r1719957  
    55Requires at least: 4.0 
    66Tested up to: 4.3 
    7 Stable tag: 0.7.4 
     7Stable tag: 0.8.0 
    88License: GPLv2 or later 
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html 
     
    5353== Changelog == 
    5454 
     55= 0.8.0 = 
     56 
     57Adds bidirectional quiz/question management, the ability to add a question to a quiz from the question editor. Improved selection field for adding questions from the quiz editor.  
     58 
    5559= 0.7.3 = 
    5660 
Note: See TracChangeset for help on using the changeset viewer.