office365 integration

This commit is contained in:
StudioTem committed 2025-03-17 09:54:13 +01:00
1 parent 264ca10078
commit e1712c8fcd
11 files changed
+551 -16

No files matched your search

@@ -0,0 +1,53 @@
<?php
namespace App\Console\Commands;
use App\Models\SubTask;
use App\Services\Office365\Office365Service;
use Illuminate\Console\Command;
class FinishOffice365Subtasks extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'office365:finish-subtasks';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Prida is_finished a timesheet subtaskom (eventom), ktore uz skoncili';
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$events = Office365Service::getCalendarEvents();
// vrati vsetky office365 subtasky z nasej DB, ktore maju is_finished = 0 a porovna to s eventami z office365. ak je nejaky end time v office365 v minulosti, tak vrati tento subtask
$subtasksThatFinished = SubTask::where('is_finished', 0)->get()->filter(function ($subtask) use ($events) {
$event = collect($events)->firstWhere('id', $subtask->office365_id);
if ( ! $event) {
return false;
}
return strtotime($event['end']['dateTime']) < time();
});
// ak neexistuju ziadne subtasky, ktore uz skoncili
if ($subtasksThatFinished->isEmpty()) {
return Command::SUCCESS;
}
Office365Service::finishSubtasks($subtasksThatFinished);
return Command::SUCCESS;
}
}