84 lines
2 KiB
PHP
84 lines
2 KiB
PHP
<?php
|
|
|
|
namespace App\Policies\Rules;
|
|
|
|
use App\Enums\TicketStatus;
|
|
use App\Models\Ticket;
|
|
use Kwaadpepper\CrudPolicies\Policies\Rules\StaticRules;
|
|
|
|
/**
|
|
* Ticket Policiy Static Rules
|
|
* ! Rules has to return boolean value
|
|
*/
|
|
abstract class TicketStaticRules extends StaticRules
|
|
{
|
|
/**
|
|
* Ticket is not in production
|
|
*
|
|
* @param \App\Models\Ticket $ticket
|
|
* @return boolean
|
|
*/
|
|
protected static function ticketIsNotInProduction(Ticket $ticket): bool
|
|
{
|
|
return !$ticket->status->equals(TicketStatus::production());
|
|
}
|
|
|
|
/**
|
|
* Ticket is not archived
|
|
*
|
|
* @param \App\Models\Ticket $ticket
|
|
* @return boolean
|
|
*/
|
|
protected static function ticketIsNotArchived(Ticket $ticket): bool
|
|
{
|
|
return !$ticket->status->equals(TicketStatus::archived());
|
|
}
|
|
|
|
/**
|
|
* Ticket has brand which has at least one account
|
|
*
|
|
* @param \App\Models\Ticket $ticket
|
|
* @return boolean
|
|
*/
|
|
protected static function ticketsBrandHasAnAccount(Ticket $ticket): bool
|
|
{
|
|
/** @var \App\Models\Brand|null */
|
|
if (!($brand = $ticket->site->brand)) {
|
|
return false;
|
|
}
|
|
return (bool)$brand->accounts()->count();
|
|
}
|
|
|
|
/**
|
|
* Ticket does already have an estimation
|
|
*
|
|
* @param \App\Models\Ticket $ticket
|
|
* @return boolean
|
|
*/
|
|
protected static function ticketDoesHaveEstimation(Ticket $ticket): bool
|
|
{
|
|
return $ticket->estimation()->exists();
|
|
}
|
|
|
|
/**
|
|
* Ticket does not already have an estimation
|
|
*
|
|
* @param \App\Models\Ticket $ticket
|
|
* @return boolean
|
|
*/
|
|
protected static function ticketDoesntHaveEstimation(Ticket $ticket): bool
|
|
{
|
|
return !$ticket->estimation()->exists();
|
|
}
|
|
|
|
/**
|
|
* Ticket is not internal
|
|
*
|
|
* @param \App\Models\Ticket $ticket
|
|
* @return boolean
|
|
*/
|
|
protected static function ticketIsNotInternal(Ticket $ticket): bool
|
|
{
|
|
return !(bool)$ticket->is_internal;
|
|
}
|
|
}
|