DONE: layout letter with letterhead and footer, notification for newly...
This commit is contained in:
@@ -1,209 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use App\Services\ContactService;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ContactController extends Controller
|
||||
{
|
||||
protected $contactService;
|
||||
|
||||
public function __construct(ContactService $contactService)
|
||||
{
|
||||
$this->contactService = $contactService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all active contact persons
|
||||
*/
|
||||
public function getContacts(): JsonResponse
|
||||
{
|
||||
try {
|
||||
$contacts = $this->contactService->getActiveContacts();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $contacts,
|
||||
'message' => 'Contact persons retrieved successfully'
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Failed to retrieve contact persons',
|
||||
'error' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get contact settings for admin (including inactive)
|
||||
*/
|
||||
public function getContactSettings(): JsonResponse
|
||||
{
|
||||
try {
|
||||
$settings = $this->contactService->getAllContactSettings();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $settings,
|
||||
'message' => 'Contact settings retrieved successfully'
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Failed to retrieve contact settings',
|
||||
'error' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update contact settings (Admin only)
|
||||
*/
|
||||
public function updateContacts(Request $request): JsonResponse
|
||||
{
|
||||
$request->validate([
|
||||
'contacts' => 'required|array',
|
||||
'contacts.*.name' => 'required|string|max:100',
|
||||
'contacts.*.position' => 'nullable|string|max:100',
|
||||
'contacts.*.email' => 'nullable|email|max:255',
|
||||
'contacts.*.phone' => 'nullable|string|max:50',
|
||||
'contacts.*.department' => 'nullable|string|max:100',
|
||||
'contacts.*.is_active' => 'boolean',
|
||||
'contacts.*.sort_order' => 'integer|min:0'
|
||||
]);
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
$result = $this->contactService->updateContactSettings($request->contacts);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $result,
|
||||
'message' => 'Contact settings updated successfully'
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Failed to update contact settings',
|
||||
'error' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new contact person (Admin only)
|
||||
*/
|
||||
public function addContact(Request $request): JsonResponse
|
||||
{
|
||||
$request->validate([
|
||||
'name' => 'required|string|max:100',
|
||||
'position' => 'nullable|string|max:100',
|
||||
'email' => 'nullable|email|max:255',
|
||||
'phone' => 'nullable|string|max:50',
|
||||
'department' => 'nullable|string|max:100',
|
||||
'is_active' => 'boolean',
|
||||
'sort_order' => 'integer|min:0'
|
||||
]);
|
||||
|
||||
try {
|
||||
$result = $this->contactService->addContactPerson($request->all());
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $result,
|
||||
'message' => 'Contact person added successfully'
|
||||
], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Failed to add contact person',
|
||||
'error' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a specific contact person (Admin only)
|
||||
*/
|
||||
public function updateContact(Request $request, int $id): JsonResponse
|
||||
{
|
||||
$request->validate([
|
||||
'name' => 'required|string|max:100',
|
||||
'position' => 'nullable|string|max:100',
|
||||
'email' => 'nullable|email|max:255',
|
||||
'phone' => 'nullable|string|max:50',
|
||||
'department' => 'nullable|string|max:100',
|
||||
'is_active' => 'boolean',
|
||||
'sort_order' => 'integer|min:0'
|
||||
]);
|
||||
|
||||
try {
|
||||
$result = $this->contactService->updateContactPerson($id, $request->all());
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $result,
|
||||
'message' => 'Contact person updated successfully'
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Failed to update contact person',
|
||||
'error' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a contact person (Admin only)
|
||||
*/
|
||||
public function deleteContact(int $id): JsonResponse
|
||||
{
|
||||
try {
|
||||
$result = $this->contactService->deleteContactPerson($id);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $result,
|
||||
'message' => 'Contact person deleted successfully'
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Failed to delete contact person',
|
||||
'error' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle active status of a contact person (Admin only)
|
||||
*/
|
||||
public function toggleContact(int $id): JsonResponse
|
||||
{
|
||||
try {
|
||||
$result = $this->contactService->toggleContactPerson($id);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $result,
|
||||
'message' => 'Contact person status toggled successfully'
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Failed to toggle contact person status',
|
||||
'error' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Country;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
class CountryController extends Controller
|
||||
{
|
||||
public function index(): JsonResponse
|
||||
{
|
||||
$countries = Country::all();
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $countries,
|
||||
'message' => 'Countries fetched successfully',
|
||||
]);
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $countries,
|
||||
'message' => 'Countries fetched successfully',
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Services\LetterService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class LetterPreviewController extends Controller
|
||||
{
|
||||
public function __construct(protected LetterService $letterService) {}
|
||||
|
||||
/**
|
||||
* Preview the base letter layout with sample content in the browser.
|
||||
*
|
||||
* GET /letters/preview?format=html|pdf
|
||||
*/
|
||||
public function show(Request $request): Response
|
||||
{
|
||||
if (! app()->environment('local', 'development')) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
$view = 'pdf.preview';
|
||||
$format = $request->query('format', 'html');
|
||||
|
||||
if ($format === 'pdf') {
|
||||
return $this->letterService->pdfResponse($view, [], 'letter-preview.pdf');
|
||||
}
|
||||
|
||||
return $this->letterService->htmlResponse($view);
|
||||
}
|
||||
|
||||
public function showMembershipApprovedLetter(Request $request): Response
|
||||
{
|
||||
if (! app()->environment('local', 'development')) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
$view = 'pdf.preview-approved-membership';
|
||||
$format = $request->query('format', 'html');
|
||||
|
||||
if ($format === 'pdf') {
|
||||
return $this->letterService->pdfResponse($view, [], 'letter-preview-approved-membership.pdf');
|
||||
}
|
||||
|
||||
return $this->letterService->htmlResponse($view);
|
||||
}
|
||||
}
|
||||
@@ -1,183 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Services\OnlineUsersService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class OnlineUsersController extends Controller
|
||||
{
|
||||
protected OnlineUsersService $onlineUsersService;
|
||||
|
||||
public function __construct(OnlineUsersService $onlineUsersService)
|
||||
{
|
||||
$this->onlineUsersService = $onlineUsersService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of online users
|
||||
*
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
try {
|
||||
$timeoutMinutes = 5; // Fixed to 5 minutes
|
||||
|
||||
$onlineUsers = $this->onlineUsersService->getOnlineUsers($timeoutMinutes);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $onlineUsers,
|
||||
'meta' => [
|
||||
'timeout_minutes' => $timeoutMinutes,
|
||||
'total_online' => $onlineUsers->count(),
|
||||
'timestamp' => now()->toISOString()
|
||||
],
|
||||
'message' => 'Online users retrieved successfully.'
|
||||
]);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Error fetching online users: ' . $e->getMessage());
|
||||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Failed to retrieve online users.',
|
||||
'error' => config('app.debug') ? $e->getMessage() : 'Internal server error'
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get online users count
|
||||
*
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function count(Request $request): JsonResponse
|
||||
{
|
||||
try {
|
||||
$timeoutMinutes = 5; // Fixed to 5 minutes
|
||||
|
||||
$count = $this->onlineUsersService->getOnlineUsersCount($timeoutMinutes);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => [
|
||||
'count' => $count,
|
||||
'timeout_minutes' => $timeoutMinutes
|
||||
],
|
||||
'message' => 'Online users count retrieved successfully.'
|
||||
]);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Error fetching online users count: ' . $e->getMessage());
|
||||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Failed to retrieve online users count.',
|
||||
'error' => config('app.debug') ? $e->getMessage() : 'Internal server error'
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get online users statistics
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function stats(): JsonResponse
|
||||
{
|
||||
try {
|
||||
$stats = $this->onlineUsersService->getOnlineUsersStats();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $stats,
|
||||
'message' => 'Online users statistics retrieved successfully.'
|
||||
]);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Error fetching online users stats: ' . $e->getMessage());
|
||||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Failed to retrieve online users statistics.',
|
||||
'error' => config('app.debug') ? $e->getMessage() : 'Internal server error'
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current user's session information
|
||||
*
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function mySession(Request $request): JsonResponse
|
||||
{
|
||||
try {
|
||||
$user = $request->user();
|
||||
|
||||
if (!$user) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'User not authenticated.'
|
||||
], 401);
|
||||
}
|
||||
|
||||
$sessionInfo = $this->onlineUsersService->getUserSessionInfo($user->id);
|
||||
|
||||
if (!$sessionInfo) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'No active session found.'
|
||||
], 404);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $sessionInfo,
|
||||
'message' => 'Session information retrieved successfully.'
|
||||
]);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Error fetching user session info: ' . $e->getMessage());
|
||||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Failed to retrieve session information.',
|
||||
'error' => config('app.debug') ? $e->getMessage() : 'Internal server error'
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear online users cache (admin only)
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function clearCache(): JsonResponse
|
||||
{
|
||||
try {
|
||||
$this->onlineUsersService->clearCache();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Online users cache cleared successfully.'
|
||||
]);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Error clearing online users cache: ' . $e->getMessage());
|
||||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Failed to clear cache.',
|
||||
'error' => config('app.debug') ? $e->getMessage() : 'Internal server error'
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,206 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use App\Services\SocialMediaService;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class SocialMediaController extends Controller
|
||||
{
|
||||
protected $socialMediaService;
|
||||
|
||||
public function __construct(SocialMediaService $socialMediaService)
|
||||
{
|
||||
$this->socialMediaService = $socialMediaService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all active social media platforms
|
||||
*/
|
||||
public function getSocialMedia(): JsonResponse
|
||||
{
|
||||
try {
|
||||
$socialMedia = $this->socialMediaService->getActiveSocialMedia();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $socialMedia,
|
||||
'message' => 'Social media platforms retrieved successfully'
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Failed to retrieve social media platforms',
|
||||
'error' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update social media settings (Admin only)
|
||||
*/
|
||||
public function updateSocialMedia(Request $request): JsonResponse
|
||||
{
|
||||
$request->validate([
|
||||
'social_media' => 'required|array',
|
||||
'social_media.*.platform' => 'required|string|max:50',
|
||||
'social_media.*.name' => 'required|string|max:100',
|
||||
'social_media.*.url' => 'required|url|max:255',
|
||||
'social_media.*.icon' => 'nullable|string|max:100',
|
||||
'social_media.*.is_active' => 'boolean',
|
||||
'social_media.*.sort_order' => 'integer|min:0'
|
||||
]);
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
$result = $this->socialMediaService->updateSocialMediaSettings($request->social_media);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $result,
|
||||
'message' => 'Social media settings updated successfully'
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Failed to update social media settings',
|
||||
'error' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get social media settings for admin (including inactive)
|
||||
*/
|
||||
public function getSocialMediaSettings(): JsonResponse
|
||||
{
|
||||
try {
|
||||
$settings = $this->socialMediaService->getAllSocialMediaSettings();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $settings,
|
||||
'message' => 'Social media settings retrieved successfully'
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Failed to retrieve social media settings',
|
||||
'error' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new social media platform (Admin only)
|
||||
*/
|
||||
public function addSocialMedia(Request $request): JsonResponse
|
||||
{
|
||||
$request->validate([
|
||||
'platform' => 'required|string|max:50',
|
||||
'name' => 'required|string|max:100',
|
||||
'url' => 'required|url|max:255',
|
||||
'icon' => 'nullable|string|max:100',
|
||||
'is_active' => 'boolean',
|
||||
'sort_order' => 'integer|min:0'
|
||||
]);
|
||||
|
||||
try {
|
||||
$result = $this->socialMediaService->addSocialMediaPlatform($request->all());
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $result,
|
||||
'message' => 'Social media platform added successfully'
|
||||
], 201);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Failed to add social media platform',
|
||||
'error' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a specific social media platform (Admin only)
|
||||
*/
|
||||
public function updateSocialMediaPlatform(Request $request, int $id): JsonResponse
|
||||
{
|
||||
$request->validate([
|
||||
'platform' => 'required|string|max:50',
|
||||
'name' => 'required|string|max:100',
|
||||
'url' => 'required|url|max:255',
|
||||
'icon' => 'nullable|string|max:100',
|
||||
'is_active' => 'boolean',
|
||||
'sort_order' => 'integer|min:0'
|
||||
]);
|
||||
|
||||
try {
|
||||
$result = $this->socialMediaService->updateSocialMediaPlatform($id, $request->all());
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $result,
|
||||
'message' => 'Social media platform updated successfully'
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Failed to update social media platform',
|
||||
'error' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a social media platform (Admin only)
|
||||
*/
|
||||
public function deleteSocialMediaPlatform(int $id): JsonResponse
|
||||
{
|
||||
try {
|
||||
$result = $this->socialMediaService->deleteSocialMediaPlatform($id);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $result,
|
||||
'message' => 'Social media platform deleted successfully'
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Failed to delete social media platform',
|
||||
'error' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle active status of a social media platform (Admin only)
|
||||
*/
|
||||
public function toggleSocialMediaPlatform(int $id): JsonResponse
|
||||
{
|
||||
try {
|
||||
$result = $this->socialMediaService->toggleSocialMediaPlatform($id);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $result,
|
||||
'message' => 'Social media platform status toggled successfully'
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Failed to toggle social media platform status',
|
||||
'error' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user