1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 07:02:34 +01:00
invoiceninja/app/Utils/EmailStats.php

71 lines
1.7 KiB
PHP
Raw Normal View History

<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2023-01-28 23:21:40 +01:00
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
*
2021-06-16 08:58:16 +02:00
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Utils;
use Illuminate\Support\Facades\Cache;
/**
* Class EmailStats.
*/
class EmailStats
{
const EMAIL = 'email_';
/**
* Increments the counter for emails sent
* for a company.
* @param string $company_key The company key
* @return void
*/
public static function inc($company_key)
{
2023-04-22 01:18:52 +02:00
Cache::increment("email_quota".self::EMAIL.$company_key);
}
/**
* Returns the email sent count.
*
* @param string $company_key The company key
* @return int The number email sent so far 'today'
*/
public static function count($company_key)
{
return Cache::get(self::EMAIL.$company_key);
}
/**
* Clears the cache for the emails sent.
*
* @param string $company_key The company key
* @return void
*/
public static function clear($company_key)
{
Cache::forget(self::EMAIL.$company_key);
}
/**
* Iterates through a list of companies
* 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
* @return void
*/
public static function clearCompanies($companies)
{
$companies->each(function ($company) {
2023-08-07 10:57:25 +02:00
/** @var \App\Models\Company $company */
self::clear($company->company_key);
});
}
}