mirror of
https://bitbucket.org/studiotem/jandl-taskmanager-app.git
synced 2026-10-21 14:29:34 +00:00
office365 integration
This commit is contained in:
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\Blocker;
|
||||
use App\Models\Project;
|
||||
use App\Models\SubTask;
|
||||
use App\Services\Office365\Office365Service;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class SyncOffice365 extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'office365:sync';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Command description';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$events = Office365Service::getCalendarEvents();
|
||||
|
||||
// TODO: asi prerobit na CreateAndUpdate
|
||||
|
||||
// determine if event is blocker or subtask. if the first word in event name is project code, then it is subtask. otherwise it is blocker
|
||||
|
||||
// but first, remove "Canceled: " from the event name in case of canceled event
|
||||
$events = array_map(function ($event) {
|
||||
if ($event['isCancelled']) {
|
||||
$event['subject'] = str_replace('Canceled: ', '', $event['subject']);
|
||||
}
|
||||
|
||||
return $event;
|
||||
}, $events);
|
||||
|
||||
$blockers_from_office365 = array_filter($events, function ($event) {
|
||||
$projectCode = explode(' ', $event['subject'])[0];
|
||||
|
||||
// if project code doesnt exist in database, then it is blocker
|
||||
return ! Project::where('code', $projectCode)->exists();
|
||||
});
|
||||
|
||||
$subtasks = array_filter($events, function ($event) {
|
||||
$projectCode = explode(' ', $event['subject'])[0];
|
||||
|
||||
// if project code exist in database, then it is subtask
|
||||
return Project::where('code', $projectCode)->exists();
|
||||
});
|
||||
|
||||
// get only new events - the ones that doesnt have any office365_id in blockers table and only events that doesnt have isCancelled => true
|
||||
|
||||
$newBlockers = array_filter($blockers_from_office365, function ($event) {
|
||||
return ! Blocker::where('office365_id', $event['id'])->exists() && ! $event['isCancelled'];
|
||||
});
|
||||
|
||||
$newSubtasks = array_filter($subtasks, function ($event) {
|
||||
return ! SubTask::where('office365_id', $event['id'])->exists() && ! $event['isCancelled'];
|
||||
});
|
||||
|
||||
|
||||
Office365Service::addBlockers($newBlockers);
|
||||
Office365Service::addSubtasks($newSubtasks);
|
||||
|
||||
// get edited blockers - the ones, that has different changeKey from our database
|
||||
$editedBlockers = array_filter($blockers_from_office365, function ($event) {
|
||||
$blocker = Blocker::where('office365_id', $event['id'])->first();
|
||||
|
||||
return $blocker && $blocker->office365_change_key !== $event['changeKey'];
|
||||
});
|
||||
|
||||
Office365Service::editBlockers($editedBlockers);
|
||||
|
||||
// get all canceled blockers - the ones, that are in our database and in the response they have isCancelled => true
|
||||
$removedBlockers = Blocker::whereNotNull('office365_id')->get()->filter(function ($blocker) use (
|
||||
$blockers_from_office365
|
||||
) {
|
||||
$event = collect($blockers_from_office365)->firstWhere('id', $blocker->office365_id);
|
||||
|
||||
return $event && $event['isCancelled'];
|
||||
});
|
||||
|
||||
// TODO dat do service
|
||||
$removedBlockers->each(function ($blocker) {
|
||||
$blocker->delete();
|
||||
});
|
||||
|
||||
dd('he');
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user