first change

This commit is contained in:
2025-07-27 17:40:56 +05:45
commit f8b9a6725b
3152 changed files with 229528 additions and 0 deletions

View File

@@ -0,0 +1,178 @@
<?php
namespace Modules\Reminder\Http\Controllers;
use App\Http\Controllers\Controller;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Mail;
use Modules\Employee\Models\Employee;
use Modules\Employee\Interfaces\EmployeeInterface;
use Modules\Reminder\Models\Reminder;
use Modules\Template\Emails\SendMail;
use Modules\Template\Repositories\TemplateRepository;
class ReminderController extends Controller
{
private $employee;
/**
* Display a listing of the resource.
*/
public function __construct(
EmployeeInterface $employee,
) {
$this->employee = $employee;
}
/**
* Display a listing of the resource.
*/
public function index()
{
$data['title'] = 'Reminder Lists';
$reminders = Reminder::all()->map(function ($reminder) {
$reminder->assignedEmployees = collect($reminder->members['ids'] ?? [])
->map(function ($id) {
return $this->employee->getEmployeeById($id);
})
->filter();
return $reminder;
});
if (auth()->user()->hasRole('employee')) {
$userId = auth()->user()->employee_id;
$reminders = $reminders->filter(function ($reminder) use ($userId) {
$memberIds = collect($reminder->members['ids'] ?? []);
return $reminder->createdBy == $userId || $memberIds->contains($userId);
});
}
$data['reminderLists'] = $reminders;
return view('reminder::reminder.index', $data);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
$data['title'] = 'Create Reminder';
$data['editable'] = false;
$data['employeeList'] = $this->employee->pluck(1);
return view('reminder::reminder.create', $data);
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
$inputData = $request->except('_token');
$inputData['createdBy'] = Auth::user()->id;
if (auth()->user()->hasRole('employee')) {
$inputData['createdBy'] = auth()->user()->employee_id;
}
$reminderDateTime = Carbon::createFromFormat('Y-m-d H:i', $inputData['reminder_date'] . ' ' . $inputData['reminder_time'], config('app.timezone'));
if ($reminderDateTime->isPast()) {
flash()->error('The reminder date and time must be in the future.');
return back()->withInput();
}
$uploadedFiles = [];
if ($request->hasFile('files')) {
$files = $request->file('files');
if (is_array($files)) {
foreach ($files as $file) {
$uploadedFiles[] = uploadImage($file, 'uploads/reminders/files');
}
} else {
$uploadedFiles[] = uploadImage($files, 'uploads/reminders/files');
}
}
$inputData['files'] = $uploadedFiles;
$reminder = Reminder::create($inputData);
if (config('app.send_mail')) {
$templateModel = (new TemplateRepository())->where(['alias' => 'reminder-template'])->first();
$message = $templateModel->message;
$message = str_replace('#image', asset('storage/' . setting('logo_pic')), $message);
$message = str_replace('#reminder_title', $reminder->title, $message);
$message = str_replace('#reminder_desc', $reminder->description, $message);
$message = str_replace('#reminder_date', Carbon::parse($reminder->reminder_date)->format('d M, Y'), $message);
$message = str_replace('#reminder_time', Carbon::parse($reminder->reminder_time)->format('h:i A'), $message);
$members = $reminder->members ?? [];
foreach ($members as $memberId) {
$employee = $this->employee->getEmployeeById($memberId);
$data = [
'subject' => "New Reminder Assigned: $reminder->title",
'body' => $message,
];
$mail = new SendMail($data);
if (!empty($uploadedFiles)) {
foreach ($uploadedFiles as $filePath) {
$mail->attach(storage_path('app/' . $filePath), [
'as' => basename($filePath),
'mime' => mime_content_type(storage_path('app/' . $filePath))
]);
}
}
Mail::to($employee->email)->send($mail);
}
}
flash()->success('Reminder created successfully!');
return to_route('reminder.index');
}
/**
* Show the specified resource.
*/
public function show(Reminder $reminder)
{
$data['title'] = 'Show Reminder';
$data['reminder'] = $reminder;
return view('reminder::reminder.show', $data);
}
/**
* Remove the specified resource from storage.
*/
public function destroy(Reminder $reminder)
{
$originalFiles = json_decode($reminder->getRawOriginal('files'));
if (!empty($originalFiles) && is_array($originalFiles)) {
foreach ($originalFiles as $filePath) {
removeFileFromStorage($filePath);
}
}
$reminder->delete();
return response()->json([
'success' => true,
'message' => 'Reminder deleted successfully!'
]);
}
}

View File

@@ -0,0 +1,37 @@
<?php
namespace Modules\Reminder\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Modules\Employee\Models\Employee;
use Modules\Reminder\Database\Factories\ReminderFactory;
class Reminder extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*/
protected $fillable = [
'title',
'members',
'files',
'reminder_date',
'reminder_time',
'createdBy',
'description',
];
/**
* The attributes that should be cast to native types.
*/
protected $casts = [
'members' => 'array',
'files' => 'array',
'reminder_date' => 'date',
'reminder_time' => 'datetime',
];
}

View File

View File

@@ -0,0 +1,32 @@
<?php
namespace Modules\Reminder\Providers;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
class EventServiceProvider extends ServiceProvider
{
/**
* The event handler mappings for the application.
*
* @var array<string, array<int, string>>
*/
protected $listen = [];
/**
* Indicates if events should be discovered.
*
* @var bool
*/
protected static $shouldDiscoverEvents = true;
/**
* Configure the proper event listeners for email verification.
*
* @return void
*/
protected function configureEmailVerification(): void
{
}
}

View File

@@ -0,0 +1,120 @@
<?php
namespace Modules\Reminder\Providers;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
class ReminderServiceProvider extends ServiceProvider
{
protected string $moduleName = 'Reminder';
protected string $moduleNameLower = 'reminder';
/**
* Boot the application events.
*/
public function boot(): void
{
$this->registerCommands();
$this->registerCommandSchedules();
$this->registerTranslations();
$this->registerConfig();
$this->registerViews();
$this->loadMigrationsFrom(module_path($this->moduleName, 'database/migrations'));
}
/**
* Register the service provider.
*/
public function register(): void
{
$this->app->register(EventServiceProvider::class);
$this->app->register(RouteServiceProvider::class);
}
/**
* Register commands in the format of Command::class
*/
protected function registerCommands(): void
{
// $this->commands([]);
}
/**
* Register command Schedules.
*/
protected function registerCommandSchedules(): void
{
// $this->app->booted(function () {
// $schedule = $this->app->make(Schedule::class);
// $schedule->command('inspire')->hourly();
// });
}
/**
* Register translations.
*/
public function registerTranslations(): void
{
$langPath = resource_path('lang/modules/'.$this->moduleNameLower);
if (is_dir($langPath)) {
$this->loadTranslationsFrom($langPath, $this->moduleNameLower);
$this->loadJsonTranslationsFrom($langPath);
} else {
$this->loadTranslationsFrom(module_path($this->moduleName, 'lang'), $this->moduleNameLower);
$this->loadJsonTranslationsFrom(module_path($this->moduleName, 'lang'));
}
}
/**
* Register config.
*/
protected function registerConfig(): void
{
$this->publishes([module_path($this->moduleName, 'config/config.php') => config_path($this->moduleNameLower.'.php')], 'config');
$this->mergeConfigFrom(module_path($this->moduleName, 'config/config.php'), $this->moduleNameLower);
}
/**
* Register views.
*/
public function registerViews(): void
{
$viewPath = resource_path('views/modules/'.$this->moduleNameLower);
$sourcePath = module_path($this->moduleName, 'resources/views');
$this->publishes([$sourcePath => $viewPath], ['views', $this->moduleNameLower.'-module-views']);
$this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower);
$componentNamespace = str_replace('/', '\\', config('modules.namespace').'\\'.$this->moduleName.'\\'.ltrim(config('modules.paths.generator.component-class.path'), config('modules.paths.app_folder', '')));
Blade::componentNamespace($componentNamespace, $this->moduleNameLower);
}
/**
* Get the services provided by the provider.
*
* @return array<string>
*/
public function provides(): array
{
return [];
}
/**
* @return array<string>
*/
private function getPublishableViewPaths(): array
{
$paths = [];
foreach (config('view.paths') as $path) {
if (is_dir($path.'/modules/'.$this->moduleNameLower)) {
$paths[] = $path.'/modules/'.$this->moduleNameLower;
}
}
return $paths;
}
}

View File

@@ -0,0 +1,49 @@
<?php
namespace Modules\Reminder\Providers;
use Illuminate\Support\Facades\Route;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
class RouteServiceProvider extends ServiceProvider
{
/**
* Called before routes are registered.
*
* Register any model bindings or pattern based filters.
*/
public function boot(): void
{
parent::boot();
}
/**
* Define the routes for the application.
*/
public function map(): void
{
$this->mapApiRoutes();
$this->mapWebRoutes();
}
/**
* Define the "web" routes for the application.
*
* These routes all receive session state, CSRF protection, etc.
*/
protected function mapWebRoutes(): void
{
Route::middleware('web')->group(module_path('Reminder', '/routes/web.php'));
}
/**
* Define the "api" routes for the application.
*
* These routes are typically stateless.
*/
protected function mapApiRoutes(): void
{
Route::middleware('api')->prefix('api')->name('api.')->group(module_path('Reminder', '/routes/api.php'));
}
}