| 1 |
<?php |
| 2 |
|
| 3 |
namespace LearnPress\MCP\Schemas; |
| 4 |
|
| 5 |
use LearnPress\MCP\Support\Schemas; |
| 6 |
|
| 7 |
defined( 'ABSPATH' ) || exit; |
| 8 |
|
| 9 |
/** |
| 10 |
* Input/output schemas for quiz question write tools. |
| 11 |
*/ |
| 12 |
class QuestionSchemas { |
| 13 |
|
| 14 |
/** |
| 15 |
* Answer input schema (create/update). |
| 16 |
* |
| 17 |
* @return array |
| 18 |
*/ |
| 19 |
protected static function answer_input(): array { |
| 20 |
return Schemas::object( |
| 21 |
array( |
| 22 |
'answer_id' => Schemas::id(), |
| 23 |
'title' => Schemas::string(), |
| 24 |
'value' => Schemas::string(), |
| 25 |
'is_correct' => Schemas::boolean(), |
| 26 |
), |
| 27 |
array( 'title' ) |
| 28 |
); |
| 29 |
} |
| 30 |
|
| 31 |
/** |
| 32 |
* Answers array schema. |
| 33 |
* |
| 34 |
* @return array |
| 35 |
*/ |
| 36 |
protected static function answers(): array { |
| 37 |
return array( |
| 38 |
'type' => 'array', |
| 39 |
'items' => self::answer_input(), |
| 40 |
); |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* add-quiz-question input. |
| 45 |
* |
| 46 |
* @return array |
| 47 |
*/ |
| 48 |
public static function add_input(): array { |
| 49 |
return Schemas::object( |
| 50 |
array( |
| 51 |
'quiz_id' => Schemas::id(), |
| 52 |
'title' => Schemas::string(), |
| 53 |
'type' => Schemas::string(), |
| 54 |
'content' => Schemas::string(), |
| 55 |
'mark' => Schemas::number( 0 ), |
| 56 |
'order' => Schemas::integer( 1 ), |
| 57 |
'answers' => self::answers(), |
| 58 |
'explanation' => Schemas::string(), |
| 59 |
'hint' => Schemas::string(), |
| 60 |
), |
| 61 |
array( 'quiz_id', 'title', 'type' ) |
| 62 |
); |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* update-quiz-question input. |
| 67 |
* |
| 68 |
* @return array |
| 69 |
*/ |
| 70 |
public static function update_input(): array { |
| 71 |
return Schemas::object( |
| 72 |
array( |
| 73 |
'quiz_id' => Schemas::id(), |
| 74 |
'question_id' => Schemas::id(), |
| 75 |
'title' => Schemas::string(), |
| 76 |
'content' => Schemas::string(), |
| 77 |
'type' => Schemas::string(), |
| 78 |
'mark' => Schemas::number( 0 ), |
| 79 |
'order' => Schemas::integer( 1 ), |
| 80 |
'answers' => self::answers(), |
| 81 |
'explanation' => Schemas::string(), |
| 82 |
'hint' => Schemas::string(), |
| 83 |
), |
| 84 |
array( 'quiz_id', 'question_id' ) |
| 85 |
); |
| 86 |
} |
| 87 |
|
| 88 |
/** |
| 89 |
* delete-quiz-question input. |
| 90 |
* |
| 91 |
* @return array |
| 92 |
*/ |
| 93 |
public static function delete_input(): array { |
| 94 |
return Schemas::object( |
| 95 |
array( |
| 96 |
'quiz_id' => Schemas::id(), |
| 97 |
'question_id' => Schemas::id(), |
| 98 |
), |
| 99 |
array( 'quiz_id', 'question_id' ) |
| 100 |
); |
| 101 |
} |
| 102 |
|
| 103 |
/** |
| 104 |
* add-quiz-question output. |
| 105 |
* |
| 106 |
* @return array |
| 107 |
*/ |
| 108 |
public static function add_output(): array { |
| 109 |
return Schemas::object( |
| 110 |
array( |
| 111 |
'question_id' => Schemas::integer(), |
| 112 |
'quiz_id' => Schemas::integer(), |
| 113 |
'type' => Schemas::string(), |
| 114 |
'mark' => Schemas::number(), |
| 115 |
'answers_count' => Schemas::integer(), |
| 116 |
), |
| 117 |
array( 'question_id', 'quiz_id' ) |
| 118 |
); |
| 119 |
} |
| 120 |
|
| 121 |
/** |
| 122 |
* Write output wrapped under "question". |
| 123 |
* |
| 124 |
* @return array |
| 125 |
*/ |
| 126 |
public static function write_output(): array { |
| 127 |
return Schemas::object_output( 'question' ); |
| 128 |
} |
| 129 |
|
| 130 |
/** |
| 131 |
* delete-quiz-question output. |
| 132 |
* |
| 133 |
* @return array |
| 134 |
*/ |
| 135 |
public static function delete_output(): array { |
| 136 |
return Schemas::object( |
| 137 |
array( |
| 138 |
'removed' => Schemas::boolean(), |
| 139 |
'removed_from_quiz' => Schemas::boolean(), |
| 140 |
'question_id' => Schemas::integer(), |
| 141 |
'recovery' => array( 'type' => 'object' ), |
| 142 |
), |
| 143 |
array( 'removed', 'question_id' ) |
| 144 |
); |
| 145 |
} |
| 146 |
} |
| 147 |
|