| 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 course write tools. |
| 11 |
*/ |
| 12 |
class CourseSchemas { |
| 13 |
|
| 14 |
/** |
| 15 |
* Shared course writable field schemas. |
| 16 |
* |
| 17 |
* @return array |
| 18 |
*/ |
| 19 |
protected static function fields(): array { |
| 20 |
return array( |
| 21 |
'description' => Schemas::string(), |
| 22 |
'excerpt' => Schemas::string(), |
| 23 |
'status' => Schemas::status(), |
| 24 |
'instructor_id' => Schemas::id(), |
| 25 |
'category_ids' => Schemas::id_array(), |
| 26 |
'tag_ids' => Schemas::id_array(), |
| 27 |
'price' => Schemas::number( 0 ), |
| 28 |
'sale_price' => Schemas::number( 0 ), |
| 29 |
'duration' => Schemas::string(), |
| 30 |
'level' => Schemas::string(), |
| 31 |
'featured_image_id' => Schemas::id(), |
| 32 |
'requirements' => Schemas::string_array(), |
| 33 |
'target_audiences' => Schemas::string_array(), |
| 34 |
'features' => Schemas::string_array(), |
| 35 |
'faqs' => array( |
| 36 |
'type' => 'array', |
| 37 |
'items' => Schemas::object( |
| 38 |
array( |
| 39 |
'question' => Schemas::string(), |
| 40 |
'answer' => Schemas::string(), |
| 41 |
) |
| 42 |
), |
| 43 |
), |
| 44 |
); |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* create-course input. |
| 49 |
* |
| 50 |
* @return array |
| 51 |
*/ |
| 52 |
public static function create_input(): array { |
| 53 |
$properties = array_merge( |
| 54 |
array( 'title' => Schemas::string() ), |
| 55 |
self::fields() |
| 56 |
); |
| 57 |
|
| 58 |
return Schemas::object( $properties, array( 'title' ) ); |
| 59 |
} |
| 60 |
|
| 61 |
/** |
| 62 |
* update-course input. |
| 63 |
* |
| 64 |
* @return array |
| 65 |
*/ |
| 66 |
public static function update_input(): array { |
| 67 |
$properties = array_merge( |
| 68 |
array( |
| 69 |
'course_id' => Schemas::id(), |
| 70 |
'title' => Schemas::string(), |
| 71 |
), |
| 72 |
self::fields() |
| 73 |
); |
| 74 |
|
| 75 |
return Schemas::object( $properties, array( 'course_id' ) ); |
| 76 |
} |
| 77 |
|
| 78 |
/** |
| 79 |
* delete-course input. |
| 80 |
* |
| 81 |
* @return array |
| 82 |
*/ |
| 83 |
public static function delete_input(): array { |
| 84 |
return Schemas::object( |
| 85 |
array( 'course_id' => Schemas::id() ), |
| 86 |
array( 'course_id' ) |
| 87 |
); |
| 88 |
} |
| 89 |
|
| 90 |
/** |
| 91 |
* Write output wrapped under "course". |
| 92 |
* |
| 93 |
* @return array |
| 94 |
*/ |
| 95 |
public static function write_output(): array { |
| 96 |
return Schemas::object_output( 'course' ); |
| 97 |
} |
| 98 |
|
| 99 |
/** |
| 100 |
* delete-course output. |
| 101 |
* |
| 102 |
* @return array |
| 103 |
*/ |
| 104 |
public static function delete_output(): array { |
| 105 |
return Schemas::object( |
| 106 |
array( |
| 107 |
'trashed' => Schemas::boolean(), |
| 108 |
'course_id' => Schemas::integer(), |
| 109 |
'previous_status' => Schemas::string(), |
| 110 |
'recovery' => array( 'type' => 'object' ), |
| 111 |
), |
| 112 |
array( 'trashed', 'course_id' ) |
| 113 |
); |
| 114 |
} |
| 115 |
|
| 116 |
/** |
| 117 |
* get-courses input (read). |
| 118 |
* |
| 119 |
* @return array |
| 120 |
*/ |
| 121 |
public static function get_courses_input(): array { |
| 122 |
return array( |
| 123 |
'type' => 'object', |
| 124 |
'additionalProperties' => false, |
| 125 |
'properties' => array( |
| 126 |
'status' => array( 'type' => array( 'string', 'array', 'null' ) ), |
| 127 |
'category' => array( |
| 128 |
'type' => 'integer', |
| 129 |
'minimum' => 1, |
| 130 |
), |
| 131 |
'instructor' => array( |
| 132 |
'type' => 'integer', |
| 133 |
'minimum' => 1, |
| 134 |
), |
| 135 |
'price_min' => array( |
| 136 |
'type' => 'number', |
| 137 |
'minimum' => 0, |
| 138 |
), |
| 139 |
'price_max' => array( |
| 140 |
'type' => 'number', |
| 141 |
'minimum' => 0, |
| 142 |
), |
| 143 |
'search' => array( 'type' => 'string' ), |
| 144 |
'page' => array( |
| 145 |
'type' => 'integer', |
| 146 |
'minimum' => 1, |
| 147 |
'default' => 1, |
| 148 |
), |
| 149 |
'per_page' => array( |
| 150 |
'type' => 'integer', |
| 151 |
'minimum' => 1, |
| 152 |
'maximum' => 100, |
| 153 |
'default' => 10, |
| 154 |
), |
| 155 |
), |
| 156 |
'default' => array(), |
| 157 |
); |
| 158 |
} |
| 159 |
|
| 160 |
/** |
| 161 |
* Course list-item summary schema (read). |
| 162 |
* |
| 163 |
* @return array |
| 164 |
*/ |
| 165 |
public static function course_summary(): array { |
| 166 |
return array( |
| 167 |
'type' => 'object', |
| 168 |
'properties' => array( |
| 169 |
'course_id' => array( 'type' => 'integer' ), |
| 170 |
'title' => array( 'type' => 'string' ), |
| 171 |
'status' => array( 'type' => 'string' ), |
| 172 |
'price' => array( 'type' => 'number' ), |
| 173 |
'duration' => array( 'type' => 'string' ), |
| 174 |
'permalink' => array( 'type' => 'string' ), |
| 175 |
'instructor' => array( 'type' => 'object' ), |
| 176 |
'categories' => array( 'type' => 'array' ), |
| 177 |
), |
| 178 |
); |
| 179 |
} |
| 180 |
} |
| 181 |
|