<?php
declare(strict_types=1);
namespace App\Entity\User;
use App\Entity\Partner\Partner;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Sylius\Component\Core\Model\AdminUser as BaseAdminUser;
use Sylius\RbacPlugin\Entity\AdministrationRoleAwareInterface;
use Sylius\RbacPlugin\Entity\AdministrationRoleAwareTrait;
use Sylius\RbacPlugin\Entity\AdministrationRoleInterface;
/**
* @ORM\Entity
* @ORM\Table(name="sylius_admin_user")
*/
class AdminUser extends BaseAdminUser implements AdministrationRoleAwareInterface
{
use AdministrationRoleAwareTrait;
/**
* @var Partner
*
* @ORM\ManyToOne(targetEntity="App\Entity\Partner\Partner")
* @ORM\JoinColumn(name="partner_id", referencedColumnName="id")
*/
private $partner;
/**
* @var CustomRoleRule
*
* @ORM\ManyToOne(targetEntity="App\Entity\User\CustomRoleRule")
* @ORM\JoinColumn(name="custom_role_rule_id", referencedColumnName="id")
*/
private $customRoleRule;
/**
* @var Collection
* @ORM\OneToMany(targetEntity="App\Entity\Reports\ReportOrderProductsLog", mappedBy="adminUser")
* @ORM\JoinColumn(name="id", referencedColumnName="admin_user_id")
*/
private $reportOrderProductsLogs;
public function getAdministrationRole(): ?AdministrationRoleInterface
{
return $this->administrationRole;
}
public function setAdministrationRole(?AdministrationRoleInterface $administrationRole): void
{
$this->administrationRole = $administrationRole;
}
public function hasPermission(string $type): bool
{
$permissions = $this->getAdministrationRole()->getPermissions();
foreach ($permissions as $permission) {
if ($permission->type() === $type) {
return true;
}
}
return false;
}
public function getPartner(): ?Partner
{
return $this->partner;
}
public function setPartner(?Partner $partner): self
{
$this->partner = $partner;
return $this;
}
public function getCustomRoleRule(): ?CustomRoleRule
{
return $this->customRoleRule;
}
public function setCustomRoleRule(?CustomRoleRule $customRoleRule): self
{
$this->customRoleRule = $customRoleRule;
return $this;
}
}