Files
laravel-backend/app/Services/CourseNotificationService.php
Joris Slagter df155bb13d
Some checks failed
continuous-integration/drone/push Build is failing
Initial Laravel API import
- Complete GGZ Ecademy Laravel backend application
- RESTful API for learning products, members, filters
- Authentication and authorization system
- Database migrations and seeders
- Custom CRUD generator commands
- Email notification system
- Integration with frontend applications
2025-12-02 17:40:21 +01:00

83 lines
2.1 KiB
PHP

<?php
namespace App\Services;
use Carbon\Carbon;
use App\Repositories\CourseNotification;
class CourseNotificationService
{
private $coursenotificationRepository;
public function __construct(CourseNotification $coursenotificationRepository)
{
$this->coursenotificationRepository = $coursenotificationRepository;
}
public function save(array $data)
{
$time = explode(':', $data['time']);
$hours = $time[0];
$minutes = $time[1];
$data['date'] = Carbon::parse($data['date'])
->copy()
->addHours($hours)
->addMinutes($minutes);
if (isset($data['id'])) {
$coursenotification = $this->coursenotificationRepository->findOrFail($data['id']);
$coursenotification->update($data);
} else {
$coursenotification = $this->coursenotificationRepository->create($data);
}
return $coursenotification;
}
public function delete($id)
{
$coursenotification = $this->coursenotificationRepository->findOrFail($id);
$coursenotification->delete();
}
public function get($id)
{
return $this->coursenotificationRepository->findOrFail($id);
}
public function getAll()
{
return $this->coursenotificationRepository->all();
}
public function getNotExpired()
{
return $this->coursenotificationRepository->NotExpired()->get();
}
public function getExpiredToSendWithProducts()
{
return $this->coursenotificationRepository
->with(['learning_product'])
->Expired()
->NotSent()
->get();
}
public function getExpiringToSend()
{
return $this->coursenotificationRepository->ExpireInFiveMinutes()->NotSent()->get();
}
public function with(array $children)
{
return $this->coursenotificationRepository->with($children)->get();
}
public function getOneWith($id, array $children)
{
return $this->coursenotificationRepository->with($children)->findOrFail($id);
}
}