2020-05-12 11:56:30 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2020-05-12 11:56:30 +02:00
|
|
|
*
|
|
|
|
* @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)
|
2020-05-12 11:56:30 +02:00
|
|
|
*
|
2021-06-16 08:58:16 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2020-05-12 11:56:30 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Utils;
|
|
|
|
|
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class EmailStats.
|
|
|
|
*/
|
|
|
|
class EmailStats
|
|
|
|
{
|
2024-01-14 05:05:00 +01:00
|
|
|
public const EMAIL = 'email_';
|
2020-05-12 11:56:30 +02:00
|
|
|
|
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Increments the counter for emails sent
|
|
|
|
* for a company.
|
2020-05-12 11:56:30 +02:00
|
|
|
* @param string $company_key The company key
|
2020-09-06 11:38:10 +02:00
|
|
|
* @return void
|
2020-05-12 11:56:30 +02:00
|
|
|
*/
|
|
|
|
public static function inc($company_key)
|
|
|
|
{
|
2023-04-22 01:18:52 +02:00
|
|
|
Cache::increment("email_quota".self::EMAIL.$company_key);
|
2020-05-12 11:56:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Returns the email sent count.
|
|
|
|
*
|
2020-05-12 11:56:30 +02:00
|
|
|
* @param string $company_key The company key
|
|
|
|
* @return int The number email sent so far 'today'
|
|
|
|
*/
|
|
|
|
public static function count($company_key)
|
|
|
|
{
|
2020-09-06 11:38:10 +02:00
|
|
|
return Cache::get(self::EMAIL.$company_key);
|
2020-05-12 11:56:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Clears the cache for the emails sent.
|
|
|
|
*
|
2020-05-12 11:56:30 +02:00
|
|
|
* @param string $company_key The company key
|
2020-09-06 11:38:10 +02:00
|
|
|
* @return void
|
2020-05-12 11:56:30 +02:00
|
|
|
*/
|
|
|
|
public static function clear($company_key)
|
|
|
|
{
|
2020-09-06 11:38:10 +02:00
|
|
|
Cache::forget(self::EMAIL.$company_key);
|
2020-05-12 11:56:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Iterates through a list of companies
|
2020-09-06 11:38:10 +02:00
|
|
|
* and flushes the email sent data.
|
|
|
|
*
|
2023-08-06 04:34:41 +02:00
|
|
|
* @param \Illuminate\Database\Eloquent\Collection<\App\Models\Company> $companies The company key
|
2020-09-06 11:38:10 +02:00
|
|
|
* @return void
|
2020-05-12 11:56:30 +02:00
|
|
|
*/
|
|
|
|
public static function clearCompanies($companies)
|
|
|
|
{
|
|
|
|
$companies->each(function ($company) {
|
2023-08-07 10:57:25 +02:00
|
|
|
/** @var \App\Models\Company $company */
|
2020-05-12 11:56:30 +02:00
|
|
|
self::clear($company->company_key);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|