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
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Utils;
|
|
|
|
|
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class EmailStats.
|
|
|
|
*/
|
|
|
|
class EmailStats
|
|
|
|
{
|
|
|
|
const EMAIL = 'email_';
|
|
|
|
|
|
|
|
/**
|
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)
|
|
|
|
{
|
2020-09-06 11:38:10 +02:00
|
|
|
Cache::increment(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.
|
|
|
|
*
|
2020-11-01 06:09:09 +01:00
|
|
|
* @param Collection $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) {
|
|
|
|
self::clear($company->company_key);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|