freescout-restricted-customers/Entities/Email.php

46 lines
1.1 KiB
PHP

<?php
/*
SPDX-License-Identifier: AGPL-3.0-only
SPDX-FileCopyrightText: © 2024 Millions Missing FRANCE <info@millionsmissing.fr>
*/
namespace Modules\MMFRestrictedCustomers;
use Illuminate\Database\Eloquent\Model;
use Watson\Rememberable\Rememberable;
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;
}
}