Files

53 lines
2.6 KiB
PHP

<?php
/**
* Batch 31 — SureForms tools. Net-new, GPL-2.0-or-later. See NOTICE.md.
* Inert unless SureForms (SRFM_VER) is active. Forms are the sureforms_form CPT; entries the sureforms_entry CPT.
*/
namespace AskTamMCP\Extensions;
defined('ABSPATH') || exit;
class Batch31 {
public static function register($registry): void {
if (!defined('SRFM_VER')) 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\\Batch31::' . $method, 'inputSchema' => $schema];
};
$registry->register($def('sureforms_detect', 'Report whether SureForms is active and its version.', [], [], 'read', 'detect'));
$registry->register($def('sureforms_list_forms', 'List SureForms forms (id, title).',
['per_page' => ['type' => 'integer', 'default' => 100]], [], 'read', 'listForms'));
$registry->register($def('sureforms_list_entries', 'List SureForms entries (newest first): id, title, date.',
['per_page' => ['type' => 'integer', 'default' => 25]], [], 'read', 'listEntries'));
}
public static function detect(array $args): array {
return ['active' => defined('SRFM_VER'), 'version' => defined('SRFM_VER') ? SRFM_VER : null];
}
public static function listForms(array $args): array {
$posts = get_posts(['post_type' => 'sureforms_form', 'post_status' => 'publish',
'numberposts' => (int) ($args['per_page'] ?? 100), 'orderby' => 'title', 'order' => 'ASC']);
$out = [];
foreach ($posts as $p) $out[] = ['id' => $p->ID, 'title' => $p->post_title];
return ['count' => count($out), 'forms' => $out];
}
public static function listEntries(array $args): array {
if (!post_type_exists('sureforms_entry')) {
return ['supported' => false, 'note' => 'sureforms_entry post type not registered.', 'entries' => []];
}
$posts = get_posts(['post_type' => 'sureforms_entry', 'post_status' => 'any',
'numberposts' => (int) ($args['per_page'] ?? 25), 'orderby' => 'date', 'order' => 'DESC']);
$out = [];
foreach ($posts as $p) $out[] = ['id' => $p->ID, 'title' => $p->post_title, 'date' => $p->post_date];
return ['supported' => true, 'count' => count($out), 'entries' => $out];
}
}