2024-07-09 12:00:52 +00:00
|
|
|
<?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;
|
2024-07-09 12:00:52 +00:00
|
|
|
|
|
|
|
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 );
|
|
|
|
}
|
2024-07-09 12:38:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
2024-07-09 12:00:52 +00:00
|
|
|
}
|