Ejemplo n.º 1
0
 /**
  * (non-PHPdoc)
  * @see WPCW_quiz_base::renderForm_toString()
  */
 public function renderForm_toString($parentQuiz, $questionNum, $selectedAnswer, $showAsError, $errorToShow = false)
 {
     $this->answerList = array();
     $this->answerList[__('True', 'wp_courseware')] = 'true';
     $this->answerList[__('False', 'wp_courseware')] = 'false';
     return parent::renderForm_toString_withClass($parentQuiz, $questionNum, $selectedAnswer, $showAsError, 'wpcw_fe_quiz_q_truefalse', $errorToShow);
 }
 /**
  * Default constructor
  * @param Object $quizItem The quiz item details.
  */
 function __construct($quizItem)
 {
     parent::__construct($quizItem);
     $this->questionType = 'random_selection';
     $this->cssClasses = 'wpcw_question_type_random';
     // Hide usage
     $this->hideQuestionUsageCount = true;
 }
Ejemplo n.º 3
0
 /**
  * (non-PHPdoc)
  * @see WPCW_quiz_base::renderForm_toString()
  */
 function renderForm_toString($parentQuiz, $questionNum, $selectedAnswer, $showAsError, $errorToShow = false)
 {
     // Process all answers to give them an index. Count must be 1 indexed to avoid disappearing
     // due to 0 evaluating to false.
     if ($this->quizItem->question_data_answers) {
         // Extract answers into raw format.
         $this->answerListRaw = WPCW_quizzes_decodeAnswers($this->quizItem->question_data_answers);
         // If the user has requested the answers to be randomized, then use this. This function
         // with automatically check and handle the randomization and update $this->answerListRaw.
         $this->processAnswersWithRandomOption();
         // Got answers, so break up into a list of answer => value
         if ($this->answerListRaw) {
             $this->answerList = array();
             $this->answerImageList = array();
             foreach ($this->answerListRaw as $idx => $answerItem) {
                 $answerKey = 'ans_' . $idx;
                 // Reversing the answer value to key here..
                 $this->answerList[trim($answerItem['answer'])] = $answerKey;
                 // Store the image if we have one.
                 if (isset($answerItem['image'])) {
                     $this->answerImageList[$answerKey] = $answerItem['image'];
                 }
             }
         }
     }
     // end of answer check
     // Add the hint if there is one
     if ($this->quizItem->question_answer_hint) {
         $this->extraQuizHTMLAfter .= sprintf('<div class="wpcw_fe_quiz_q_hint">%s</div>', nl2br(htmlspecialchars($this->quizItem->question_answer_hint)));
     }
     // Handover to parent. All multiple choice answers are prefixed with 'ans_'.
     return parent::renderForm_toString_withClass($parentQuiz, $questionNum, 'ans_' . $selectedAnswer, $showAsError, 'wpcw_fe_quiz_q_multi', $errorToShow);
 }
Ejemplo n.º 4
0
 /**
  * (non-PHPdoc)
  * @see WPCW_quiz_base::renderForm_toString()
  */
 function renderForm_toString($parentQuiz, $questionNum, $selectedAnswer, $showAsError, $errorToShow = false)
 {
     $this->answerList = false;
     // Process all answers to give them an index. Count must be 1 indexed to avoid disappearing
     // due to 0 evaluating to false.
     $answerCount = 1;
     if ($this->quizItem->question_answers) {
         $this->answerListRaw = explode("\n", $this->quizItem->question_answers);
         // Got answers, so break up into a list of answer => value
         if ($this->answerListRaw) {
             $this->answerList = array();
             foreach ($this->answerListRaw as $answerItem) {
                 $this->answerList[trim($answerItem)] = 'ans_' . $answerCount++;
             }
         }
     }
     // end of answer check
     // Handover to parent. All multiple choice answers are prefixed with 'ans_'.
     return parent::renderForm_toString_withClass($parentQuiz, $questionNum, 'ans_' . $selectedAnswer, $showAsError, 'wpcw_fe_quiz_q_multi', $errorToShow);
 }
Ejemplo n.º 5
0
 /**
  * (non-PHPdoc)
  * @see WPCW_quiz_base::renderForm_toString()
  */
 public function renderForm_toString($parentQuiz, $questionNum, $selectedAnswer, $showAsError, $errorToShow = false)
 {
     // Generate the ID of the field, also used for the CSS ID
     $fieldID = sprintf('question_%d_%s_%d', $parentQuiz->quiz_id, $this->questionType, $this->quizItem->question_id);
     // Set CSS wrapper to type of answer.
     $cssClass = $this->quizItem->question_answer_type;
     // Add the open-entry field, based on what field type has been asked for.
     switch ($this->quizItem->question_answer_type) {
         case 'single_line':
             $this->extraQuizHTML .= sprintf('<input type="text" name="%s" id="%s" value="%s"/>', $fieldID, $fieldID, $selectedAnswer);
             break;
         case 'medium_textarea':
             $this->extraQuizHTML .= sprintf('<textarea name="%s" id="%s" rows="8">%s</textarea>', $fieldID, $fieldID, $selectedAnswer);
             break;
         case 'large_textarea':
             $this->extraQuizHTML .= sprintf('<textarea name="%s" id="%s" rows="15">%s</textarea>', $fieldID, $fieldID, $selectedAnswer);
             break;
             // case 'small_textarea':
         // case 'small_textarea':
         default:
             $cssClass = 'small_textarea';
             // Just in case it's different to what we expect for the answer type.
             $this->extraQuizHTML .= sprintf('<textarea name="%s" id="%s" rows="4">%s</textarea>', $fieldID, $fieldID, $selectedAnswer);
             break;
     }
     // Add the hint if there is one
     if ($this->quizItem->question_answer_hint) {
         $this->extraQuizHTML .= sprintf('<div class="wpcw_fe_quiz_q_hint">%s</div>', $this->quizItem->question_answer_hint);
     }
     return parent::renderForm_toString_withClass($parentQuiz, $questionNum, $selectedAnswer, $showAsError, 'wpcw_fe_quiz_q_open wpcw_fe_quiz_q_open_' . $cssClass, $errorToShow);
 }
Ejemplo n.º 6
0
 /**
  * (non-PHPdoc)
  * @see WPCW_quiz_base::renderForm_toString()
  */
 public function renderForm_toString($parentQuiz, $questionNum, $selectedAnswer, $showAsError, $errorToShow = false)
 {
     // Generate the ID of the field, also used for the CSS ID
     $fieldID = sprintf('question_%d_%s_%d', $parentQuiz->quiz_id, $this->questionType, $this->quizItem->question_id);
     // The file upload bit.
     $this->extraQuizHTML .= sprintf('<div class="wpcw_fe_quiz_q_upload_wrapper" id="%s">', $fieldID);
     $this->extraQuizHTML .= sprintf('<input type="file" name="%s" >', $fieldID);
     $this->extraQuizHTML .= '</div>';
     // Work out what file types are permitted
     $fileTypes = WPCW_files_cleanFileExtensionList($this->quizItem->question_answer_file_types);
     $permittedFiles = false;
     if (!empty($fileTypes)) {
         // Show message about permitted file types, which can be customised if needed.
         $permittedFiles = apply_filters('wpcw_front_quiz_upload_permitted_files', __('Allowed file types: ', 'wp_courseware') . implode(', ', $fileTypes) . '. ', $fileTypes);
     }
     // Add the hint if there is one
     if ($this->quizItem->question_answer_hint) {
         $this->extraQuizHTML .= sprintf('<div class="wpcw_fe_quiz_q_hint">%s</div>', $this->quizItem->question_answer_hint);
     }
     // Add the file type list if there are any
     if ($permittedFiles) {
         $this->extraQuizHTML .= sprintf('<div class="wpcw_fe_quiz_q_hint wpcw_fe_quiz_q_upload_permitted_files">%s</div>', $permittedFiles);
     }
     return parent::renderForm_toString_withClass($parentQuiz, $questionNum, $selectedAnswer, $showAsError, 'wpcw_fe_quiz_q_upload', $errorToShow);
 }
 /**
  * (non-PHPdoc)
  * @see WPCW_quiz_base::renderForm_toString()
  */
 public function renderForm_toString($parentQuiz, $questionNum, $selectedAnswer, $showAsError, $errorToShow = false)
 {
     $this->answerList = array();
     $this->answerList[__('True', 'wp_courseware')] = 'true';
     $this->answerList[__('False', 'wp_courseware')] = 'false';
     // Add the hint if there is one
     if ($this->quizItem->question_answer_hint) {
         $this->extraQuizHTMLAfter .= sprintf('<div class="wpcw_fe_quiz_q_hint">%s</div>', $this->quizItem->question_answer_hint);
     }
     return parent::renderForm_toString_withClass($parentQuiz, $questionNum, $selectedAnswer, $showAsError, 'wpcw_fe_quiz_q_truefalse', $errorToShow);
 }
    /**
     * (non-PHPdoc)
     * @see WPCW_quiz_base::renderForm_toString()
     */
    public function renderForm_toString($parentQuiz, $questionNum, $selectedAnswer, $showAsError, $errorToShow = false)
    {
        // Generate the ID of the field, also used for the CSS ID
        $fieldID = sprintf('question_%d_%s_%d', $parentQuiz->quiz_id, $this->questionType, $this->quizItem->question_id);
        // Have they already uploaded a file? If so, tell them with a link to open the file.
        if ($selectedAnswer) {
            // Shows the link for the existing file.
            $this->extraQuizHTML .= sprintf('<div class="wpcw_fe_quiz_q_upload_existing">
												%s <b><a href="%s%s" target="_blank">.%s %s (%s)</a></b> %s 
											 </div>', __('You have uploaded a', 'wp_courseware'), WP_CONTENT_URL, $selectedAnswer, pathinfo($selectedAnswer, PATHINFO_EXTENSION), __('file', 'wp_courseware'), WPCW_files_getFileSize_human($selectedAnswer), __('for this answer.', 'wp_courseware'));
            // Shows the link to change the file
            $this->extraQuizHTML .= sprintf('<div class="wpcw_fe_quiz_q_upload_change_file_wrap">
												<a href="#" class="wpcw_fe_quiz_q_upload_change_file" data-fieldid="%s">%s</a>
												<a href="#" class="wpcw_fe_quiz_q_upload_change_file_cancel">%s</a>
												<div class="wpcw_fe_quiz_q_upload_change_holder"></div>
											</div>', $fieldID, __('Click here to upload a different file...', 'wp_courseware'), __('Cancel uploading a different file', 'wp_courseware'));
        } else {
            // The file upload bit.
            $this->extraQuizHTML .= sprintf('<div class="wpcw_fe_quiz_q_upload_wrapper" id="%s">', $fieldID);
            $this->extraQuizHTML .= sprintf('<input type="file" name="%s" >', $fieldID);
            $this->extraQuizHTML .= '</div>';
        }
        // Work out what file types are permitted
        $fileTypes = WPCW_files_cleanFileExtensionList($this->quizItem->question_answer_file_types);
        $permittedFiles = false;
        if (!empty($fileTypes)) {
            // Show message about permitted file types, which can be customised if needed.
            $permittedFiles = apply_filters('wpcw_front_quiz_upload_permitted_files', __('Allowed file types: ', 'wp_courseware') . implode(', ', $fileTypes) . '. ', $fileTypes);
        }
        // Add the hint if there is one
        if ($this->quizItem->question_answer_hint) {
            $this->extraQuizHTML .= sprintf('<div class="wpcw_fe_quiz_q_hint">%s</div>', $this->quizItem->question_answer_hint);
        }
        // Add the file type list if there are any
        if ($permittedFiles) {
            $this->extraQuizHTML .= sprintf('<div class="wpcw_fe_quiz_q_hint wpcw_fe_quiz_q_upload_permitted_files">%s</div>', $permittedFiles);
        }
        return parent::renderForm_toString_withClass($parentQuiz, $questionNum, $selectedAnswer, $showAsError, 'wpcw_fe_quiz_q_upload', $errorToShow);
    }