14f97dad3f
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q8t9GEyyLZbUQu26na1JQg
57 lines
2.8 KiB
PHP
57 lines
2.8 KiB
PHP
<?php
|
|
/**
|
|
* Batch 32 — Tutor LMS tools. Net-new, GPL-2.0-or-later. See NOTICE.md.
|
|
* Inert unless Tutor LMS (TUTOR_VERSION) is active. Courses are the 'courses' CPT.
|
|
*/
|
|
|
|
namespace AskTamMCP\Extensions;
|
|
|
|
defined('ABSPATH') || exit;
|
|
|
|
class Batch32 {
|
|
|
|
public static function register($registry): void {
|
|
if (!defined('TUTOR_VERSION')) return;
|
|
|
|
$def = function (string $name, string $desc, array $props, array $required, string $scope, string $method) {
|
|
$schema = ['type' => 'object', 'properties' => $props ?: new \stdClass()];
|
|
if ($required) $schema['required'] = $required;
|
|
return ['name' => $name, 'description' => $desc, 'scope' => $scope,
|
|
'handler' => 'AskTamMCP\\Extensions\\Batch32::' . $method, 'inputSchema' => $schema];
|
|
};
|
|
|
|
$registry->register($def('tutor_detect', 'Report whether Tutor LMS is active and its version.', [], [], 'read', 'detect'));
|
|
$registry->register($def('tutor_list_courses', 'List Tutor LMS courses (id, title, status).',
|
|
['per_page' => ['type' => 'integer', 'default' => 50]], [], 'read', 'listCourses'));
|
|
$registry->register($def('tutor_get_course', 'Get one Tutor course: title, price type, lesson count, and enrolled-student count.',
|
|
['course_id' => ['type' => 'integer']], ['course_id'], 'read', 'getCourse'));
|
|
}
|
|
|
|
public static function detect(array $args): array {
|
|
return ['active' => defined('TUTOR_VERSION'), 'version' => defined('TUTOR_VERSION') ? TUTOR_VERSION : null];
|
|
}
|
|
|
|
public static function listCourses(array $args): array {
|
|
$posts = get_posts(['post_type' => 'courses', 'post_status' => ['publish', 'draft', 'pending'],
|
|
'numberposts' => (int) ($args['per_page'] ?? 50), 'orderby' => 'title', 'order' => 'ASC']);
|
|
$out = [];
|
|
foreach ($posts as $p) $out[] = ['id' => $p->ID, 'title' => $p->post_title, 'status' => $p->post_status];
|
|
return ['count' => count($out), 'courses' => $out];
|
|
}
|
|
|
|
public static function getCourse(array $args): array {
|
|
$id = (int) ($args['course_id'] ?? 0);
|
|
$p = get_post($id);
|
|
if (!$p || $p->post_type !== 'courses') throw new \RuntimeException("Tutor course not found: {$id}");
|
|
$lessons = null; $students = null;
|
|
if (function_exists('tutor_utils')) {
|
|
$u = tutor_utils();
|
|
if (method_exists($u, 'get_lesson_count_by_course')) $lessons = (int) $u->get_lesson_count_by_course($id);
|
|
if (method_exists($u, 'count_enrolled_users_by_course')) $students = (int) $u->count_enrolled_users_by_course($id);
|
|
}
|
|
return ['id' => $id, 'title' => $p->post_title, 'status' => $p->post_status,
|
|
'price_type' => get_post_meta($id, '_tutor_course_price_type', true) ?: 'free',
|
|
'lessons' => $lessons, 'enrolled' => $students];
|
|
}
|
|
}
|