1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 15:13:29 +01:00
invoiceninja/app/Http/Controllers/EmailHistoryController.php

70 lines
2.2 KiB
PHP
Raw Normal View History

2023-08-23 07:01:37 +02:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2024-04-12 06:15:41 +02:00
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
2023-08-23 07:01:37 +02:00
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Http\Controllers;
2023-08-23 07:02:32 +02:00
use App\Http\Requests\Email\ClientEmailHistoryRequest;
use App\Http\Requests\Email\EntityEmailHistoryRequest;
2023-08-23 07:01:37 +02:00
use App\Models\Client;
use App\Models\SystemLog;
use App\Utils\Traits\MakesHash;
class EmailHistoryController extends BaseController
{
use MakesHash;
public function __construct()
{
}
public function clientHistory(ClientEmailHistoryRequest $request, Client $client)
{
$data = SystemLog::where('client_id', $client->id)
->where('category_id', SystemLog::CATEGORY_MAIL)
2023-08-23 07:02:32 +02:00
->orderBy('id', 'DESC')
2023-08-23 09:13:46 +02:00
->cursor()
2023-10-17 04:39:36 +02:00
->filter(function ($system_log) {
2024-01-14 05:05:00 +01:00
return (isset($system_log->log['history']) && isset($system_log->log['history']['events']) && count($system_log->log['history']['events']) >= 1) !== false;
2023-10-26 04:57:44 +02:00
})->map(function ($system_log) {
2023-10-17 04:39:36 +02:00
return $system_log->log['history'];
})->values()->all();
2023-08-23 07:01:37 +02:00
return response()->json($data, 200);
}
2024-01-14 05:05:00 +01:00
2023-08-23 07:02:32 +02:00
/**
* May need to expand on this using
* just the message-id and search for the
* entity in the invitations
*/
2023-08-23 07:01:37 +02:00
public function entityHistory(EntityEmailHistoryRequest $request)
{
/** @var \App\Models\User $user */
$user = auth()->user();
2023-10-17 04:39:36 +02:00
2023-08-23 07:01:37 +02:00
$data = SystemLog::where('company_id', $user->company()->id)
2023-10-17 04:39:36 +02:00
->where('category_id', SystemLog::CATEGORY_MAIL)
->whereJsonContains('log->history->entity_id', $this->encodePrimaryKey($request->entity_id))
->orderBy('id', 'DESC')
->cursor()
->filter(function ($system_log) {
2024-01-14 05:05:00 +01:00
return ($system_log->log['history'] && isset($system_log->log['history']['events']) && count($system_log->log['history']['events']) >= 1) !== false;
2023-10-26 04:57:44 +02:00
})->map(function ($system_log) {
2023-10-17 04:39:36 +02:00
return $system_log->log['history'];
})->values()->all();
2023-08-23 07:01:37 +02:00
return response()->json($data, 200);
}
2023-08-23 07:02:32 +02:00
}