| @@ -1,50 +1,50 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | -namespace LearnPress\Models\Question; | |
| 4 | - | |
| 5 | -/** | |
| 6 | - * Class QuestionPostFIBModel | |
| 7 | - * Question type Fill in the Blank | |
| 8 | - * | |
| 9 | - * @package LearnPress/Classes | |
| 10 | - * @version 1.0.0 | |
| 11 | - * @since 4.2.9 | |
| 12 | - */ | |
| 13 | -class QuestionPostFIBModel extends QuestionPostModel { | |
| 14 | - public $question_type = 'fill_in_blanks'; | |
| 15 | - | |
| 16 | - /** | |
| 17 | - * Create default answers for question | |
| 18 | - * | |
| 19 | - * @return array[] | |
| 20 | - */ | |
| 21 | - public function get_default_answers(): array { | |
| 22 | - return array( | |
| 23 | - array( | |
| 24 | - 'value' => $this->random_value(), | |
| 25 | - 'title' => '', | |
| 26 | - ), | |
| 27 | - ); | |
| 28 | - } | |
| 29 | - | |
| 30 | - /** | |
| 31 | - * Convert content to format [fib fill="" id="" ] | |
| 32 | - * | |
| 33 | - * @param string $content | |
| 34 | - * | |
| 35 | - * @return string | |
| 36 | - */ | |
| 37 | - public function convert_content_from_editor_to_db( string $content ): string { | |
| 38 | - $pattern = '#<span class="lp-question-fib-input" data-id="([^"]+)">([^<]+)<\/span>#'; | |
| 39 | - | |
| 40 | - return preg_replace_callback( | |
| 41 | - $pattern, | |
| 42 | - function ( $matches ) { | |
| 43 | - $id = $matches[1]; | |
| 44 | - $fill = $matches[2]; | |
| 45 | - return '[fib fill="' . $fill . '" id="' . $id . '" ]'; | |
| 46 | - }, | |
| 47 | - $content | |
| 48 | - ); | |
| 49 | - } | |
| 50 | -} | |
| 1 | +<?php | |
| 2 | + | |
| 3 | +namespace LearnPress\Models\Question; | |
| 4 | + | |
| 5 | +/** | |
| 6 | + * Class QuestionPostFIBModel | |
| 7 | + * Question type Fill in the Blank | |
| 8 | + * | |
| 9 | + * @package LearnPress/Classes | |
| 10 | + * @version 1.0.0 | |
| 11 | + * @since 4.2.9 | |
| 12 | + */ | |
| 13 | +class QuestionPostFIBModel extends QuestionPostModel { | |
| 14 | + public $question_type = 'fill_in_blanks'; | |
| 15 | + | |
| 16 | + /** | |
| 17 | + * Create default answers for question | |
| 18 | + * | |
| 19 | + * @return array[] | |
| 20 | + */ | |
| 21 | + public function get_default_answers(): array { | |
| 22 | + return array( | |
| 23 | + array( | |
| 24 | + 'value' => $this->random_value(), | |
| 25 | + 'title' => '', | |
| 26 | + ), | |
| 27 | + ); | |
| 28 | + } | |
| 29 | + | |
| 30 | + /** | |
| 31 | + * Convert content to format [fib fill="" id="" ] | |
| 32 | + * | |
| 33 | + * @param string $content | |
| 34 | + * | |
| 35 | + * @return string | |
| 36 | + */ | |
| 37 | + public function convert_content_from_editor_to_db( string $content ): string { | |
| 38 | + $pattern = '#<span class="lp-question-fib-input" data-id="([^"]+)">([^<]+)<\/span>#'; | |
| 39 | + | |
| 40 | + return preg_replace_callback( | |
| 41 | + $pattern, | |
| 42 | + function ( $matches ) { | |
| 43 | + $id = $matches[1]; | |
| 44 | + $fill = $matches[2]; | |
| 45 | + return '[fib fill="' . $fill . '" id="' . $id . '" ]'; | |
| 46 | + }, | |
| 47 | + $content | |
| 48 | + ); | |
| 49 | + } | |
| 50 | +} | |