Files
alrahma_sunday_school_api/app/Http/Controllers/Api/PolicyController.php
T
2026-03-05 12:29:37 -05:00

88 lines
3.1 KiB
PHP
Executable File

<?php
namespace App\Http\Controllers\Api;
use Symfony\Component\HttpFoundation\Response;
class PolicyController extends BaseApiController
{
public function index()
{
return $this->success([], 'Policy index');
}
/**
* GET /api/v1/policy/picture
* Get school picture policy content
*/
public function schoolPicturePolicy()
{
$partialPath = base_path('resources/views/policy/picture_policy_partial.php');
$viewPath = base_path('resources/views/policy/picture_policy.blade.php');
if (!is_readable($partialPath)) {
return $this->respondError('Picture policy partial not found', Response::HTTP_NOT_FOUND);
}
try {
// Include the PHP partial file (may return data array or output HTML)
$content = include $partialPath;
// If partial returns an array, try to render the view with it
// Otherwise, use the content directly
if (is_array($content)) {
if (is_readable($viewPath)) {
$html = view('policy.picture_policy', $content)->render();
} else {
// Fallback: if view doesn't exist, return the content as-is
$html = is_string($content) ? $content : json_encode($content);
}
} else {
// Content is already HTML string
$html = (string) $content;
}
} catch (\Throwable $e) {
log_message('error', 'Picture policy load error: ' . $e->getMessage());
return $this->respondError('Failed to load picture policy', Response::HTTP_INTERNAL_SERVER_ERROR);
}
return $this->success(['html' => $html], 'Picture policy content retrieved');
}
/**
* GET /api/v1/policy/school
* Get school policy content
*/
public function schoolPolicy()
{
$metaPath = base_path('resources/views/policy/school_policy_partial.php');
$viewPath = base_path('resources/views/policy/school_policy.blade.php');
if (!is_readable($metaPath)) {
return $this->respondError('School policy partial not found', Response::HTTP_NOT_FOUND);
}
try {
// Include the PHP partial file (returns data array)
$content = include $metaPath;
$meta = is_array($content) ? $content : [];
// Render the Blade view with the meta data
if (is_readable($viewPath)) {
$html = view('policy.school_policy', $meta)->render();
} else {
// Fallback: if view doesn't exist, return meta as JSON
$html = json_encode($meta, JSON_PRETTY_PRINT);
}
} catch (\Throwable $e) {
log_message('error', 'School policy load error: ' . $e->getMessage());
return $this->respondError('Failed to load school policy', Response::HTTP_INTERNAL_SERVER_ERROR);
}
return $this->success([
'meta' => $meta,
'html' => $html,
], 'School policy content retrieved');
}
}