freescout-restricted-customers/Entities/Email.php

45 lines
1,010 B
PHP
Raw Normal View History

<?php
/*
SPDX-License-Identifier: AGPL-3.0-only
SPDX-FileCopyrightText: © 2024 Millions Missing FRANCE <info@millionsmissing.fr>
*/
2024-07-10 15:26:43 +00:00
namespace Modules\MMFRestrictedCustomers\Entities;
use App\Email as BaseEmail;
class Email extends BaseEmail {
/**
* Check if an Email already exists for a given Mailbox.
*
* @param Mailbox $mailbox
* @param string $email
*
* @return bool
*/
public static function alreadyExistsInMailbox($mailbox, $email) {
$emails_count = self
::whereHas('customer', function($query) use($mailbox) {
$query->where('mailbox_id', '=', $mailbox->id);
})
->where('email', $email)
->count();
return ( $emails_count != 0 );
}
/**
* Return a query limited to a specific Mailbox
*
* @param Mailbox $mailbox
*
* @return QueryBuilder
*/
public static function whereInMailbox($mailbox) {
$query = self
::whereHas('customer', function($query) use($mailbox) {
$query->where('mailbox_id', '=', $mailbox->id);
});
return $query;
}
}