Files
casadoc/public/userportal/api/sections.php
T
2026-07-27 21:04:07 +03:00

41 lines
1.2 KiB
PHP

<?php
require __DIR__ . '/_bootstrap.php';
/**
* @OA\Get(
* path="/sections.php",
* tags={"Documents"},
* summary="Home document sections",
* security={{"bearerAuth":{}}},
* @OA\Parameter(name="idhome", in="query", required=true, @OA\Schema(type="integer")),
* @OA\Parameter(name="slug", in="query", @OA\Schema(type="string", default="legal")),
* @OA\Response(response=200, description="OK", @OA\JsonContent(
* @OA\Property(property="data", type="array", @OA\Items(ref="#/components/schemas/Section"))
* )),
* @OA\Response(response=403, ref="#/components/responses/Forbidden")
* )
*/
require_method('GET');
$user = require_auth($pdo);
$idhome = (int) query('idhome', 0);
$slug = (string) query('slug', 'legal');
if ($idhome <= 0) {
json_error(422, 'idhome is required');
}
if (!user_can_access_home($pdo, $user, $idhome)) {
json_error(403, 'No access to this home');
}
$stmt = $pdo->prepare(
'SELECT DISTINCT s.idsections, s.section_name, s.description
FROM documents d
JOIN sections s ON s.idsections = d.idsections
JOIN pages p ON p.idpages = d.page_id
WHERE p.slug = ?
ORDER BY s.section_name'
);
$stmt->execute([$slug]);
json_data(array_map('present_section', $stmt->fetchAll()));