Batch35: Amelia booking tools (guarded, net-new)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q8t9GEyyLZbUQu26na1JQg
This commit is contained in:
@@ -0,0 +1,71 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Batch 35 — Amelia booking tools (reads the plugin's own tables via $wpdb).
|
||||||
|
* Net-new, GPL-2.0-or-later. See NOTICE.md. Inert unless Amelia (AMELIA_VERSION) is active.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace AskTamMCP\Extensions;
|
||||||
|
|
||||||
|
defined('ABSPATH') || exit;
|
||||||
|
|
||||||
|
class Batch35 {
|
||||||
|
|
||||||
|
public static function register($registry): void {
|
||||||
|
if (!defined('AMELIA_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\\Batch35::' . $method, 'inputSchema' => $schema];
|
||||||
|
};
|
||||||
|
|
||||||
|
$registry->register($def('amelia_detect', 'Report whether Amelia is active and its version.', [], [], 'read', 'detect'));
|
||||||
|
$registry->register($def('amelia_list_services', 'List Amelia services (id, name, price, duration).',
|
||||||
|
['per_page' => ['type' => 'integer', 'default' => 100]], [], 'read', 'listServices'));
|
||||||
|
$registry->register($def('amelia_list_appointments', 'List Amelia appointments (newest first): id, status, booking start.',
|
||||||
|
['per_page' => ['type' => 'integer', 'default' => 30]], [], 'read', 'listAppointments'));
|
||||||
|
$registry->register($def('amelia_list_employees', 'List Amelia employees/providers (id, name, email).', [], [], 'read', 'listEmployees'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function detect(array $args): array {
|
||||||
|
return ['active' => defined('AMELIA_VERSION'), 'version' => defined('AMELIA_VERSION') ? AMELIA_VERSION : null];
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function tableExists(string $t): bool {
|
||||||
|
global $wpdb;
|
||||||
|
return $wpdb->get_var($wpdb->prepare('SHOW TABLES LIKE %s', $t)) === $t;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function listServices(array $args): array {
|
||||||
|
global $wpdb;
|
||||||
|
$t = $wpdb->prefix . 'amelia_services';
|
||||||
|
if (!self::tableExists($t)) return ['supported' => false, 'note' => 'amelia_services table not found.', 'services' => []];
|
||||||
|
$per = max(1, (int) ($args['per_page'] ?? 100));
|
||||||
|
$rows = $wpdb->get_results($wpdb->prepare("SELECT id, name, price, duration, status FROM {$t} ORDER BY id DESC LIMIT %d", $per), ARRAY_A);
|
||||||
|
$out = [];
|
||||||
|
foreach ((array) $rows as $r) $out[] = ['id' => (int) $r['id'], 'name' => $r['name'], 'price' => $r['price'], 'duration' => (int) $r['duration'], 'status' => $r['status']];
|
||||||
|
return ['supported' => true, 'count' => count($out), 'services' => $out];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function listAppointments(array $args): array {
|
||||||
|
global $wpdb;
|
||||||
|
$t = $wpdb->prefix . 'amelia_appointments';
|
||||||
|
if (!self::tableExists($t)) return ['supported' => false, 'note' => 'amelia_appointments table not found.', 'appointments' => []];
|
||||||
|
$per = max(1, (int) ($args['per_page'] ?? 30));
|
||||||
|
$rows = $wpdb->get_results($wpdb->prepare("SELECT id, status, bookingStart FROM {$t} ORDER BY id DESC LIMIT %d", $per), ARRAY_A);
|
||||||
|
$out = [];
|
||||||
|
foreach ((array) $rows as $r) $out[] = ['id' => (int) $r['id'], 'status' => $r['status'], 'start' => $r['bookingStart']];
|
||||||
|
return ['supported' => true, 'count' => count($out), 'appointments' => $out];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function listEmployees(array $args): array {
|
||||||
|
global $wpdb;
|
||||||
|
$t = $wpdb->prefix . 'amelia_users';
|
||||||
|
if (!self::tableExists($t)) return ['supported' => false, 'note' => 'amelia_users table not found.', 'employees' => []];
|
||||||
|
$rows = $wpdb->get_results("SELECT id, firstName, lastName, email FROM {$t} WHERE type = 'provider' ORDER BY id ASC LIMIT 200", ARRAY_A);
|
||||||
|
$out = [];
|
||||||
|
foreach ((array) $rows as $r) $out[] = ['id' => (int) $r['id'], 'name' => trim(($r['firstName'] ?? '') . ' ' . ($r['lastName'] ?? '')), 'email' => $r['email'] ?? ''];
|
||||||
|
return ['supported' => true, 'count' => count($out), 'employees' => $out];
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user